Пример #1
0
        public BasicBlock SplitEdge(BasicBlock predecessor, BasicBlock successor)
        {
            BasicBlock splitBlock = new BasicBlock(Blocks.Count);

            if (predecessor.Next == successor)
            {
                predecessor.Next = splitBlock;
            }

            if (predecessor.Branch == successor)
            {
                predecessor.Branch = splitBlock;
            }

            if (splitBlock.Predecessors.Count == 0)
            {
                throw new ArgumentException("Predecessor and successor are not connected.");
            }

            // Insert the new block on the list of blocks.
            BasicBlock succPrev = successor.Node.Previous?.Value;

            if (succPrev != null && succPrev != predecessor && succPrev.Next == successor)
            {
                // Can't insert after the predecessor or before the successor.
                // Here, we insert it before the successor by also spliting another
                // edge (the one between the block before "successor" and "successor").
                BasicBlock splitBlock2 = new BasicBlock(splitBlock.Index + 1);

                succPrev.Next = splitBlock2;

                splitBlock2.Branch = successor;

                splitBlock2.Operations.AddLast(new Operation(Instruction.Branch, null));

                Blocks.AddBefore(successor.Node, splitBlock2);
            }

            splitBlock.Next = successor;

            Blocks.AddBefore(successor.Node, splitBlock);

            return(splitBlock);
        }
Пример #2
0
        public BasicBlock SplitEdge(BasicBlock predecessor, BasicBlock successor)
        {
            BasicBlock splitBlock = new BasicBlock(Blocks.Count);

            for (int i = 0; i < predecessor.SuccessorCount; i++)
            {
                if (predecessor.GetSuccessor(i) == successor)
                {
                    predecessor.SetSuccessor(i, splitBlock);
                }
            }

            if (splitBlock.Predecessors.Count == 0)
            {
                throw new ArgumentException("Predecessor and successor are not connected.");
            }

            splitBlock.AddSuccessor(successor);

            Blocks.AddBefore(successor, splitBlock);

            return splitBlock;
        }