Example #1
0
        private void Transform4DoomedCheck(Implementation impl)
        {
            variable2SequenceNumber = new Dictionary<Variable, int>();
            incarnationOriginMap = new Dictionary<Incarnation, Absy>();
            if (impl.Blocks.Count < 1) return;

            impl.PruneUnreachableBlocks();
            AddBlocksBetween(impl.Blocks);
            ResetPredecessors(impl.Blocks);

            GraphAnalyzer ga = new GraphAnalyzer(impl.Blocks);
            LoopRemover lr = new LoopRemover(ga);
            lr.AbstractLoopUnrolling();

            impl.Blocks = ga.ToImplementation(out m_UncheckableBlocks);
            ResetPredecessors(impl.Blocks);

            // Check for the "BlocksBetween" if all their successors are in m_UncheckableBlocks
            List<Block> oldblocks = new List<Block>();
            oldblocks.AddRange(impl.Blocks);
            GenerateHelperBlocks(impl);
            #region Check for the "BlocksBetween" if all their successors are in m_UncheckableBlocks
            foreach (Block b in impl.Blocks)
            {
            if (oldblocks.Contains(b)) continue;
            GotoCmd gc = b.TransferCmd as GotoCmd;
            if (gc != null)
            {
                bool allsuccUncheckable = true;
                foreach (Block _b in gc.labelTargets)
                {
                    if (!m_UncheckableBlocks.Contains(_b))
                    {
                        allsuccUncheckable = false; break;
                    }
                }
                if (allsuccUncheckable && !m_UncheckableBlocks.Contains(b)) m_UncheckableBlocks.Add(b);
            }
            }
            #endregion

            impl.Blocks = DeepCopyBlocks(impl.Blocks, m_UncheckableBlocks);

            m_BlockReachabilityMap = new Dictionary<Block, Variable>();
            List<Cmd> cs = GenerateReachabilityPredicates(impl);

            //foreach (Block test in getTheFFinalBlock(impl.Blocks[0]))
            //{
            //    test.Cmds.AddRange(cs);
            //}

            ResetPredecessors(impl.Blocks);
            //EmitImpl(impl,false);

            Dictionary<Variable, Expr> var2Expr = PassifyProgram(impl, new ModelViewInfo(program, impl));

            // Collect the last incarnation of each reachability variable in the passive program
            foreach (KeyValuePair<Block, Variable> kvp in m_BlockReachabilityMap)
            {
            if (var2Expr.ContainsKey(kvp.Value))
            {
                m_LastReachVarIncarnation[kvp.Value] = (Expr)var2Expr[kvp.Value];
            }
            }
        }
Example #2
0
        private void Transform4DoomedCheck(Implementation impl)
        {
            variable2SequenceNumber = new Dictionary <Variable, int>();
            incarnationOriginMap    = new Dictionary <Incarnation, Absy>();
            if (impl.Blocks.Count < 1)
            {
                return;
            }

            impl.PruneUnreachableBlocks();
            AddBlocksBetween(impl.Blocks);
            ResetPredecessors(impl.Blocks);

            GraphAnalyzer ga = new GraphAnalyzer(impl.Blocks);
            LoopRemover   lr = new LoopRemover(ga);

            lr.AbstractLoopUnrolling();

            impl.Blocks = ga.ToImplementation(out m_UncheckableBlocks);
            ResetPredecessors(impl.Blocks);

            // Check for the "BlocksBetween" if all their successors are in m_UncheckableBlocks
            List <Block> oldblocks = new List <Block>();

            oldblocks.AddRange(impl.Blocks);
            GenerateHelperBlocks(impl);
            #region Check for the "BlocksBetween" if all their successors are in m_UncheckableBlocks
            foreach (Block b in impl.Blocks)
            {
                if (oldblocks.Contains(b))
                {
                    continue;
                }
                GotoCmd gc = b.TransferCmd as GotoCmd;
                if (gc != null)
                {
                    bool allsuccUncheckable = true;
                    foreach (Block _b in gc.labelTargets)
                    {
                        if (!m_UncheckableBlocks.Contains(_b))
                        {
                            allsuccUncheckable = false; break;
                        }
                    }
                    if (allsuccUncheckable && !m_UncheckableBlocks.Contains(b))
                    {
                        m_UncheckableBlocks.Add(b);
                    }
                }
            }
            #endregion

            impl.Blocks = DeepCopyBlocks(impl.Blocks, m_UncheckableBlocks);

            m_BlockReachabilityMap = new Dictionary <Block, Variable>();
            List <Cmd> cs = GenerateReachabilityPredicates(impl);

            //foreach (Block test in getTheFFinalBlock(impl.Blocks[0]))
            //{
            //    test.Cmds.AddRange(cs);
            //}

            ResetPredecessors(impl.Blocks);
            //EmitImpl(impl,false);

            Dictionary <Variable, Expr> var2Expr = PassifyProgram(impl, new ModelViewInfo(program, impl));

            // Collect the last incarnation of each reachability variable in the passive program
            foreach (KeyValuePair <Block, Variable> kvp in m_BlockReachabilityMap)
            {
                if (var2Expr.ContainsKey(kvp.Value))
                {
                    m_LastReachVarIncarnation[kvp.Value] = (Expr)var2Expr[kvp.Value];
                }
            }
        }
