comparison graal/GraalCompiler/src/com/sun/c1x/alloc/EdgeMoveOptimizer.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 7ed72769d51a
children 2ac7b30b7290
comparison
equal deleted inserted replaced
2717:bd85cf08720a 2718:c1ce2a53d6c3
57 /** 57 /**
58 * Optimizes moves on block edges. 58 * Optimizes moves on block edges.
59 * 59 *
60 * @param blockList a list of blocks whose moves should be optimized 60 * @param blockList a list of blocks whose moves should be optimized
61 */ 61 */
62 public static void optimize(List<BlockBegin> blockList) { 62 public static void optimize(List<LIRBlock> blockList) {
63 EdgeMoveOptimizer optimizer = new EdgeMoveOptimizer(); 63 EdgeMoveOptimizer optimizer = new EdgeMoveOptimizer();
64 64
65 // ignore the first block in the list (index 0 is not processed) 65 // ignore the first block in the list (index 0 is not processed)
66 for (int i = blockList.size() - 1; i >= 1; i--) { 66 for (int i = blockList.size() - 1; i >= 1; i--) {
67 BlockBegin block = blockList.get(i); 67 LIRBlock block = blockList.get(i);
68 68
69 if (block.numberOfPreds() > 1) { 69 if (block.numberOfPreds() > 1) {
70 optimizer.optimizeMovesAtBlockEnd(block); 70 optimizer.optimizeMovesAtBlockEnd(block);
71 } 71 }
72 if (block.numberOfSux() == 2) { 72 if (block.numberOfSux() == 2) {
109 109
110 /** 110 /**
111 * Moves the longest {@linkplain #same common} subsequence at the end all 111 * Moves the longest {@linkplain #same common} subsequence at the end all
112 * predecessors of {@code block} to the start of {@code block}. 112 * predecessors of {@code block} to the start of {@code block}.
113 */ 113 */
114 private void optimizeMovesAtBlockEnd(BlockBegin block) { 114 private void optimizeMovesAtBlockEnd(LIRBlock block) {
115 if (block.isPredecessor(block.end())) { 115 if (block.isPredecessor(block)) {
116 // currently we can't handle this correctly. 116 // currently we can't handle this correctly.
117 return; 117 return;
118 } 118 }
119 119
120 // clear all internal data structures 120 // clear all internal data structures
123 int numPreds = block.numberOfPreds(); 123 int numPreds = block.numberOfPreds();
124 assert numPreds > 1 : "do not call otherwise"; 124 assert numPreds > 1 : "do not call otherwise";
125 125
126 // setup a list with the LIR instructions of all predecessors 126 // setup a list with the LIR instructions of all predecessors
127 for (int i = 0; i < numPreds; i++) { 127 for (int i = 0; i < numPreds; i++) {
128 BlockBegin pred = block.predAt(i).block(); 128 LIRBlock pred = block.predAt(i);
129 List<LIRInstruction> predInstructions = pred.lir().instructionsList(); 129 List<LIRInstruction> predInstructions = pred.lir().instructionsList();
130 130
131 if (pred.numberOfSux() != 1) { 131 if (pred.numberOfSux() != 1) {
132 // this can happen with switch-statements where multiple edges are between 132 // this can happen with switch-statements where multiple edges are between
133 // the same blocks. 133 // the same blocks.
178 /** 178 /**
179 * Moves the longest {@linkplain #same common} subsequence at the start of all 179 * Moves the longest {@linkplain #same common} subsequence at the start of all
180 * successors of {@code block} to the end of {@code block} just prior to the 180 * successors of {@code block} to the end of {@code block} just prior to the
181 * branch instruction ending {@code block}. 181 * branch instruction ending {@code block}.
182 */ 182 */
183 private void optimizeMovesAtBlockBegin(BlockBegin block) { 183 private void optimizeMovesAtBlockBegin(LIRBlock block) {
184 184
185 edgeInstructionSeqences.clear(); 185 edgeInstructionSeqences.clear();
186 int numSux = block.numberOfSux(); 186 int numSux = block.numberOfSux();
187 187
188 List<LIRInstruction> instructions = block.lir().instructionsList(); 188 List<LIRInstruction> instructions = block.lir().instructionsList();
218 } 218 }
219 } 219 }
220 220
221 // setup a list with the lir-instructions of all successors 221 // setup a list with the lir-instructions of all successors
222 for (int i = 0; i < numSux; i++) { 222 for (int i = 0; i < numSux; i++) {
223 BlockBegin sux = block.suxAt(i); 223 LIRBlock sux = block.suxAt(i);
224 List<LIRInstruction> suxInstructions = sux.lir().instructionsList(); 224 List<LIRInstruction> suxInstructions = sux.lir().instructionsList();
225 225
226 assert suxInstructions.get(0).code == LIROpcode.Label : "block must start with label"; 226 assert suxInstructions.get(0).code == LIROpcode.Label : "block must start with label";
227 227
228 if (sux.numberOfPreds() != 1) { 228 if (sux.numberOfPreds() != 1) {
229 // this can happen with switch-statements where multiple edges are between 229 // this can happen with switch-statements where multiple edges are between
230 // the same blocks. 230 // the same blocks.
231 return; 231 return;
232 } 232 }
233 assert sux.predAt(0).block() == block : "invalid control flow"; 233 assert sux.predAt(0) == block : "invalid control flow";
234 234
235 // ignore the label at the beginning of the block 235 // ignore the label at the beginning of the block
236 List<LIRInstruction> seq = suxInstructions.subList(1, suxInstructions.size()); 236 List<LIRInstruction> seq = suxInstructions.subList(1, suxInstructions.size());
237 edgeInstructionSeqences.add(seq); 237 edgeInstructionSeqences.add(seq);
238 } 238 }