43972
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
50330
|
3 |
* Copyright (c) 2018, Red Hat Inc. All rights reserved.
|
43972
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
5 |
*
|
|
6 |
* This code is free software; you can redistribute it and/or modify it
|
|
7 |
* under the terms of the GNU General Public License version 2 only, as
|
|
8 |
* published by the Free Software Foundation.
|
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
|
23 |
*/
|
50858
|
24 |
|
|
25 |
|
43972
|
26 |
package org.graalvm.compiler.hotspot.aarch64;
|
|
27 |
|
|
28 |
import static jdk.vm.ci.aarch64.AArch64.sp;
|
|
29 |
import static jdk.vm.ci.common.InitTimer.timer;
|
|
30 |
|
50858
|
31 |
import java.util.ArrayList;
|
57537
|
32 |
import java.util.Arrays;
|
50858
|
33 |
import java.util.List;
|
|
34 |
|
43972
|
35 |
import org.graalvm.compiler.bytecode.BytecodeProvider;
|
46536
|
36 |
import org.graalvm.compiler.core.aarch64.AArch64AddressLoweringByUse;
|
|
37 |
import org.graalvm.compiler.core.aarch64.AArch64LIRKindTool;
|
|
38 |
import org.graalvm.compiler.core.aarch64.AArch64SuitesCreator;
|
43972
|
39 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
|
40 |
import org.graalvm.compiler.hotspot.HotSpotBackend;
|
|
41 |
import org.graalvm.compiler.hotspot.HotSpotBackendFactory;
|
|
42 |
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
|
|
43 |
import org.graalvm.compiler.hotspot.HotSpotReplacementsImpl;
|
49873
|
44 |
import org.graalvm.compiler.hotspot.meta.AddressLoweringHotSpotSuitesProvider;
|
43972
|
45 |
import org.graalvm.compiler.hotspot.meta.HotSpotConstantFieldProvider;
|
|
46 |
import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
|
55509
|
47 |
import org.graalvm.compiler.hotspot.meta.HotSpotGCProvider;
|
43972
|
48 |
import org.graalvm.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider;
|
|
49 |
import org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins;
|
|
50 |
import org.graalvm.compiler.hotspot.meta.HotSpotHostForeignCallsProvider;
|
|
51 |
import org.graalvm.compiler.hotspot.meta.HotSpotLoweringProvider;
|
|
52 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
|
|
53 |
import org.graalvm.compiler.hotspot.meta.HotSpotRegisters;
|
|
54 |
import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider;
|
|
55 |
import org.graalvm.compiler.hotspot.meta.HotSpotSnippetReflectionProvider;
|
|
56 |
import org.graalvm.compiler.hotspot.meta.HotSpotStampProvider;
|
|
57 |
import org.graalvm.compiler.hotspot.meta.HotSpotSuitesProvider;
|
|
58 |
import org.graalvm.compiler.hotspot.word.HotSpotWordTypes;
|
|
59 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
49873
|
60 |
import org.graalvm.compiler.nodes.spi.Replacements;
|
46344
|
61 |
import org.graalvm.compiler.options.OptionValues;
|
49873
|
62 |
import org.graalvm.compiler.phases.Phase;
|
|
63 |
import org.graalvm.compiler.phases.common.AddressLoweringByUsePhase;
|
|
64 |
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
43972
|
65 |
import org.graalvm.compiler.phases.tiers.CompilerConfiguration;
|
|
66 |
import org.graalvm.compiler.phases.util.Providers;
|
|
67 |
import org.graalvm.compiler.replacements.aarch64.AArch64GraphBuilderPlugins;
|
|
68 |
import org.graalvm.compiler.serviceprovider.ServiceProvider;
|
|
69 |
import org.graalvm.compiler.word.WordTypes;
|
|
70 |
|
|
71 |
import jdk.vm.ci.aarch64.AArch64;
|
50858
|
72 |
import jdk.vm.ci.code.Architecture;
|
|
73 |
import jdk.vm.ci.code.Register;
|
|
74 |
import jdk.vm.ci.code.RegisterConfig;
|
|
75 |
import jdk.vm.ci.code.TargetDescription;
|
43972
|
76 |
import jdk.vm.ci.common.InitTimer;
|
|
77 |
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
|
|
78 |
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
|
50858
|
79 |
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
|
43972
|
80 |
import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider;
|
|
81 |
import jdk.vm.ci.hotspot.aarch64.AArch64HotSpotRegisterConfig;
|
|
82 |
import jdk.vm.ci.meta.Value;
|
|
83 |
import jdk.vm.ci.runtime.JVMCIBackend;
|
|
84 |
|
|
85 |
@ServiceProvider(HotSpotBackendFactory.class)
|
55509
|
86 |
public class AArch64HotSpotBackendFactory extends HotSpotBackendFactory {
|
43972
|
87 |
|
|
88 |
@Override
|
|
89 |
public String getName() {
|
49873
|
90 |
return "community";
|
43972
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
public Class<? extends Architecture> getArchitecture() {
|
|
95 |
return AArch64.class;
|
|
96 |
}
|
|
97 |
|
|
98 |
@Override
|
|
99 |
@SuppressWarnings("try")
|
50858
|
100 |
public HotSpotBackend createBackend(HotSpotGraalRuntimeProvider graalRuntime, CompilerConfiguration compilerConfiguration, HotSpotJVMCIRuntime jvmciRuntime, HotSpotBackend host) {
|
43972
|
101 |
assert host == null;
|
|
102 |
|
|
103 |
JVMCIBackend jvmci = jvmciRuntime.getHostJVMCIBackend();
|
|
104 |
GraalHotSpotVMConfig config = graalRuntime.getVMConfig();
|
|
105 |
HotSpotProviders providers;
|
|
106 |
HotSpotRegistersProvider registers;
|
|
107 |
HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmci.getCodeCache();
|
|
108 |
TargetDescription target = codeCache.getTarget();
|
|
109 |
HotSpotHostForeignCallsProvider foreignCalls;
|
|
110 |
Value[] nativeABICallerSaveRegisters;
|
|
111 |
HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) jvmci.getMetaAccess();
|
|
112 |
HotSpotConstantReflectionProvider constantReflection = (HotSpotConstantReflectionProvider) jvmci.getConstantReflection();
|
|
113 |
HotSpotConstantFieldProvider constantFieldProvider = new HotSpotGraalConstantFieldProvider(config, metaAccess);
|
|
114 |
HotSpotLoweringProvider lowerer;
|
55509
|
115 |
HotSpotStampProvider stampProvider;
|
|
116 |
HotSpotGCProvider gc;
|
43972
|
117 |
HotSpotSnippetReflectionProvider snippetReflection;
|
|
118 |
HotSpotReplacementsImpl replacements;
|
|
119 |
HotSpotSuitesProvider suites;
|
|
120 |
HotSpotWordTypes wordTypes;
|
|
121 |
Plugins plugins;
|
|
122 |
BytecodeProvider bytecodeProvider;
|
|
123 |
try (InitTimer t = timer("create providers")) {
|
|
124 |
try (InitTimer rt = timer("create HotSpotRegisters provider")) {
|
|
125 |
registers = createRegisters();
|
|
126 |
}
|
|
127 |
try (InitTimer rt = timer("create NativeABICallerSaveRegisters")) {
|
|
128 |
nativeABICallerSaveRegisters = createNativeABICallerSaveRegisters(config, codeCache.getRegisterConfig());
|
|
129 |
}
|
|
130 |
try (InitTimer rt = timer("create WordTypes")) {
|
55509
|
131 |
wordTypes = createWordTypes(metaAccess, target);
|
43972
|
132 |
}
|
|
133 |
try (InitTimer rt = timer("create ForeignCalls provider")) {
|
|
134 |
foreignCalls = createForeignCalls(jvmciRuntime, graalRuntime, metaAccess, codeCache, wordTypes, nativeABICallerSaveRegisters);
|
|
135 |
}
|
|
136 |
try (InitTimer rt = timer("create Lowerer provider")) {
|
|
137 |
lowerer = createLowerer(graalRuntime, metaAccess, foreignCalls, registers, constantReflection, target);
|
|
138 |
}
|
55509
|
139 |
try (InitTimer rt = timer("create stamp provider")) {
|
|
140 |
stampProvider = createStampProvider();
|
|
141 |
}
|
|
142 |
try (InitTimer rt = timer("create GC provider")) {
|
|
143 |
gc = createGCProvider(config);
|
|
144 |
}
|
|
145 |
|
|
146 |
Providers p = new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, null, stampProvider, gc);
|
43972
|
147 |
|
|
148 |
try (InitTimer rt = timer("create SnippetReflection provider")) {
|
|
149 |
snippetReflection = createSnippetReflection(graalRuntime, constantReflection, wordTypes);
|
|
150 |
}
|
|
151 |
try (InitTimer rt = timer("create Bytecode provider")) {
|
55509
|
152 |
bytecodeProvider = createBytecodeProvider(metaAccess, snippetReflection);
|
43972
|
153 |
}
|
|
154 |
try (InitTimer rt = timer("create Replacements provider")) {
|
55509
|
155 |
replacements = createReplacements(target, p, snippetReflection, bytecodeProvider);
|
43972
|
156 |
}
|
|
157 |
try (InitTimer rt = timer("create GraphBuilderPhase plugins")) {
|
58299
|
158 |
plugins = createGraphBuilderPlugins(graalRuntime, compilerConfiguration, config, constantReflection, foreignCalls, metaAccess, snippetReflection, replacements, wordTypes,
|
|
159 |
graalRuntime.getOptions());
|
43972
|
160 |
replacements.setGraphBuilderPlugins(plugins);
|
|
161 |
}
|
|
162 |
try (InitTimer rt = timer("create Suites provider")) {
|
49873
|
163 |
suites = createSuites(config, graalRuntime, compilerConfiguration, plugins, replacements);
|
43972
|
164 |
}
|
46393
|
165 |
providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, suites, registers,
|
55509
|
166 |
snippetReflection, wordTypes, plugins, gc);
|
54601
|
167 |
replacements.setProviders(providers);
|
43972
|
168 |
}
|
|
169 |
try (InitTimer rt = timer("instantiate backend")) {
|
|
170 |
return createBackend(config, graalRuntime, providers);
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
58299
|
174 |
protected Plugins createGraphBuilderPlugins(HotSpotGraalRuntimeProvider graalRuntime,
|
|
175 |
CompilerConfiguration compilerConfiguration,
|
|
176 |
GraalHotSpotVMConfig config,
|
|
177 |
HotSpotConstantReflectionProvider constantReflection,
|
|
178 |
HotSpotHostForeignCallsProvider foreignCalls,
|
|
179 |
HotSpotMetaAccessProvider metaAccess,
|
|
180 |
HotSpotSnippetReflectionProvider snippetReflection,
|
|
181 |
HotSpotReplacementsImpl replacements,
|
|
182 |
HotSpotWordTypes wordTypes,
|
|
183 |
OptionValues options) {
|
|
184 |
Plugins plugins = HotSpotGraphBuilderPlugins.create(graalRuntime,
|
|
185 |
compilerConfiguration,
|
|
186 |
config,
|
|
187 |
wordTypes,
|
|
188 |
metaAccess,
|
|
189 |
constantReflection,
|
|
190 |
snippetReflection,
|
|
191 |
foreignCalls,
|
|
192 |
replacements,
|
|
193 |
options);
|
|
194 |
AArch64GraphBuilderPlugins.register(plugins, replacements.getDefaultReplacementBytecodeProvider(), false,
|
58533
|
195 |
/* registerMathPlugins */true, /* emitJDK9StringSubstitutions */true, config.useFMAIntrinsics);
|
43972
|
196 |
return plugins;
|
|
197 |
}
|
|
198 |
|
|
199 |
protected AArch64HotSpotBackend createBackend(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) {
|
|
200 |
return new AArch64HotSpotBackend(config, runtime, providers);
|
|
201 |
}
|
|
202 |
|
|
203 |
protected HotSpotRegistersProvider createRegisters() {
|
|
204 |
return new HotSpotRegisters(AArch64HotSpotRegisterConfig.threadRegister, AArch64HotSpotRegisterConfig.heapBaseRegister, sp);
|
|
205 |
}
|
|
206 |
|
50858
|
207 |
protected HotSpotHostForeignCallsProvider createForeignCalls(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalRuntimeProvider runtime, HotSpotMetaAccessProvider metaAccess,
|
43972
|
208 |
HotSpotCodeCacheProvider codeCache, WordTypes wordTypes, Value[] nativeABICallerSaveRegisters) {
|
|
209 |
return new AArch64HotSpotForeignCallsProvider(jvmciRuntime, runtime, metaAccess, codeCache, wordTypes, nativeABICallerSaveRegisters);
|
|
210 |
}
|
|
211 |
|
49873
|
212 |
protected HotSpotSuitesProvider createSuites(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, Plugins plugins,
|
|
213 |
@SuppressWarnings("unused") Replacements replacements) {
|
57537
|
214 |
AArch64SuitesCreator suitesCreator = new AArch64SuitesCreator(compilerConfiguration, plugins, Arrays.asList(SchedulePhase.class));
|
49873
|
215 |
Phase addressLoweringPhase = new AddressLoweringByUsePhase(new AArch64AddressLoweringByUse(new AArch64LIRKindTool()));
|
|
216 |
return new AddressLoweringHotSpotSuitesProvider(suitesCreator, config, runtime, addressLoweringPhase);
|
43972
|
217 |
}
|
|
218 |
|
|
219 |
protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider runtime, HotSpotMetaAccessProvider metaAccess, HotSpotForeignCallsProvider foreignCalls,
|
|
220 |
HotSpotRegistersProvider registers, HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
|
|
221 |
return new AArch64HotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, constantReflection, target);
|
|
222 |
}
|
|
223 |
|
|
224 |
protected static Value[] createNativeABICallerSaveRegisters(@SuppressWarnings("unused") GraalHotSpotVMConfig config, RegisterConfig regConfig) {
|
50330
|
225 |
List<Register> callerSave = new ArrayList<>(regConfig.getAllocatableRegisters().asList());
|
|
226 |
callerSave.remove(AArch64.r19);
|
|
227 |
callerSave.remove(AArch64.r20);
|
|
228 |
callerSave.remove(AArch64.r21);
|
|
229 |
callerSave.remove(AArch64.r22);
|
|
230 |
callerSave.remove(AArch64.r23);
|
|
231 |
callerSave.remove(AArch64.r24);
|
|
232 |
callerSave.remove(AArch64.r25);
|
|
233 |
callerSave.remove(AArch64.r26);
|
|
234 |
callerSave.remove(AArch64.r27);
|
|
235 |
callerSave.remove(AArch64.r28);
|
|
236 |
Value[] nativeABICallerSaveRegisters = new Value[callerSave.size()];
|
|
237 |
for (int i = 0; i < callerSave.size(); i++) {
|
|
238 |
nativeABICallerSaveRegisters[i] = callerSave.get(i).asValue();
|
43972
|
239 |
}
|
|
240 |
return nativeABICallerSaveRegisters;
|
|
241 |
}
|
|
242 |
|
|
243 |
@Override
|
|
244 |
public String toString() {
|
|
245 |
return "AArch64";
|
|
246 |
}
|
|
247 |
}
|