Exemple #1
0
        private void SetupPredecessorEdges()
        {
            Contract.Ensures(this.predecessorEdges != null);

            var predecessorEdges = this.predecessorEdges = new List <BasicBlock>(this.cfg.SuccessorEdges.Count);
            MultiHashtable <BasicBlock> blocksThatTarget = new MultiHashtable <BasicBlock>();

            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                foreach (var successor in this.cfg.SuccessorsFor(block))
                {
                    blocksThatTarget.Add(successor.Offset, block);
                }
            }
            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                block.firstPredecessorEdge = predecessorEdges.Count;
                foreach (var predecessor in blocksThatTarget.GetValuesFor(block.Offset))
                {
                    predecessorEdges.Add(predecessor);
                }
                block.predeccessorCount = predecessorEdges.Count - block.firstPredecessorEdge;
            }
        }
Exemple #2
0
        private void SetupDominanceFrontier()
        {
            Contract.Ensures(this.dominanceFrontier != null);
            MultiHashtable <BasicBlock> frontierFor = new MultiHashtable <BasicBlock>();

            if (!this.immediateDominatorsAreInitialized)
            {
                this.SetupImmediateDominators();
            }
            var predecessorEdges = this.predecessorEdges;

            Contract.Assume(predecessorEdges != null);

            var dominanceFrontier = this.dominanceFrontier = new List <BasicBlock>(this.cfg.AllBlocks.Count * 2);

            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                var n = block.predeccessorCount;
                if (n < 2)
                {
                    continue;
                }
                for (int i = 0; i < n; i++)
                {
                    Contract.Assume(block.firstPredecessorEdge + i >= 0);
                    Contract.Assume(block.firstPredecessorEdge + i < predecessorEdges.Count);
                    var pred = predecessorEdges[block.firstPredecessorEdge + i];
                    Contract.Assume(pred != null);
                    var a = pred;
                    while (true)
                    {
                        if (a == block.immediateDominator)
                        {
                            break;                    //Any node that dominates node a will also dominate node block and hence block will not be in its dominance frontier.
                        }
                        frontierFor.Add(a.Offset, block);
                        if (a == a.immediateDominator)
                        {
                            break;                //Since there are multiple roots, block can be its own immediate dominator while still having predecessors.
                        }
                        a = (BasicBlock)a.immediateDominator;
                        Contract.Assume(a != null);
                    }
                }
            }
            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                block.firstDominanceFrontierNode = dominanceFrontier.Count;
                foreach (var frontierNode in frontierFor.GetValuesFor(block.Offset))
                {
                    dominanceFrontier.Add(frontierNode);
                }
                block.dominanceFrontierCount = dominanceFrontier.Count - block.firstDominanceFrontierNode;
            }
            dominanceFrontier.TrimExcess();
        }
Exemple #3
0
 internal void AddBinaryError(
     uint offset,
     MetadataReaderErrorKind errorKind
     )
 {
     foreach (MetadataReaderErrorMessage errMessage in _errorList.GetValuesFor((uint)errorKind))
     {
         IBinaryLocation /*?*/ binaryLocation = errMessage.Location as IBinaryLocation;
         if (binaryLocation == null)
         {
             continue;
         }
         if (binaryLocation.Offset == offset)
         {
             return;
         }
     }
     this.AddMetadataReaderErrorMessage(new MetadataReaderErrorMessage(_metadataReader.ErrorsReporter, new BinaryLocation(_binaryDocument, offset), errorKind));
 }
        private void SetupDominanceFrontier()
        {
            Contract.Ensures(this.dominanceFrontier != null);
            MultiHashtable <BasicBlock> frontierFor = new MultiHashtable <BasicBlock>();

            if (!this.immediateDominatorsAreInitialized)
            {
                this.SetupImmediateDominators();
            }
            var predecessorEdges = this.predecessorEdges;

            Contract.Assume(predecessorEdges != null);

            var dominanceFrontier = this.dominanceFrontier = new List <BasicBlock>(this.cfg.AllBlocks.Count * 2);

            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                var n = block.predeccessorCount;
                if (n < 2)
                {
                    continue;
                }
                for (int i = 0; i < n; i++)
                {
                    Contract.Assume(block.firstPredecessorEdge + i >= 0);
                    Contract.Assume(block.firstPredecessorEdge + i < predecessorEdges.Count);
                    var pred = predecessorEdges[block.firstPredecessorEdge + i];
                    Contract.Assume(pred != null);
                    var a = pred;
                    while (a != block.immediateDominator)
                    {
                        frontierFor.Add(a.Offset, block);
                        a = (BasicBlock)a.immediateDominator;
                        Contract.Assume(a != null);
                    }
                }
            }
            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                block.firstDominanceFrontierNode = dominanceFrontier.Count;
                foreach (var frontierNode in frontierFor.GetValuesFor(block.Offset))
                {
                    dominanceFrontier.Add(frontierNode);
                }
                block.dominanceFrontierCount = dominanceFrontier.Count - block.firstDominanceFrontierNode;
            }
            dominanceFrontier.TrimExcess();
        }