コード例 #1
0
 public BarrierInterval(Block start, Block end, DomRelation <Block> dom, DomRelation <Block> pdom, Implementation impl)
 {
     blocks = impl.Blocks.Where(Item =>
                                Item != end &&
                                dom.DominatedBy(Item, start) &&
                                pdom.DominatedBy(Item, end)).ToList();
 }
コード例 #2
0
        void AssignPredicates()
        {
            DomRelation <Block> dom = blockGraph.DominatorMap;

            Graph <Block>       dualGraph       = blockGraph.Dual(new Block());
            DomRelation <Block> pdom            = dualGraph.DominatorMap;
            IEnumerable <Block> headerDominance = blockGraph.SortHeadersByDominance();

            var iter = sortedBlocks.GetEnumerator();

            if (!iter.MoveNext())
            {
                predMap  = defMap = null;
                ownedMap = null;
                return;
            }

            int predCount = 0;

            predMap   = new Dictionary <Block, Variable>();
            defMap    = new Dictionary <Block, Variable>();
            ownedMap  = new Dictionary <Block, HashSet <Variable> >();
            parentMap = new Dictionary <Block, Block>();
            AssignPredicates(blockGraph, dom, pdom, headerDominance, iter,
                             myUseProcedurePredicates ? impl.InParams[0] : null,
                             ref predCount);
        }
コード例 #3
0
        void AssignPredicates(Graph <Block> blockGraph,
                              DomRelation <Block> dom,
                              DomRelation <Block> pdom,
                              IEnumerable <Block> headerDominance,
                              IEnumerator <Tuple <Block, bool> > i,
                              Variable headPredicate,
                              ref int predCount)
        {
            var header      = i.Current.Item1;
            var regionPreds = new List <Tuple <Block, Variable> >();
            var ownedPreds  = new HashSet <Variable>();

            ownedMap[header] = ownedPreds;

            if (headPredicate != null)
            {
                predMap[header] = headPredicate;
                defMap[header]  = headPredicate;
                regionPreds.Add(new Tuple <Block, Variable>(header, headPredicate));
            }

            while (i.MoveNext())
            {
                var block = i.Current;

                if (block.Item2)
                {
                    if (block.Item1 == header)
                    {
                        return;
                    }
                }

                if (uni != null && uni.IsUniform(impl.Name, block.Item1))
                {
                    if (blockGraph.Headers.Contains(block.Item1))
                    {
                        parentMap[block.Item1] = header;
                        AssignPredicates(blockGraph, dom, pdom, headerDominance, i, headPredicate, ref predCount);
                    }
                    continue;
                }

                if (!block.Item2)
                {
                    if (blockGraph.Headers.Contains(block.Item1))
                    {
                        parentMap[block.Item1] = header;
                        var loopPred = FreshPredicate(ref predCount);
                        ownedPreds.Add(loopPred);
                        AssignPredicates(blockGraph, dom, pdom, headerDominance, i, loopPred, ref predCount);
                    }
                    else
                    {
                        bool foundExisting = false;
                        foreach (var regionPred in regionPreds)
                        {
                            if (dom.DominatedBy(block.Item1, regionPred.Item1) &&
                                pdom.DominatedBy(regionPred.Item1, block.Item1))
                            {
                                predMap[block.Item1] = regionPred.Item2;
                                foundExisting        = true;
                                break;
                            }
                        }
                        if (!foundExisting)
                        {
                            var condPred = FreshPredicate(ref predCount);
                            predMap[block.Item1] = condPred;
                            defMap[block.Item1]  = condPred;
                            var headerIterator = headerDominance.GetEnumerator();
                            // Add the predicate to the loop header H that dominates the node (if one
                            // exists) such that H does not dominate another header which also dominates
                            // the node. Since predicates are owned by loop headers (or the program entry
                            // node), this is the block 'closest' to block to which we are assigning a
                            // that can be made to own the predicate.
                            Block node = null;
                            while (headerIterator.MoveNext())
                            {
                                var current = headerIterator.Current;
                                if (dom.DominatedBy(block.Item1, current))
                                {
                                    node = current;
                                    break;
                                }
                            }
                            if (node != null)
                            {
                                ownedMap[node].Add(condPred);
                            }
                            else
                            {
                                // In this case the header is the program entry node.
                                ownedPreds.Add(condPred);
                            }
                            regionPreds.Add(new Tuple <Block, Variable>(block.Item1, condPred));
                        }
                    }
                }
            }
        }
