Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/target/amd64/AMD64GlobalStubEmitter.java @ 2677:0ea5f12e873a
use com.oracle.max.asm project for assembler
author | Christian.Wimmer@Oracle.com |
---|---|
date | Fri, 13 May 2011 17:09:20 -0700 |
parents | 16b9a8b5ad39 |
children | a2f62de90c76 |
comparison
equal
deleted
inserted
replaced
2676:e0e89714e2f1 | 2677:0ea5f12e873a |
---|---|
24 | 24 |
25 import static com.sun.cri.ci.CiCallingConvention.Type.*; | 25 import static com.sun.cri.ci.CiCallingConvention.Type.*; |
26 | 26 |
27 import java.util.*; | 27 import java.util.*; |
28 | 28 |
29 import com.oracle.max.asm.*; | |
30 import com.oracle.max.asm.target.amd64.*; | |
31 import com.oracle.max.asm.target.amd64.AMD64Assembler.*; | |
29 import com.sun.c1x.*; | 32 import com.sun.c1x.*; |
30 import com.sun.c1x.asm.*; | 33 import com.sun.c1x.asm.*; |
31 import com.sun.c1x.globalstub.*; | 34 import com.sun.c1x.globalstub.*; |
32 import com.sun.c1x.target.amd64.AMD64Assembler.ConditionFlag; | |
33 import com.sun.cri.ci.*; | 35 import com.sun.cri.ci.*; |
34 import com.sun.cri.ci.CiRegister.RegisterFlag; | 36 import com.sun.cri.ci.CiRegister.RegisterFlag; |
35 import com.sun.cri.ri.*; | 37 import com.sun.cri.ri.*; |
36 import com.sun.cri.xir.*; | 38 import com.sun.cri.xir.*; |
37 import com.sun.cri.xir.CiXirAssembler.XirConstant; | 39 import com.sun.cri.xir.CiXirAssembler.XirConstant; |
50 private static final CiRegister convertArgument = AMD64.xmm0; | 52 private static final CiRegister convertArgument = AMD64.xmm0; |
51 private static final CiRegister convertResult = AMD64.rax; | 53 private static final CiRegister convertResult = AMD64.rax; |
52 private static final CiRegister negateArgument = AMD64.xmm0; | 54 private static final CiRegister negateArgument = AMD64.xmm0; |
53 private static final CiRegister negateTemp = AMD64.xmm1; | 55 private static final CiRegister negateTemp = AMD64.xmm1; |
54 | 56 |
57 private TargetMethodAssembler tasm; | |
55 private AMD64MacroAssembler asm; | 58 private AMD64MacroAssembler asm; |
56 private final CiTarget target; | 59 private final CiTarget target; |
57 private int argsSize; | 60 private int argsSize; |
58 private int[] argOffsets; | 61 private int[] argOffsets; |
59 private int resultOffset; | 62 private int resultOffset; |
71 this.target = compiler.target; | 74 this.target = compiler.target; |
72 this.runtime = compiler.runtime; | 75 this.runtime = compiler.runtime; |
73 } | 76 } |
74 | 77 |
75 private void reset(CiKind resultKind, CiKind[] argTypes) { | 78 private void reset(CiKind resultKind, CiKind[] argTypes) { |
76 asm = new AMD64MacroAssembler.WithCompiler(compiler, compiler.globalStubRegisterConfig); | 79 asm = new AMD64MacroAssembler(compiler.target, compiler.globalStubRegisterConfig); |
80 tasm = new TargetMethodAssembler(asm); | |
77 saveSize = 0; | 81 saveSize = 0; |
78 argsSize = 0; | 82 argsSize = 0; |
79 argOffsets = new int[argTypes.length]; | 83 argOffsets = new int[argTypes.length]; |
80 resultOffset = 0; | 84 resultOffset = 0; |
81 registerRestoreEpilogueOffset = -1; | 85 registerRestoreEpilogueOffset = -1; |
96 | 100 |
97 public GlobalStub emit(CiRuntimeCall runtimeCall, RiRuntime runtime) { | 101 public GlobalStub emit(CiRuntimeCall runtimeCall, RiRuntime runtime) { |
98 reset(runtimeCall.resultKind, runtimeCall.arguments); | 102 reset(runtimeCall.resultKind, runtimeCall.arguments); |
99 emitStandardForward(null, runtimeCall); | 103 emitStandardForward(null, runtimeCall); |
100 String name = "stub-" + runtimeCall; | 104 String name = "stub-" + runtimeCall; |
101 CiTargetMethod targetMethod = asm.finishTargetMethod(name, runtime, registerRestoreEpilogueOffset, true); | 105 CiTargetMethod targetMethod = tasm.finishTargetMethod(name, runtime, registerRestoreEpilogueOffset, true); |
102 Object stubObject = runtime.registerGlobalStub(targetMethod, name); | 106 Object stubObject = runtime.registerGlobalStub(targetMethod, name); |
103 return new GlobalStub(null, runtimeCall.resultKind, stubObject, argsSize, argOffsets, resultOffset); | 107 return new GlobalStub(null, runtimeCall.resultKind, stubObject, argsSize, argOffsets, resultOffset); |
104 } | 108 } |
105 | 109 |
106 public GlobalStub emit(GlobalStub.Id stub, RiRuntime runtime) { | 110 public GlobalStub emit(GlobalStub.Id stub, RiRuntime runtime) { |
126 emitDNEG(); | 130 emitDNEG(); |
127 break; | 131 break; |
128 } | 132 } |
129 | 133 |
130 String name = "stub-" + stub; | 134 String name = "stub-" + stub; |
131 CiTargetMethod targetMethod = asm.finishTargetMethod(name, runtime, registerRestoreEpilogueOffset, true); | 135 CiTargetMethod targetMethod = tasm.finishTargetMethod(name, runtime, registerRestoreEpilogueOffset, true); |
132 Object stubObject = runtime.registerGlobalStub(targetMethod, name); | 136 Object stubObject = runtime.registerGlobalStub(targetMethod, name); |
133 return new GlobalStub(stub, stub.resultKind, stubObject, argsSize, argOffsets, resultOffset); | 137 return new GlobalStub(stub, stub.resultKind, stubObject, argsSize, argOffsets, resultOffset); |
134 } | 138 } |
135 | 139 |
136 private CiValue allocateParameterOperand(XirParameter param, int parameterIndex) { | 140 private CiValue allocateParameterOperand(XirParameter param, int parameterIndex) { |
169 reset(template.resultOperand.kind, getArgumentKinds(template)); | 173 reset(template.resultOperand.kind, getArgumentKinds(template)); |
170 compilation.initFrameMap(0); | 174 compilation.initFrameMap(0); |
171 compilation.frameMap().setFrameSize(frameSize()); | 175 compilation.frameMap().setFrameSize(frameSize()); |
172 AMD64LIRAssembler assembler = new AMD64LIRAssembler(compilation); | 176 AMD64LIRAssembler assembler = new AMD64LIRAssembler(compilation); |
173 asm = assembler.masm; | 177 asm = assembler.masm; |
178 tasm = assembler.tasm; | |
174 | 179 |
175 ArrayList<CiRegister> allocatableRegisters = new ArrayList<CiRegister>(Arrays.asList(compiler.globalStubRegisterConfig.getCategorizedAllocatableRegisters().get(RegisterFlag.CPU))); | 180 ArrayList<CiRegister> allocatableRegisters = new ArrayList<CiRegister>(Arrays.asList(compiler.globalStubRegisterConfig.getCategorizedAllocatableRegisters().get(RegisterFlag.CPU))); |
176 for (XirTemp t : template.temps) { | 181 for (XirTemp t : template.temps) { |
177 if (t instanceof XirRegister) { | 182 if (t instanceof XirRegister) { |
178 final XirRegister fixed = (XirRegister) t; | 183 final XirRegister fixed = (XirRegister) t; |
235 } | 240 } |
236 | 241 |
237 assert template.marks.length == 0 : "marks not supported in global stubs"; | 242 assert template.marks.length == 0 : "marks not supported in global stubs"; |
238 assembler.emitXirInstructions(null, template.fastPath, labels, operands, null); | 243 assembler.emitXirInstructions(null, template.fastPath, labels, operands, null); |
239 epilogue(); | 244 epilogue(); |
240 CiTargetMethod targetMethod = asm.finishTargetMethod(template.name, runtime, registerRestoreEpilogueOffset, true); | 245 CiTargetMethod targetMethod = tasm.finishTargetMethod(template.name, runtime, registerRestoreEpilogueOffset, true); |
241 Object stubObject = runtime.registerGlobalStub(targetMethod, template.name); | 246 Object stubObject = runtime.registerGlobalStub(targetMethod, template.name); |
242 return new GlobalStub(null, template.resultOperand.kind, stubObject, argsSize, argOffsets, resultOffset); | 247 return new GlobalStub(null, template.resultOperand.kind, stubObject, argsSize, argOffsets, resultOffset); |
243 } | 248 } |
244 | 249 |
245 private CiKind[] getArgumentKinds(XirTemplate template) { | 250 private CiKind[] getArgumentKinds(XirTemplate template) { |
261 epilogue(); | 266 epilogue(); |
262 } | 267 } |
263 | 268 |
264 private void emitDNEG() { | 269 private void emitDNEG() { |
265 negatePrologue(); | 270 negatePrologue(); |
266 asm.movsd(negateTemp, asm.recordDataReferenceInCode(CiConstant.forLong(DoubleSignFlip))); | 271 asm.movsd(negateTemp, tasm.recordDataReferenceInCode(CiConstant.forLong(DoubleSignFlip))); |
267 asm.xorpd(negateArgument, negateTemp); | 272 asm.xorpd(negateArgument, negateTemp); |
268 negateEpilogue(); | 273 negateEpilogue(); |
269 } | 274 } |
270 | 275 |
271 private void emitFNEG() { | 276 private void emitFNEG() { |
272 negatePrologue(); | 277 negatePrologue(); |
273 asm.movsd(negateTemp, asm.recordDataReferenceInCode(CiConstant.forLong(FloatSignFlip))); | 278 asm.movsd(negateTemp, tasm.recordDataReferenceInCode(CiConstant.forLong(FloatSignFlip))); |
274 asm.xorps(negateArgument, negateTemp); | 279 asm.xorps(negateArgument, negateTemp); |
275 negateEpilogue(); | 280 negateEpilogue(); |
276 } | 281 } |
277 | 282 |
278 private void convertPrologue() { | 283 private void convertPrologue() { |
302 } | 307 } |
303 | 308 |
304 private void emitCOMISSD(boolean isDouble, boolean isInt) { | 309 private void emitCOMISSD(boolean isDouble, boolean isInt) { |
305 convertPrologue(); | 310 convertPrologue(); |
306 if (isDouble) { | 311 if (isDouble) { |
307 asm.ucomisd(convertArgument, asm.recordDataReferenceInCode(CiConstant.DOUBLE_0)); | 312 asm.ucomisd(convertArgument, tasm.recordDataReferenceInCode(CiConstant.DOUBLE_0)); |
308 } else { | 313 } else { |
309 asm.ucomiss(convertArgument, asm.recordDataReferenceInCode(CiConstant.FLOAT_0)); | 314 asm.ucomiss(convertArgument, tasm.recordDataReferenceInCode(CiConstant.FLOAT_0)); |
310 } | 315 } |
311 Label nan = new Label(); | 316 Label nan = new Label(); |
312 Label ret = new Label(); | 317 Label ret = new Label(); |
313 asm.jccb(ConditionFlag.parity, nan); | 318 asm.jccb(ConditionFlag.parity, nan); |
314 asm.jccb(ConditionFlag.below, ret); | 319 asm.jccb(ConditionFlag.below, ret); |
370 for (CiRegister r : registersToSave) { | 375 for (CiRegister r : registersToSave) { |
371 asm.movq(new CiAddress(CiKind.Word, AMD64.RSP, index * target.arch.wordSize), r); | 376 asm.movq(new CiAddress(CiKind.Word, AMD64.RSP, index * target.arch.wordSize), r); |
372 index++; | 377 index++; |
373 } | 378 } |
374 | 379 |
375 asm.setFrameSize(frameSize()); | 380 tasm.setFrameSize(frameSize()); |
376 this.savedAllRegisters = false; | 381 this.savedAllRegisters = false; |
377 } | 382 } |
378 | 383 |
379 private void completeSavePrologue() { | 384 private void completeSavePrologue() { |
380 CiCalleeSaveArea csa = compiler.globalStubRegisterConfig.getCalleeSaveArea(); | 385 CiCalleeSaveArea csa = compiler.globalStubRegisterConfig.getCalleeSaveArea(); |
383 if (entryCodeOffset != 0) { | 388 if (entryCodeOffset != 0) { |
384 // align to code size | 389 // align to code size |
385 asm.nop(entryCodeOffset); | 390 asm.nop(entryCodeOffset); |
386 } | 391 } |
387 asm.subq(AMD64.rsp, frameSize()); | 392 asm.subq(AMD64.rsp, frameSize()); |
388 asm.setFrameSize(frameSize()); | 393 tasm.setFrameSize(frameSize()); |
389 int frameToCSA = 0; | 394 int frameToCSA = 0; |
390 asm.save(csa, frameToCSA); | 395 asm.save(csa, frameToCSA); |
391 this.savedAllRegisters = true; | 396 this.savedAllRegisters = true; |
392 } | 397 } |
393 | 398 |
424 CiValue location = cc.locations[i]; | 429 CiValue location = cc.locations[i]; |
425 loadArgument(i, location.asRegister()); | 430 loadArgument(i, location.asRegister()); |
426 } | 431 } |
427 | 432 |
428 // Call to the runtime | 433 // Call to the runtime |
429 asm.directCall(call, null); | 434 int before = asm.codeBuffer.position(); |
435 asm.call(); | |
436 int after = asm.codeBuffer.position(); | |
437 tasm.recordDirectCall(before, after, call, null); | |
430 | 438 |
431 if (call.resultKind != CiKind.Void) { | 439 if (call.resultKind != CiKind.Void) { |
432 CiRegister returnRegister = compiler.globalStubRegisterConfig.getReturnRegister(call.resultKind); | 440 CiRegister returnRegister = compiler.globalStubRegisterConfig.getReturnRegister(call.resultKind); |
433 this.storeArgument(0, returnRegister); | 441 this.storeArgument(0, returnRegister); |
434 } | 442 } |