Mercurial > hg > truffle
annotate graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java @ 13229:325b4e4efb60
added CompilationResultBuilderFactory to support peep-hole instrumentation of methods as their code is emitted
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 03 Dec 2013 16:33:41 +0100 |
parents | 4568980f7257 |
children | bb35fc7e0d68 |
rev | line source |
---|---|
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
12363
diff
changeset
|
24 package com.oracle.graal.hotspot.hsail; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
26 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
27 |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
28 import java.lang.reflect.*; |
13229
325b4e4efb60
added CompilationResultBuilderFactory to support peep-hole instrumentation of methods as their code is emitted
Doug Simon <doug.simon@oracle.com>
parents:
13228
diff
changeset
|
29 |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.code.*; |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
31 import com.oracle.graal.api.code.CallingConvention.Type; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.api.meta.*; |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
33 import com.oracle.graal.api.runtime.*; |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
34 import com.oracle.graal.compiler.*; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.debug.*; |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
36 import com.oracle.graal.graph.*; |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
37 import com.oracle.graal.graph.iterators.*; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
38 import com.oracle.graal.hotspot.*; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
39 import com.oracle.graal.hotspot.bridge.CompilerToGPU; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
12363
diff
changeset
|
40 import com.oracle.graal.hotspot.meta.*; |
12488
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12474
diff
changeset
|
41 import com.oracle.graal.hsail.*; |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
42 import com.oracle.graal.java.*; |
13229
325b4e4efb60
added CompilationResultBuilderFactory to support peep-hole instrumentation of methods as their code is emitted
Doug Simon <doug.simon@oracle.com>
parents:
13228
diff
changeset
|
43 import com.oracle.graal.lir.asm.*; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 import com.oracle.graal.nodes.*; |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
45 import com.oracle.graal.nodes.java.MethodCallTargetNode; |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
46 import com.oracle.graal.nodes.type.*; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 import com.oracle.graal.phases.*; |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
48 import com.oracle.graal.phases.PhasePlan.PhasePosition; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 import com.oracle.graal.phases.tiers.*; |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
50 import com.oracle.graal.phases.util.*; |
12488
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12474
diff
changeset
|
51 import com.oracle.graal.runtime.*; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 /** |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 * Class that represents a HSAIL compilation result. Includes the compiled HSAIL code. |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 */ |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
56 public class HSAILCompilationResult extends ExternalCompilationResult { |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 |
12474
f04f58c8206b
made HSAILCompilationResult subclass CompilationResult
Doug Simon <doug.simon@oracle.com>
parents:
12465
diff
changeset
|
58 private static final long serialVersionUID = -4178700465275724625L; |
f04f58c8206b
made HSAILCompilationResult subclass CompilationResult
Doug Simon <doug.simon@oracle.com>
parents:
12465
diff
changeset
|
59 |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
60 private static CompilerToGPU toGPU = HotSpotGraalRuntime.runtime().getCompilerToGPU(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
61 private static boolean validDevice = toGPU.deviceInit(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
62 |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
63 // The installedCode is the executable representation of the kernel in the code cache |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
64 private InstalledCode installedCode; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
65 |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
66 public void setInstalledCode(InstalledCode newCode) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
67 installedCode = newCode; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
68 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
69 |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
70 public InstalledCode getInstalledCode() { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
71 return installedCode; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
72 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
73 |
12465
9c35e2cef4a2
removed yet more uses of HotSpotGraalRuntime.getHostProviders() (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12456
diff
changeset
|
74 static final HSAILHotSpotBackend backend; |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
75 static { |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
76 // Look for installed HSAIL backend |
12488
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12474
diff
changeset
|
77 RuntimeProvider runtime = Graal.getRequiredCapability(RuntimeProvider.class); |
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12474
diff
changeset
|
78 HSAILHotSpotBackend b = (HSAILHotSpotBackend) runtime.getBackend(HSAIL.class); |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
79 if (b == null) { |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
80 // Fall back to a new instance |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
81 b = new HSAILHotSpotBackendFactory().createBackend(runtime(), runtime().getHostBackend()); |
12580
7876c59a7a2f
refactored all deferred initialization of backends into HotSpotBackend
Doug Simon <doug.simon@oracle.com>
parents:
12488
diff
changeset
|
82 b.completeInitialization(); |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
83 } |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
84 backend = b; |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
85 } |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
12363
diff
changeset
|
86 |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 public static HSAILCompilationResult getHSAILCompilationResult(Method meth) { |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
88 HotSpotMetaAccessProvider metaAccess = backend.getProviders().getMetaAccess(); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11739
diff
changeset
|
89 ResolvedJavaMethod javaMethod = metaAccess.lookupJavaMethod(meth); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 return getHSAILCompilationResult(javaMethod); |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 public static HSAILCompilationResult getHSAILCompilationResult(ResolvedJavaMethod javaMethod) { |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
94 HotSpotMetaAccessProvider metaAccess = backend.getProviders().getMetaAccess(); |
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
95 ForeignCallsProvider foreignCalls = backend.getProviders().getForeignCalls(); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 StructuredGraph graph = new StructuredGraph(javaMethod); |
12362
f53dc8bbb88c
refactored isReexecutable(), getKilledLocations() and canDeoptimize() out of MetaAccessProvider into ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12054
diff
changeset
|
97 new GraphBuilderPhase(metaAccess, foreignCalls, GraphBuilderConfiguration.getEagerDefault(), OptimisticOptimizations.ALL).apply(graph); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 return getHSAILCompilationResult(graph); |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
101 /** |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
102 * HSAIL doesn't have a calling convention as such. Function arguments are actually passed in |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
103 * memory but then loaded into registers in the function body. This routine makes sure that |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
104 * arguments to a kernel or function are loaded (by the kernel or function body) into registers |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
105 * of the appropriate sizes. For example, int and float parameters should appear in S registers, |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
106 * whereas double and long parameters should appear in d registers. |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
107 */ |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
108 public static CallingConvention getHSAILCallingConvention(CallingConvention.Type type, TargetDescription target, ResolvedJavaMethod method, boolean stackOnly) { |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
109 Signature sig = method.getSignature(); |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
110 JavaType retType = sig.getReturnType(null); |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
111 int sigCount = sig.getParameterCount(false); |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
112 JavaType[] argTypes; |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
113 int argIndex = 0; |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
114 if (!Modifier.isStatic(method.getModifiers())) { |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
115 argTypes = new JavaType[sigCount + 1]; |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
116 argTypes[argIndex++] = method.getDeclaringClass(); |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
117 } else { |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
118 argTypes = new JavaType[sigCount]; |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
119 } |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
120 for (int i = 0; i < sigCount; i++) { |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
121 argTypes[argIndex++] = sig.getParameterType(i, null); |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
122 } |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
123 |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
124 RegisterConfig registerConfig = backend.getProviders().getCodeCache().getRegisterConfig(); |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
125 return registerConfig.getCallingConvention(type, retType, argTypes, target, stackOnly); |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
126 } |
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
127 |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
128 public static HSAILCompilationResult getCompiledLambda(Class consumerClass) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
129 /** |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
130 * Find the accept() method in the IntConsumer, then use Graal API to find the target lambda |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
131 * that accept will call. |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
132 */ |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
133 Method[] icMethods = consumerClass.getMethods(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
134 Method acceptMethod = null; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
135 for (Method m : icMethods) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
136 if (m.getName().equals("accept") && acceptMethod == null) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
137 acceptMethod = m; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
138 break; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
139 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
140 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
141 |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
142 Providers providers = backend.getProviders(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
143 HotSpotMetaAccessProvider metaAccess = (HotSpotMetaAccessProvider) providers.getMetaAccess(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
144 ResolvedJavaMethod rm = metaAccess.lookupJavaMethod(acceptMethod); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
145 StructuredGraph graph = new StructuredGraph(rm); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
146 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(providers.getMetaAccess(), providers.getForeignCalls(), GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
147 graphBuilderPhase.apply(graph); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
148 NodeIterable<Node> nin = graph.getNodes(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
149 ResolvedJavaMethod lambdaMethod = null; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
150 for (Node n : nin) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
151 if (n instanceof MethodCallTargetNode) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
152 lambdaMethod = ((MethodCallTargetNode) n).targetMethod(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
153 Debug.log("target ... " + lambdaMethod); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
154 break; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
155 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
156 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
157 if (lambdaMethod == null) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
158 // Did not find call in Consumer.accept. |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
159 Debug.log("Should not Reach here, did not find call in accept()"); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
160 return null; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
161 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
162 // Now that we have the target lambda, compile it. |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
163 HSAILCompilationResult hsailCompResult = HSAILCompilationResult.getHSAILCompilationResult(lambdaMethod); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
164 return hsailCompResult; |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
165 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
166 |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 public static HSAILCompilationResult getHSAILCompilationResult(StructuredGraph graph) { |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
168 Debug.dump(graph, "Graph"); |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
169 Providers providers = backend.getProviders(); |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
12363
diff
changeset
|
170 TargetDescription target = providers.getCodeCache().getTarget(); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
171 PhasePlan phasePlan = new PhasePlan(); |
12362
f53dc8bbb88c
refactored isReexecutable(), getKilledLocations() and canDeoptimize() out of MetaAccessProvider into ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12054
diff
changeset
|
172 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(providers.getMetaAccess(), providers.getForeignCalls(), GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.NONE); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
173 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
174 phasePlan.addPhase(PhasePosition.AFTER_PARSING, new HSAILPhase()); |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 new HSAILPhase().apply(graph); |
11739
b8695542d41b
added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
176 CallingConvention cc = getHSAILCallingConvention(Type.JavaCallee, target, graph.method(), false); |
12488
1a4dc163cd0a
abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12474
diff
changeset
|
177 SuitesProvider suitesProvider = backend.getSuites(); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 try { |
12474
f04f58c8206b
made HSAILCompilationResult subclass CompilationResult
Doug Simon <doug.simon@oracle.com>
parents:
12465
diff
changeset
|
179 HSAILCompilationResult compResult = GraalCompiler.compileGraph(graph, cc, graph.method(), providers, backend, target, null, phasePlan, OptimisticOptimizations.NONE, new SpeculationLog(), |
13229
325b4e4efb60
added CompilationResultBuilderFactory to support peep-hole instrumentation of methods as their code is emitted
Doug Simon <doug.simon@oracle.com>
parents:
13228
diff
changeset
|
180 suitesProvider.getDefaultSuites(), true, new HSAILCompilationResult(), CompilationResultBuilderFactory.Default); |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
181 if ((validDevice) && (compResult.getTargetCode() != null)) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
182 long kernel = toGPU.generateKernel(compResult.getTargetCode(), graph.method().getName()); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
183 |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
184 if (kernel == 0) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
185 throw new GraalInternalError("Failed to compile kernel."); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
186 } |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
187 |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
188 ((ExternalCompilationResult) compResult).setEntryPoint(kernel); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
189 HotSpotResolvedJavaMethod compiledMethod = (HotSpotResolvedJavaMethod) graph.method(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
190 InstalledCode installedCode = ((HotSpotCodeCacheProvider) providers.getCodeCache()).addExternalMethod(compiledMethod, compResult); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
191 compResult.setInstalledCode(installedCode); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
192 } |
12474
f04f58c8206b
made HSAILCompilationResult subclass CompilationResult
Doug Simon <doug.simon@oracle.com>
parents:
12465
diff
changeset
|
193 return compResult; |
12743
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
194 } catch (InvalidInstalledCodeException e) { |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
195 e.printStackTrace(); |
f1a55428a8d7
more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents:
12580
diff
changeset
|
196 return null; |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
197 } catch (GraalInternalError e) { |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
198 String partialCode = backend.getPartialCodeString(); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
199 if (partialCode != null && !partialCode.equals("")) { |
13105
d3fc35a43376
HSAIL: addressed issues in JUnit tests
Doug Simon <doug.simon@oracle.com>
parents:
12743
diff
changeset
|
200 Debug.log("-------------------\nPartial Code Generation:\n--------------------"); |
d3fc35a43376
HSAIL: addressed issues in JUnit tests
Doug Simon <doug.simon@oracle.com>
parents:
12743
diff
changeset
|
201 Debug.log(partialCode); |
d3fc35a43376
HSAIL: addressed issues in JUnit tests
Doug Simon <doug.simon@oracle.com>
parents:
12743
diff
changeset
|
202 Debug.log("-------------------\nEnd of Partial Code Generation\n--------------------"); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
203 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
204 throw e; |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
205 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
206 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
207 |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
208 private static class HSAILPhase extends Phase { |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
209 |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
210 @Override |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
211 protected void run(StructuredGraph graph) { |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
212 for (LocalNode local : graph.getNodes(LocalNode.class)) { |
11265 | 213 if (local.stamp() instanceof ObjectStamp) { |
214 local.setStamp(StampFactory.declaredNonNull(((ObjectStamp) local.stamp()).type())); | |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
215 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
216 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
217 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
218 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
219 |
12474
f04f58c8206b
made HSAILCompilationResult subclass CompilationResult
Doug Simon <doug.simon@oracle.com>
parents:
12465
diff
changeset
|
220 protected HSAILCompilationResult() { |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
221 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
222 |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
223 public String getHSAILCode() { |
12474
f04f58c8206b
made HSAILCompilationResult subclass CompilationResult
Doug Simon <doug.simon@oracle.com>
parents:
12465
diff
changeset
|
224 return new String(getTargetCode(), 0, getTargetCodeSize()); |
10662
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
225 } |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
226 |
4ef92b67aeae
added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
227 } |