Exemplo n.º 1
0
        public static void FindLoops(LBlock[] blocks)
        {
            // Mark backedges and headers.
            for (int i = 1; i < blocks.Length; i++)
            {
                LBlock block = blocks[i];
                for (int j = 0; j < block.numSuccessors; j++)
                {
                    LBlock successor = block.getSuccessor(j);
                    if (successor.id < block.id)
                    {
                        successor.setLoopHeader(block);
                        block.setInLoop(successor);
                        break;
                    }
                }
            }

            for (int i = 0; i < blocks.Length; i++)
            {
                LBlock block = blocks[i];
                if (block.backedge != null)
                {
                    MarkLoop(block.backedge);
                }
            }
        }
Exemplo n.º 2
0
        private static void MarkLoop(LBlock backedge)
        {
            var worklist = new LoopBodyWorklist(backedge);

            worklist.scan(backedge);
            while (!worklist.empty)
            {
                LBlock block = worklist.pop();
                worklist.scan(block);
                block.setInLoop(backedge.loop);
            }
        }