< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/ConditionalEliminationPhase.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 292         protected final EconomicMap<MergeNode, EconomicMap<ValuePhiNode, PhiInfoElement>> mergeMaps;
 293 
 294         protected final ArrayDeque<GuardedCondition> conditions;
 295 
 296         /**
 297          * Tests which may be eliminated because post dominating tests to prove a broader condition.
 298          */
 299         private Deque<DeoptimizingGuard> pendingTests;
 300 
 301         public Instance(StructuredGraph graph, BlockMap<List<Node>> blockToNodes, NodeMap<Block> nodeToBlock, CoreProviders context) {
 302             this.graph = graph;
 303             this.debug = graph.getDebug();
 304             this.blockToNodes = blockToNodes;
 305             this.nodeToBlock = nodeToBlock;
 306             this.undoOperations = new NodeStack();
 307             this.map = graph.createNodeMap();
 308             this.pendingTests = new ArrayDeque<>();
 309             this.conditions = new ArrayDeque<>();
 310             tool = GraphUtil.getDefaultSimplifier(context.getMetaAccess(), context.getConstantReflection(), context.getConstantFieldProvider(), false, graph.getAssumptions(), graph.getOptions(),
 311                             context.getLowerer());
 312             mergeMaps = EconomicMap.create();
 313         }
 314 
 315         protected void processConditionAnchor(ConditionAnchorNode node) {
 316             tryProveCondition(node.condition(), (guard, result, guardedValueStamp, newInput) -> {
 317                 if (result != node.isNegated()) {
 318                     node.replaceAtUsages(guard.asNode());
 319                     GraphUtil.unlinkFixedNode(node);
 320                     GraphUtil.killWithUnusedFloatingInputs(node);
 321                 } else {
 322                     ValueAnchorNode valueAnchor = node.graph().add(new ValueAnchorNode(null));
 323                     node.replaceAtUsages(valueAnchor);
 324                     node.graph().replaceFixedWithFixed(node, valueAnchor);
 325                 }
 326                 return true;
 327             });
 328         }
 329 
 330         protected void processGuard(GuardNode node) {
 331             if (!tryProveGuardCondition(node, node.getCondition(), (guard, result, guardedValueStamp, newInput) -> {
 332                 if (result != node.isNegated()) {


 599                             phi.replaceAtUsagesAndDelete(newPhi);
 600                         }
 601                     }
 602                 }
 603             }
 604         }
 605 
 606         protected void processEnd(EndNode end) {
 607             AbstractMergeNode abstractMerge = end.merge();
 608             if (abstractMerge instanceof MergeNode) {
 609                 MergeNode merge = (MergeNode) abstractMerge;
 610 
 611                 EconomicMap<ValuePhiNode, PhiInfoElement> mergeMap = this.mergeMaps.get(merge);
 612                 for (ValuePhiNode phi : merge.valuePhis()) {
 613                     ValueNode valueAt = phi.valueAt(end);
 614                     InfoElement infoElement = this.getInfoElements(valueAt);
 615                     while (infoElement != null) {
 616                         Stamp newStamp = infoElement.getStamp();
 617                         if (phi.stamp(NodeView.DEFAULT).tryImproveWith(newStamp) != null) {
 618                             if (mergeMap == null) {
 619                                 mergeMap = EconomicMap.create();
 620                                 mergeMaps.put(merge, mergeMap);
 621                             }
 622 
 623                             PhiInfoElement phiInfoElement = mergeMap.get(phi);
 624                             if (phiInfoElement == null) {
 625                                 phiInfoElement = new PhiInfoElement();
 626                                 mergeMap.put(phi, phiInfoElement);
 627                             }
 628 
 629                             phiInfoElement.set(end, infoElement);
 630                             break;
 631                         }
 632                         infoElement = nextElement(infoElement);
 633                     }
 634                 }
 635             }
 636         }
 637 
 638         protected void registerNewCondition(LogicNode condition, boolean negated, GuardingNode guard) {
 639             if (condition instanceof UnaryOpLogicNode) {


   1 /*
   2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 292         protected final EconomicMap<MergeNode, EconomicMap<ValuePhiNode, PhiInfoElement>> mergeMaps;
 293 
 294         protected final ArrayDeque<GuardedCondition> conditions;
 295 
 296         /**
 297          * Tests which may be eliminated because post dominating tests to prove a broader condition.
 298          */
 299         private Deque<DeoptimizingGuard> pendingTests;
 300 
 301         public Instance(StructuredGraph graph, BlockMap<List<Node>> blockToNodes, NodeMap<Block> nodeToBlock, CoreProviders context) {
 302             this.graph = graph;
 303             this.debug = graph.getDebug();
 304             this.blockToNodes = blockToNodes;
 305             this.nodeToBlock = nodeToBlock;
 306             this.undoOperations = new NodeStack();
 307             this.map = graph.createNodeMap();
 308             this.pendingTests = new ArrayDeque<>();
 309             this.conditions = new ArrayDeque<>();
 310             tool = GraphUtil.getDefaultSimplifier(context.getMetaAccess(), context.getConstantReflection(), context.getConstantFieldProvider(), false, graph.getAssumptions(), graph.getOptions(),
 311                             context.getLowerer());
 312             mergeMaps = EconomicMap.create(Equivalence.IDENTITY);
 313         }
 314 
 315         protected void processConditionAnchor(ConditionAnchorNode node) {
 316             tryProveCondition(node.condition(), (guard, result, guardedValueStamp, newInput) -> {
 317                 if (result != node.isNegated()) {
 318                     node.replaceAtUsages(guard.asNode());
 319                     GraphUtil.unlinkFixedNode(node);
 320                     GraphUtil.killWithUnusedFloatingInputs(node);
 321                 } else {
 322                     ValueAnchorNode valueAnchor = node.graph().add(new ValueAnchorNode(null));
 323                     node.replaceAtUsages(valueAnchor);
 324                     node.graph().replaceFixedWithFixed(node, valueAnchor);
 325                 }
 326                 return true;
 327             });
 328         }
 329 
 330         protected void processGuard(GuardNode node) {
 331             if (!tryProveGuardCondition(node, node.getCondition(), (guard, result, guardedValueStamp, newInput) -> {
 332                 if (result != node.isNegated()) {


 599                             phi.replaceAtUsagesAndDelete(newPhi);
 600                         }
 601                     }
 602                 }
 603             }
 604         }
 605 
 606         protected void processEnd(EndNode end) {
 607             AbstractMergeNode abstractMerge = end.merge();
 608             if (abstractMerge instanceof MergeNode) {
 609                 MergeNode merge = (MergeNode) abstractMerge;
 610 
 611                 EconomicMap<ValuePhiNode, PhiInfoElement> mergeMap = this.mergeMaps.get(merge);
 612                 for (ValuePhiNode phi : merge.valuePhis()) {
 613                     ValueNode valueAt = phi.valueAt(end);
 614                     InfoElement infoElement = this.getInfoElements(valueAt);
 615                     while (infoElement != null) {
 616                         Stamp newStamp = infoElement.getStamp();
 617                         if (phi.stamp(NodeView.DEFAULT).tryImproveWith(newStamp) != null) {
 618                             if (mergeMap == null) {
 619                                 mergeMap = EconomicMap.create(Equivalence.IDENTITY);
 620                                 mergeMaps.put(merge, mergeMap);
 621                             }
 622 
 623                             PhiInfoElement phiInfoElement = mergeMap.get(phi);
 624                             if (phiInfoElement == null) {
 625                                 phiInfoElement = new PhiInfoElement();
 626                                 mergeMap.put(phi, phiInfoElement);
 627                             }
 628 
 629                             phiInfoElement.set(end, infoElement);
 630                             break;
 631                         }
 632                         infoElement = nextElement(infoElement);
 633                     }
 634                 }
 635             }
 636         }
 637 
 638         protected void registerNewCondition(LogicNode condition, boolean negated, GuardingNode guard) {
 639             if (condition instanceof UnaryOpLogicNode) {


< prev index next >