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));
}
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;
}
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");
}
}
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;
}
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;
}
Aggregations