Mercurial > hg > graal-compiler
view graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java @ 23222:56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 30 Dec 2015 18:08:59 +0100 |
parents | b00ef2b9cd00 |
children | 0a2e40f7a5d2 |
line wrap: on
line source
/* * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.hotspot.amd64; import static jdk.vm.ci.inittimer.InitTimer.timer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import jdk.vm.ci.amd64.AMD64; import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.Register; import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider; import jdk.vm.ci.hotspot.HotSpotVMConfig; import jdk.vm.ci.inittimer.InitTimer; import jdk.vm.ci.meta.Value; import jdk.vm.ci.runtime.JVMCIBackend; import com.oracle.graal.api.replacements.SnippetReflectionProvider; import com.oracle.graal.compiler.amd64.AMD64SuitesProvider; import com.oracle.graal.hotspot.DefaultHotSpotGraalCompilerFactory; import com.oracle.graal.hotspot.HotSpotBackend; import com.oracle.graal.hotspot.HotSpotBackendFactory; import com.oracle.graal.hotspot.HotSpotGraalRuntimeProvider; import com.oracle.graal.hotspot.HotSpotReplacementsImpl; import com.oracle.graal.hotspot.meta.HotSpotForeignCallsProvider; import com.oracle.graal.hotspot.meta.HotSpotGraalConstantReflectionProvider; import com.oracle.graal.hotspot.meta.HotSpotGraphBuilderPlugins; import com.oracle.graal.hotspot.meta.HotSpotHostForeignCallsProvider; import com.oracle.graal.hotspot.meta.HotSpotLoweringProvider; import com.oracle.graal.hotspot.meta.HotSpotProviders; import com.oracle.graal.hotspot.meta.HotSpotRegisters; import com.oracle.graal.hotspot.meta.HotSpotRegistersProvider; import com.oracle.graal.hotspot.meta.HotSpotSnippetReflectionProvider; import com.oracle.graal.hotspot.meta.HotSpotStampProvider; import com.oracle.graal.hotspot.meta.HotSpotSuitesProvider; import com.oracle.graal.hotspot.word.HotSpotWordTypes; import com.oracle.graal.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.phases.tiers.CompilerConfiguration; import com.oracle.graal.phases.util.Providers; import com.oracle.graal.replacements.amd64.AMD64GraphBuilderPlugins; import com.oracle.graal.serviceprovider.ServiceProvider; import com.oracle.graal.word.WordTypes; @ServiceProvider(HotSpotBackendFactory.class) public class AMD64HotSpotBackendFactory implements HotSpotBackendFactory { @Override public void register() { DefaultHotSpotGraalCompilerFactory.registerBackend(AMD64.class, this); } @Override @SuppressWarnings("try") public HotSpotBackend createBackend(HotSpotGraalRuntimeProvider graalRuntime, CompilerConfiguration compilerConfiguration, HotSpotJVMCIRuntimeProvider jvmciRuntime, HotSpotBackend host) { assert host == null; JVMCIBackend jvmci = jvmciRuntime.getHostJVMCIBackend(); HotSpotVMConfig config = jvmciRuntime.getConfig(); HotSpotProviders providers; HotSpotRegistersProvider registers; HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmci.getCodeCache(); TargetDescription target = codeCache.getTarget(); HotSpotConstantReflectionProvider constantReflection = new HotSpotGraalConstantReflectionProvider(jvmciRuntime); HotSpotHostForeignCallsProvider foreignCalls; Value[] nativeABICallerSaveRegisters; HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) jvmci.getMetaAccess(); HotSpotLoweringProvider lowerer; HotSpotSnippetReflectionProvider snippetReflection; HotSpotReplacementsImpl replacements; HotSpotSuitesProvider suites; HotSpotWordTypes wordTypes; Plugins plugins; try (InitTimer t = timer("create providers")) { try (InitTimer rt = timer("create HotSpotRegisters provider")) { registers = createRegisters(); } try (InitTimer rt = timer("create NativeABICallerSaveRegisters")) { nativeABICallerSaveRegisters = createNativeABICallerSaveRegisters(config, codeCache.getRegisterConfig()); } try (InitTimer rt = timer("create ForeignCalls provider")) { foreignCalls = createForeignCalls(jvmciRuntime, graalRuntime, metaAccess, codeCache, nativeABICallerSaveRegisters); } try (InitTimer rt = timer("create Lowerer provider")) { lowerer = createLowerer(graalRuntime, metaAccess, foreignCalls, registers, constantReflection, target); } HotSpotStampProvider stampProvider = new HotSpotStampProvider(); Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, stampProvider); try (InitTimer rt = timer("create WordTypes")) { wordTypes = new HotSpotWordTypes(metaAccess, target.wordJavaKind); } try (InitTimer rt = timer("create SnippetReflection provider")) { snippetReflection = createSnippetReflection(graalRuntime, constantReflection, wordTypes); } try (InitTimer rt = timer("create Replacements provider")) { replacements = createReplacements(config, p, snippetReflection); } try (InitTimer rt = timer("create GraphBuilderPhase plugins")) { plugins = createGraphBuilderPlugins(config, target, constantReflection, foreignCalls, metaAccess, snippetReflection, replacements, wordTypes, stampProvider); replacements.setGraphBuilderPlugins(plugins); } try (InitTimer rt = timer("create Suites provider")) { suites = createSuites(config, graalRuntime, compilerConfiguration, plugins, codeCache, registers); } providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, suites, registers, snippetReflection, wordTypes, plugins); } try (InitTimer rt = timer("instantiate backend")) { return createBackend(config, graalRuntime, providers); } } protected Plugins createGraphBuilderPlugins(HotSpotVMConfig config, TargetDescription target, HotSpotConstantReflectionProvider constantReflection, HotSpotHostForeignCallsProvider foreignCalls, HotSpotMetaAccessProvider metaAccess, HotSpotSnippetReflectionProvider snippetReflection, HotSpotReplacementsImpl replacements, HotSpotWordTypes wordTypes, HotSpotStampProvider stampProvider) { Plugins plugins = HotSpotGraphBuilderPlugins.create(config, wordTypes, metaAccess, constantReflection, snippetReflection, foreignCalls, stampProvider, replacements); AMD64GraphBuilderPlugins.register(plugins, foreignCalls, (AMD64) target.arch); return plugins; } protected AMD64HotSpotBackend createBackend(HotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) { return new AMD64HotSpotBackend(config, runtime, providers); } protected HotSpotRegistersProvider createRegisters() { return new HotSpotRegisters(AMD64.r15, AMD64.r12, AMD64.rsp); } protected HotSpotReplacementsImpl createReplacements(HotSpotVMConfig config, Providers p, SnippetReflectionProvider snippetReflection) { return new HotSpotReplacementsImpl(p, snippetReflection, config, p.getCodeCache().getTarget()); } protected AMD64HotSpotForeignCallsProvider createForeignCalls(HotSpotJVMCIRuntimeProvider jvmciRuntime, HotSpotGraalRuntimeProvider runtime, HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, Value[] nativeABICallerSaveRegisters) { return new AMD64HotSpotForeignCallsProvider(jvmciRuntime, runtime, metaAccess, codeCache, nativeABICallerSaveRegisters); } protected HotSpotSuitesProvider createSuites(HotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, Plugins plugins, CodeCacheProvider codeCache, HotSpotRegistersProvider registers) { return new HotSpotSuitesProvider(new AMD64SuitesProvider(compilerConfiguration, plugins), config, runtime, new AMD64HotSpotAddressLowering(codeCache, config.getOopEncoding().base, registers.getHeapBaseRegister())); } protected HotSpotSnippetReflectionProvider createSnippetReflection(HotSpotGraalRuntimeProvider runtime, HotSpotConstantReflectionProvider constantReflection, WordTypes wordTypes) { return new HotSpotSnippetReflectionProvider(runtime, constantReflection, wordTypes); } protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider runtime, HotSpotMetaAccessProvider metaAccess, HotSpotForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, HotSpotConstantReflectionProvider constantReflection, TargetDescription target) { return new AMD64HotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, constantReflection, target); } protected Value[] createNativeABICallerSaveRegisters(HotSpotVMConfig config, RegisterConfig regConfig) { List<Register> callerSave = new ArrayList<>(Arrays.asList(regConfig.getAllocatableRegisters())); if (config.windowsOs) { // http://msdn.microsoft.com/en-us/library/9z1stfyw.aspx callerSave.remove(AMD64.rdi); callerSave.remove(AMD64.rsi); callerSave.remove(AMD64.rbx); callerSave.remove(AMD64.rbp); callerSave.remove(AMD64.rsp); callerSave.remove(AMD64.r12); callerSave.remove(AMD64.r13); callerSave.remove(AMD64.r14); callerSave.remove(AMD64.r15); callerSave.remove(AMD64.xmm6); callerSave.remove(AMD64.xmm7); callerSave.remove(AMD64.xmm8); callerSave.remove(AMD64.xmm9); callerSave.remove(AMD64.xmm10); callerSave.remove(AMD64.xmm11); callerSave.remove(AMD64.xmm12); callerSave.remove(AMD64.xmm13); callerSave.remove(AMD64.xmm14); callerSave.remove(AMD64.xmm15); } else { /* * System V Application Binary Interface, AMD64 Architecture Processor Supplement * * Draft Version 0.96 * * http://www.uclibc.org/docs/psABI-x86_64.pdf * * 3.2.1 * * ... * * This subsection discusses usage of each register. Registers %rbp, %rbx and %r12 * through %r15 "belong" to the calling function and the called function is required to * preserve their values. In other words, a called function must preserve these * registers' values for its caller. Remaining registers "belong" to the called * function. If a calling function wants to preserve such a register value across a * function call, it must save the value in its local stack frame. */ callerSave.remove(AMD64.rbp); callerSave.remove(AMD64.rbx); callerSave.remove(AMD64.r12); callerSave.remove(AMD64.r13); callerSave.remove(AMD64.r14); callerSave.remove(AMD64.r15); } Value[] nativeABICallerSaveRegisters = new Value[callerSave.size()]; for (int i = 0; i < callerSave.size(); i++) { nativeABICallerSaveRegisters[i] = callerSave.get(i).asValue(); } return nativeABICallerSaveRegisters; } @Override public String toString() { return "AMD64"; } }