private LGraph buildBlocks() throws Exception { lir_.entry = new LBlock(lir_.entry_pc); BlockBuilder builder = new BlockBuilder(lir_); LBlock entry = builder.parse(); // Get an RPO ordering of the blocks, since we don't have predecessors yet. LBlock[] blocks = BlockAnalysis.Order(entry); // Remove dead references. // Ignore blocks that are unreachable and are always jumped over // e.g. // if(1 != 1) // loop().. for (LBlock block : blocks) { int numPredecessors = block.numPredecessors(); for (int i = 0; i < numPredecessors; i++) { if (!ContainsBlock(blocks, block.getPredecessor(i))) { block.removePredecessor(block.getPredecessor(i)); numPredecessors--; } } } if (!BlockAnalysis.IsReducible(blocks)) throw new Exception("control flow graph is not reducible"); // Split critical edges in the graph (is this even needed?) BlockAnalysis.SplitCriticalEdges(blocks); // Reorder the blocks since we could have introduced new nodes. blocks = BlockAnalysis.Order(entry); assert (BlockAnalysis.IsReducible(blocks)); BlockAnalysis.ComputeDominators(blocks); BlockAnalysis.ComputeImmediateDominators(blocks); BlockAnalysis.ComputeDominatorTree(blocks); BlockAnalysis.FindLoops(blocks); LGraph graph = new LGraph(); graph.blocks = blocks; graph.entry = blocks[0]; if (lir_.argDepth > 0) graph.nargs = ((lir_.argDepth - 12) / 4) + 1; else graph.nargs = 0; return graph; }