Example #3
0
        // Copy Constructor
        public Loop(Loop l, GraphAnalyzer ga, string prefix)
        {
            Dictionary <GraphNode, GraphNode> clonemap = new Dictionary <GraphNode, GraphNode>();
            GraphNode clonecutpoint = null;

            foreach (GraphNode gn in l.LoopNodes)
            {
                clonemap[gn] = ga.CloneGraphNode(gn, prefix);
                if (gn == l.Cutpoint)
                {
                    clonecutpoint = clonemap[gn];
                }
            }

            if (clonecutpoint == null)
            {
                Debugger.Break();
                return;
            }
            // Replace the pre and post nodes by the corresponding clone
            foreach (GraphNode gn in l.LoopNodes)
            {
                List <GraphNode> newl = new List <GraphNode>();
                foreach (GraphNode g in clonemap[gn].Pre)
                {
                    if (clonemap.ContainsKey(g))
                    {
                        newl.Add(clonemap[g]);
                    }
                    else
                    {
                        newl.Add(g);
                    }
                }
                clonemap[gn].Pre = newl;
                newl             = new List <GraphNode>();
                foreach (GraphNode g in clonemap[gn].Suc)
                {
                    if (clonemap.ContainsKey(g))
                    {
                        newl.Add(clonemap[g]);
                    }
                    else
                    {
                        newl.Add(g);
                    }
                }
                clonemap[gn].Suc = newl;
                newl             = new List <GraphNode>();
                foreach (GraphNode g in clonemap[gn].LoopingPred)
                {
                    if (clonemap.ContainsKey(g))
                    {
                        newl.Add(clonemap[g]);
                    }
                    else
                    {
                        newl.Add(g);
                    }
                }
                clonemap[gn].LoopingPred = newl;
            }

            foreach (GraphNode gn in l.Cutpoint.LoopingPred)
            {
                clonecutpoint.LoopingPred.Remove(gn);
                clonecutpoint.LoopingPred.Add(clonemap[gn]);
            }



            SucLoops.AddRange(l.SucLoops);
            PreLoops.AddRange(l.PreLoops);
            Cutpoint = clonecutpoint;
            LoopNodes.Add(Cutpoint);
            foreach (GraphNode gn in Cutpoint.LoopingPred)
            {
                CollectLoopBody(gn);
            }
            CollectLoopExitNodes();
        }
Example #4
0
 public LoopRemover(GraphAnalyzer ga)
 {
     m_GraphAnalyzer = ga;
 }
        // Copy Constructor
        public Loop(Loop l, GraphAnalyzer ga, string prefix)
        {
            
            Dictionary<GraphNode, GraphNode> clonemap = new Dictionary<GraphNode, GraphNode>();
            GraphNode clonecutpoint = null;
            foreach (GraphNode gn in l.LoopNodes)
            {
                clonemap[gn] = ga.CloneGraphNode(gn, prefix);
                if (gn == l.Cutpoint) clonecutpoint = clonemap[gn];
            }

            if (clonecutpoint == null)
            {
                Debugger.Break();
                return;
            }
            // Replace the pre and post nodes by the corresponding clone
            foreach (GraphNode gn in l.LoopNodes)
            {
                List<GraphNode> newl = new List<GraphNode>();
                foreach (GraphNode g in clonemap[gn].Pre)
                {
                    if (clonemap.ContainsKey(g)) newl.Add(clonemap[g]);
                    else newl.Add(g);
                }
                clonemap[gn].Pre = newl;
                newl = new List<GraphNode>();
                foreach (GraphNode g in clonemap[gn].Suc)
                {
                    if (clonemap.ContainsKey(g)) newl.Add(clonemap[g]);
                    else newl.Add(g);
                }
                clonemap[gn].Suc = newl;
                newl = new List<GraphNode>();
                foreach (GraphNode g in clonemap[gn].LoopingPred)
                {
                    if (clonemap.ContainsKey(g)) newl.Add(clonemap[g]);
                    else newl.Add(g);
                }
                clonemap[gn].LoopingPred = newl;
            }

            foreach (GraphNode gn in l.Cutpoint.LoopingPred)
            {
                clonecutpoint.LoopingPred.Remove(gn);
                clonecutpoint.LoopingPred.Add(clonemap[gn]);
            }

            

            SucLoops.AddRange(l.SucLoops);
            PreLoops.AddRange(l.PreLoops);
            Cutpoint = clonecutpoint;
            LoopNodes.Add(Cutpoint);
            foreach (GraphNode gn in Cutpoint.LoopingPred)
            {
                CollectLoopBody(gn);
            }
            CollectLoopExitNodes();
        }
 public LoopRemover(GraphAnalyzer ga)
 {
     m_GraphAnalyzer = ga;
 }