Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2749:36440e516e44
block entry instructions created on-demand
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 20 May 2011 14:09:28 +0200 |
parents | 84f4c7dceb14 |
children | 6048da340364 |
comparison
equal
deleted
inserted
replaced
2748:861449bd8b86 | 2749:36440e516e44 |
---|---|
113 | 113 |
114 private final Graph graph; | 114 private final Graph graph; |
115 | 115 |
116 private BlockBegin unwindBlock; | 116 private BlockBegin unwindBlock; |
117 | 117 |
118 private final Set<Instruction> loopHeaders = new HashSet<Instruction>(); | |
119 | |
120 /** | 118 /** |
121 * Creates a new, initialized, {@code GraphBuilder} instance for a given compilation. | 119 * Creates a new, initialized, {@code GraphBuilder} instance for a given compilation. |
122 * | 120 * |
123 * @param compilation the compilation | 121 * @param compilation the compilation |
124 * @param ir the IR to build the graph into | 122 * @param ir the IR to build the graph into |
154 // 2. compute the block map, setup exception handlers and get the entrypoint(s) | 152 // 2. compute the block map, setup exception handlers and get the entrypoint(s) |
155 BlockMap blockMap = compilation.getBlockMap(rootMethod); | 153 BlockMap blockMap = compilation.getBlockMap(rootMethod); |
156 | 154 |
157 blockList = new Block[rootMethod.code().length]; | 155 blockList = new Block[rootMethod.code().length]; |
158 for (int i = 0; i < blockMap.blocks.size(); i++) { | 156 for (int i = 0; i < blockMap.blocks.size(); i++) { |
157 int blockID = ir.nextBlockNumber(); | |
158 assert blockID == i; | |
159 Block block = blockMap.blocks.get(i); | 159 Block block = blockMap.blocks.get(i); |
160 | 160 blockList[block.startBci] = block; |
161 // if (block.isLoopHeader) { | 161 } |
162 BlockBegin blockBegin = new BlockBegin(block.startBci, ir.nextBlockNumber(), graph); | |
163 | |
164 block.firstInstruction = blockBegin; | |
165 blockList[block.startBci] = block; | |
166 | |
167 if (block.isLoopHeader) { | |
168 loopHeaders.add(blockBegin); | |
169 } | |
170 // } else { | |
171 // blockList[block.startBci] = new Placeholder(graph); | |
172 // } | |
173 } | |
174 | |
175 | 162 |
176 // 1. create the start block | 163 // 1. create the start block |
177 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); | 164 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); |
178 BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); | 165 BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); |
179 startBlock.firstInstruction = startBlockBegin; | 166 startBlock.firstInstruction = startBlockBegin; |
379 | 366 |
380 ArrayList<BlockBegin> newBlocks = new ArrayList<BlockBegin>(); | 367 ArrayList<BlockBegin> newBlocks = new ArrayList<BlockBegin>(); |
381 | 368 |
382 int current = exceptionHandlers.size() - 1; | 369 int current = exceptionHandlers.size() - 1; |
383 if (exceptionHandlers.get(current).isCatchAll()) { | 370 if (exceptionHandlers.get(current).isCatchAll()) { |
384 successor = exceptionHandlers.get(current).entryBlock().firstInstruction; | 371 successor = createTarget(exceptionHandlers.get(current).entryBlock(), null); |
385 current--; | 372 current--; |
386 } else { | 373 } else { |
387 if (unwindBlock == null) { | 374 if (unwindBlock == null) { |
388 unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); | 375 unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); |
389 Unwind unwind = new Unwind(null, graph); | 376 Unwind unwind = new Unwind(null, graph); |
410 successor = newSucc; | 397 successor = newSucc; |
411 } else { | 398 } else { |
412 BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); | 399 BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); |
413 | 400 |
414 if (handler.handler.catchType().isResolved()) { | 401 if (handler.handler.catchType().isResolved()) { |
402 Instruction entry = createTarget(handler.entryBlock(), null); | |
415 ExceptionDispatch end = new ExceptionDispatch(null, (BlockBegin) handler.entryBlock().firstInstruction, null, handler, null, graph); | 403 ExceptionDispatch end = new ExceptionDispatch(null, (BlockBegin) handler.entryBlock().firstInstruction, null, handler, null, graph); |
416 end.setBlockSuccessor(0, (BlockBegin) successor); | 404 end.setBlockSuccessor(0, (BlockBegin) successor); |
417 dispatchEntry.appendNext(end); | 405 dispatchEntry.appendNext(end); |
418 dispatchEntry.setEnd(end); | 406 dispatchEntry.setEnd(end); |
419 } else { | 407 } else { |
1070 private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) { | 1058 private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) { |
1071 return createTarget(blockList[bci], stateAfter); | 1059 return createTarget(blockList[bci], stateAfter); |
1072 } | 1060 } |
1073 | 1061 |
1074 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { | 1062 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { |
1075 mergeOrClone(block, stateAfter); | 1063 if (block.firstInstruction == null) { |
1064 BlockBegin blockBegin = new BlockBegin(block.startBci, block.blockID, graph); | |
1065 block.firstInstruction = blockBegin; | |
1066 } | |
1067 if (stateAfter != null) { | |
1068 mergeOrClone(block, stateAfter); | |
1069 } | |
1076 addToWorkList(block); | 1070 addToWorkList(block); |
1077 return block.firstInstruction; | 1071 return block.firstInstruction; |
1078 } | 1072 } |
1079 | 1073 |
1080 private void genLookupswitch() { | 1074 private void genLookupswitch() { |