use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.
the class GraalCompilerTest method getCanonicalGraphString.
protected static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.EARLIEST);
schedule.apply(graph);
ScheduleResult scheduleResult = graph.getLastSchedule();
NodeMap<Integer> canonicalId = graph.createNodeMap();
int nextId = 0;
List<String> constantsLines = new ArrayList<>();
StringBuilder result = new StringBuilder();
for (Block block : scheduleResult.getCFG().getBlocks()) {
result.append("Block ").append(block).append(' ');
if (block == scheduleResult.getCFG().getStartBlock()) {
result.append("* ");
}
result.append("-> ");
for (Block succ : block.getSuccessors()) {
result.append(succ).append(' ');
}
result.append('\n');
for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
if (node instanceof ValueNode && node.isAlive()) {
if (!excludeVirtual || !(node instanceof VirtualObjectNode || node instanceof ProxyNode || node instanceof FullInfopointNode || node instanceof ParameterNode)) {
if (node instanceof ConstantNode) {
String name = checkConstants ? node.toString(Verbosity.Name) : node.getClass().getSimpleName();
if (excludeVirtual) {
constantsLines.add(name);
} else {
constantsLines.add(name + " (" + filteredUsageCount(node) + ")");
}
} else {
int id;
if (canonicalId.get(node) != null) {
id = canonicalId.get(node);
} else {
id = nextId++;
canonicalId.set(node, id);
}
String name = node.getClass().getSimpleName();
result.append(" ").append(id).append('|').append(name);
if (node instanceof AccessFieldNode) {
result.append('#');
result.append(((AccessFieldNode) node).field());
}
if (!excludeVirtual) {
result.append(" (");
result.append(filteredUsageCount(node));
result.append(')');
}
result.append('\n');
}
}
}
}
}
StringBuilder constantsLinesResult = new StringBuilder();
constantsLinesResult.append(constantsLines.size()).append(" constants:\n");
Collections.sort(constantsLines);
for (String s : constantsLines) {
constantsLinesResult.append(s);
constantsLinesResult.append('\n');
}
return constantsLinesResult.toString() + result.toString();
}
use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.
the class GraalCompilerTest method getScheduledGraphString.
/**
* @param graph
* @return a scheduled textual dump of {@code graph} .
*/
protected static String getScheduledGraphString(StructuredGraph graph) {
SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
schedule.apply(graph);
ScheduleResult scheduleResult = graph.getLastSchedule();
StringBuilder result = new StringBuilder();
Block[] blocks = scheduleResult.getCFG().getBlocks();
for (Block block : blocks) {
result.append("Block ").append(block).append(' ');
if (block == scheduleResult.getCFG().getStartBlock()) {
result.append("* ");
}
result.append("-> ");
for (Block succ : block.getSuccessors()) {
result.append(succ).append(' ');
}
result.append('\n');
for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
result.append(String.format("%1S\n", node));
}
}
return result.toString();
}
use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.
the class GraphScheduleTest method assertOrderedAfterSchedule.
protected void assertOrderedAfterSchedule(StructuredGraph graph, SchedulePhase.SchedulingStrategy strategy, Node a, Node b) {
SchedulePhase ibp = new SchedulePhase(strategy);
ibp.apply(graph);
assertOrderedAfterLastSchedule(graph, a, b);
}
use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.
the class MemoryScheduleTest method getFinalSchedule.
@SuppressWarnings("try")
private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode, final SchedulingStrategy schedulingStrategy) {
OptionValues options = new OptionValues(getInitialOptions(), OptScheduleOutOfLoops, schedulingStrategy == SchedulingStrategy.LATEST_OUT_OF_LOOPS, OptImplicitNullChecks, false);
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, options);
DebugContext debug = graph.getDebug();
try (DebugContext.Scope d = debug.scope("FloatingReadTest", graph)) {
HighTierContext context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
canonicalizer.apply(graph, context);
if (mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
new InliningPhase(canonicalizer).apply(graph, context);
}
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
graph.clearAllStateAfter();
}
debug.dump(DebugContext.BASIC_LEVEL, graph, "after removal of framestates");
new FloatingReadPhase().apply(graph);
new RemoveValueProxyPhase().apply(graph);
MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
new GuardLoweringPhase().apply(graph, midContext);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, midContext);
SchedulePhase schedule = new SchedulePhase(schedulingStrategy);
schedule.apply(graph);
assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
return graph.getLastSchedule();
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.
the class SchedulingTest method testValueProxyInputs.
@Test
public void testValueProxyInputs() {
StructuredGraph graph = parseEager("testValueProxyInputsSnippet", AllowAssumptions.YES);
for (FrameState fs : graph.getNodes().filter(FrameState.class).snapshot()) {
fs.replaceAtUsages(null);
GraphUtil.killWithUnusedFloatingInputs(fs);
}
SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST);
schedulePhase.apply(graph);
ScheduleResult schedule = graph.getLastSchedule();
NodeMap<Block> nodeToBlock = schedule.getCFG().getNodeToBlock();
assertTrue(graph.getNodes().filter(LoopExitNode.class).count() == 1);
LoopExitNode loopExit = graph.getNodes().filter(LoopExitNode.class).first();
List<Node> list = schedule.nodesFor(nodeToBlock.get(loopExit));
for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
if (!(node instanceof AddNode)) {
assertTrue(node.toString(), nodeToBlock.get(node) == nodeToBlock.get(loopExit));
assertTrue(list.indexOf(node) + " < " + list.indexOf(loopExit) + ", " + node + ", " + loopExit, list.indexOf(node) < list.indexOf(loopExit));
}
}
}
Aggregations