Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java @ 2708:4272b7af2d17
merge
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 18 May 2011 18:40:58 +0200 |
parents | 7ed72769d51a 42450f536d24 |
children | c1ce2a53d6c3 |
comparison
equal
deleted
inserted
replaced
2707:7ed72769d51a | 2708:4272b7af2d17 |
---|---|
561 int opId = 0; | 561 int opId = 0; |
562 int index = 0; | 562 int index = 0; |
563 | 563 |
564 for (int i = 0; i < numBlocks; i++) { | 564 for (int i = 0; i < numBlocks; i++) { |
565 BlockBegin block = blockAt(i); | 565 BlockBegin block = blockAt(i); |
566 block.setFirstLirInstructionId(opId); | 566 block.lirBlock.setFirstLirInstructionId(opId); |
567 List<LIRInstruction> instructions = block.lir().instructionsList(); | 567 List<LIRInstruction> instructions = block.lir().instructionsList(); |
568 | 568 |
569 int numInst = instructions.size(); | 569 int numInst = instructions.size(); |
570 for (int j = 0; j < numInst; j++) { | 570 for (int j = 0; j < numInst; j++) { |
571 LIRInstruction op = instructions.get(j); | 571 LIRInstruction op = instructions.get(j); |
576 assert instructionForId(opId) == op : "must match"; | 576 assert instructionForId(opId) == op : "must match"; |
577 | 577 |
578 index++; | 578 index++; |
579 opId += 2; // numbering of lirOps by two | 579 opId += 2; // numbering of lirOps by two |
580 } | 580 } |
581 block.setLastLirInstructionId(opId - 2); | 581 block.lirBlock.setLastLirInstructionId((opId - 2)); |
582 } | 582 } |
583 assert index == numInstructions : "must match"; | 583 assert index == numInstructions : "must match"; |
584 assert (index << 1) == opId : "must match: " + (index << 1); | 584 assert (index << 1) == opId : "must match: " + (index << 1); |
585 } | 585 } |
586 | 586 |
1157 | 1157 |
1158 // iterate all blocks in reverse order | 1158 // iterate all blocks in reverse order |
1159 for (int i = blockCount() - 1; i >= 0; i--) { | 1159 for (int i = blockCount() - 1; i >= 0; i--) { |
1160 BlockBegin block = blockAt(i); | 1160 BlockBegin block = blockAt(i); |
1161 List<LIRInstruction> instructions = block.lir().instructionsList(); | 1161 List<LIRInstruction> instructions = block.lir().instructionsList(); |
1162 final int blockFrom = block.firstLirInstructionId(); | 1162 final int blockFrom = block.lirBlock.firstLirInstructionId(); |
1163 int blockTo = block.lastLirInstructionId(); | 1163 int blockTo = block.lirBlock.lastLirInstructionId(); |
1164 | 1164 |
1165 assert blockFrom == instructions.get(0).id; | 1165 assert blockFrom == instructions.get(0).id; |
1166 assert blockTo == instructions.get(instructions.size() - 1).id; | 1166 assert blockTo == instructions.get(instructions.size() - 1).id; |
1167 | 1167 |
1168 // Update intervals for operands live at the end of this block; | 1168 // Update intervals for operands live at the end of this block; |
1510 | 1510 |
1511 Interval intervalAtBlockBegin(BlockBegin block, CiValue operand) { | 1511 Interval intervalAtBlockBegin(BlockBegin block, CiValue operand) { |
1512 assert operand.isVariable() : "register number out of bounds"; | 1512 assert operand.isVariable() : "register number out of bounds"; |
1513 assert intervalFor(operand) != null : "no interval found"; | 1513 assert intervalFor(operand) != null : "no interval found"; |
1514 | 1514 |
1515 return splitChildAtOpId(intervalFor(operand), block.firstLirInstructionId(), LIRInstruction.OperandMode.Output); | 1515 return splitChildAtOpId(intervalFor(operand), block.lirBlock.firstLirInstructionId(), LIRInstruction.OperandMode.Output); |
1516 } | 1516 } |
1517 | 1517 |
1518 Interval intervalAtBlockEnd(BlockBegin block, CiValue operand) { | 1518 Interval intervalAtBlockEnd(BlockBegin block, CiValue operand) { |
1519 assert operand.isVariable() : "register number out of bounds"; | 1519 assert operand.isVariable() : "register number out of bounds"; |
1520 assert intervalFor(operand) != null : "no interval found"; | 1520 assert intervalFor(operand) != null : "no interval found"; |
1521 | 1521 |
1522 return splitChildAtOpId(intervalFor(operand), block.lastLirInstructionId() + 1, LIRInstruction.OperandMode.Output); | 1522 return splitChildAtOpId(intervalFor(operand), block.lirBlock.lastLirInstructionId() + 1, LIRInstruction.OperandMode.Output); |
1523 } | 1523 } |
1524 | 1524 |
1525 Interval intervalAtOpId(CiValue operand, int opId) { | 1525 Interval intervalAtOpId(CiValue operand, int opId) { |
1526 assert operand.isVariable() : "register number out of bounds"; | 1526 assert operand.isVariable() : "register number out of bounds"; |
1527 assert intervalFor(operand) != null : "no interval found"; | 1527 assert intervalFor(operand) != null : "no interval found"; |
1726 assert interval != null : "interval must exist"; | 1726 assert interval != null : "interval must exist"; |
1727 | 1727 |
1728 if (opId != -1) { | 1728 if (opId != -1) { |
1729 if (C1XOptions.DetailedAsserts) { | 1729 if (C1XOptions.DetailedAsserts) { |
1730 BlockBegin block = blockForId(opId); | 1730 BlockBegin block = blockForId(opId); |
1731 if (block.numberOfSux() <= 1 && opId == block.lastLirInstructionId()) { | 1731 if (block.numberOfSux() <= 1 && opId == block.lirBlock.lastLirInstructionId()) { |
1732 // check if spill moves could have been appended at the end of this block, but | 1732 // check if spill moves could have been appended at the end of this block, but |
1733 // before the branch instruction. So the split child information for this branch would | 1733 // before the branch instruction. So the split child information for this branch would |
1734 // be incorrect. | 1734 // be incorrect. |
1735 LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1); | 1735 LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1); |
1736 if (instr instanceof LIRBranch) { | 1736 if (instr instanceof LIRBranch) { |
1846 assert con == null || operand.isVariable() || operand.isConstant() || operand.isIllegal() : "Constant instructions have only constant operands (or illegal if constant is optimized away)"; | 1846 assert con == null || operand.isVariable() || operand.isConstant() || operand.isIllegal() : "Constant instructions have only constant operands (or illegal if constant is optimized away)"; |
1847 | 1847 |
1848 if (operand.isVariable()) { | 1848 if (operand.isVariable()) { |
1849 OperandMode mode = OperandMode.Input; | 1849 OperandMode mode = OperandMode.Input; |
1850 BlockBegin block = blockForId(opId); | 1850 BlockBegin block = blockForId(opId); |
1851 if (block.numberOfSux() == 1 && opId == block.lastLirInstructionId()) { | 1851 if (block.numberOfSux() == 1 && opId == block.lirBlock.lastLirInstructionId()) { |
1852 // generating debug information for the last instruction of a block. | 1852 // generating debug information for the last instruction of a block. |
1853 // if this instruction is a branch, spill moves are inserted before this branch | 1853 // if this instruction is a branch, spill moves are inserted before this branch |
1854 // and so the wrong operand would be returned (spill moves at block boundaries are not | 1854 // and so the wrong operand would be returned (spill moves at block boundaries are not |
1855 // considered in the live ranges of intervals) | 1855 // considered in the live ranges of intervals) |
1856 // Solution: use the first opId of the branch target block instead. | 1856 // Solution: use the first opId of the branch target block instead. |
1857 final LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1); | 1857 final LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1); |
1858 if (instr instanceof LIRBranch) { | 1858 if (instr instanceof LIRBranch) { |
1859 if (block.lirBlock.liveOut.get(operandNumber(operand))) { | 1859 if (block.lirBlock.liveOut.get(operandNumber(operand))) { |
1860 opId = block.suxAt(0).firstLirInstructionId(); | 1860 opId = block.suxAt(0).lirBlock.firstLirInstructionId(); |
1861 mode = OperandMode.Output; | 1861 mode = OperandMode.Output; |
1862 } | 1862 } |
1863 } | 1863 } |
1864 } | 1864 } |
1865 | 1865 |
2081 C1XTimers.DEBUG_INFO.stop(); | 2081 C1XTimers.DEBUG_INFO.stop(); |
2082 C1XTimers.CODE_CREATE.start(); | 2082 C1XTimers.CODE_CREATE.start(); |
2083 } | 2083 } |
2084 | 2084 |
2085 printLir("After register number assignment", true); | 2085 printLir("After register number assignment", true); |
2086 | |
2087 EdgeMoveOptimizer.optimize(ir.linearScanOrder()); | 2086 EdgeMoveOptimizer.optimize(ir.linearScanOrder()); |
2088 if (C1XOptions.OptControlFlow) { | |
2089 ControlFlowOptimizer.optimize(ir); | |
2090 } | |
2091 | |
2092 printLir("After control flow optimization", false); | 2087 printLir("After control flow optimization", false); |
2093 } | 2088 } |
2094 | 2089 |
2095 void printIntervals(String label) { | 2090 void printIntervals(String label) { |
2096 if (C1XOptions.TraceLinearScanLevel >= 1) { | 2091 if (C1XOptions.TraceLinearScanLevel >= 1) { |
2106 | 2101 |
2107 TTY.println(); | 2102 TTY.println(); |
2108 TTY.println("--- Basic Blocks ---"); | 2103 TTY.println("--- Basic Blocks ---"); |
2109 for (i = 0; i < blockCount(); i++) { | 2104 for (i = 0; i < blockCount(); i++) { |
2110 BlockBegin block = blockAt(i); | 2105 BlockBegin block = blockAt(i); |
2111 TTY.print("B%d [%d, %d, %d, %d] ", block.blockID, block.firstLirInstructionId(), block.lastLirInstructionId(), block.loopIndex(), block.loopDepth()); | 2106 TTY.print("B%d [%d, %d, %d, %d] ", block.blockID, block.lirBlock.firstLirInstructionId(), block.lirBlock.lastLirInstructionId(), block.loopIndex(), block.loopDepth()); |
2112 } | 2107 } |
2113 TTY.println(); | 2108 TTY.println(); |
2114 TTY.println(); | 2109 TTY.println(); |
2115 } | 2110 } |
2116 | 2111 |