예제 #1
0
        /// <summary>
        /// Traverses the call graph, and for each strongly connected
        /// component (SCC) performs SSA transformation and detection of
        /// trashed and preserved registers.
        /// </summary>
        /// <returns></returns>
        public List <SsaTransform> RewriteProceduresToSsa()
        {
            this.ssts = new List <SsaTransform>();
            var sscf = new SccFinder <Procedure>(new ProcedureGraph(program), UntangleProcedureScc);

            sscf.FindAll();
            return(ssts);
        }
예제 #2
0
        public HashSet <StructureNode> FindLoop()
        {
            loopNodeSet = new HashSet <StructureNode>();
            var f = new SccFinder <StructureNode>(new GraphAdapter(this), x => {}, ProcessScc);

            f.Find(interval.Header);
            return(loopNodeSet);
        }
예제 #3
0
        /// <summary>
        /// Find all linear induction variables in this procedure.
        /// </summary>
        public void Find()
        {
            var sccFinder = new SccFinder <SsaIdentifier>(new SsaGraph(ssa.Identifiers), x => {}, ProcessScc);

            foreach (SsaIdentifier sid in ssa.Identifiers)
            {
                sccFinder.Find(sid);
            }
        }
예제 #4
0
        public void UntangleProcedures2()
        {
            eventListener.ShowStatus("Eliminating intra-block dead registers.");
            IntraBlockDeadRegisters.Apply(program);

            var sscf = new SccFinder <Procedure>(new ProcedureGraph(program), UntangleProcedureScc);

            foreach (var procedure in program.Procedures.Values)
            {
                sscf.Find(procedure);
            }
        }
예제 #5
0
        // EXPERIMENTAL - consult uxmal before using
        /// <summary>
        /// Analyizes the procedures of a program by finding all strongly
        /// connected components (SCCs) and processing the SCCs one by one.
        /// </summary>
        public void AnalyzeProgram2()
        {
            var usb = new UserSignatureBuilder(program);

            usb.BuildSignatures();

            var sscf = new SccFinder <Procedure>(new ProcedureGraph(program), UntangleProcedureScc);

            foreach (var procedure in program.Procedures.Values)
            {
                sscf.Find(procedure);
            }
        }
        private void RunTest()
        {
            this.program  = builder.BuildProgram();
            this.dataFlow = new ProgramDataFlow(program);
            var sscf = new SccFinder <Procedure>(new ProcedureGraph(program), ProcessScc);

            foreach (var procedure in program.Procedures.Values)
            {
                sscf.Find(procedure);
            }
            var sbActual = new StringBuilder();
            var sw       = new StringWriter();

            foreach (var procedure in program.Procedures.Values)
            {
                var flow = dataFlow[procedure];
                sw.WriteLine("== {0} ====", procedure.Name);
                sw.Write("Preserved: ");
                sw.WriteLine(string.Join(",", flow.Preserved.OrderBy(p => p.ToString())));
                sw.Write("Trashed: ");
                sw.WriteLine(string.Join(",", flow.Trashed.OrderBy(p => p.ToString())));
                if (flow.Constants.Count > 0)
                {
                    sw.Write("Constants: ");
                    sw.Write(string.Join(
                                 ",",
                                 flow.Constants
                                 .OrderBy(kv => kv.Key.ToString())
                                 .Select(kv => string.Format(
                                             "{0}:{1}", kv.Key, kv.Value))));
                }
                sw.WriteLine();
            }
            var sExp    = sbExpected.ToString();
            var sActual = sw.ToString();

            if (sActual != sExp)
            {
                foreach (var proc in program.Procedures.Values)
                {
                    Debug.Print("------");
                    proc.Dump(true);
                }
                Debug.WriteLine(sActual);
                Assert.AreEqual(sExp, sActual);
            }
        }
예제 #7
0
        private List <Procedure> ProceduresInSccOrder(Program program)
        {
            var list = new List <Procedure>();

            void CollectScc(IList <Procedure> sccProcs)
            {
                list.AddRange(sccProcs);
            }

            var sscf = new SccFinder <Procedure>(new ProcedureGraph(program), CollectScc);

            foreach (var procedure in program.Procedures.Values)
            {
                sscf.Find(procedure);
            }
            return(list);
        }
예제 #8
0
        public ICollection <StructureNode> FindInfiniteLoops(DirectedGraph <StructureNode> graph, StructureNode entry)
        {
            List <StructureNode>      infiniteLoopHeaders = new List <StructureNode>();
            SccFinder <StructureNode> finder = new SccFinder <StructureNode>(graph, delegate(IList <StructureNode> scc)
            {
                if (!IsInfiniteLoop(graph, scc))
                {
                    return;
                }

                var header = FindNodeWithHighestPostOrderNumber(scc);
                foreach (StructureNode tail in graph.Predecessors(header))
                {
                    if (scc.Contains(tail))
                    {
                        infiniteLoopHeaders.Add(tail);
                    }
                }
            });

            finder.Find(entry);
            return(infiniteLoopHeaders);
        }
예제 #9
0
        /// <summary>
        /// Writes the strongly-connected components (SCCs) of the given <see cref="Program"/>'s
        /// call graph.
        /// </summary>
        /// <remarks>
        /// The entries are reverse depth first ordered, which means leaf procedures are written
        /// before their callers. The intent is to assist in debugging large program with deep
        /// call hierarchies.
        /// </remarks>
        public void WriteSccs(Program program)
        {
            var filename    = Path.ChangeExtension(Path.GetFileName(program.Filename), "sccs");
            var globalsPath = Path.Combine(program.SourceDirectory, filename);

            using (TextWriter output = host.CreateTextWriter(globalsPath))
            {
                var sscf = new SccFinder <Procedure>(new ProcedureGraph(program), procs =>
                {
                    output.WriteLine("== {0} procedures ===", procs.Count);
                    procs = procs.OrderBy(p => p.EntryAddress).ToList();
                    foreach (var proc in procs)
                    {
                        output.Write(proc.Name);
                        if (program.EntryPoints.ContainsKey(proc.EntryAddress))
                        {
                            output.Write(" (Entry point)");
                        }
                        output.WriteLine();
                    }
                });
                sscf.FindAll();
            }
        }
예제 #10
0
        public void UntangleProcedures2()
        {
            eventListener.ShowStatus("Eliminating intra-block dead registers.");
            IntraBlockDeadRegisters.Apply(program);

            var sscf = new SccFinder<Procedure>(new ProcedureGraph(program), UntangleProcedureScc);
            foreach (var procedure in program.Procedures.Values)
            {
                sscf.Find(procedure);
            }
        }
예제 #11
0
        // EXPERIMENTAL - consult uxmal before using
        /// <summary>
        /// Analyizes the procedures of a program by finding all strongly 
        /// connected components (SCCs) and processing the SCCs one by one.
        /// </summary>
        public void AnalyzeProgram2()
        {
            var usb = new UserSignatureBuilder(program);
            usb.BuildSignatures();

            var sscf = new SccFinder<Procedure>(new ProcedureGraph(program), UntangleProcedureScc);
            foreach (var procedure in program.Procedures.Values)
            {
                sscf.Find(procedure);
            }
        }