Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/lir/LIRAssembler.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 | 9f557e940180 |
children | bd4c3be86fb7 7ed72769d51a |
comparison
equal
deleted
inserted
replaced
2676:e0e89714e2f1 | 2677:0ea5f12e873a |
---|---|
22 */ | 22 */ |
23 package com.sun.c1x.lir; | 23 package com.sun.c1x.lir; |
24 | 24 |
25 import java.util.*; | 25 import java.util.*; |
26 | 26 |
27 import com.oracle.max.asm.*; | |
27 import com.sun.c1x.*; | 28 import com.sun.c1x.*; |
28 import com.sun.c1x.asm.*; | 29 import com.sun.c1x.asm.*; |
29 import com.sun.c1x.debug.*; | 30 import com.sun.c1x.debug.*; |
30 import com.sun.c1x.gen.*; | 31 import com.sun.c1x.gen.*; |
31 import com.sun.c1x.ir.*; | 32 import com.sun.c1x.ir.*; |
36 import com.sun.cri.ri.*; | 37 import com.sun.cri.ri.*; |
37 import com.sun.cri.xir.CiXirAssembler.XirMark; | 38 import com.sun.cri.xir.CiXirAssembler.XirMark; |
38 | 39 |
39 /** | 40 /** |
40 * The {@code LIRAssembler} class definition. | 41 * The {@code LIRAssembler} class definition. |
41 * | |
42 * @author Marcelo Cintra | |
43 * @author Thomas Wuerthinger | |
44 * @author Ben L. Titzer | |
45 */ | 42 */ |
46 public abstract class LIRAssembler { | 43 public abstract class LIRAssembler { |
47 | 44 |
48 public final C1XCompilation compilation; | 45 public final C1XCompilation compilation; |
46 public final TargetMethodAssembler tasm; | |
49 public final AbstractAssembler asm; | 47 public final AbstractAssembler asm; |
50 public final FrameMap frameMap; | 48 public final FrameMap frameMap; |
51 public int registerRestoreEpilogueOffset = -1; | 49 public int registerRestoreEpilogueOffset = -1; |
52 | 50 |
53 protected final List<SlowPath> xirSlowPath; | 51 protected final List<SlowPath> xirSlowPath; |
67 } | 65 } |
68 } | 66 } |
69 | 67 |
70 public LIRAssembler(C1XCompilation compilation) { | 68 public LIRAssembler(C1XCompilation compilation) { |
71 this.compilation = compilation; | 69 this.compilation = compilation; |
72 this.asm = compilation.masm(); | 70 this.tasm = compilation.assembler(); |
71 this.asm = tasm.asm; | |
73 this.frameMap = compilation.frameMap(); | 72 this.frameMap = compilation.frameMap(); |
74 this.branchTargetBlocks = new ArrayList<BlockBegin>(); | 73 this.branchTargetBlocks = new ArrayList<BlockBegin>(); |
75 this.xirSlowPath = new ArrayList<SlowPath>(); | 74 this.xirSlowPath = new ArrayList<SlowPath>(); |
76 } | 75 } |
77 | 76 |
96 } | 95 } |
97 | 96 |
98 public abstract void emitTraps(); | 97 public abstract void emitTraps(); |
99 | 98 |
100 public void emitExceptionEntries() { | 99 public void emitExceptionEntries() { |
101 if (asm.exceptionInfoList == null) { | 100 if (tasm.exceptionInfoList == null) { |
102 return; | 101 return; |
103 } | 102 } |
104 for (ExceptionInfo ilist : asm.exceptionInfoList) { | 103 for (ExceptionInfo ilist : tasm.exceptionInfoList) { |
105 List<ExceptionHandler> handlers = ilist.exceptionHandlers; | 104 List<ExceptionHandler> handlers = ilist.exceptionHandlers; |
106 | 105 |
107 for (ExceptionHandler handler : handlers) { | 106 for (ExceptionHandler handler : handlers) { |
108 assert handler.lirOpId() != -1 : "handler not processed by LinearScan"; | 107 assert handler.lirOpId() != -1 : "handler not processed by LinearScan"; |
109 assert handler.entryCode() == null || handler.entryCode().instructionsList().get(handler.entryCode().instructionsList().size() - 1).code == LIROpcode.Branch : "last operation must be branch"; | 108 assert handler.entryCode() == null || handler.entryCode().instructionsList().get(handler.entryCode().instructionsList().size() - 1).code == LIROpcode.Branch : "last operation must be branch"; |
111 if (handler.entryCodeOffset() == -1) { | 110 if (handler.entryCodeOffset() == -1) { |
112 // entry code not emitted yet | 111 // entry code not emitted yet |
113 if (handler.entryCode() != null && handler.entryCode().instructionsList().size() > 1) { | 112 if (handler.entryCode() != null && handler.entryCode().instructionsList().size() > 1) { |
114 handler.setEntryCodeOffset(codePos()); | 113 handler.setEntryCodeOffset(codePos()); |
115 if (C1XOptions.CommentedAssembly) { | 114 if (C1XOptions.CommentedAssembly) { |
116 asm.blockComment("Exception adapter block"); | 115 tasm.blockComment("Exception adapter block"); |
117 } | 116 } |
118 emitLirList(handler.entryCode()); | 117 emitLirList(handler.entryCode()); |
119 } else { | 118 } else { |
120 handler.setEntryCodeOffset(handler.entryBlock().exceptionHandlerPco()); | 119 handler.setEntryCodeOffset(handler.entryBlock().exceptionHandlerPco()); |
121 } | 120 } |
155 } | 154 } |
156 | 155 |
157 assert block.lir() != null : "must have LIR"; | 156 assert block.lir() != null : "must have LIR"; |
158 if (C1XOptions.CommentedAssembly) { | 157 if (C1XOptions.CommentedAssembly) { |
159 String st = String.format(" block B%d [%d, %d]", block.blockID, block.bci(), block.end().bci()); | 158 String st = String.format(" block B%d [%d, %d]", block.blockID, block.bci(), block.end().bci()); |
160 asm.blockComment(st); | 159 tasm.blockComment(st); |
161 } | 160 } |
162 | 161 |
163 emitLirList(block.lir()); | 162 emitLirList(block.lir()); |
164 } | 163 } |
165 | 164 |
168 | 167 |
169 for (LIRInstruction op : list.instructionsList()) { | 168 for (LIRInstruction op : list.instructionsList()) { |
170 if (C1XOptions.CommentedAssembly) { | 169 if (C1XOptions.CommentedAssembly) { |
171 // Only print out branches | 170 // Only print out branches |
172 if (op.code == LIROpcode.Branch) { | 171 if (op.code == LIROpcode.Branch) { |
173 asm.blockComment(op.toStringWithIdPrefix()); | 172 tasm.blockComment(op.toStringWithIdPrefix()); |
174 } | 173 } |
175 } | 174 } |
176 if (C1XOptions.PrintLIRWithAssembly && !TTY.isSuppressed()) { | 175 if (C1XOptions.PrintLIRWithAssembly && !TTY.isSuppressed()) { |
177 // print out the LIR operation followed by the resulting assembly | 176 // print out the LIR operation followed by the resulting assembly |
178 TTY.println(op.toStringWithIdPrefix()); | 177 TTY.println(op.toStringWithIdPrefix()); |
218 switch (op.code) { | 217 switch (op.code) { |
219 case DirectCall: | 218 case DirectCall: |
220 emitCallAlignment(op.code); | 219 emitCallAlignment(op.code); |
221 // fall through | 220 // fall through |
222 case ConstDirectCall: | 221 case ConstDirectCall: |
223 if (op.marks != null) { | 222 if (op.marks != null) { |
224 op.marks.put(XirMark.CALLSITE, asm.recordMark(null, new Mark[0])); | 223 op.marks.put(XirMark.CALLSITE, tasm.recordMark(null, new Mark[0])); |
225 } | 224 } |
226 emitDirectCall(op.target, op.info); | 225 emitDirectCall(op.target, op.info); |
227 break; | 226 break; |
228 case IndirectCall: | 227 case IndirectCall: |
229 emitCallAlignment(op.code); | 228 emitCallAlignment(op.code); |
230 if (op.marks != null) { | 229 if (op.marks != null) { |
231 op.marks.put(XirMark.CALLSITE, asm.recordMark(null, new Mark[0])); | 230 op.marks.put(XirMark.CALLSITE, tasm.recordMark(null, new Mark[0])); |
232 } | 231 } |
233 emitIndirectCall(op.target, op.info, op.targetAddress()); | 232 emitIndirectCall(op.target, op.info, op.targetAddress()); |
234 break; | 233 break; |
235 case NativeCall: { | 234 case NativeCall: { |
236 emitNativeCall((String) op.target, op.info, op.targetAddress()); | 235 emitNativeCall((String) op.target, op.info, op.targetAddress()); |
272 break; | 271 break; |
273 case Lea: | 272 case Lea: |
274 emitLea(op.operand(), op.result()); | 273 emitLea(op.operand(), op.result()); |
275 break; | 274 break; |
276 case NullCheck: | 275 case NullCheck: |
277 assert op.operand().isRegister(); | 276 emitNullCheck(op.operand(), op.info); |
278 if (C1XOptions.NullCheckUniquePc) { | |
279 asm.nop(); | |
280 } | |
281 asm.recordImplicitException(codePos(), op.info); | |
282 asm.nullCheck(op.operand().asRegister()); | |
283 break; | 277 break; |
284 case Lsb: | 278 case Lsb: |
285 emitSignificantBitOp(false, op.operand(), op.result()); | 279 emitSignificantBitOp(false, op.operand(), op.result()); |
286 break; | 280 break; |
287 case Msb: | 281 case Msb: |
288 emitSignificantBitOp(true, op.operand(), op.result()); | 282 emitSignificantBitOp(true, op.operand(), op.result()); |
289 break; | 283 break; |
290 default: | 284 default: |
291 throw Util.shouldNotReachHere(); | 285 throw Util.shouldNotReachHere(); |
292 } | 286 } |
293 } | 287 } |
294 | 288 |
295 public void emitOp0(LIROp0 op) { | 289 public void emitOp0(LIROp0 op) { |
446 | 440 |
447 protected abstract void emitBreakpoint(); | 441 protected abstract void emitBreakpoint(); |
448 | 442 |
449 protected abstract void emitLea(CiValue src, CiValue dst); | 443 protected abstract void emitLea(CiValue src, CiValue dst); |
450 | 444 |
445 protected abstract void emitNullCheck(CiValue src, LIRDebugInfo info); | |
446 | |
451 protected abstract void emitNegate(LIRNegate negate); | 447 protected abstract void emitNegate(LIRNegate negate); |
452 | 448 |
453 protected abstract void emitHere(CiValue dst, LIRDebugInfo info, boolean infoOnly); | 449 protected abstract void emitHere(CiValue dst, LIRDebugInfo info, boolean infoOnly); |
454 | 450 |
455 protected abstract void emitMonitorAddress(int monitor, CiValue dst); | 451 protected abstract void emitMonitorAddress(int monitor, CiValue dst); |