Example #1
0
 internal Enumerator(
     CFG <TOrder, TDirection> cfg,
     ReadOnlySpan <BasicBlock> .Enumerator enumerator)
 {
     nestedEnumerator = enumerator;
     CFG = cfg;
 }
Example #2
0
        /// <summary>
        /// Constructs the dominators for the given control flow graph.
        /// </summary>
        /// <param name="cfg">The control flow graph.</param>
        private Dominators(CFG cfg)
        {
            CFG = cfg ?? throw new ArgumentNullException(nameof(cfg));

            idomsInRPO = new int[cfg.Count];
            nodesInRPO = new CFG.Node[cfg.Count];

            idomsInRPO[0] = 0;
            for (int i = 1, e = idomsInRPO.Length; i < e; ++i)
            {
                idomsInRPO[i] = -1;
            }

            bool changed;

            do
            {
                changed = false;
                using (var enumerator = cfg.GetEnumerator())
                {
                    enumerator.MoveNext();
                    var node = enumerator.Current;
                    nodesInRPO[node.RPONumber] = node;

                    while (enumerator.MoveNext())
                    {
                        node = enumerator.Current;
                        nodesInRPO[node.RPONumber] = node;
                        int currentIdom = -1;
                        foreach (var pred in node.Predecessors)
                        {
                            var predRPO = pred.RPONumber;
                            if (idomsInRPO[predRPO] != -1)
                            {
                                currentIdom = predRPO;
                                break;
                            }
                        }

                        Debug.Assert(currentIdom != -1, "Invalid idom");
                        foreach (var pred in node.Predecessors)
                        {
                            var predRPO = pred.RPONumber;
                            if (idomsInRPO[predRPO] != -1)
                            {
                                currentIdom = Intersect(currentIdom, predRPO);
                            }
                        }

                        var rpoNumber = node.RPONumber;
                        if (idomsInRPO[rpoNumber] != currentIdom)
                        {
                            idomsInRPO[rpoNumber] = currentIdom;
                            changed = true;
                        }
                    }
                }
            }while (changed);
        }
Example #3
0
        /// <summary>
        /// Constructs the dominators for the given control-flow graph.
        /// </summary>
        /// <param name="cfg">The parent graph.</param>
        private Dominators(CFG <DominanceOrder, TDirection> cfg)
        {
            idomsInRPO = new int[cfg.Count];
            nodesInRPO = new BasicBlock[cfg.Count];
            CFG        = cfg;
            Root       = cfg.Root;

            idomsInRPO[0] = 0;
            for (int i = 1, e = idomsInRPO.Length; i < e; ++i)
            {
                idomsInRPO[i] = -1;
            }

            bool changed;

            do
            {
                changed = false;
                var enumerator = cfg.GetEnumerator();
                enumerator.MoveNext();
                var node = enumerator.Current;
                nodesInRPO[node.TraversalIndex] = node;

                while (enumerator.MoveNext())
                {
                    node = enumerator.Current;
                    nodesInRPO[node.TraversalIndex] = node;
                    int currentIdom = -1;
                    foreach (var pred in node.Predecessors)
                    {
                        var predRPO = pred.TraversalIndex;
                        if (idomsInRPO[predRPO] != -1)
                        {
                            currentIdom = predRPO;
                            break;
                        }
                    }

                    Debug.Assert(currentIdom != -1, "Invalid idom");
                    foreach (var pred in node.Predecessors)
                    {
                        var predRPO = pred.TraversalIndex;
                        if (idomsInRPO[predRPO] != -1)
                        {
                            currentIdom = Intersect(currentIdom, predRPO);
                        }
                    }

                    var rpoNumber = node.TraversalIndex;
                    if (idomsInRPO[rpoNumber] != currentIdom)
                    {
                        idomsInRPO[rpoNumber] = currentIdom;
                        changed = true;
                    }
                }
            }while (changed);
        }
Example #4
0
 public static NodeMapping <T> Create <TProvider>(
     CFG cfg,
     in TProvider provider)
Example #5
0
 internal NodeCollection(
     CFG <TOrder, TDirection> cfg,
     in ReadOnlySpan <BasicBlock> collection)
Example #6
0
 /// <summary>
 /// Creates a new dominator analysis.
 /// </summary>
 /// <param name="cfg">The parent graph.</param>
 /// <returns>The created dominator analysis.</returns>
 public static Dominators <TDirection> Create(
     CFG <DominanceOrder, TDirection> cfg) =>
 new Dominators <TDirection>(cfg);
Example #7
0
        private SCCs(CFG cfg)
        {
            Debug.Assert(cfg != null, "Invalid CFG");

            CFG = cfg;
            var mapping = cfg.CreateNodeMapping <NodeData, NodeDataProvider>(default);
Example #8
0
 public static SCCs Create(CFG cfg)
 {
     Debug.Assert(cfg != null, "Invalid CFG");
     return(new SCCs(cfg));
 }
Example #9
0
 /// <summary>
 /// Creates a dominator analysis.
 /// </summary>
 /// <param name="cfg">The control flow graph.</param>
 public static Dominators Create(CFG cfg) => new Dominators(cfg);