Search in sources :

Example 1 with FrameMap

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

the class AMD64HotSpotLeaveCurrentStackFrameOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
    FrameMap frameMap = crb.frameMap;
    RegisterConfig registerConfig = frameMap.getRegisterConfig();
    RegisterSaveLayout registerSaveLayout = saveRegisterOp.getMap(frameMap);
    Register stackPointer = registerConfig.getFrameRegister();
    // Restore integer result register.
    final int stackSlotSize = frameMap.getTarget().wordSize;
    Register integerResultRegister = registerConfig.getReturnRegister(JavaKind.Long);
    masm.movptr(integerResultRegister, new AMD64Address(stackPointer, registerSaveLayout.registerToSlot(integerResultRegister) * stackSlotSize));
    masm.movptr(rdx, new AMD64Address(stackPointer, registerSaveLayout.registerToSlot(rdx) * stackSlotSize));
    // Restore float result register.
    Register floatResultRegister = registerConfig.getReturnRegister(JavaKind.Double);
    masm.movdbl(floatResultRegister, new AMD64Address(stackPointer, registerSaveLayout.registerToSlot(floatResultRegister) * stackSlotSize));
    /*
         * All of the register save area will be popped of the stack. Only the return address
         * remains.
         */
    leaveFrameAndRestoreRbp(crb, masm);
    // Remove return address.
    masm.addq(stackPointer, crb.target.arch.getReturnAddressSize());
}
Also used : RegisterConfig(jdk.vm.ci.code.RegisterConfig) FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) RegisterSaveLayout(jdk.vm.ci.code.RegisterSaveLayout) Register(jdk.vm.ci.code.Register) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 2 with FrameMap

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

the class AArch64HotSpotBackend method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner) {
    AArch64MacroAssembler masm = (AArch64MacroAssembler) crb.asm;
    FrameMap frameMap = crb.frameMap;
    RegisterConfig regConfig = frameMap.getRegisterConfig();
    Label verifiedStub = new Label();
    emitCodePrefix(crb, installedCodeOwner, masm, regConfig, verifiedStub);
    emitCodeBody(crb, lir, masm);
    emitCodeSuffix(crb, masm, frameMap);
}
Also used : AArch64MacroAssembler(org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler) AArch64HotSpotRegisterConfig(jdk.vm.ci.hotspot.aarch64.AArch64HotSpotRegisterConfig) RegisterConfig(jdk.vm.ci.code.RegisterConfig) AArch64FrameMap(org.graalvm.compiler.lir.aarch64.AArch64FrameMap) FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) Label(org.graalvm.compiler.asm.Label)

Example 3 with FrameMap

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

the class GraalCompiler method emitCode.

@SuppressWarnings("try")
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields, int bytecodeSize, LIRGenerationResult lirGenRes, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
    DebugContext debug = lirGenRes.getLIR().getDebug();
    try (DebugCloseable a = EmitCode.start(debug)) {
        FrameMap frameMap = lirGenRes.getFrameMap();
        CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
        backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
        if (assumptions != null && !assumptions.isEmpty()) {
            compilationResult.setAssumptions(assumptions.toArray());
        }
        if (rootMethod != null) {
            compilationResult.setMethods(rootMethod, inlinedMethods);
            compilationResult.setFields(accessedFields);
            compilationResult.setBytecodeSize(bytecodeSize);
        }
        crb.finish();
        if (debug.isCountEnabled()) {
            List<DataPatch> ldp = compilationResult.getDataPatches();
            JavaKind[] kindValues = JavaKind.values();
            CounterKey[] dms = new CounterKey[kindValues.length];
            for (int i = 0; i < dms.length; i++) {
                dms[i] = DebugContext.counter("DataPatches-%s", kindValues[i]);
            }
            for (DataPatch dp : ldp) {
                JavaKind kind = JavaKind.Illegal;
                if (dp.reference instanceof ConstantReference) {
                    VMConstant constant = ((ConstantReference) dp.reference).getConstant();
                    if (constant instanceof JavaConstant) {
                        kind = ((JavaConstant) constant).getJavaKind();
                    }
                }
                dms[kind.ordinal()].add(debug, 1);
            }
            DebugContext.counter("CompilationResults").increment(debug);
            DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
            DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
            DebugContext.counter("DataPatches").add(debug, ldp.size());
            DebugContext.counter("ExceptionHandlersEmitted").add(debug, compilationResult.getExceptionHandlers().size());
        }
        debug.dump(DebugContext.BASIC_LEVEL, compilationResult, "After code generation");
    }
}
Also used : FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) ConstantReference(jdk.vm.ci.code.site.ConstantReference) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) CounterKey(org.graalvm.compiler.debug.CounterKey) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) DataPatch(jdk.vm.ci.code.site.DataPatch) VMConstant(jdk.vm.ci.meta.VMConstant) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 4 with FrameMap

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

