< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/target/Backend.java

Print this page

        

*** 24,70 **** package org.graalvm.compiler.core.target; import java.util.ArrayList; - import jdk.internal.vm.compiler.collections.EconomicSet; - import org.graalvm.compiler.asm.Assembler; import org.graalvm.compiler.code.CompilationResult; import org.graalvm.compiler.core.common.CompilationIdentifier; import org.graalvm.compiler.core.common.LIRKind; import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig; import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; import org.graalvm.compiler.debug.DebugContext; - import org.graalvm.compiler.lir.LIR; - import org.graalvm.compiler.lir.asm.CompilationResultBuilder; import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory; ! import org.graalvm.compiler.lir.framemap.FrameMap; ! import org.graalvm.compiler.lir.framemap.FrameMapBuilder; ! import org.graalvm.compiler.lir.gen.LIRGenerationResult; ! import org.graalvm.compiler.lir.gen.LIRGeneratorTool; import org.graalvm.compiler.nodes.StructuredGraph; - import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.tiers.SuitesProvider; import org.graalvm.compiler.phases.tiers.TargetProvider; import org.graalvm.compiler.phases.util.Providers; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.CompilationRequest; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.InstalledCode; - import jdk.vm.ci.code.Register; import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.code.ValueKindFactory; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; - import jdk.vm.ci.meta.SpeculationLog; /** * Represents a compiler backend for Graal. */ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKind> { --- 24,61 ---- package org.graalvm.compiler.core.target; import java.util.ArrayList; import org.graalvm.compiler.code.CompilationResult; import org.graalvm.compiler.core.common.CompilationIdentifier; import org.graalvm.compiler.core.common.LIRKind; import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig; import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; + import org.graalvm.compiler.core.gen.LIRCompilerBackend; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory; ! import org.graalvm.compiler.lir.phases.LIRSuites; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.tiers.SuitesProvider; import org.graalvm.compiler.phases.tiers.TargetProvider; import org.graalvm.compiler.phases.util.Providers; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.CompilationRequest; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.code.ValueKindFactory; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; /** * Represents a compiler backend for Graal. */ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKind> {
*** 115,180 **** public LIRKind getValueKind(JavaKind javaKind) { return LIRKind.fromJavaKind(getTarget().arch, javaKind); } /** - * The given registerConfig is optional, in case null is passed the default RegisterConfig from - * the CodeCacheProvider will be used. - */ - public abstract FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig); - - /** * Creates a new configuration for register allocation. * * @param allocationRestrictedTo if not {@code null}, register allocation will be restricted to * registers whose names appear in this array */ public abstract RegisterAllocationConfig newRegisterAllocationConfig(RegisterConfig registerConfig, String[] allocationRestrictedTo); - public abstract FrameMap newFrameMap(RegisterConfig registerConfig); - - public abstract LIRGeneratorTool newLIRGenerator(LIRGenerationResult lirGenRes); - - public abstract LIRGenerationResult newLIRGenerationResult(CompilationIdentifier compilationId, LIR lir, FrameMapBuilder frameMapBuilder, StructuredGraph graph, - Object stub); - - public abstract NodeLIRBuilderTool newNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen); - - /** - * Creates the assembler used to emit the machine code. - */ - protected abstract Assembler createAssembler(FrameMap frameMap); - - /** - * Creates the object used to fill in the details of a given compilation result. - */ - public abstract CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenResult, FrameMap frameMap, CompilationResult compilationResult, - CompilationResultBuilderFactory factory); - /** * Turns a Graal {@link CompilationResult} into a {@link CompiledCode} object that can be passed * to the VM for code installation. */ protected abstract CompiledCode createCompiledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, boolean isDefault, OptionValues options); /** * @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest, ! * CompilationResult, SpeculationLog, InstalledCode, boolean, Object[]) */ ! public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult, ! SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) { ! return createInstalledCode(debug, method, null, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null); } /** * @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest, ! * CompilationResult, SpeculationLog, InstalledCode, boolean, Object[]) */ @SuppressWarnings("try") ! public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, ! SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) { ! return createInstalledCode(debug, method, compilationRequest, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null); } /** * Installs code based on a given compilation result. * --- 106,152 ---- public LIRKind getValueKind(JavaKind javaKind) { return LIRKind.fromJavaKind(getTarget().arch, javaKind); } /** * Creates a new configuration for register allocation. * * @param allocationRestrictedTo if not {@code null}, register allocation will be restricted to * registers whose names appear in this array */ public abstract RegisterAllocationConfig newRegisterAllocationConfig(RegisterConfig registerConfig, String[] allocationRestrictedTo); /** * Turns a Graal {@link CompilationResult} into a {@link CompiledCode} object that can be passed * to the VM for code installation. */ protected abstract CompiledCode createCompiledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, boolean isDefault, OptionValues options); /** * @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest, ! * CompilationResult, InstalledCode, boolean, Object[]) */ ! public InstalledCode createInstalledCode(DebugContext debug, ! ResolvedJavaMethod method, ! CompilationResult compilationResult, ! InstalledCode predefinedInstalledCode, ! boolean isDefault) { ! return createInstalledCode(debug, method, null, compilationResult, predefinedInstalledCode, isDefault, null); } /** * @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest, ! * CompilationResult, InstalledCode, boolean, Object[]) */ @SuppressWarnings("try") ! public InstalledCode createInstalledCode(DebugContext debug, ! ResolvedJavaMethod method, ! CompilationRequest compilationRequest, ! CompilationResult compilationResult, ! InstalledCode predefinedInstalledCode, ! boolean isDefault) { ! return createInstalledCode(debug, method, compilationRequest, compilationResult, predefinedInstalledCode, isDefault, null); } /** * Installs code based on a given compilation result. *
*** 183,193 **** * @param compilationRequest the compilation request or {@code null} * @param compilationResult the code to be installed * @param predefinedInstalledCode a pre-allocated {@link InstalledCode} object to use as a * reference to the installed code. If {@code null}, a new {@link InstalledCode} * object will be created. - * @param speculationLog the speculation log to be used * @param isDefault specifies if the installed code should be made the default implementation of * {@code compRequest.getMethod()}. The default implementation for a method is the * code executed for standard calls to the method. This argument is ignored if * {@code compRequest == null}. * @param context a custom debug context to use for the code installation --- 155,164 ----
*** 196,207 **** * @throws IllegalArgumentException if {@code installedCode != null} and this platform does not * {@linkplain CodeCacheProvider#installCode support} a predefined * {@link InstalledCode} object */ @SuppressWarnings("try") ! public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, ! SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) { Object[] debugContext = context != null ? context : new Object[]{getProviders().getCodeCache(), method, compilationResult}; CodeInstallationTask[] tasks; synchronized (this) { tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()]; for (int i = 0; i < codeInstallationTaskFactories.size(); i++) { --- 167,183 ---- * @throws IllegalArgumentException if {@code installedCode != null} and this platform does not * {@linkplain CodeCacheProvider#installCode support} a predefined * {@link InstalledCode} object */ @SuppressWarnings("try") ! public InstalledCode createInstalledCode(DebugContext debug, ! ResolvedJavaMethod method, ! CompilationRequest compilationRequest, ! CompilationResult compilationResult, ! InstalledCode predefinedInstalledCode, ! boolean isDefault, ! Object[] context) { Object[] debugContext = context != null ? context : new Object[]{getProviders().getCodeCache(), method, compilationResult}; CodeInstallationTask[] tasks; synchronized (this) { tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()]; for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
*** 213,223 **** InstalledCode installedCode; try { preCodeInstallationTasks(tasks, compilationResult); CompiledCode compiledCode = createCompiledCode(method, compilationRequest, compilationResult, isDefault, debug.getOptions()); ! installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, speculationLog, isDefault); assert predefinedInstalledCode == null || installedCode == predefinedInstalledCode; } catch (Throwable t) { failCodeInstallationTasks(tasks, t); throw t; } --- 189,199 ---- InstalledCode installedCode; try { preCodeInstallationTasks(tasks, compilationResult); CompiledCode compiledCode = createCompiledCode(method, compilationRequest, compilationResult, isDefault, debug.getOptions()); ! installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, compilationResult.getSpeculationLog(), isDefault); assert predefinedInstalledCode == null || installedCode == predefinedInstalledCode; } catch (Throwable t) { failCodeInstallationTasks(tasks, t); throw t; }
*** 257,313 **** * Installs code based on a given compilation result. * * @param method the method compiled to produce {@code compiledCode} or {@code null} if the * input to {@code compResult} was not a {@link ResolvedJavaMethod} * @param compilationRequest the request or {@code null} ! * @param compilationResult the code to be compiled * @return a reference to the compiled and ready-to-run installed code * @throws BailoutException if the code installation failed */ ! public InstalledCode addInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult) { ! return createInstalledCode(debug, method, compilationRequest, compilationResult, null, null, false); } /** * Installs code based on a given compilation result and sets it as the default code to be used * when {@code method} is invoked. * * @param method the method compiled to produce {@code compiledCode} or {@code null} if the * input to {@code compResult} was not a {@link ResolvedJavaMethod} ! * @param compilationResult the code to be compiled * @return a reference to the compiled and ready-to-run installed code * @throws BailoutException if the code installation failed */ public InstalledCode createDefaultInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult) { ! return createInstalledCode(debug, method, compilationResult, null, null, true); } /** - * Emits the code for a given graph. - * - * @param installedCodeOwner the method the compiled code will be associated with once - * installed. This argument can be null. - */ - public abstract void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner); - - /** - * Translates a set of registers from the callee's perspective to the caller's perspective. This - * is needed for architectures where input/output registers are renamed during a call (e.g. - * register windows on SPARC). Registers which are not visible by the caller are removed. - */ - public abstract EconomicSet<Register> translateToCallerRegisters(EconomicSet<Register> calleeRegisters); - - /** * Gets the compilation id for a given {@link ResolvedJavaMethod}. Returns * {@code CompilationIdentifier#INVALID_COMPILATION_ID} in case there is no such id. * * @param resolvedJavaMethod */ public CompilationIdentifier getCompilationIdentifier(ResolvedJavaMethod resolvedJavaMethod) { return CompilationIdentifier.INVALID_COMPILATION_ID; } /** * Encapsulates custom tasks done before and after code installation. */ public abstract static class CodeInstallationTask { /** --- 233,287 ---- * Installs code based on a given compilation result. * * @param method the method compiled to produce {@code compiledCode} or {@code null} if the * input to {@code compResult} was not a {@link ResolvedJavaMethod} * @param compilationRequest the request or {@code null} ! * @param compilationResult the compiled code * @return a reference to the compiled and ready-to-run installed code * @throws BailoutException if the code installation failed */ ! public InstalledCode addInstalledCode(DebugContext debug, ! ResolvedJavaMethod method, ! CompilationRequest compilationRequest, ! CompilationResult compilationResult) { ! return createInstalledCode(debug, method, compilationRequest, compilationResult, null, false); } /** * Installs code based on a given compilation result and sets it as the default code to be used * when {@code method} is invoked. * * @param method the method compiled to produce {@code compiledCode} or {@code null} if the * input to {@code compResult} was not a {@link ResolvedJavaMethod} ! * @param compilationResult the compiled code * @return a reference to the compiled and ready-to-run installed code * @throws BailoutException if the code installation failed */ public InstalledCode createDefaultInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult) { ! System.out.println(compilationResult.getSpeculationLog()); ! return createInstalledCode(debug, method, compilationResult, null, true); } /** * Gets the compilation id for a given {@link ResolvedJavaMethod}. Returns * {@code CompilationIdentifier#INVALID_COMPILATION_ID} in case there is no such id. * * @param resolvedJavaMethod */ public CompilationIdentifier getCompilationIdentifier(ResolvedJavaMethod resolvedJavaMethod) { return CompilationIdentifier.INVALID_COMPILATION_ID; } + public void emitBackEnd(StructuredGraph graph, + Object stub, + ResolvedJavaMethod installedCodeOwner, + CompilationResult compilationResult, + CompilationResultBuilderFactory factory, + RegisterConfig config, LIRSuites lirSuites) { + LIRCompilerBackend.emitBackEnd(graph, stub, installedCodeOwner, this, compilationResult, factory, config, lirSuites); + } + /** * Encapsulates custom tasks done before and after code installation. */ public abstract static class CodeInstallationTask { /**
< prev index next >