Search in sources :

Example 1 with FrameMapBuilder

use of org.graalvm.compiler.lir.framemap.FrameMapBuilder 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 FrameMapBuilder

use of org.graalvm.compiler.lir.framemap.FrameMapBuilder 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);
}
Also used : LIR(org.graalvm.compiler.lir.LIR) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 3 with FrameMapBuilder

use of org.graalvm.compiler.lir.framemap.FrameMapBuilder in project graal by oracle.

the class NodeLIRBuilder method emitInvoke.

@Override
public void emitInvoke(Invoke x) {
    LoweredCallTargetNode callTarget = (LoweredCallTargetNode) x.callTarget();
    FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
    CallingConvention invokeCc = frameMapBuilder.getRegisterConfig().getCallingConvention(callTarget.callType(), x.asNode().stamp(NodeView.DEFAULT).javaType(gen.getMetaAccess()), callTarget.signature(), gen);
    frameMapBuilder.callsMethod(invokeCc);
    Value[] parameters = visitInvokeArguments(invokeCc, callTarget.arguments());
    LabelRef exceptionEdge = null;
    if (x instanceof InvokeWithExceptionNode) {
        exceptionEdge = getLIRBlock(((InvokeWithExceptionNode) x).exceptionEdge());
    }
    LIRFrameState callState = stateWithExceptionEdge(x, exceptionEdge);
    Value result = invokeCc.getReturn();
    if (callTarget instanceof DirectCallTargetNode) {
        emitDirectCall((DirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
    } else if (callTarget instanceof IndirectCallTargetNode) {
        emitIndirectCall((IndirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
    } else {
        throw GraalError.shouldNotReachHere();
    }
    if (isLegal(result)) {
        setResult(x.asNode(), gen.emitMove(result));
    }
    if (x instanceof InvokeWithExceptionNode) {
        gen.emitJump(getLIRBlock(((InvokeWithExceptionNode) x).next()));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) LabelRef(org.graalvm.compiler.lir.LabelRef)

Aggregations

FrameMapBuilder (org.graalvm.compiler.lir.framemap.FrameMapBuilder)3 LIR (org.graalvm.compiler.lir.LIR)2 Block (org.graalvm.compiler.nodes.cfg.Block)2 CallingConvention (jdk.vm.ci.code.CallingConvention)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 Value (jdk.vm.ci.meta.Value)1 LIRGenerationContext (org.graalvm.compiler.core.LIRGenerationPhase.LIRGenerationContext)1 AbstractBlockBase (org.graalvm.compiler.core.common.cfg.AbstractBlockBase)1 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)1 LabelRef (org.graalvm.compiler.lir.LabelRef)1 LIRGenerationResult (org.graalvm.compiler.lir.gen.LIRGenerationResult)1 LIRGeneratorTool (org.graalvm.compiler.lir.gen.LIRGeneratorTool)1 DirectCallTargetNode (org.graalvm.compiler.nodes.DirectCallTargetNode)1 IndirectCallTargetNode (org.graalvm.compiler.nodes.IndirectCallTargetNode)1 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)1 LoweredCallTargetNode (org.graalvm.compiler.nodes.LoweredCallTargetNode)1 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)1