comparison graal/GraalCompiler/src/com/sun/c1x/graph/IR.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 ae1c50a03297
comparison
equal deleted inserted replaced
2717:bd85cf08720a 2718:c1ce2a53d6c3
22 */ 22 */
23 package com.sun.c1x.graph; 23 package com.sun.c1x.graph;
24 24
25 import java.util.*; 25 import java.util.*;
26 26
27 import com.oracle.graal.graph.*;
27 import com.sun.c1x.*; 28 import com.sun.c1x.*;
28 import com.sun.c1x.debug.*; 29 import com.sun.c1x.debug.*;
29 import com.sun.c1x.ir.*; 30 import com.sun.c1x.ir.*;
31 import com.sun.c1x.lir.*;
30 import com.sun.c1x.observer.*; 32 import com.sun.c1x.observer.*;
31 import com.sun.c1x.value.*; 33 import com.sun.c1x.value.*;
32 34
33 /** 35 /**
34 * This class implements the overall container for the HIR (high-level IR) graph 36 * This class implements the overall container for the HIR (high-level IR) graph
45 public final C1XCompilation compilation; 47 public final C1XCompilation compilation;
46 48
47 /** 49 /**
48 * The start block of this IR. 50 * The start block of this IR.
49 */ 51 */
50 public BlockBegin startBlock; 52 public LIRBlock startBlock;
51 53
52 private int maxLocks; 54 private int maxLocks;
53 55
54 /** 56 /**
55 * The linear-scan ordered list of blocks. 57 * The linear-scan ordered list of blocks.
56 */ 58 */
57 private List<BlockBegin> orderedBlocks; 59 private List<LIRBlock> orderedBlocks;
58 60
59 /** 61 /**
60 * Creates a new IR instance for the specified compilation. 62 * Creates a new IR instance for the specified compilation.
61 * @param compilation the compilation 63 * @param compilation the compilation
62 */ 64 */
104 } 106 }
105 107
106 private void makeLinearScanOrder() { 108 private void makeLinearScanOrder() {
107 if (orderedBlocks == null) { 109 if (orderedBlocks == null) {
108 CriticalEdgeFinder finder = new CriticalEdgeFinder(this); 110 CriticalEdgeFinder finder = new CriticalEdgeFinder(this);
109 startBlock.iteratePreOrder(finder); 111 getHIRStartBlock().iteratePreOrder(finder);
110 finder.splitCriticalEdges(); 112 finder.splitCriticalEdges();
111 ComputeLinearScanOrder computeLinearScanOrder = new ComputeLinearScanOrder(compilation.stats.blockCount, startBlock); 113 ComputeLinearScanOrder computeLinearScanOrder = new ComputeLinearScanOrder(compilation.stats.blockCount, getHIRStartBlock());
112 orderedBlocks = computeLinearScanOrder.linearScanOrder(); 114 List<BlockBegin> blocks = computeLinearScanOrder.linearScanOrder();
115 orderedBlocks = new ArrayList<LIRBlock>();
116
117 for (BlockBegin bb : blocks) {
118 LIRBlock lirBlock = new LIRBlock(bb.blockID);
119 bb.setLIRBlock(lirBlock);
120 lirBlock.setLinearScanNumber(bb.linearScanNumber());
121 if (bb.isLinearScanLoopHeader()) {
122 lirBlock.setLinearScanLoopHeader();
123 }
124 if (bb.isLinearScanLoopEnd()) {
125 lirBlock.setLinearScanLoopEnd();
126 }
127 lirBlock.setStateBefore(bb.stateBefore());
128 orderedBlocks.add(lirBlock);
129 }
130
131 for (BlockBegin bb : blocks) {
132 LIRBlock lirBlock = bb.lirBlock();
133 for (Node n : bb.predecessors()) {
134 if (n instanceof BlockEnd) {
135 BlockEnd end = (BlockEnd) n;
136 lirBlock.blockPredecessors().add(end.block().lirBlock());
137 }
138 }
139
140 for (Node n : bb.successors()) {
141 if (n instanceof BlockBegin) {
142 BlockBegin begin = (BlockBegin) n;
143 lirBlock.blockSuccessors().add(begin.lirBlock());
144 }
145 }
146
147 Instruction first = bb;
148 while (first != null) {
149 lirBlock.getInstructions().add(first);
150 first = first.next();
151 }
152 }
153
154 startBlock = getHIRStartBlock().lirBlock();
155 assert startBlock != null;
113 compilation.stats.loopCount = computeLinearScanOrder.numLoops(); 156 compilation.stats.loopCount = computeLinearScanOrder.numLoops();
114 computeLinearScanOrder.printBlocks(); 157 computeLinearScanOrder.printBlocks();
115 } 158 }
116 } 159 }
117 160
118 /** 161 /**
119 * Gets the linear scan ordering of blocks as a list. 162 * Gets the linear scan ordering of blocks as a list.
120 * @return the blocks in linear scan order 163 * @return the blocks in linear scan order
121 */ 164 */
122 public List<BlockBegin> linearScanOrder() { 165 public List<LIRBlock> linearScanOrder() {
123 return orderedBlocks; 166 return orderedBlocks;
124 } 167 }
125 168
126 private void print(boolean cfgOnly) { 169 private void print(boolean cfgOnly) {
127 if (!TTY.isSuppressed()) { 170 if (!TTY.isSuppressed()) {
128 TTY.println("IR for " + compilation.method); 171 TTY.println("IR for " + compilation.method);
129 final InstructionPrinter ip = new InstructionPrinter(TTY.out()); 172 final InstructionPrinter ip = new InstructionPrinter(TTY.out());
130 final BlockPrinter bp = new BlockPrinter(this, ip, cfgOnly); 173 final BlockPrinter bp = new BlockPrinter(this, ip, cfgOnly);
131 startBlock.iteratePreOrder(bp); 174 getHIRStartBlock().iteratePreOrder(bp);
132 } 175 }
133 } 176 }
134 177
135 /** 178 /**
136 * Verifies the IR and prints it out if the relevant options are set. 179 * Verifies the IR and prints it out if the relevant options are set.
141 TTY.println(phase); 184 TTY.println(phase);
142 print(false); 185 print(false);
143 } 186 }
144 187
145 if (compilation.compiler.isObserved()) { 188 if (compilation.compiler.isObserved()) {
146 compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, startBlock, true, false)); 189 // TODO(tw): FIXME
190 // compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, startBlock, true, false));
147 } 191 }
148 } 192 }
149 193
150 /** 194 /**
151 * Creates and inserts a new block between this block and the specified successor, 195 * Creates and inserts a new block between this block and the specified successor,
217 * @return the number of locks 261 * @return the number of locks
218 */ 262 */
219 public final int maxLocks() { 263 public final int maxLocks() {
220 return maxLocks; 264 return maxLocks;
221 } 265 }
266
267 public BlockBegin getHIRStartBlock() {
268 return (BlockBegin) compilation.graph.root().successors().get(0);
269 }
222 } 270 }