コード例 #4
0
        private HashSet <BarrierInterval> ComputeBarrierIntervals(Implementation impl)
        {
            HashSet <BarrierInterval> result = new HashSet <BarrierInterval>();

            ExtractCommandsIntoBlocks(impl, item => (item is CallCmd && GPUVerifier.IsBarrier(((CallCmd)item).Proc)));
            Graph <Block> cfg = Program.GraphFromImpl(impl);

            // If the CFG has no exit nodes, i.e. it cannot terminate,
            // we bail out; we need a single-entry single-exit CFG
            // and we cannot get one under such circumstances
            if (NoExitFromCFG(cfg))
            {
                return(result);
            }

            // To make the CFG single-exit, we add a special exit block
            Block specialExitBlock = new Block();

            cfg.Nodes.Add(specialExitBlock);

            // Now link any existing CFG node that has no successors to the
            // special exit node.
            foreach (var b in cfg.Nodes)
            {
                if (b == specialExitBlock)
                {
                    continue;
                }

                if (cfg.Successors(b).Count() == 0)
                {
                    cfg.AddEdge(b, specialExitBlock);
                }
            }

            Graph <Block>       dual = cfg.Dual(new Block());
            DomRelation <Block> dom  = cfg.DominatorMap;
            DomRelation <Block> pdom = dual.DominatorMap;

            foreach (var dominator in cfg.Nodes.Where(item => StartsWithUnconditionalBarrier(item, impl, specialExitBlock)))
            {
                Block smallestBarrierIntervalEnd = null;
                foreach (var postdominator in cfg.Nodes
                         .Where(item => item != dominator &&
                                StartsWithUnconditionalBarrier(item, impl, specialExitBlock) &&
                                dom.DominatedBy(item, dominator) &&
                                pdom.DominatedBy(dominator, item)))
                {
                    if (smallestBarrierIntervalEnd == null || dom.DominatedBy(smallestBarrierIntervalEnd, postdominator))
                    {
                        smallestBarrierIntervalEnd = postdominator;
                    }
                    else
                    {
                        Debug.Assert(dom.DominatedBy(postdominator, smallestBarrierIntervalEnd));
                    }
                }

                if (smallestBarrierIntervalEnd != null)
                {
                    result.Add(new BarrierInterval(dominator, smallestBarrierIntervalEnd, dom, pdom, impl));
                }
            }

            if (GPUVerifyVCGenCommandLineOptions.DebugGPUVerify)
            {
                Console.WriteLine("Found " + result.Count() + " barrier interval(s) in " + impl.Name);
            }

            return(result);
        }
コード例 #5
0
  void AssignPredicates(Graph<Block> blockGraph,
                        DomRelation<Block> dom,
                        DomRelation<Block> pdom,
                        IEnumerable<Block> headerDominance,
                        IEnumerator<Tuple<Block, bool>> i,
                        Variable headPredicate,
                        ref int predCount) {
    var header = i.Current.Item1;
    var regionPreds = new List<Tuple<Block, Variable>>();
    var ownedPreds = new HashSet<Variable>();
    ownedMap[header] = ownedPreds;

    if (headPredicate != null) {
      predMap[header] = headPredicate;
      defMap[header] = headPredicate;
      regionPreds.Add(new Tuple<Block, Variable>(header, headPredicate));
    }

    while (i.MoveNext()) {
      var block = i.Current;

      if (block.Item2) {
        if (block.Item1 == header) {
          return;
        }
      }

      if (uni != null && uni.IsUniform(impl.Name, block.Item1)) {
        if (blockGraph.Headers.Contains(block.Item1)) {
          parentMap[block.Item1] = header;
          AssignPredicates(blockGraph, dom, pdom, headerDominance, i, headPredicate, ref predCount);
        }
        continue;
      }

      if (!block.Item2) {
        if (blockGraph.Headers.Contains(block.Item1)) {
          parentMap[block.Item1] = header;
          var loopPred = FreshPredicate(ref predCount);
          ownedPreds.Add(loopPred);
          AssignPredicates(blockGraph, dom, pdom, headerDominance, i, loopPred, ref predCount);
        } else {
          bool foundExisting = false;
          foreach (var regionPred in regionPreds) {
            if (dom.DominatedBy(block.Item1, regionPred.Item1) &&
                pdom.DominatedBy(regionPred.Item1, block.Item1)) {
              predMap[block.Item1] = regionPred.Item2;
              foundExisting = true;
              break;
            }
          }
          if (!foundExisting) {
            var condPred = FreshPredicate(ref predCount);
            predMap[block.Item1] = condPred;
            defMap[block.Item1] = condPred;
            var headerIterator = headerDominance.GetEnumerator();
            // Add the predicate to the loop header H that dominates the node (if one
            // exists) such that H does not dominate another header which also dominates
            // the node. Since predicates are owned by loop headers (or the program entry
            // node), this is the block 'closest' to block to which we are assigning a
            // that can be made to own the predicate.
            Block node = null;
            while (headerIterator.MoveNext()) {
              var current = headerIterator.Current;
              if (dom.DominatedBy(block.Item1, current)) {
                node = current;
                break;
              }
            }
            if (node != null) {
              ownedMap[node].Add(condPred);
            } else {
               // In this case the header is the program entry node.
              ownedPreds.Add(condPred);
            }
            regionPreds.Add(new Tuple<Block, Variable>(block.Item1, condPred));
          }
        }
      }
    }
  }
