< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/util/GraphOrder.java

Print this page




  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  */
  23 
  24 
  25 package org.graalvm.compiler.phases.util;
  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 import jdk.internal.vm.compiler.collections.EconomicMap;
  31 import jdk.internal.vm.compiler.collections.Equivalence;
  32 import org.graalvm.compiler.core.common.cfg.Loop;

  33 import org.graalvm.compiler.debug.GraalError;
  34 import org.graalvm.compiler.graph.GraalGraphError;
  35 import org.graalvm.compiler.graph.Node;
  36 import org.graalvm.compiler.graph.NodeBitMap;
  37 import org.graalvm.compiler.nodes.AbstractEndNode;
  38 import org.graalvm.compiler.nodes.AbstractMergeNode;
  39 import org.graalvm.compiler.nodes.ConstantNode;
  40 import org.graalvm.compiler.nodes.EndNode;
  41 import org.graalvm.compiler.nodes.FixedNode;
  42 import org.graalvm.compiler.nodes.FrameState;
  43 import org.graalvm.compiler.nodes.FullInfopointNode;
  44 import org.graalvm.compiler.nodes.LoopBeginNode;
  45 import org.graalvm.compiler.nodes.LoopExitNode;
  46 import org.graalvm.compiler.nodes.PhiNode;
  47 import org.graalvm.compiler.nodes.ProxyNode;
  48 import org.graalvm.compiler.nodes.StateSplit;
  49 import org.graalvm.compiler.nodes.StructuredGraph;
  50 import org.graalvm.compiler.nodes.StructuredGraph.GuardsStage;
  51 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  52 import org.graalvm.compiler.nodes.ValueNode;


 136                 nodes.add(node);
 137                 if (node instanceof AbstractMergeNode) {
 138                     for (PhiNode phi : ((AbstractMergeNode) node).phis()) {
 139                         visited.mark(phi);
 140                         nodes.add(phi);
 141                     }
 142                 }
 143                 if (stateAfter != null) {
 144                     visitForward(nodes, visited, stateAfter, true);
 145                 }
 146             }
 147         } catch (GraalError e) {
 148             throw GraalGraphError.transformAndAddContext(e, node);
 149         }
 150     }
 151 
 152     /**
 153      * This method schedules the graph and makes sure that, for every node, all inputs are available
 154      * at the position where it is scheduled. This is a very expensive assertion.
 155      */

 156     public static boolean assertSchedulableGraph(final StructuredGraph graph) {
 157         assert graph.getGuardsStage() != GuardsStage.AFTER_FSA : "Cannot use the BlockIteratorClosure after FrameState Assignment, HIR Loop Data Structures are no longer valid.";
 158         try {
 159             final SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, true);
 160             final EconomicMap<LoopBeginNode, NodeBitMap> loopEntryStates = EconomicMap.create(Equivalence.IDENTITY);
 161             schedulePhase.apply(graph, false);
 162             final ScheduleResult schedule = graph.getLastSchedule();
 163 
 164             BlockIteratorClosure<NodeBitMap> closure = new BlockIteratorClosure<NodeBitMap>() {
 165 
 166                 @Override
 167                 protected List<NodeBitMap> processLoop(Loop<Block> loop, NodeBitMap initialState) {
 168                     return ReentrantBlockIterator.processLoop(this, loop, initialState).exitStates;
 169                 }
 170 
 171                 @Override
 172                 protected NodeBitMap processBlock(final Block block, final NodeBitMap currentState) {
 173                     final List<Node> list = graph.getLastSchedule().getBlockToNodesMap().get(block);
 174 
 175                     /*
 176                      * A stateAfter is not valid directly after its associated state split, but
 177                      * right before the next fixed node. Therefore a pending stateAfter is kept that
 178                      * will be checked at the correct position.




  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  */
  23 
  24 
  25 package org.graalvm.compiler.phases.util;
  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 import jdk.internal.vm.compiler.collections.EconomicMap;
  31 import jdk.internal.vm.compiler.collections.Equivalence;
  32 import org.graalvm.compiler.core.common.cfg.Loop;
  33 import org.graalvm.compiler.debug.DebugContext;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.GraalGraphError;
  36 import org.graalvm.compiler.graph.Node;
  37 import org.graalvm.compiler.graph.NodeBitMap;
  38 import org.graalvm.compiler.nodes.AbstractEndNode;
  39 import org.graalvm.compiler.nodes.AbstractMergeNode;
  40 import org.graalvm.compiler.nodes.ConstantNode;
  41 import org.graalvm.compiler.nodes.EndNode;
  42 import org.graalvm.compiler.nodes.FixedNode;
  43 import org.graalvm.compiler.nodes.FrameState;
  44 import org.graalvm.compiler.nodes.FullInfopointNode;
  45 import org.graalvm.compiler.nodes.LoopBeginNode;
  46 import org.graalvm.compiler.nodes.LoopExitNode;
  47 import org.graalvm.compiler.nodes.PhiNode;
  48 import org.graalvm.compiler.nodes.ProxyNode;
  49 import org.graalvm.compiler.nodes.StateSplit;
  50 import org.graalvm.compiler.nodes.StructuredGraph;
  51 import org.graalvm.compiler.nodes.StructuredGraph.GuardsStage;
  52 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  53 import org.graalvm.compiler.nodes.ValueNode;


 137                 nodes.add(node);
 138                 if (node instanceof AbstractMergeNode) {
 139                     for (PhiNode phi : ((AbstractMergeNode) node).phis()) {
 140                         visited.mark(phi);
 141                         nodes.add(phi);
 142                     }
 143                 }
 144                 if (stateAfter != null) {
 145                     visitForward(nodes, visited, stateAfter, true);
 146                 }
 147             }
 148         } catch (GraalError e) {
 149             throw GraalGraphError.transformAndAddContext(e, node);
 150         }
 151     }
 152 
 153     /**
 154      * This method schedules the graph and makes sure that, for every node, all inputs are available
 155      * at the position where it is scheduled. This is a very expensive assertion.
 156      */
 157     @SuppressWarnings("try")
 158     public static boolean assertSchedulableGraph(final StructuredGraph graph) {
 159         assert graph.getGuardsStage() != GuardsStage.AFTER_FSA : "Cannot use the BlockIteratorClosure after FrameState Assignment, HIR Loop Data Structures are no longer valid.";
 160         try (DebugContext.Scope s = graph.getDebug().scope("AssertSchedulableGraph")) {
 161             final SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, true);
 162             final EconomicMap<LoopBeginNode, NodeBitMap> loopEntryStates = EconomicMap.create(Equivalence.IDENTITY);
 163             schedulePhase.apply(graph, false);
 164             final ScheduleResult schedule = graph.getLastSchedule();
 165 
 166             BlockIteratorClosure<NodeBitMap> closure = new BlockIteratorClosure<NodeBitMap>() {
 167 
 168                 @Override
 169                 protected List<NodeBitMap> processLoop(Loop<Block> loop, NodeBitMap initialState) {
 170                     return ReentrantBlockIterator.processLoop(this, loop, initialState).exitStates;
 171                 }
 172 
 173                 @Override
 174                 protected NodeBitMap processBlock(final Block block, final NodeBitMap currentState) {
 175                     final List<Node> list = graph.getLastSchedule().getBlockToNodesMap().get(block);
 176 
 177                     /*
 178                      * A stateAfter is not valid directly after its associated state split, but
 179                      * right before the next fixed node. Therefore a pending stateAfter is kept that
 180                      * will be checked at the correct position.


< prev index next >