Beispiel #1
0
        public static void RunPass(ControlFlowGraph cfg)
        {
            bool modified;

            do
            {
                modified = false;

                for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext)
                {
                    Node node = block.Operations.First;

                    while (node != null)
                    {
                        Node nextNode = node.ListNext;

                        bool isUnused = IsUnused(node);

                        if (!(node is Operation operation) || isUnused)
                        {
                            if (isUnused)
                            {
                                RemoveNode(block, node);

                                modified = true;
                            }

                            node = nextNode;

                            continue;
                        }

                        ConstantFolding.RunPass(operation);

                        Simplification.RunPass(operation);

                        if (DestIsLocalVar(operation))
                        {
                            if (IsPropagableCompare(operation))
                            {
                                modified |= PropagateCompare(operation);

                                if (modified && IsUnused(operation))
                                {
                                    RemoveNode(block, node);
                                }
                            }
                            else if (IsPropagableCopy(operation))
                            {
                                PropagateCopy(operation);

                                RemoveNode(block, node);

                                modified = true;
                            }
                        }

                        node = nextNode;
                    }
                }
            }while (modified);
        }