Search in sources :

Example 1 with LIRGenerationResult

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();
    }
}
Also used : ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) NodeLIRBuilderTool(org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) LIRGenerationContext(org.graalvm.compiler.core.LIRGenerationPhase.LIRGenerationContext) LIR(org.graalvm.compiler.lir.LIR) Block(org.graalvm.compiler.nodes.cfg.Block) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool)

Example 2 with LIRGenerationResult

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);
                    }
                }
            }
        }
    }
}
Also used : ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) FrameMapBuilderTool(org.graalvm.compiler.lir.framemap.FrameMapBuilderTool) AllocationPhase(org.graalvm.compiler.lir.phases.AllocationPhase) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) StackSlotAllocatorUtil.allocatedSlots(org.graalvm.compiler.lir.stackslotalloc.StackSlotAllocatorUtil.allocatedSlots) VirtualStackSlotRange(org.graalvm.compiler.lir.framemap.VirtualStackSlotRange) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) TargetDescription(jdk.vm.ci.code.TargetDescription) LIRValueUtil.asVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot) SimpleVirtualStackSlot(org.graalvm.compiler.lir.framemap.SimpleVirtualStackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext) StackSlotAllocatorUtil.virtualFramesize(org.graalvm.compiler.lir.stackslotalloc.StackSlotAllocatorUtil.virtualFramesize) Indent(org.graalvm.compiler.debug.Indent) GraalError(org.graalvm.compiler.debug.GraalError) StackSlot(jdk.vm.ci.code.StackSlot) LIRValueUtil.isVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot) ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) StackSlotAllocatorUtil.allocatedFramesize(org.graalvm.compiler.lir.stackslotalloc.StackSlotAllocatorUtil.allocatedFramesize) VirtualStackSlot(org.graalvm.compiler.lir.VirtualStackSlot) Indent(org.graalvm.compiler.debug.Indent) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) LIRValueUtil.asVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot) SimpleVirtualStackSlot(org.graalvm.compiler.lir.framemap.SimpleVirtualStackSlot) StackSlot(jdk.vm.ci.code.StackSlot) LIRValueUtil.isVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot) VirtualStackSlot(org.graalvm.compiler.lir.VirtualStackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 3 with LIRGenerationResult

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;
}
Also used : LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 4 with LIRGenerationResult

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();
    }
}
Also used : LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Aggregations

DebugContext (org.graalvm.compiler.debug.DebugContext)4 LIRGenerationResult (org.graalvm.compiler.lir.gen.LIRGenerationResult)4 AbstractBlockBase (org.graalvm.compiler.core.common.cfg.AbstractBlockBase)2 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2 StackSlot (jdk.vm.ci.code.StackSlot)1 TargetDescription (jdk.vm.ci.code.TargetDescription)1 LIRGenerationContext (org.graalvm.compiler.core.LIRGenerationPhase.LIRGenerationContext)1 GraalError (org.graalvm.compiler.debug.GraalError)1 Indent (org.graalvm.compiler.debug.Indent)1 LIR (org.graalvm.compiler.lir.LIR)1 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)1 LIRValueUtil.asVirtualStackSlot (org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot)1 LIRValueUtil.isVirtualStackSlot (org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot)1 ValueProcedure (org.graalvm.compiler.lir.ValueProcedure)1 VirtualStackSlot (org.graalvm.compiler.lir.VirtualStackSlot)1 FrameMapBuilder (org.graalvm.compiler.lir.framemap.FrameMapBuilder)1 FrameMapBuilderTool (org.graalvm.compiler.lir.framemap.FrameMapBuilderTool)1 SimpleVirtualStackSlot (org.graalvm.compiler.lir.framemap.SimpleVirtualStackSlot)1 VirtualStackSlotRange (org.graalvm.compiler.lir.framemap.VirtualStackSlotRange)1 LIRGeneratorTool (org.graalvm.compiler.lir.gen.LIRGeneratorTool)1