コード例 #6
0
        void AssignPredicates(Graph <Block> blockGraph,
                              DomRelation <Block> dom,
                              DomRelation <Block> pdom,
                              IEnumerator <Tuple <Block, bool> > i,
                              Variable headPredicate,
                              ref int predCount)
        {
            var header      = i.Current.Item1;
            var regionPreds = new List <Tuple <Block, Variable> >();
            var ownedPreds  = new HashSet <Variable>();

            ownedMap[header] = ownedPreds;

            if (headPredicate != null)
            {
                predMap[header] = headPredicate;
                defMap[header]  = headPredicate;
                regionPreds.Add(new Tuple <Block, Variable>(header, headPredicate));
            }

            while (i.MoveNext())
            {
                var block = i.Current;

                if (block.Item2)
                {
                    if (block.Item1 == header)
                    {
                        return;
                    }
                }

                if (uni != null && uni.IsUniform(impl.Name, block.Item1))
                {
                    if (blockGraph.Headers.Contains(block.Item1))
                    {
                        parentMap[block.Item1] = header;
                        AssignPredicates(blockGraph, dom, pdom, i, headPredicate, ref predCount);
                    }
                    continue;
                }

                if (!block.Item2)
                {
                    if (blockGraph.Headers.Contains(block.Item1))
                    {
                        parentMap[block.Item1] = header;
                        var loopPred = FreshPredicate(ref predCount);
                        ownedPreds.Add(loopPred);
                        AssignPredicates(blockGraph, dom, pdom, i, loopPred, ref predCount);
                    }
                    else
                    {
                        bool foundExisting = false;
                        foreach (var regionPred in regionPreds)
                        {
                            if (dom.DominatedBy(block.Item1, regionPred.Item1) &&
                                pdom.DominatedBy(regionPred.Item1, block.Item1))
                            {
                                predMap[block.Item1] = regionPred.Item2;
                                foundExisting        = true;
                                break;
                            }
                        }
                        if (!foundExisting)
                        {
                            var condPred = FreshPredicate(ref predCount);
                            predMap[block.Item1] = condPred;
                            defMap[block.Item1]  = condPred;
                            ownedPreds.Add(condPred);
                            regionPreds.Add(new Tuple <Block, Variable>(block.Item1, condPred));
                        }
                    }
                }
            }
        }
コード例 #7
0
        void AssignPredicates(Graph<Block> blockGraph,
            DomRelation<Block> dom,
            DomRelation<Block> pdom,
            IEnumerator<Tuple<Block, bool>> i,
            Variable headPredicate,
            ref int predCount)
        {
            var header = i.Current.Item1;
            var regionPreds = new List<Tuple<Block, Variable>>();
            var ownedPreds = new HashSet<Variable>();
            ownedMap[header] = ownedPreds;

            if (headPredicate != null) {
              predMap[header] = headPredicate;
              defMap[header] = headPredicate;
              regionPreds.Add(new Tuple<Block, Variable>(header, headPredicate));
            }

            while (i.MoveNext()) {
              var block = i.Current;

              if (block.Item2) {
            if (block.Item1 == header) {
              return;
            }
              }

              if (uni != null && uni.IsUniform(impl.Name, block.Item1)) {
            if (blockGraph.Headers.Contains(block.Item1)) {
              parentMap[block.Item1] = header;
              AssignPredicates(blockGraph, dom, pdom, i, headPredicate, ref predCount);
            }
            continue;
              }

              if (!block.Item2) {
            if (blockGraph.Headers.Contains(block.Item1)) {
              parentMap[block.Item1] = header;
              var loopPred = FreshPredicate(ref predCount);
              ownedPreds.Add(loopPred);
              AssignPredicates(blockGraph, dom, pdom, i, loopPred, ref predCount);
            } else {
              bool foundExisting = false;
              foreach (var regionPred in regionPreds) {
            if (dom.DominatedBy(block.Item1, regionPred.Item1) &&
                pdom.DominatedBy(regionPred.Item1, block.Item1)) {
              predMap[block.Item1] = regionPred.Item2;
              foundExisting = true;
              break;
            }
              }
              if (!foundExisting) {
            var condPred = FreshPredicate(ref predCount);
            predMap[block.Item1] = condPred;
            defMap[block.Item1] = condPred;
            ownedPreds.Add(condPred);
            regionPreds.Add(new Tuple<Block, Variable>(block.Item1, condPred));
              }
            }
              }
            }
        }