Search in sources :

Example 1 with CompilationResultBuilder

use of org.graalvm.compiler.lir.asm.CompilationResultBuilder in project graal by oracle.

the class AMD64HotSpotCounterOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb) {
    AMD64MacroAssembler masm = (AMD64MacroAssembler) crb.asm;
    TargetDescription target = crb.target;
    Register scratch;
    // want to spill it to the stack.
    if (!contains(increments, rax)) {
        scratch = rax;
    } else if (!contains(increments, rbx)) {
        scratch = rbx;
    } else {
        // emitIncrement().
        throw GraalError.unimplemented("RAX and RBX are increment registers at the same time, spilling over the scratch register is not supported right now");
    }
    // address for counters array
    AMD64Address countersArrayAddr = new AMD64Address(thread, config.jvmciCountersThreadOffset);
    Register countersArrayReg = scratch;
    // backup scratch register
    masm.movq((AMD64Address) crb.asAddress(backupSlot), scratch);
    // load counters array
    masm.movptr(countersArrayReg, countersArrayAddr);
    CounterProcedure emitProcedure = (counterIndex, increment, displacement) -> emitIncrement(masm, countersArrayReg, increment, displacement);
    forEachCounter(emitProcedure, target);
    // restore scratch register
    masm.movq(scratch, (AMD64Address) crb.asAddress(backupSlot));
}
Also used : HotSpotCounterOp(org.graalvm.compiler.hotspot.HotSpotCounterOp) AMD64.rax(jdk.vm.ci.amd64.AMD64.rax) AMD64.rbx(jdk.vm.ci.amd64.AMD64.rbx) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) Register(jdk.vm.ci.code.Register) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) TargetDescription(jdk.vm.ci.code.TargetDescription) Value(jdk.vm.ci.meta.Value) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address) HotSpotRegistersProvider(org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider) ValueUtil.isRegister(jdk.vm.ci.code.ValueUtil.isRegister) Opcode(org.graalvm.compiler.lir.Opcode) GraalError(org.graalvm.compiler.debug.GraalError) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) LIRInstructionClass(org.graalvm.compiler.lir.LIRInstructionClass) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) Register(jdk.vm.ci.code.Register) ValueUtil.isRegister(jdk.vm.ci.code.ValueUtil.isRegister) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) TargetDescription(jdk.vm.ci.code.TargetDescription) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 2 with CompilationResultBuilder

use of org.graalvm.compiler.lir.asm.CompilationResultBuilder in project graal by oracle.

the class SubstrateAMD64Backend method newCompilationResultBuilder.

@Override
public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenResult, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) {
    Assembler masm = createAssembler(frameMap);
    SharedMethod method = ((SubstrateLIRGenerationResult) lirGenResult).getMethod();
    Deoptimizer.StubType stubType = method.getDeoptStubType();
    DataBuilder dataBuilder = new SubstrateDataBuilder();
    FrameContext frameContext;
    if (stubType == Deoptimizer.StubType.EntryStub) {
        frameContext = new DeoptEntryStubContext();
    } else if (stubType == Deoptimizer.StubType.ExitStub) {
        frameContext = new DeoptExitStubContext();
    } else {
        frameContext = new SubstrateAMD64FrameContext();
    }
    LIR lir = lirGenResult.getLIR();
    OptionValues options = lir.getOptions();
    DebugContext debug = lir.getDebug();
    CompilationResultBuilder tasm = factory.createBuilder(getCodeCache(), getForeignCalls(), lirGenResult.getFrameMap(), masm, dataBuilder, frameContext, options, debug, compilationResult);
    tasm.setTotalFrameSize(lirGenResult.getFrameMap().totalFrameSize());
    return tasm;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) FrameContext(org.graalvm.compiler.lir.asm.FrameContext) DebugContext(org.graalvm.compiler.debug.DebugContext) Deoptimizer(com.oracle.svm.core.deopt.Deoptimizer) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) LIR(org.graalvm.compiler.lir.LIR) SubstrateDataBuilder(com.oracle.svm.core.graal.code.SubstrateDataBuilder) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) SharedMethod(com.oracle.svm.core.meta.SharedMethod) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) Assembler(org.graalvm.compiler.asm.Assembler) SubstrateDataBuilder(com.oracle.svm.core.graal.code.SubstrateDataBuilder)

Example 3 with CompilationResultBuilder

use of org.graalvm.compiler.lir.asm.CompilationResultBuilder 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 CompilationResultBuilder

use of org.graalvm.compiler.lir.asm.CompilationResultBuilder in project graal by oracle.

the class SPARCHotSpotBackend method newCompilationResultBuilder.

