use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.
the class GraalCompilerState method preLIRGeneration.
/**
* Sets up {@link LIR} generation.
*/
protected final void preLIRGeneration() {
assert request.graph.isFrozen() : "Graph not frozen.";
Object stub = null;
schedule = request.graph.getLastSchedule();
ControlFlowGraph cfg = deepCopy(schedule.getCFG());
Block[] blocks = cfg.getBlocks();
Block startBlock = cfg.getStartBlock();
assert startBlock != null;
assert startBlock.getPredecessorCount() == 0;
codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
LIR lir = new LIR(cfg, linearScanOrder, codeEmittingOrder, getGraphOptions(), getGraphDebug());
FrameMapBuilder frameMapBuilder = request.backend.newFrameMapBuilder(registerConfig);
lirGenRes = request.backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, request.graph, stub);
lirGenTool = request.backend.newLIRGenerator(lirGenRes);
nodeLirGen = request.backend.newNodeLIRBuilder(request.graph, lirGenTool);
}
use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.
the class EffectsPhase method runAnalysis.
@SuppressWarnings("try")
public boolean runAnalysis(StructuredGraph graph, PhaseContextT context) {
boolean changed = false;
CompilationAlarm compilationAlarm = CompilationAlarm.current();
DebugContext debug = graph.getDebug();
for (int iteration = 0; iteration < maxIterations && !compilationAlarm.hasExpired(); iteration++) {
try (DebugContext.Scope s = debug.scope(debug.areScopesEnabled() ? "iteration " + iteration : null)) {
ScheduleResult schedule;
ControlFlowGraph cfg;
if (unscheduled) {
schedule = null;
cfg = ControlFlowGraph.compute(graph, true, true, false, false);
} else {
new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST).apply(graph, false);
schedule = graph.getLastSchedule();
cfg = schedule.getCFG();
}
try (DebugContext.Scope scheduleScope = debug.scope("EffectsPhaseWithSchedule", schedule)) {
Closure<?> closure = createEffectsClosure(context, schedule, cfg);
ReentrantBlockIterator.apply(closure, cfg.getStartBlock());
if (closure.needsApplyEffects()) {
// apply the effects collected during this iteration
HashSetNodeEventListener listener = new HashSetNodeEventListener();
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
closure.applyEffects();
}
if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
debug.dump(DebugContext.VERBOSE_LEVEL, graph, "%s iteration", getName());
}
new DeadCodeEliminationPhase(Required).apply(graph);
EconomicSet<Node> changedNodes = listener.getNodes();
for (Node node : graph.getNodes()) {
if (node instanceof Simplifiable) {
changedNodes.add(node);
}
}
postIteration(graph, context, changedNodes);
}
if (closure.hasChanged()) {
changed = true;
} else {
break;
}
} catch (Throwable t) {
throw debug.handle(t);
}
}
}
return changed;
}
use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.
the class NestedLoopTest method test.
private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
DebugContext debug = graph.getDebug();
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
Assert.assertEquals(3, cfg.getLoops().size());
Loop<Block> rootLoop = cfg.getLoops().get(0);
Loop<Block> nestedLoop = cfg.getLoops().get(1);
Loop<Block> innerMostLoop = cfg.getLoops().get(2);
Invoke a = getInvoke("a", graph);
Invoke b = getInvoke("b", graph);
Invoke c = getInvoke("c", graph);
Invoke d = getInvoke("d", graph);
Assert.assertTrue(containsDirect(rootLoop, a, cfg));
Assert.assertTrue(containsDirect(nestedLoop, b, cfg));
Assert.assertTrue(containsDirect(innerMostLoop, c, cfg));
Assert.assertTrue(containsDirect(innerMostLoop, d, cfg));
Assert.assertTrue(contains(rootLoop, d, cfg));
Assert.assertTrue(contains(nestedLoop, d, cfg));
Assert.assertEquals(rootExits, rootLoop.getExits().size());
Assert.assertEquals(nestedExits, nestedLoop.getExits().size());
Assert.assertEquals(innerExits, innerMostLoop.getExits().size());
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
}
use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.
the class NodeLIRBuilder method getLIRBlock.
public LabelRef getLIRBlock(FixedNode b) {
assert gen.getResult().getLIR().getControlFlowGraph() instanceof ControlFlowGraph;
Block result = ((ControlFlowGraph) gen.getResult().getLIR().getControlFlowGraph()).blockFor(b);
int suxIndex = 0;
for (AbstractBlockBase<?> succ : gen.getCurrentBlock().getSuccessors()) {
if (succ == result) {
assert gen.getCurrentBlock() instanceof Block;
return LabelRef.forSuccessor(gen.getResult().getLIR(), gen.getCurrentBlock(), suxIndex);
}
suxIndex++;
}
throw GraalError.shouldNotReachHere("Block not in successor list of current block");
}
use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.
the class PartialEscapeAnalysisTest method testPartialEscapeAnalysis.
@SafeVarargs
protected final void testPartialEscapeAnalysis(String snippet, double expectedProbability, int expectedCount, Class<? extends Node>... invalidNodeClasses) {
prepareGraph(snippet, false);
for (AbstractMergeNode merge : graph.getNodes(AbstractMergeNode.TYPE)) {
merge.setStateAfter(null);
}
new DeadCodeEliminationPhase().apply(graph);
new CanonicalizerPhase().apply(graph, context);
try {
Assert.assertTrue("partial escape analysis should have removed all NewInstanceNode allocations", graph.getNodes().filter(NewInstanceNode.class).isEmpty());
Assert.assertTrue("partial escape analysis should have removed all NewArrayNode allocations", graph.getNodes().filter(NewArrayNode.class).isEmpty());
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
double probabilitySum = 0;
int materializeCount = 0;
for (CommitAllocationNode materialize : graph.getNodes().filter(CommitAllocationNode.class)) {
probabilitySum += cfg.blockFor(materialize).probability() * materialize.getVirtualObjects().size();
materializeCount += materialize.getVirtualObjects().size();
}
Assert.assertEquals("unexpected number of MaterializeObjectNodes", expectedCount, materializeCount);
Assert.assertEquals("unexpected probability of MaterializeObjectNodes", expectedProbability, probabilitySum, 0.01);
for (Node node : graph.getNodes()) {
for (Class<? extends Node> clazz : invalidNodeClasses) {
Assert.assertFalse("instance of invalid class: " + clazz.getSimpleName(), clazz.isInstance(node) && node.usages().isNotEmpty());
}
}
} catch (AssertionError e) {
TypeSystemTest.outputGraph(graph, snippet + ": " + e.getMessage());
throw e;
}
}
Aggregations