annotate graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILBackend.java @ 12363:78e5badf4b8e

moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
author Doug Simon <doug.simon@oracle.com>
date Sat, 12 Oct 2013 01:03:47 +0200
parents 0fc653a9e019
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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) 2013, 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 package com.oracle.graal.compiler.hsail;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import static com.oracle.graal.api.code.CallingConvention.Type.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import static com.oracle.graal.api.code.ValueUtil.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.api.code.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.asm.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.asm.hsail.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.compiler.gen.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.compiler.target.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.debug.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.lir.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.lir.asm.*;
10956
563c6d1994c0 added architecture specific frame maps
twisti
parents: 10662
diff changeset
37 import com.oracle.graal.lir.hsail.*;
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 import com.oracle.graal.nodes.*;
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
39 import com.oracle.graal.phases.util.*;
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.hsail.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 import java.util.Map;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 import java.util.HashMap;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 import java.lang.reflect.Modifier;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 import java.util.Arrays;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 * HSAIL specific backend.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 public class HSAILBackend extends Backend {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 private Map<String, String> paramTypeMap = new HashMap<>();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 private Buffer codeBuffer;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
55 public HSAILBackend(Providers providers, TargetDescription target) {
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
56 super(providers, target);
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 paramTypeMap.put("HotSpotResolvedPrimitiveType<int>", "s32");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 paramTypeMap.put("HotSpotResolvedPrimitiveType<float>", "f32");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 paramTypeMap.put("HotSpotResolvedPrimitiveType<double>", "f64");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 paramTypeMap.put("HotSpotResolvedPrimitiveType<long>", "s64");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62
11775
b04b94b71649 Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents: 11739
diff changeset
63 @Override
b04b94b71649 Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents: 11739
diff changeset
64 public boolean shouldAllocateRegisters() {
b04b94b71649 Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents: 11739
diff changeset
65 return true;
b04b94b71649 Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents: 11739
diff changeset
66 }
b04b94b71649 Finished PTX assembler and Register -> Variable conversion
Morris Meyer <morris.meyer@oracle.com>
parents: 11739
diff changeset
67
11739
b8695542d41b added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents: 10956
diff changeset
68 /**
b8695542d41b added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents: 10956
diff changeset
69 * Use the HSAIL register set when the compilation target is HSAIL.
b8695542d41b added HSAIL register configuration
Doug Simon <doug.simon@oracle.com>
parents: 10956
diff changeset
70 */
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 @Override
10956
563c6d1994c0 added architecture specific frame maps
twisti
parents: 10662
diff changeset
72 public FrameMap newFrameMap() {
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
73 return new HSAILFrameMap(getCodeCache(), target, new HSAILRegisterConfig());
10956
563c6d1994c0 added architecture specific frame maps
twisti
parents: 10662
diff changeset
74 }
563c6d1994c0 added architecture specific frame maps
twisti
parents: 10662
diff changeset
75
563c6d1994c0 added architecture specific frame maps
twisti
parents: 10662
diff changeset
76 @Override
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 public LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir) {
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
78 return new HSAILLIRGenerator(graph, getProviders(), target, frameMap, cc, lir);
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 public String getPartialCodeString() {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 return (codeBuffer == null ? "" : new String(codeBuffer.copyData(0, codeBuffer.position())));
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 class HotSpotFrameContext implements FrameContext {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 @Override
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 public void enter(TargetMethodAssembler tasm) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 Debug.log("Nothing to do here");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 }
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 @Override
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 public void leave(TargetMethodAssembler tasm) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 Debug.log("Nothing to do here");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 @Override
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 protected AbstractAssembler createAssembler(FrameMap frameMap) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 return new HSAILAssembler(target);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 @Override
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104 public TargetMethodAssembler newAssembler(LIRGenerator lirGen, CompilationResult compilationResult) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
105 FrameMap frameMap = lirGen.frameMap;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 AbstractAssembler masm = new HSAILAssembler(target);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107 HotSpotFrameContext frameContext = new HotSpotFrameContext();
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
108 TargetMethodAssembler tasm = new TargetMethodAssembler(target, getCodeCache(), getForeignCalls(), frameMap, masm, frameContext, compilationResult);
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 tasm.setFrameSize(frameMap.frameSize());
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 return tasm;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
111 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113 @Override
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
114 public void emitCode(TargetMethodAssembler tasm, LIRGenerator lirGen, ResolvedJavaMethod method) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
115 assert method != null : lirGen.getGraph() + " is not associated with a method";
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
116 // Emit the prologue.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
117 codeBuffer = tasm.asm.codeBuffer;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
118 codeBuffer.emitString0("version 0:95: $full : $large;");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
119 codeBuffer.emitString("");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
120 Signature signature = method.getSignature();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
121 int sigParamCount = signature.getParameterCount(false);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
122 // We're subtracting 1 because we're not making the final gid as a parameter.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
123 int nonConstantParamCount = sigParamCount - 1;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124 boolean isStatic = (Modifier.isStatic(method.getModifiers()));
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125 // Determine if this is an object lambda.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126 boolean isObjectLambda = true;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
127 if (signature.getParameterType(nonConstantParamCount, null).getKind() == Kind.Int) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
128 isObjectLambda = false;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 } else {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
130 // Add space for gid int reg.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
131 nonConstantParamCount++;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
132 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
134 // If this is an instance method, include mappings for the "this" parameter
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
135 // as the first parameter.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
136 if (!isStatic) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
137 nonConstantParamCount++;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
139 // Add in any "constant" parameters (currently none).
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
140 int totalParamCount = nonConstantParamCount;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141 JavaType[] paramtypes = new JavaType[totalParamCount];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 String[] paramNames = new String[totalParamCount];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 int pidx = 0;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 for (int i = 0; i < totalParamCount; i++) {
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
145 MetaAccessProvider metaAccess = getProviders().getMetaAccess();
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146 if (i == 0 && !isStatic) {
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
147 paramtypes[i] = metaAccess.lookupJavaType(Object.class);
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 paramNames[i] = "%_this";
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 } else if (i < nonConstantParamCount) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 if (isObjectLambda && (i == (nonConstantParamCount))) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 // Set up the gid register mapping.
12363
78e5badf4b8e moved lookupForeignCall() from CodeCacheProvider to ForeignCallsProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
152 paramtypes[i] = metaAccess.lookupJavaType(int.class);
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
153 paramNames[i] = "%_gid";
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
154 } else {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 paramtypes[i] = signature.getParameterType(pidx++, null);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156 paramNames[i] = "%_arg" + i;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
157 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
159 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 codeBuffer.emitString0("// " + (isStatic ? "static" : "instance") + " method " + method);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 codeBuffer.emitString("");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
162 codeBuffer.emitString0("kernel &run (");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
163 codeBuffer.emitString("");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
164 FrameMap frameMap = tasm.frameMap;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
165 RegisterConfig regConfig = frameMap.registerConfig;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
166 // Build list of param types which does include the gid (for cc register mapping query).
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
167 JavaType[] ccParamTypes = new JavaType[nonConstantParamCount + 1];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
168 // Include the gid.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
169 System.arraycopy(paramtypes, 0, ccParamTypes, 0, nonConstantParamCount);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170 // Last entry comes from the signature.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
171 ccParamTypes[ccParamTypes.length - 1] = signature.getParameterType(sigParamCount - 1, null);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
172 CallingConvention cc = regConfig.getCallingConvention(JavaCallee, null, ccParamTypes, target, false);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
174 * Compute the hsail size mappings up to but not including the last non-constant parameter
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
175 * (which is the gid).
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
176 *
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
177 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
178 String[] paramHsailSizes = new String[totalParamCount];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
179 for (int i = 0; i < totalParamCount; i++) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
180 String paramtypeStr = paramtypes[i].toString();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
181 String sizeStr = paramTypeMap.get(paramtypeStr);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 // Catch all for any unmapped paramtype that is u64 (address of an object).
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 paramHsailSizes[i] = (sizeStr != null ? sizeStr : "u64");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
184 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185 // Emit the kernel function parameters.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
186 for (int i = 0; i < totalParamCount; i++) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
187 String str = "kernarg_" + paramHsailSizes[i] + " " + paramNames[i];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
188 if (i != totalParamCount - 1) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
189 str += ",";
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191 codeBuffer.emitString(str);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
192 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
193 codeBuffer.emitString(") {");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
194
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
195 /*
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
196 * End of parameters start of prolog code. Emit the load instructions for loading of the
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
197 * kernel non-constant parameters into registers. The constant class parameters will not be
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
198 * loaded up front but will be loaded as needed.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
199 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
200 for (int i = 0; i < nonConstantParamCount; i++) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
201 codeBuffer.emitString("ld_kernarg_" + paramHsailSizes[i] + " " + HSAIL.mapRegister(cc.getArgument(i)) + ", [" + paramNames[i] + "];");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
202 }
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 /*
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
205 * Emit the workitemaid instruction for loading the hidden gid parameter. This is assigned
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
206 * the register as if it were the last of the nonConstant parameters.
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 String workItemReg = "$s" + Integer.toString(asRegister(cc.getArgument(nonConstantParamCount)).encoding());
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
209 codeBuffer.emitString("workitemabsid_u32 " + workItemReg + ", 0;");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
210
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
211 /*
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
212 * Note the logic used for this spillseg size is to leave space and then go back and patch
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
213 * in the correct size once we have generated all the instructions. This should probably be
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 * done in a more robust way by implementing something like codeBuffer.insertString.
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 int spillsegDeclarationPosition = codeBuffer.position() + 1;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
217 String spillsegTemplate = "align 4 spill_u8 %spillseg[123456];";
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
218 codeBuffer.emitString(spillsegTemplate);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
219 // Emit object array load prologue here.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
220 if (isObjectLambda) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
221 final int arrayElementsOffset = 24;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
222 String iterationObjArgReg = HSAIL.mapRegister(cc.getArgument(nonConstantParamCount - 1));
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
223 String tmpReg = workItemReg.replace("s", "d"); // "$d1";
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
224 // Convert gid to long.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
225 codeBuffer.emitString("cvt_u64_s32 " + tmpReg + ", " + workItemReg + "; // Convert gid to long");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
226 // Adjust index for sizeof ref.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
227 codeBuffer.emitString("mul_u64 " + tmpReg + ", " + tmpReg + ", " + 8 + "; // Adjust index for sizeof ref");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
228 // Adjust for actual data start.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
229 codeBuffer.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + arrayElementsOffset + "; // Adjust for actual elements data start");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
230 // Add to array ref ptr.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
231 codeBuffer.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + iterationObjArgReg + "; // Add to array ref ptr");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
232 // Load the object into the parameter reg.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
233 codeBuffer.emitString("ld_global_u64 " + iterationObjArgReg + ", " + "[" + tmpReg + "]" + "; // Load from array element into parameter reg");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
234 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
235 // Prologue done, Emit code for the LIR.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
236 lirGen.lir.emitCode(tasm);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
237 // Now that code is emitted go back and figure out what the upper Bound stack size was.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
238 long maxStackSize = ((HSAILAssembler) tasm.asm).upperBoundStackSize();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
239 String spillsegStringFinal;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
240 if (maxStackSize == 0) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
241 // If no spilling, get rid of spillseg declaration.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
242 char[] array = new char[spillsegTemplate.length()];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
243 Arrays.fill(array, ' ');
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
244 spillsegStringFinal = new String(array);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
245 } else {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
246 spillsegStringFinal = spillsegTemplate.replace("123456", String.format("%6d", maxStackSize));
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
247 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
248 codeBuffer.emitString(spillsegStringFinal, spillsegDeclarationPosition);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
249 // Emit the epilogue.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
250 codeBuffer.emitString0("};");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
251 codeBuffer.emitString("");
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
252 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
253 }