use of org.graalvm.compiler.lir.gen.LIRGenerationResult 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.lir.gen.LIRGenerationResult 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);
}
}
}
}
}
}
use of org.graalvm.compiler.lir.gen.LIRGenerationResult in project graal by oracle.
the class BackendTest method getLIRGenerationResult.
@SuppressWarnings("try")
protected LIRGenerationResult getLIRGenerationResult(final StructuredGraph graph) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("FrontEnd")) {
GraalCompiler.emitFrontEnd(getProviders(), getBackend(), graph, getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE, graph.getProfilingInfo(), createSuites(graph.getOptions()));
} catch (Throwable e) {
throw debug.handle(e);
}
LIRGenerationResult lirGen = GraalCompiler.emitLIR(getBackend(), graph, null, null, createLIRSuites(graph.getOptions()));
return lirGen;
}
use of org.graalvm.compiler.lir.gen.LIRGenerationResult in project graal by oracle.
the class GraalCompiler method emitBackEnd.
@SuppressWarnings("try")
public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, Backend backend, T compilationResult, CompilationResultBuilderFactory factory, RegisterConfig registerConfig, LIRSuites lirSuites) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("BackEnd", graph.getLastSchedule());
DebugCloseable a = BackEnd.start(debug)) {
LIRGenerationResult lirGen = null;
lirGen = emitLIR(backend, graph, stub, registerConfig, lirSuites);
try (DebugContext.Scope s2 = debug.scope("CodeGen", lirGen, lirGen.getLIR())) {
int bytecodeSize = graph.method() == null ? 0 : graph.getBytecodeSize();
compilationResult.setHasUnsafeAccess(graph.hasUnsafeAccess());
emitCode(backend, graph.getAssumptions(), graph.method(), graph.getMethods(), graph.getFields(), bytecodeSize, lirGen, compilationResult, installedCodeOwner, factory);
} catch (Throwable e) {
throw debug.handle(e);
}
} catch (Throwable e) {
throw debug.handle(e);
} finally {
graph.checkCancellation();
}
}
Aggregations