comparison graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java @ 2703:42450f536d24

More cleanup towards separation of graphbuilding<>graph<>lirgeneration
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 18 May 2011 17:04:47 +0200
parents 618f545fcac5
children 4272b7af2d17
comparison
equal deleted inserted replaced
2702:618f545fcac5 2703:42450f536d24
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
1172 1172
1173 // iterate all blocks in reverse order 1173 // iterate all blocks in reverse order
1174 for (int i = blockCount() - 1; i >= 0; i--) { 1174 for (int i = blockCount() - 1; i >= 0; i--) {
1175 BlockBegin block = blockAt(i); 1175 BlockBegin block = blockAt(i);
1176 List<LIRInstruction> instructions = block.lir().instructionsList(); 1176 List<LIRInstruction> instructions = block.lir().instructionsList();
1177 final int blockFrom = block.firstLirInstructionId(); 1177 final int blockFrom = block.lirBlock.firstLirInstructionId();
1178 int blockTo = block.lastLirInstructionId(); 1178 int blockTo = block.lirBlock.lastLirInstructionId();
1179 1179
1180 assert blockFrom == instructions.get(0).id; 1180 assert blockFrom == instructions.get(0).id;
1181 assert blockTo == instructions.get(instructions.size() - 1).id; 1181 assert blockTo == instructions.get(instructions.size() - 1).id;
1182 1182
1183 // Update intervals for operands live at the end of this block; 1183 // Update intervals for operands live at the end of this block;
1525 1525
1526 Interval intervalAtBlockBegin(BlockBegin block, CiValue operand) { 1526 Interval intervalAtBlockBegin(BlockBegin block, CiValue operand) {
1527 assert operand.isVariable() : "register number out of bounds"; 1527 assert operand.isVariable() : "register number out of bounds";
1528 assert intervalFor(operand) != null : "no interval found"; 1528 assert intervalFor(operand) != null : "no interval found";
1529 1529
1530 return splitChildAtOpId(intervalFor(operand), block.firstLirInstructionId(), LIRInstruction.OperandMode.Output); 1530 return splitChildAtOpId(intervalFor(operand), block.lirBlock.firstLirInstructionId(), LIRInstruction.OperandMode.Output);
1531 } 1531 }
1532 1532
1533 Interval intervalAtBlockEnd(BlockBegin block, CiValue operand) { 1533 Interval intervalAtBlockEnd(BlockBegin block, CiValue operand) {
1534 assert operand.isVariable() : "register number out of bounds"; 1534 assert operand.isVariable() : "register number out of bounds";
1535 assert intervalFor(operand) != null : "no interval found"; 1535 assert intervalFor(operand) != null : "no interval found";
1536 1536
1537 return splitChildAtOpId(intervalFor(operand), block.lastLirInstructionId() + 1, LIRInstruction.OperandMode.Output); 1537 return splitChildAtOpId(intervalFor(operand), block.lirBlock.lastLirInstructionId() + 1, LIRInstruction.OperandMode.Output);
1538 } 1538 }
1539 1539
1540 Interval intervalAtOpId(CiValue operand, int opId) { 1540 Interval intervalAtOpId(CiValue operand, int opId) {
1541 assert operand.isVariable() : "register number out of bounds"; 1541 assert operand.isVariable() : "register number out of bounds";
1542 assert intervalFor(operand) != null : "no interval found"; 1542 assert intervalFor(operand) != null : "no interval found";
1693 // are necessary for resolving the states when an exception uses this exception handler 1693 // are necessary for resolving the states when an exception uses this exception handler
1694 // * the interval would be on the fpu stack at the begin of the exception handler 1694 // * the interval would be on the fpu stack at the begin of the exception handler
1695 // this is not allowed because of the complicated fpu stack handling on Intel 1695 // this is not allowed because of the complicated fpu stack handling on Intel
1696 1696
1697 // range that will be spilled to memory 1697 // range that will be spilled to memory
1698 int fromOpId = block.firstLirInstructionId(); 1698 int fromOpId = block.lirBlock.firstLirInstructionId();
1699 int toOpId = fromOpId + 1; // short live range of length 1 1699 int toOpId = fromOpId + 1; // short live range of length 1
1700 assert interval.from() <= fromOpId && interval.to() >= toOpId : "no split allowed between exception entry and first instruction"; 1700 assert interval.from() <= fromOpId && interval.to() >= toOpId : "no split allowed between exception entry and first instruction";
1701 1701
1702 if (interval.from() != fromOpId) { 1702 if (interval.from() != fromOpId) {
1703 // the part before fromOpId is unchanged 1703 // the part before fromOpId is unchanged
1926 assert interval != null : "interval must exist"; 1926 assert interval != null : "interval must exist";
1927 1927
1928 if (opId != -1) { 1928 if (opId != -1) {
1929 if (C1XOptions.DetailedAsserts) { 1929 if (C1XOptions.DetailedAsserts) {
1930 BlockBegin block = blockForId(opId); 1930 BlockBegin block = blockForId(opId);
1931 if (block.numberOfSux() <= 1 && opId == block.lastLirInstructionId()) { 1931 if (block.numberOfSux() <= 1 && opId == block.lirBlock.lastLirInstructionId()) {
1932 // check if spill moves could have been appended at the end of this block, but 1932 // check if spill moves could have been appended at the end of this block, but
1933 // before the branch instruction. So the split child information for this branch would 1933 // before the branch instruction. So the split child information for this branch would
1934 // be incorrect. 1934 // be incorrect.
1935 LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1); 1935 LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1);
1936 if (instr instanceof LIRBranch) { 1936 if (instr instanceof LIRBranch) {
2046 assert con == null || operand.isVariable() || operand.isConstant() || operand.isIllegal() : "Constant instructions have only constant operands (or illegal if constant is optimized away)"; 2046 assert con == null || operand.isVariable() || operand.isConstant() || operand.isIllegal() : "Constant instructions have only constant operands (or illegal if constant is optimized away)";
2047 2047
2048 if (operand.isVariable()) { 2048 if (operand.isVariable()) {
2049 OperandMode mode = OperandMode.Input; 2049 OperandMode mode = OperandMode.Input;
2050 BlockBegin block = blockForId(opId); 2050 BlockBegin block = blockForId(opId);
2051 if (block.numberOfSux() == 1 && opId == block.lastLirInstructionId()) { 2051 if (block.numberOfSux() == 1 && opId == block.lirBlock.lastLirInstructionId()) {
2052 // generating debug information for the last instruction of a block. 2052 // generating debug information for the last instruction of a block.
2053 // if this instruction is a branch, spill moves are inserted before this branch 2053 // if this instruction is a branch, spill moves are inserted before this branch
2054 // and so the wrong operand would be returned (spill moves at block boundaries are not 2054 // and so the wrong operand would be returned (spill moves at block boundaries are not
2055 // considered in the live ranges of intervals) 2055 // considered in the live ranges of intervals)
2056 // Solution: use the first opId of the branch target block instead. 2056 // Solution: use the first opId of the branch target block instead.
2057 final LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1); 2057 final LIRInstruction instr = block.lir().instructionsList().get(block.lir().instructionsList().size() - 1);
2058 if (instr instanceof LIRBranch) { 2058 if (instr instanceof LIRBranch) {
2059 if (block.lirBlock.liveOut.get(operandNumber(operand))) { 2059 if (block.lirBlock.liveOut.get(operandNumber(operand))) {
2060 opId = block.suxAt(0).firstLirInstructionId(); 2060 opId = block.suxAt(0).lirBlock.firstLirInstructionId();
2061 mode = OperandMode.Output; 2061 mode = OperandMode.Output;
2062 } 2062 }
2063 } 2063 }
2064 } 2064 }
2065 2065
2306 2306
2307 TTY.println(); 2307 TTY.println();
2308 TTY.println("--- Basic Blocks ---"); 2308 TTY.println("--- Basic Blocks ---");
2309 for (i = 0; i < blockCount(); i++) { 2309 for (i = 0; i < blockCount(); i++) {
2310 BlockBegin block = blockAt(i); 2310 BlockBegin block = blockAt(i);
2311 TTY.print("B%d [%d, %d, %d, %d] ", block.blockID, block.firstLirInstructionId(), block.lastLirInstructionId(), block.loopIndex(), block.loopDepth()); 2311 TTY.print("B%d [%d, %d, %d, %d] ", block.blockID, block.lirBlock.firstLirInstructionId(), block.lirBlock.lastLirInstructionId(), block.loopIndex(), block.loopDepth());
2312 } 2312 }
2313 TTY.println(); 2313 TTY.println();
2314 TTY.println(); 2314 TTY.println();
2315 } 2315 }
2316 2316