@Override
public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenRes, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) {
    HotSpotLIRGenerationResult gen = (HotSpotLIRGenerationResult) lirGenRes;
    LIR lir = gen.getLIR();
    assert gen.getDeoptimizationRescueSlot() == null || frameMap.frameNeedsAllocating() : "method that can deoptimize must have a frame";
    Stub stub = gen.getStub();
    Assembler masm = createAssembler(frameMap);
    // On SPARC we always use stack frames.
    HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null);
    DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());
    OptionValues options = lir.getOptions();
    DebugContext debug = lir.getDebug();
    CompilationResultBuilder crb = factory.createBuilder(getProviders().getCodeCache(), getProviders().getForeignCalls(), frameMap, masm, dataBuilder, frameContext, options, debug, compilationResult);
    crb.setTotalFrameSize(frameMap.totalFrameSize());
    crb.setMaxInterpreterFrameSize(gen.getMaxInterpreterFrameSize());
    StackSlot deoptimizationRescueSlot = gen.getDeoptimizationRescueSlot();
    if (deoptimizationRescueSlot != null && stub == null) {
        crb.compilationResult.setCustomStackAreaOffset(deoptimizationRescueSlot);
    }
    if (stub != null) {
        // Even on sparc we need to save floating point registers
        EconomicSet<Register> destroyedCallerRegisters = gatherDestroyedCallerRegisters(lir);
        EconomicMap<LIRFrameState, SaveRegistersOp> calleeSaveInfo = gen.getCalleeSaveInfo();
        updateStub(stub, destroyedCallerRegisters, calleeSaveInfo, frameMap);
    }
    assert registerSizePredictionValidator(crb, debug);
    return crb;
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotLIRGenerationResult(org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) Stub(org.graalvm.compiler.hotspot.stubs.Stub) StackSlot(jdk.vm.ci.code.StackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) LIR(org.graalvm.compiler.lir.LIR) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) 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) SPARCAssembler(org.graalvm.compiler.asm.sparc.SPARCAssembler) SPARCMacroAssembler(org.graalvm.compiler.asm.sparc.SPARCMacroAssembler) Assembler(org.graalvm.compiler.asm.Assembler) SaveRegistersOp(org.graalvm.compiler.lir.StandardOp.SaveRegistersOp)

Example 5 with CompilationResultBuilder

use of org.graalvm.compiler.lir.asm.CompilationResultBuilder in project graal by oracle.

the class AMD64HotSpotBackend method newCompilationResultBuilder.

@Override
public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenRen, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) {
    // Omit the frame if the method:
    // - has no spill slots or other slots allocated during register allocation
    // - has no callee-saved registers
    // - has no incoming arguments passed on the stack
    // - has no deoptimization points
    // - makes no foreign calls (which require an aligned stack)
    HotSpotLIRGenerationResult gen = (HotSpotLIRGenerationResult) lirGenRen;
    LIR lir = gen.getLIR();
    assert gen.getDeoptimizationRescueSlot() == null || frameMap.frameNeedsAllocating() : "method that can deoptimize must have a frame";
    OptionValues options = lir.getOptions();
    DebugContext debug = lir.getDebug();
    boolean omitFrame = CanOmitFrame.getValue(options) && !frameMap.frameNeedsAllocating() && !lir.hasArgInCallerFrame() && !gen.hasForeignCall();
    Stub stub = gen.getStub();
    Assembler masm = createAssembler(frameMap);
    HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null, omitFrame);
    DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());
    CompilationResultBuilder crb = factory.createBuilder(getCodeCache(), getForeignCalls(), frameMap, masm, dataBuilder, frameContext, options, debug, compilationResult);
    crb.setTotalFrameSize(frameMap.totalFrameSize());
    crb.setMaxInterpreterFrameSize(gen.getMaxInterpreterFrameSize());
    StackSlot deoptimizationRescueSlot = gen.getDeoptimizationRescueSlot();
    if (deoptimizationRescueSlot != null && stub == null) {
        crb.compilationResult.setCustomStackAreaOffset(deoptimizationRescueSlot);
    }
    if (stub != null) {
        EconomicSet<Register> destroyedCallerRegisters = gatherDestroyedCallerRegisters(lir);
        updateStub(stub, destroyedCallerRegisters, gen.getCalleeSaveInfo(), frameMap);
    }
    return crb;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotLIRGenerationResult(org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) Stub(org.graalvm.compiler.hotspot.stubs.Stub) StackSlot(jdk.vm.ci.code.StackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) LIR(org.graalvm.compiler.lir.LIR) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) Assembler(org.graalvm.compiler.asm.Assembler) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)

Aggregations

CompilationResultBuilder (org.graalvm.compiler.lir.asm.CompilationResultBuilder)7 Register (jdk.vm.ci.code.Register)4 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)4 Assembler (org.graalvm.compiler.asm.Assembler)4 DebugContext (org.graalvm.compiler.debug.DebugContext)4 LIR (org.graalvm.compiler.lir.LIR)4 DataBuilder (org.graalvm.compiler.lir.asm.DataBuilder)4 StackSlot (jdk.vm.ci.code.StackSlot)3 AMD64MacroAssembler (org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)3 HotSpotDataBuilder (org.graalvm.compiler.hotspot.HotSpotDataBuilder)3 HotSpotLIRGenerationResult (org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult)3 Stub (org.graalvm.compiler.hotspot.stubs.Stub)3 OptionValues (org.graalvm.compiler.options.OptionValues)3 ValueUtil.isRegister (jdk.vm.ci.code.ValueUtil.isRegister)2 Deoptimizer (com.oracle.svm.core.deopt.Deoptimizer)1 SubstrateDataBuilder (com.oracle.svm.core.graal.code.SubstrateDataBuilder)1 SharedMethod (com.oracle.svm.core.meta.SharedMethod)1 HashSet (java.util.HashSet)1 AMD64.rax (jdk.vm.ci.amd64.AMD64.rax)1 AMD64.rbx (jdk.vm.ci.amd64.AMD64.rbx)1