Пример #1
0
        public BitVector[] GetDominance( )
        {
            N[] idom = GetImmediateDominators();
            int num  = idom.Length;

            BitVector[] res = BitVector.AllocateBitVectors(num, num);

            for (int pos = 0; pos < num; pos++)
            {
                N   node = m_nodesSpanningTree[pos];
                var vec  = res[pos];

                while (true)
                {
                    int idx = node.SpanningTreeIndex;

                    vec.Set(idx);

                    N next = idom[idx];
                    if (next == node)
                    {
                        break;
                    }

                    node = next;
                }
            }

            return(res);
        }
Пример #2
0
        public BitVector[] GetDominanceFrontier( )
        {
            //
            // This is an implementation of the algorithm in "A Simple, Fast Dominance Algorithm", by Keith D. Cooper, Timothy J. Harvey, and Ken Kennedy.
            //
            //   "for all nodes, b
            //      if the number of predecessors of b >= 2
            //          for all predecessors, p, of b
            //              runner = p
            //              while runner != doms[b]
            //                  add b to runner’s dominance frontier set
            //                  runner = doms[runner]"
            //
            N[] idom = GetImmediateDominators();
            int num  = idom.Length;

            BitVector[] res = BitVector.AllocateBitVectors(num, num);

            for (int nodeBidx = 0; nodeBidx < num; nodeBidx++)
            {
                N nodeB = m_nodesSpanningTree[nodeBidx];

                if (nodeB.Predecessors.Length >= 2)
                {
                    foreach (var edge in nodeB.Predecessors)
                    {
                        N nodeP = (N)edge.Predecessor;

                        N runner = nodeP;
                        while (runner != idom[nodeBidx])
                        {
                            int idx = runner.SpanningTreeIndex;

                            res[idx].Set(nodeBidx);

                            runner = idom[idx];
                        }
                    }
                }
            }

            return(res);
        }
Пример #3
0
        private void ComputeImmediatePostDominators( )
        {
            int len = m_nodes.Length;

            BitVector[] tmp = BitVector.AllocateBitVectors(len, len);

            for (int n = 0; n < len; n++)
            {
                // Tmp(n) := PostDomin(n) - {n}
                tmp[n].Assign(m_postDominance[n]);
                tmp[n].Clear(n);
            }

            for (int n = 0; n < len; n++)  // Walk the basic blocks in pre-order.
            {
                // for each n in N do

                BitVector tmpN = tmp[n];

                for (int s = 0; s < len; s++)
                {
                    if (tmpN[s])
                    {
                        // for each s in Tmp(n) do

                        BitVector tmpS = tmp[s];

                        for (int t = 0; t < len; t++)
                        {
                            if (t != s && tmpN[t])
                            {
                                // for each t in Tmp(n) - {s} do

                                if (tmpS[t])
                                {
                                    // if t in Tmp(s) then Tmp(n) -= {t}

                                    tmpN.Clear(t);
                                }
                            }
                        }
                    }
                }
            }

            m_immediatePostDominators = new N[len];

            for (int n = 0; n < len; n++)
            {
                bool fGot = false;

                foreach (int idom in tmp[n])
                {
                    CHECKS.ASSERT(fGot == false, "Internal failure, found more than one immediate post dominators");

                    m_immediatePostDominators[n] = m_nodes[idom];

                    fGot = true;
                }
            }
        }