use of org.graalvm.compiler.nodes.cfg.Block in project graal by oracle.
the class ProfileCompiledMethodsPhase method run.
@Override
protected void run(StructuredGraph graph) {
SchedulePhase schedule = new SchedulePhase(graph.getOptions());
schedule.apply(graph, false);
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
for (Loop<Block> loop : cfg.getLoops()) {
double loopProbability = cfg.blockFor(loop.getHeader().getBeginNode()).probability();
if (loopProbability > (1D / Integer.MAX_VALUE)) {
addSectionCounters(loop.getHeader().getBeginNode(), loop.getBlocks(), loop.getChildren(), graph.getLastSchedule(), cfg);
}
}
// don't put the counter increase directly after the start (problems with OSR)
FixedWithNextNode current = graph.start();
while (current.next() instanceof FixedWithNextNode) {
current = (FixedWithNextNode) current.next();
}
addSectionCounters(current, Arrays.asList(cfg.getBlocks()), cfg.getLoops(), graph.getLastSchedule(), cfg);
if (WITH_INVOKES) {
for (Node node : graph.getNodes()) {
if (node instanceof Invoke) {
Invoke invoke = (Invoke) node;
DynamicCounterNode.addCounterBefore(GROUP_NAME_INVOKES, invoke.callTarget().targetName(), 1, true, invoke.asNode());
}
}
}
}
use of org.graalvm.compiler.nodes.cfg.Block in project graal by oracle.
the class AMD64NodeLIRBuilder method doBlockPrologue.
@Override
public void doBlockPrologue(Block block, OptionValues options) {
if (MitigateSpeculativeExecutionAttacks.getValue(options)) {
boolean hasControlSplitPredecessor = false;
for (Block b : block.getPredecessors()) {
if (b.getSuccessorCount() > 1) {
hasControlSplitPredecessor = true;
break;
}
}
boolean isStartBlock = block.getPredecessorCount() == 0;
if (hasControlSplitPredecessor || isStartBlock) {
getLIRGeneratorTool().emitLFence();
}
}
}
use of org.graalvm.compiler.nodes.cfg.Block 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.cfg.Block 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.cfg.Block in project graal by oracle.
the class TypeSystemTest method outputGraph.
public static void outputGraph(StructuredGraph graph, String message) {
TTY.println("========================= " + message);
SchedulePhase schedulePhase = new SchedulePhase(graph.getOptions());
schedulePhase.apply(graph);
ScheduleResult schedule = graph.getLastSchedule();
for (Block block : schedule.getCFG().getBlocks()) {
TTY.print("Block " + block + " ");
if (block == schedule.getCFG().getStartBlock()) {
TTY.print("* ");
}
TTY.print("-> ");
for (Block succ : block.getSuccessors()) {
TTY.print(succ + " ");
}
TTY.println();
for (Node node : schedule.getBlockToNodesMap().get(block)) {
outputNode(node);
}
}
}
Aggregations