Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java @ 2718:c1ce2a53d6c3
Attempt to remove dependency between backend and BlockBegin.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Thu, 19 May 2011 16:05:42 +0200 |
parents | c1a9bf38da28 |
children | c379183d1c54 |
comparison
equal
deleted
inserted
replaced
2717:bd85cf08720a | 2718:c1ce2a53d6c3 |
---|---|
54 import com.sun.cri.xir.CiXirAssembler.XirTemp; | 54 import com.sun.cri.xir.CiXirAssembler.XirTemp; |
55 import com.sun.cri.xir.*; | 55 import com.sun.cri.xir.*; |
56 | 56 |
57 /** | 57 /** |
58 * This class traverses the HIR instructions and generates LIR instructions from them. | 58 * This class traverses the HIR instructions and generates LIR instructions from them. |
59 * | |
60 * @author Thomas Wuerthinger | |
61 * @author Ben L. Titzer | |
62 * @author Marcelo Cintra | |
63 * @author Doug Simon | |
64 */ | 59 */ |
65 public abstract class LIRGenerator extends ValueVisitor { | 60 public abstract class LIRGenerator extends ValueVisitor { |
66 | 61 |
67 /** | 62 /** |
68 * Helper class for inserting memory barriers as necessary to implement the Java Memory Model | 63 * Helper class for inserting memory barriers as necessary to implement the Java Memory Model |
175 protected final IR ir; | 170 protected final IR ir; |
176 protected final XirSupport xirSupport; | 171 protected final XirSupport xirSupport; |
177 protected final RiXirGenerator xir; | 172 protected final RiXirGenerator xir; |
178 protected final boolean isTwoOperand; | 173 protected final boolean isTwoOperand; |
179 | 174 |
180 private BlockBegin currentBlock; | 175 private LIRBlock currentBlock; |
181 | 176 |
182 public final OperandPool operands; | 177 public final OperandPool operands; |
183 | 178 |
184 private Value currentInstruction; | 179 private Value currentInstruction; |
185 private Value lastInstructionPrinted; // Debugging only | 180 private Value lastInstructionPrinted; // Debugging only |
225 public DeoptimizationStub(FrameState state) { | 220 public DeoptimizationStub(FrameState state) { |
226 info = new LIRDebugInfo(state, null); | 221 info = new LIRDebugInfo(state, null); |
227 } | 222 } |
228 } | 223 } |
229 | 224 |
230 public void doBlock(BlockBegin block) { | 225 public void doBlock(LIRBlock block) { |
231 blockDoProlog(block); | 226 blockDoProlog(block); |
232 this.currentBlock = block; | 227 this.currentBlock = block; |
233 | 228 |
234 if (C1XOptions.TraceLIRGeneratorLevel >= 1) { | 229 if (C1XOptions.TraceLIRGeneratorLevel >= 1) { |
235 TTY.println("BEGIN Generating LIR for block B" + block.blockID); | 230 TTY.println("BEGIN Generating LIR for block B" + block.blockID()); |
236 } | 231 } |
237 | 232 |
238 for (Instruction instr = block; instr != null; instr = instr.next()) { | 233 for (Instruction instr : block.getInstructions()) { |
239 FrameState stateAfter = instr.stateAfter(); | 234 FrameState stateAfter = instr.stateAfter(); |
240 FrameState stateBefore = null; | 235 FrameState stateBefore = null; |
241 if (instr instanceof StateSplit && ((StateSplit) instr).stateBefore() != null) { | 236 if (instr instanceof StateSplit && ((StateSplit) instr).stateBefore() != null) { |
242 stateBefore = ((StateSplit) instr).stateBefore(); | 237 stateBefore = ((StateSplit) instr).stateBefore(); |
243 } | 238 } |
264 } | 259 } |
265 } | 260 } |
266 } | 261 } |
267 | 262 |
268 if (C1XOptions.TraceLIRGeneratorLevel >= 1) { | 263 if (C1XOptions.TraceLIRGeneratorLevel >= 1) { |
269 TTY.println("END Generating LIR for block B" + block.blockID); | 264 TTY.println("END Generating LIR for block B" + block.blockID()); |
270 } | 265 } |
271 | 266 |
272 this.currentBlock = null; | 267 this.currentBlock = null; |
273 blockDoEpilog(block); | 268 blockDoEpilog(); |
274 } | 269 } |
275 | 270 |
276 @Override | 271 @Override |
277 public void visitArrayLength(ArrayLength x) { | 272 public void visitArrayLength(ArrayLength x) { |
278 emitArrayLength(x); | 273 emitArrayLength(x); |
393 } | 388 } |
394 } | 389 } |
395 | 390 |
396 @Override | 391 @Override |
397 public void visitExceptionObject(ExceptionObject x) { | 392 public void visitExceptionObject(ExceptionObject x) { |
398 assert currentBlock.next() == x : "ExceptionObject must be first instruction of block"; | |
399 | 393 |
400 // no moves are created for phi functions at the begin of exception | 394 // no moves are created for phi functions at the begin of exception |
401 // handlers, so assign operands manually here | 395 // handlers, so assign operands manually here |
402 currentBlock.stateBefore().forEachLivePhi(currentBlock, new PhiProcedure() { | 396 currentBlock.stateBefore().forEachLivePhi(currentBlock.blockID(), new PhiProcedure() { |
403 public boolean doPhi(Phi phi) { | 397 public boolean doPhi(Phi phi) { |
404 operandForPhi(phi); | 398 operandForPhi(phi); |
405 return true; | 399 return true; |
406 } | 400 } |
407 }); | 401 }); |
888 DeoptimizationStub stub = new DeoptimizationStub(lastState); | 882 DeoptimizationStub stub = new DeoptimizationStub(lastState); |
889 addDeoptimizationStub(stub); | 883 addDeoptimizationStub(stub); |
890 lir.branch(Condition.TRUE, stub.label, stub.info); | 884 lir.branch(Condition.TRUE, stub.label, stub.info); |
891 } | 885 } |
892 | 886 |
893 private void blockDoEpilog(BlockBegin block) { | 887 private void blockDoEpilog() { |
894 if (C1XOptions.PrintIRWithLIR) { | 888 if (C1XOptions.PrintIRWithLIR) { |
895 TTY.println(); | 889 TTY.println(); |
896 } | 890 } |
897 | 891 |
898 // clear out variables for local constants | 892 // clear out variables for local constants |
899 constants.clear(); | 893 constants.clear(); |
900 variablesForConstants.clear(); | 894 variablesForConstants.clear(); |
901 } | 895 } |
902 | 896 |
903 private void blockDoProlog(BlockBegin block) { | 897 private void blockDoProlog(LIRBlock block) { |
904 if (C1XOptions.PrintIRWithLIR) { | 898 if (C1XOptions.PrintIRWithLIR) { |
905 TTY.print(block.toString()); | 899 TTY.print(block.toString()); |
906 } | 900 } |
907 // set up the list of LIR instructions | 901 // set up the list of LIR instructions |
908 assert block.lir() == null : "LIR list already computed for this block"; | 902 assert block.lir() == null : "LIR list already computed for this block"; |
913 if (block == ir.startBlock) { | 907 if (block == ir.startBlock) { |
914 XirSnippet prologue = xir.genPrologue(null, compilation.method); | 908 XirSnippet prologue = xir.genPrologue(null, compilation.method); |
915 if (prologue != null) { | 909 if (prologue != null) { |
916 emitXir(prologue, null, null, null, false); | 910 emitXir(prologue, null, null, null, false); |
917 } | 911 } |
918 setOperandsForLocals(block.end().stateAfter()); | 912 setOperandsForLocals(ir.getHIRStartBlock().end().stateAfter()); |
919 } | 913 } |
920 } | 914 } |
921 | 915 |
922 /** | 916 /** |
923 * Copies a given value into an operand that is forced to be a stack location. | 917 * Copies a given value into an operand that is forced to be a stack location. |
1285 this.moveToPhi(lastState); | 1279 this.moveToPhi(lastState); |
1286 } | 1280 } |
1287 | 1281 |
1288 protected void moveToPhi(FrameState curState) { | 1282 protected void moveToPhi(FrameState curState) { |
1289 // Moves all stack values into their phi position | 1283 // Moves all stack values into their phi position |
1290 BlockBegin bb = currentBlock; | 1284 LIRBlock bb = currentBlock; |
1291 if (bb.numberOfSux() == 1) { | 1285 if (bb.numberOfSux() == 1) { |
1292 BlockBegin sux = bb.suxAt(0); | 1286 LIRBlock sux = bb.suxAt(0); |
1293 assert sux.numberOfPreds() > 0 : "invalid CFG"; | 1287 assert sux.numberOfPreds() > 0 : "invalid CFG"; |
1294 | 1288 |
1295 // a block with only one predecessor never has phi functions | 1289 // a block with only one predecessor never has phi functions |
1296 if (sux.numberOfPreds() > 1) { | 1290 if (sux.numberOfPreds() > 1) { |
1297 PhiResolver resolver = new PhiResolver(this); | 1291 PhiResolver resolver = new PhiResolver(this); |
1435 if (compilation.placeholderState != null) { | 1429 if (compilation.placeholderState != null) { |
1436 state = compilation.placeholderState; | 1430 state = compilation.placeholderState; |
1437 } | 1431 } |
1438 | 1432 |
1439 assert state != null; | 1433 assert state != null; |
1440 return new LIRDebugInfo(state, (x instanceof ExceptionEdgeInstruction) ? ((ExceptionEdgeInstruction) x).exceptionEdge() : null); | 1434 LIRBlock exceptionEdge = null; |
1435 if (x instanceof ExceptionEdgeInstruction) { | |
1436 BlockBegin begin = ((ExceptionEdgeInstruction) x).exceptionEdge(); | |
1437 if (begin != null) { | |
1438 exceptionEdge = begin.lirBlock(); | |
1439 } | |
1440 } | |
1441 return new LIRDebugInfo(state, exceptionEdge); | |
1441 } | 1442 } |
1442 | 1443 |
1443 List<CiValue> visitInvokeArguments(CiCallingConvention cc, Invoke x, List<CiValue> pointerSlots) { | 1444 List<CiValue> visitInvokeArguments(CiCallingConvention cc, Invoke x, List<CiValue> pointerSlots) { |
1444 // for each argument, load it into the correct location | 1445 // for each argument, load it into the correct location |
1445 List<CiValue> argList = new ArrayList<CiValue>(x.argumentCount()); | 1446 List<CiValue> argList = new ArrayList<CiValue>(x.argumentCount()); |