the class SPARCHotSpotBackend method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner) {
    SPARCMacroAssembler masm = (SPARCMacroAssembler) crb.asm;
    // TODO: (sa) Fold the two traversals into one
    stuffDelayedControlTransfers(lir);
    int constantSize = calculateConstantSize(lir);
    boolean canUseImmediateConstantLoad = constantSize < (1 << 13);
    masm.setImmediateConstantLoad(canUseImmediateConstantLoad);
    FrameMap frameMap = crb.frameMap;
    RegisterConfig regConfig = frameMap.getRegisterConfig();
    Label unverifiedStub = installedCodeOwner == null || installedCodeOwner.isStatic() ? null : new Label();
    for (int i = 0; i < 2; i++) {
        if (i > 0) {
            crb.resetForEmittingCode();
            lir.resetLabels();
            resetDelayedControlTransfers(lir);
        }
        // Emit the prefix
        if (unverifiedStub != null) {
            crb.recordMark(config.MARKID_UNVERIFIED_ENTRY);
            // We need to use JavaCall here because we haven't entered the frame yet.
            CallingConvention cc = regConfig.getCallingConvention(HotSpotCallingConventionType.JavaCall, null, new JavaType[] { getProviders().getMetaAccess().lookupJavaType(Object.class) }, this);
            // see MacroAssembler::ic_call
            Register inlineCacheKlass = g5;
            try (ScratchRegister sc = masm.getScratchRegister()) {
                Register scratch = sc.getRegister();
                Register receiver = asRegister(cc.getArgument(0));
                SPARCAddress src = new SPARCAddress(receiver, config.hubOffset);
                masm.ldx(src, scratch);
                masm.cmp(scratch, inlineCacheKlass);
            }
            BPCC.emit(masm, Xcc, NotEqual, NOT_ANNUL, PREDICT_NOT_TAKEN, unverifiedStub);
            // delay slot
            masm.nop();
        }
        masm.align(config.codeEntryAlignment);
        crb.recordMark(config.MARKID_OSR_ENTRY);
        crb.recordMark(config.MARKID_VERIFIED_ENTRY);
        // Emit code for the LIR
        crb.emit(lir);
    }
    profileInstructions(lir, crb);
    HotSpotFrameContext frameContext = (HotSpotFrameContext) crb.frameContext;
    HotSpotForeignCallsProvider foreignCalls = getProviders().getForeignCalls();
    if (!frameContext.isStub) {
        crb.recordMark(config.MARKID_EXCEPTION_HANDLER_ENTRY);
        SPARCCall.directCall(crb, masm, foreignCalls.lookupForeignCall(EXCEPTION_HANDLER), null, null);
        crb.recordMark(config.MARKID_DEOPT_HANDLER_ENTRY);
        SPARCCall.directCall(crb, masm, foreignCalls.lookupForeignCall(DEOPTIMIZATION_HANDLER), null, null);
    } else {
    // No need to emit the stubs for entries back into the method since
    // it has no calls that can cause such "return" entries
    }
    if (unverifiedStub != null) {
        masm.bind(unverifiedStub);
        try (ScratchRegister sc = masm.getScratchRegister()) {
            Register scratch = sc.getRegister();
            SPARCCall.indirectJmp(crb, masm, scratch, foreignCalls.lookupForeignCall(IC_MISS_HANDLER));
        }
    }
    masm.peephole();
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) ScratchRegister(org.graalvm.compiler.asm.sparc.SPARCMacroAssembler.ScratchRegister) SPARCFrameMap(org.graalvm.compiler.lir.sparc.SPARCFrameMap) FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) Label(org.graalvm.compiler.asm.Label) Register(jdk.vm.ci.code.Register) ValueUtil.isRegister(jdk.vm.ci.code.ValueUtil.isRegister) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) ScratchRegister(org.graalvm.compiler.asm.sparc.SPARCMacroAssembler.ScratchRegister) SPARCAssembler.isGlobalRegister(org.graalvm.compiler.asm.sparc.SPARCAssembler.isGlobalRegister) SPARCMacroAssembler(org.graalvm.compiler.asm.sparc.SPARCMacroAssembler) HotSpotForeignCallsProvider(org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider) SPARCAddress(org.graalvm.compiler.asm.sparc.SPARCAddress)

Example 5 with FrameMap

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

the class AMD64HotSpotBackend method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner) {
    AMD64MacroAssembler asm = (AMD64MacroAssembler) crb.asm;
    FrameMap frameMap = crb.frameMap;
    RegisterConfig regConfig = frameMap.getRegisterConfig();
    Label verifiedEntry = new Label();
    // Emit the prefix
    emitCodePrefix(installedCodeOwner, crb, asm, regConfig, verifiedEntry);
    // Emit code for the LIR
    emitCodeBody(installedCodeOwner, crb, lir);
    // Emit the suffix
    emitCodeSuffix(installedCodeOwner, crb, asm, frameMap);
    // Profile assembler instructions
    profileInstructions(lir, crb);
}
Also used : RegisterConfig(jdk.vm.ci.code.RegisterConfig) AMD64FrameMap(org.graalvm.compiler.lir.amd64.AMD64FrameMap) FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) Label(org.graalvm.compiler.asm.Label)

Aggregations

FrameMap (org.graalvm.compiler.lir.framemap.FrameMap)6 RegisterConfig (jdk.vm.ci.code.RegisterConfig)4 Label (org.graalvm.compiler.asm.Label)3 Register (jdk.vm.ci.code.Register)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 CallingConvention (jdk.vm.ci.code.CallingConvention)1 RegisterSaveLayout (jdk.vm.ci.code.RegisterSaveLayout)1 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)1 ValueUtil.isRegister (jdk.vm.ci.code.ValueUtil.isRegister)1 ConstantReference (jdk.vm.ci.code.site.ConstantReference)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 AArch64HotSpotRegisterConfig (jdk.vm.ci.hotspot.aarch64.AArch64HotSpotRegisterConfig)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 VMConstant (jdk.vm.ci.meta.VMConstant)1 AArch64MacroAssembler (org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler)1 AMD64Address (org.graalvm.compiler.asm.amd64.AMD64Address)1 AMD64MacroAssembler (org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)1 SPARCAddress (org.graalvm.compiler.asm.sparc.SPARCAddress)1 SPARCAssembler.isGlobalRegister (org.graalvm.compiler.asm.sparc.SPARCAssembler.isGlobalRegister)1