Ejemplo n.º 1
0
        private static void Delete(IntrusiveList <Node> nodes, Node node, Operation operation)
        {
            operation.Destination = null;

            for (int index = 0; index < operation.SourcesCount; index++)
            {
                operation.SetSource(index, null);
            }

            nodes.Remove(node);
        }
Ejemplo n.º 2
0
        private void RemoveUnreachableBlocks(IntrusiveList <BasicBlock> blocks)
        {
            var visited   = new HashSet <BasicBlock>();
            var workQueue = new Queue <BasicBlock>();

            visited.Add(Entry);
            workQueue.Enqueue(Entry);

            while (workQueue.TryDequeue(out BasicBlock block))
            {
                Debug.Assert(block.Index != -1, "Invalid block index.");

                for (int i = 0; i < block.SuccessorsCount; i++)
                {
                    BasicBlock succ = block.GetSuccessor(i);

                    if (visited.Add(succ))
                    {
                        workQueue.Enqueue(succ);
                    }
                }
            }

            if (visited.Count < blocks.Count)
            {
                // Remove unreachable blocks and renumber.
                int index = 0;

                for (BasicBlock block = blocks.First; block != null;)
                {
                    BasicBlock nextBlock = block.ListNext;

                    if (!visited.Contains(block))
                    {
                        while (block.SuccessorsCount > 0)
                        {
                            block.RemoveSuccessor(index: block.SuccessorsCount - 1);
                        }

                        blocks.Remove(block);
                    }
                    else
                    {
                        block.Index = index++;
                    }

                    block = nextBlock;
                }
            }
        }
Ejemplo n.º 3
0
        private void RemoveUnreachableBlocks(IntrusiveList <BasicBlock> blocks)
        {
            HashSet <BasicBlock> visited = new HashSet <BasicBlock>();

            Queue <BasicBlock> workQueue = new Queue <BasicBlock>();

            visited.Add(Entry);

            workQueue.Enqueue(Entry);

            while (workQueue.TryDequeue(out BasicBlock block))
            {
                Debug.Assert(block.Index != -1, "Invalid block index.");

                if (block.Next != null && visited.Add(block.Next))
                {
                    workQueue.Enqueue(block.Next);
                }

                if (block.Branch != null && visited.Add(block.Branch))
                {
                    workQueue.Enqueue(block.Branch);
                }
            }

            if (visited.Count < blocks.Count)
            {
                // Remove unreachable blocks and renumber.
                int index = 0;

                for (BasicBlock block = blocks.First; block != null;)
                {
                    BasicBlock nextBlock = block.ListNext;

                    if (!visited.Contains(block))
                    {
                        block.Next   = null;
                        block.Branch = null;

                        blocks.Remove(block);
                    }
                    else
                    {
                        block.Index = index++;
                    }

                    block = nextBlock;
                }
            }
        }