use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class ReentrantBlockIteratorTest method getVisitedBlocksInOrder.
private List<Block> getVisitedBlocksInOrder(String snippet) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
// after FSA to ensure HIR loop data structure does not contain loop exits
graph.setGuardsStage(GuardsStage.AFTER_FSA);
ArrayList<Block> blocks = new ArrayList<>();
class VoidState {
}
final VoidState voidState = new VoidState();
BlockIteratorClosure<VoidState> closure = new BlockIteratorClosure<VoidState>() {
@Override
protected VoidState getInitialState() {
return voidState;
}
@Override
protected VoidState processBlock(Block block, VoidState currentState) {
// remember the visit order
blocks.add(block);
return currentState;
}
@Override
protected VoidState merge(Block merge, List<VoidState> states) {
return voidState;
}
@Override
protected VoidState cloneState(VoidState oldState) {
return voidState;
}
@Override
protected List<VoidState> processLoop(Loop<Block> loop, VoidState initialState) {
return ReentrantBlockIterator.processLoop(this, loop, initialState).exitStates;
}
};
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, false);
ReentrantBlockIterator.apply(closure, cfg.getStartBlock());
// schedule for IGV
new SchedulePhase(graph.getOptions()).apply(graph);
return blocks;
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class ScalarTypeSystemTest method test.
private void test(final String snippet, final String referenceSnippet) {
// No debug scope to reduce console noise for @Test(expected = ...) tests
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
PhaseContext context = new PhaseContext(getProviders());
new CanonicalizerPhase().apply(graph, context);
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
assertEquals(referenceGraph, graph);
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class SimpleCFGTest method testImplies.
@Test
public void testImplies() {
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, new GraalDebugHandlersFactory(getSnippetReflection()));
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
EndNode trueEnd = graph.add(new EndNode());
EndNode falseEnd = graph.add(new EndNode());
AbstractBeginNode trueBegin = graph.add(new BeginNode());
trueBegin.setNext(trueEnd);
AbstractBeginNode falseBegin = graph.add(new BeginNode());
falseBegin.setNext(falseEnd);
IfNode ifNode = graph.add(new IfNode(null, trueBegin, falseBegin, 0.5));
graph.start().setNext(ifNode);
AbstractMergeNode merge = graph.add(new MergeNode());
merge.addForwardEnd(trueEnd);
merge.addForwardEnd(falseEnd);
ReturnNode returnNode = graph.add(new ReturnNode(null));
merge.setNext(returnNode);
dumpGraph(graph);
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
Block[] blocks = cfg.getBlocks();
// check number of blocks
assertDeepEquals(4, blocks.length);
// check block - node assignment
assertDeepEquals(blocks[0], cfg.blockFor(graph.start()));
assertDeepEquals(blocks[0], cfg.blockFor(ifNode));
assertDeepEquals(blocks[1], cfg.blockFor(trueBegin));
assertDeepEquals(blocks[1], cfg.blockFor(trueEnd));
assertDeepEquals(blocks[2], cfg.blockFor(falseBegin));
assertDeepEquals(blocks[2], cfg.blockFor(falseEnd));
assertDeepEquals(blocks[3], cfg.blockFor(merge));
assertDeepEquals(blocks[3], cfg.blockFor(returnNode));
// check dominators
assertDominator(blocks[0], null);
assertDominator(blocks[1], blocks[0]);
assertDominator(blocks[2], blocks[0]);
assertDominator(blocks[3], blocks[0]);
// check dominated
assertDominatedSize(blocks[0], 3);
assertDominatedSize(blocks[1], 0);
assertDominatedSize(blocks[2], 0);
assertDominatedSize(blocks[3], 0);
// check postdominators
assertPostdominator(blocks[0], blocks[3]);
assertPostdominator(blocks[1], blocks[3]);
assertPostdominator(blocks[2], blocks[3]);
assertPostdominator(blocks[3], null);
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class StampCanonicalizerTest method testZeroReturn.
private void testZeroReturn(String methodName) {
StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES);
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
new DeadCodeEliminationPhase().apply(graph);
assertConstantReturn(graph, 0);
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class MonitorDeoptTest method run0.
@Test
public void run0() throws Throwable {
ResolvedJavaMethod javaMethod = getResolvedJavaMethod("test");
StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
removeLoopSafepoint(graph);
CompilationResult compilationResult = compile(javaMethod, graph);
final InstalledCode installedCode = getBackend().createDefaultInstalledCode(graph.getDebug(), javaMethod, compilationResult);
final Monitor monitor = new Monitor();
Thread controlThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// Wait for thread to reach RUNNING_GRAAL and then invalidate the code
monitor.invalidate(installedCode);
// wait for the main thread to continue running in the interpreter
monitor.waitState(State.RUNNING_INTERPRETER);
// terminate the main thread
monitor.setState(State.TERMINATED);
} catch (InterruptedException e) {
}
}
});
controlThread.start();
boolean result = test(monitor);
Assert.assertTrue(result);
}
Aggregations