Example #1
0
 /// <summary>
 /// Constructs a new phi binding allocator.
 /// </summary>
 /// <param name="parent">The parent code generator.</param>
 /// <param name="cfg">The CFG to use.</param>
 public PhiBindingAllocator(CLCodeGenerator parent, CFG cfg)
 {
     phiMapping = new Dictionary <BasicBlock, List <Variable> >(cfg.Count);
     Parent     = parent;
     CFG        = cfg;
     Dominators = Dominators.Create(cfg);
 }
Example #2
0
 /// <summary>
 /// Creates a new if infos instance.
 /// </summary>
 /// <param name="dominators">The current dominators.</param>
 /// <returns>The created info instance.</returns>
 public static IfInfos Create(Dominators dominators)
 {
     if (dominators == null)
     {
         throw new ArgumentNullException(nameof(dominators));
     }
     return(new IfInfos(dominators));
 }
Example #3
0
 /// <summary>
 /// Creates a new if infos instance.
 /// </summary>
 /// <param name="cfg">The current CFG.</param>
 /// <returns>The created info instance.</returns>
 public static IfInfos Create(CFG cfg)
 {
     if (cfg == null)
     {
         throw new ArgumentNullException(nameof(cfg));
     }
     return(Create(Dominators.Create(cfg)));
 }
Example #4
0
        public override string ToString()
        {
            var inBlocks  = string.Join(", ", InBlocks.Select(x => x.Id));
            var outBlocks = string.Join(", ", OutBlocks.Select(x => x.Id));
            var idom      = IDom == null ? "null" : IDom.Id.ToString();
            var doms      = string.Join(", ", Dominators.Select(x => x.Id));
            var children  = string.Join(", ", DominantChildren.Select(x => x.Id));
            var df        = string.Join(", ", DominanceFrontiers.Select(x => x.Id));
            var variables = string.Join(", ", Variables);

            return($"Block {Id} ({Name}): nodes={Nodes.Count}, exited={Exited}, in=({inBlocks}), out=({outBlocks}), idom={idom}, doms=({doms}), domchildren=({children}), df=({df}), variables=({variables})");
        }
Example #5
0
        private static bool TryCreate(
            Dominators dominators,
            CFG.Node exitNode,
            out IfInfo ifInfo)
        {
            Debug.Assert(dominators != null, "Invalid dominators");
            Debug.Assert(exitNode != null, "Invalid exit node");

            ifInfo = default;

            // Check whether this node can be the exit node of an if branch
            if (exitNode.NumPredecessors != 2)
            {
                return(false);
            }

            // Interpret each predecessor as one branch
            var truePred  = exitNode.Predecessors[0];
            var falsePred = exitNode.Predecessors[1];

            // Try to resolve the branch node
            var entryNode = dominators.GetImmediateCommonDominator(truePred, falsePred);

            if (entryNode.NumSuccessors != 2)
            {
                return(false);
            }

            var entryBlock = entryNode.Block;

            if (!(entryBlock.Terminator is ConditionalBranch branch))
            {
                return(false);
            }

            ifInfo = new IfInfo(
                branch.Condition,
                entryBlock,
                branch.TrueTarget,
                branch.FalseTarget,
                exitNode.Block);

            return(true);
        }
Example #6
0
        /// <summary>
        /// Constructs a new info infos instance.
        /// </summary>
        /// <param name="dominators">The source dominators.</param>
        private IfInfos(Dominators dominators)
        {
            Debug.Assert(dominators != null, "Invalid dominators");
            Dominators = dominators;

            var cfg = dominators.CFG;

            ifs   = new Dictionary <CFG.Node, IfInfo>(cfg.Count);
            infos = new List <IfInfo>(cfg.Count);

            foreach (var exitNode in cfg)
            {
                // True to resolve if information for the current node
                if (TryCreate(dominators, exitNode, out var ifInfo))
                {
                    ifs.Add(exitNode, ifInfo);
                    infos.Add(ifInfo);
                }
            }
        }