use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.
the class TraceStatisticsPrinter method print.
@SuppressWarnings("try")
protected static void print(DebugContext debug, TraceBuilderResult result, String compilationUnitName) {
List<Trace> traces = result.getTraces();
int numTraces = traces.size();
try (Indent indent0 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<tracestatistics>")) {
debug.log(DebugContext.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null");
try (Indent indent1 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<traces>")) {
printRawLine(debug, "tracenumber", "total", "min", "max", "numBlocks");
for (int i = 0; i < numTraces; i++) {
AbstractBlockBase<?>[] t = traces.get(i).getBlocks();
double total = 0;
double max = Double.NEGATIVE_INFINITY;
double min = Double.POSITIVE_INFINITY;
for (AbstractBlockBase<?> block : t) {
double probability = block.probability();
total += probability;
if (probability < min) {
min = probability;
}
if (probability > max) {
max = probability;
}
}
printLine(debug, i, total, min, max, t.length);
}
}
debug.log(DebugContext.VERBOSE_LEVEL, "</traces>");
}
debug.log(DebugContext.VERBOSE_LEVEL, "</tracestatistics>");
}
use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.
the class UniDirectionalTraceBuilder method findTrace.
/**
* Build a new trace starting at {@code block}.
*/
@SuppressWarnings("try")
private List<AbstractBlockBase<?>> findTrace(DebugContext debug, AbstractBlockBase<?> traceStart) {
assert checkPredecessorsProcessed(traceStart);
ArrayList<AbstractBlockBase<?>> trace = new ArrayList<>();
int blockNumber = 0;
try (Indent i = debug.logAndIndent("StartTrace: %s", traceStart)) {
for (AbstractBlockBase<?> block = traceStart; block != null; block = selectNext(block)) {
debug.log("add %s (prob: %f)", block, block.probability());
processed.set(block.getId());
trace.add(block);
unblock(block);
block.setLinearScanNumber(blockNumber++);
}
}
return trace;
}
use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.
the class ConstantTreeAnalyzer method analyzeBlocks.
/**
* Queues all relevant blocks for {@linkplain #process processing}.
*
* This is a worklist-style algorithm because a (more elegant) recursive implementation may
* cause {@linkplain StackOverflowError stack overflows} on larger graphs.
*
* @param startBlock The start block of the dominator subtree.
*/
@SuppressWarnings("try")
private void analyzeBlocks(DebugContext debug, AbstractBlockBase<?> startBlock) {
Deque<AbstractBlockBase<?>> worklist = new ArrayDeque<>();
worklist.offerLast(startBlock);
while (!worklist.isEmpty()) {
AbstractBlockBase<?> block = worklist.pollLast();
try (Indent i = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "analyze: %s", block)) {
assert block != null : "worklist is empty!";
assert isMarked(block) : "Block not part of the dominator tree: " + block;
if (isLeafBlock(block)) {
debug.log(DebugContext.VERBOSE_LEVEL, "leaf block");
leafCost(block);
continue;
}
if (!visited.get(block.getId())) {
// if not yet visited (and not a leaf block) process all children first!
debug.log(DebugContext.VERBOSE_LEVEL, "not marked");
worklist.offerLast(block);
AbstractBlockBase<?> dominated = block.getFirstDominated();
while (dominated != null) {
filteredPush(debug, worklist, dominated);
dominated = dominated.getDominatedSibling();
}
visited.set(block.getId());
} else {
debug.log(DebugContext.VERBOSE_LEVEL, "marked");
// otherwise, process block
process(block);
}
}
}
}
use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.
the class GraalCompiler method emitLIR0.
@SuppressWarnings("try")
private static LIRGenerationResult emitLIR0(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites, String[] allocationRestrictedTo) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope ds = debug.scope("EmitLIR");
DebugCloseable a = EmitLIR.start(debug)) {
assert !graph.hasValueProxies();
ScheduleResult schedule = graph.getLastSchedule();
Block[] blocks = schedule.getCFG().getBlocks();
Block startBlock = schedule.getCFG().getStartBlock();
assert startBlock != null;
assert startBlock.getPredecessorCount() == 0;
AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions(), graph.getDebug());
FrameMapBuilder frameMapBuilder = backend.newFrameMapBuilder(registerConfig);
LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, graph, stub);
LIRGeneratorTool lirGen = backend.newLIRGenerator(lirGenRes);
NodeLIRBuilderTool nodeLirGen = backend.newNodeLIRBuilder(graph, lirGen);
// LIR generation
LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
try (DebugContext.Scope s = debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
// Dump LIR along with HIR (the LIR is looked up from context)
debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo));
return result;
} catch (Throwable e) {
throw debug.handle(e);
}
} catch (Throwable e) {
throw debug.handle(e);
} finally {
graph.checkCancellation();
}
}
use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.
the class SimpleStackSlotAllocator method updateLIR.
@SuppressWarnings("try")
protected void updateLIR(LIRGenerationResult res, StackSlot[] mapping) {
DebugContext debug = res.getLIR().getDebug();
try (DebugContext.Scope scope = debug.scope("StackSlotMappingLIR")) {
ValueProcedure updateProc = (value, mode, flags) -> {
if (isVirtualStackSlot(value)) {
StackSlot stackSlot = mapping[asVirtualStackSlot(value).getId()];
debug.log("map %s -> %s", value, stackSlot);
return stackSlot;
}
return value;
};
for (AbstractBlockBase<?> block : res.getLIR().getControlFlowGraph().getBlocks()) {
try (Indent indent0 = debug.logAndIndent("block: %s", block)) {
for (LIRInstruction inst : res.getLIR().getLIRforBlock(block)) {
try (Indent indent1 = debug.logAndIndent("Inst: %d: %s", inst.id(), inst)) {
inst.forEachAlive(updateProc);
inst.forEachInput(updateProc);
inst.forEachOutput(updateProc);
inst.forEachTemp(updateProc);
inst.forEachState(updateProc);
}
}
}
}
}
}
Aggregations