Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java @ 2823:ac4b086cbd72
Merge
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Mon, 30 May 2011 16:35:08 +0200 |
parents | 530366123e46 d27bdbec3d67 |
children | 9ba6a8abe894 |
comparison
equal
deleted
inserted
replaced
2822:530366123e46 | 2823:ac4b086cbd72 |
---|---|
196 | 196 |
197 constants = new ArrayList<CiConstant>(); | 197 constants = new ArrayList<CiConstant>(); |
198 variablesForConstants = new ArrayList<CiVariable>(); | 198 variablesForConstants = new ArrayList<CiVariable>(); |
199 | 199 |
200 this.operands = new OperandPool(compilation.target); | 200 this.operands = new OperandPool(compilation.target); |
201 | |
202 new PhiSimplifier(ir); | |
203 } | 201 } |
204 | 202 |
205 public ArrayList<DeoptimizationStub> deoptimizationStubs() { | 203 public ArrayList<DeoptimizationStub> deoptimizationStubs() { |
206 return deoptimizationStubs; | 204 return deoptimizationStubs; |
207 } | 205 } |
228 | 226 |
229 if (C1XOptions.TraceLIRGeneratorLevel >= 1) { | 227 if (C1XOptions.TraceLIRGeneratorLevel >= 1) { |
230 TTY.println("BEGIN Generating LIR for block B" + block.blockID()); | 228 TTY.println("BEGIN Generating LIR for block B" + block.blockID()); |
231 } | 229 } |
232 | 230 |
233 for (Instruction instr : block.getInstructions()) { | 231 if (block.blockPredecessors().size() > 1) { |
234 FrameState stateAfter = instr.stateAfter(); | 232 lastState = null; |
233 } | |
234 | |
235 for (Node instr : block.getInstructions()) { | |
236 FrameState stateAfter = null; | |
237 if (instr instanceof Instruction) { | |
238 stateAfter = ((Instruction) instr).stateAfter(); | |
239 } | |
235 FrameState stateBefore = null; | 240 FrameState stateBefore = null; |
236 if (instr instanceof StateSplit && ((StateSplit) instr).stateBefore() != null) { | 241 if (instr instanceof StateSplit && ((StateSplit) instr).stateBefore() != null) { |
237 stateBefore = ((StateSplit) instr).stateBefore(); | 242 stateBefore = ((StateSplit) instr).stateBefore(); |
238 } | 243 } |
239 if (stateBefore != null) { | 244 if (stateBefore != null) { |
243 if (C1XOptions.TraceLIRGeneratorLevel >= 3) { | 248 if (C1XOptions.TraceLIRGeneratorLevel >= 3) { |
244 TTY.println(stateBefore.toString()); | 249 TTY.println(stateBefore.toString()); |
245 } | 250 } |
246 } | 251 } |
247 } | 252 } |
248 if (!(instr instanceof Merge)) { | 253 if (!(instr instanceof Merge) && instr != instr.graph().start()) { |
249 walkState(instr, stateAfter); | 254 walkState(instr, stateAfter); |
250 doRoot(instr); | 255 doRoot((Value) instr); |
251 } | 256 } |
252 if (stateAfter != null) { | 257 if (stateAfter != null) { |
253 lastState = stateAfter; | 258 lastState = stateAfter; |
254 if (C1XOptions.TraceLIRGeneratorLevel >= 2) { | 259 if (C1XOptions.TraceLIRGeneratorLevel >= 2) { |
255 TTY.println("STATE CHANGE"); | 260 TTY.println("STATE CHANGE"); |
271 block.setLastState(lastState); | 276 block.setLastState(lastState); |
272 this.currentBlock = null; | 277 this.currentBlock = null; |
273 blockDoEpilog(); | 278 blockDoEpilog(); |
274 } | 279 } |
275 | 280 |
276 private static boolean jumpsToNextBlock(Instruction instr) { | 281 private static boolean jumpsToNextBlock(Node node) { |
277 return instr instanceof BlockEnd; | 282 return node instanceof BlockEnd; |
278 } | 283 } |
279 | 284 |
280 @Override | 285 @Override |
281 public void visitArrayLength(ArrayLength x) { | 286 public void visitArrayLength(ArrayLength x) { |
282 emitArrayLength(x); | 287 emitArrayLength(x); |
693 return item.result(); | 698 return item.result(); |
694 } | 699 } |
695 } | 700 } |
696 } | 701 } |
697 | 702 |
698 protected CiValue emitXir(XirSnippet snippet, Instruction x, LIRDebugInfo info, RiMethod method, boolean setInstructionResult) { | 703 protected CiValue emitXir(XirSnippet snippet, Value x, LIRDebugInfo info, RiMethod method, boolean setInstructionResult) { |
699 return emitXir(snippet, x, info, null, method, setInstructionResult, null); | 704 return emitXir(snippet, x, info, null, method, setInstructionResult, null); |
700 } | 705 } |
701 | 706 |
702 protected CiValue emitXir(XirSnippet snippet, Instruction instruction, LIRDebugInfo info, LIRDebugInfo infoAfter, RiMethod method, boolean setInstructionResult, List<CiValue> pointerSlots) { | 707 protected CiValue emitXir(XirSnippet snippet, Value instruction, LIRDebugInfo info, LIRDebugInfo infoAfter, RiMethod method, boolean setInstructionResult, List<CiValue> pointerSlots) { |
703 if (C1XOptions.PrintXirTemplates) { | 708 if (C1XOptions.PrintXirTemplates) { |
704 TTY.println("Emit XIR template " + snippet.template.name); | 709 TTY.println("Emit XIR template " + snippet.template.name); |
705 } | 710 } |
706 | 711 |
707 final CiValue[] operands = new CiValue[snippet.template.variableCount]; | 712 final CiValue[] operands = new CiValue[snippet.template.variableCount]; |
1223 } | 1228 } |
1224 } | 1229 } |
1225 return res.toArray(new SwitchRange[res.size()]); | 1230 return res.toArray(new SwitchRange[res.size()]); |
1226 } | 1231 } |
1227 | 1232 |
1228 void doRoot(Instruction instr) { | 1233 void doRoot(Value instr) { |
1229 if (C1XOptions.TraceLIRGeneratorLevel >= 2) { | 1234 if (C1XOptions.TraceLIRGeneratorLevel >= 2) { |
1230 TTY.println("Emitting LIR for instruction " + instr.toString()); | 1235 TTY.println("Emitting LIR for instruction " + instr); |
1231 } | 1236 } |
1232 currentInstruction = instr; | 1237 currentInstruction = instr; |
1233 assert !instr.hasSubst() : "shouldn't have missed substitution"; | |
1234 | 1238 |
1235 if (C1XOptions.TraceLIRVisit) { | 1239 if (C1XOptions.TraceLIRVisit) { |
1236 TTY.println("Visiting " + instr); | 1240 TTY.println("Visiting " + instr); |
1237 } | 1241 } |
1238 instr.accept(this); | 1242 instr.accept(this); |
1297 } | 1301 } |
1298 } | 1302 } |
1299 | 1303 |
1300 private List<Phi> getPhis(LIRBlock block) { | 1304 private List<Phi> getPhis(LIRBlock block) { |
1301 if (block.getInstructions().size() > 0) { | 1305 if (block.getInstructions().size() > 0) { |
1302 Instruction i = block.getInstructions().get(0); | 1306 Node i = block.firstInstruction(); |
1303 if (i instanceof Merge) { | 1307 if (i instanceof Merge) { |
1304 List<Phi> result = new ArrayList<Phi>(); | 1308 List<Phi> result = new ArrayList<Phi>(); |
1305 for (Node n : i.usages()) { | 1309 for (Node n : i.usages()) { |
1306 if (n instanceof Phi) { | 1310 if (n instanceof Phi) { |
1307 result.add((Phi) n); | 1311 result.add((Phi) n); |
1439 default: | 1443 default: |
1440 Util.shouldNotReachHere(); | 1444 Util.shouldNotReachHere(); |
1441 } | 1445 } |
1442 } | 1446 } |
1443 | 1447 |
1444 protected void walkState(Instruction x, FrameState state) { | 1448 protected void walkState(Node x, FrameState state) { |
1445 if (state == null) { | 1449 if (state == null) { |
1446 return; | 1450 return; |
1447 } | 1451 } |
1448 for (int index = 0; index < state.stackSize(); index++) { | 1452 for (int index = 0; index < state.stackSize(); index++) { |
1449 Value value = state.stackAt(index); | 1453 Value value = state.stackAt(index); |
1461 } | 1465 } |
1462 } | 1466 } |
1463 | 1467 |
1464 private void walkStateValue(Value value) { | 1468 private void walkStateValue(Value value) { |
1465 if (value != null) { | 1469 if (value != null) { |
1466 assert !value.hasSubst() : "missed substitution on " + value.toString(); | |
1467 if (value instanceof Phi && !value.isIllegal()) { | 1470 if (value instanceof Phi && !value.isIllegal()) { |
1468 // phi's are special | 1471 // phi's are special |
1469 operandForPhi((Phi) value); | 1472 operandForPhi((Phi) value); |
1470 } else if (value.operand().isIllegal()) { | 1473 } else if (value.operand().isIllegal()) { |
1471 // instruction doesn't have an operand yet | 1474 // instruction doesn't have an operand yet |
1473 assert operand.isLegal() : "must be evaluated now"; | 1476 assert operand.isLegal() : "must be evaluated now"; |
1474 } | 1477 } |
1475 } | 1478 } |
1476 } | 1479 } |
1477 | 1480 |
1478 protected LIRDebugInfo stateFor(Instruction x) { | 1481 protected LIRDebugInfo stateFor(Value x) { |
1479 assert lastState != null : "must have state before instruction for " + x; | 1482 assert lastState != null : "must have state before instruction for " + x; |
1480 return stateFor(x, lastState); | 1483 return stateFor(x, lastState); |
1481 } | 1484 } |
1482 | 1485 |
1483 protected LIRDebugInfo stateFor(Instruction x, FrameState state) { | 1486 protected LIRDebugInfo stateFor(Value x, FrameState state) { |
1484 if (compilation.placeholderState != null) { | 1487 if (compilation.placeholderState != null) { |
1485 state = compilation.placeholderState; | 1488 state = compilation.placeholderState; |
1486 } | 1489 } |
1487 | 1490 |
1488 assert state != null; | 1491 assert state != null; |
1547 } else if (instruction instanceof Constant) { | 1550 } else if (instruction instanceof Constant) { |
1548 operand = operandForInstruction(instruction); | 1551 operand = operandForInstruction(instruction); |
1549 } | 1552 } |
1550 } | 1553 } |
1551 // the value must be a constant or have a valid operand | 1554 // the value must be a constant or have a valid operand |
1552 assert operand.isLegal() : "this root has not been visited yet"; | 1555 assert operand.isLegal() : "this root has not been visited yet; instruction=" + instruction; |
1553 return operand; | 1556 return operand; |
1554 } | 1557 } |
1555 | 1558 |
1556 /** | 1559 /** |
1557 * Gets the ABI specific operand used to return a value of a given kind from a method. | 1560 * Gets the ABI specific operand used to return a value of a given kind from a method. |