Beispiel #1
0
        /// <summary>
        /// Summarizes the net effect each procedure has on registers,
        /// then removes trashed registers that aren't live-out.
        /// </summary>
        public List <SsaTransform> UntangleProcedures()
        {
            eventListener.ShowProgress("Rewriting procedures.", 0, program.Procedures.Count);

            IntraBlockDeadRegisters.Apply(program, eventListener);

            AdjacentBranchCollector.Transform(program, eventListener);

            var ssts = RewriteProceduresToSsa();

            // Recreate user-defined signatures. It should prevent type
            // inference between user-defined parameters and other expressions
            var usb = new UserSignatureBuilder(program);

            usb.BuildSignatures(eventListener);

            // Discover ssaId's that are live out at each call site.
            // Delete all others.
            var uvr = new UnusedOutValuesRemover(
                program,
                ssts.Select(sst => sst.SsaState),
                this.flow,
                dynamicLinker,
                eventListener);

            uvr.Transform();

            // At this point, the exit blocks contain only live out registers.
            // We can create signatures from that.
            CallRewriter.Rewrite(program.Platform, ssts, this.flow, eventListener);
            return(ssts);
        }
Beispiel #2
0
 public static void Apply(Program program)
 {
     foreach (var block in program.Procedures.Values.SelectMany(p => p.ControlGraph.Blocks))
     {
         var ibdr = new IntraBlockDeadRegisters();
         ibdr.Apply(block);
     }
 }
Beispiel #3
0
 public static void Apply(Program program, DecompilerEventListener eventListener)
 {
     foreach (var block in program.Procedures.Values.SelectMany(p => p.ControlGraph.Blocks))
     {
         if (eventListener.IsCanceled())
         {
             break;
         }
         var ibdr = new IntraBlockDeadRegisters();
         ibdr.Apply(block);
     }
 }
Beispiel #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);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Finds all interprocedural register dependencies (in- and out-parameters) and
        /// abstracts them away by rewriting as calls.
        /// </summary>
        /// <returns>A RegisterLiveness object that summarizes the interprocedural register
        /// liveness analysis. This information can be used to generate SSA form.
        /// </returns>
        public void UntangleProcedures()
        {
            eventListener.ShowStatus("Eliminating intra-block dead registers.");
            IntraBlockDeadRegisters.Apply(program);
            eventListener.ShowStatus("Finding terminating procedures.");
            var term = new TerminationAnalysis(flow);

            term.Analyze(program);
            eventListener.ShowStatus("Finding trashed registers.");
            var trf = new TrashedRegisterFinder(program, program.Procedures.Values, flow, eventListener);

            trf.Compute();
            eventListener.ShowStatus("Rewriting affine expressions.");
            trf.RewriteBasicBlocks();
            eventListener.ShowStatus("Computing register liveness.");
            var rl = RegisterLiveness.Compute(program, flow, eventListener);

            eventListener.ShowStatus("Rewriting calls.");
            GlobalCallRewriter.Rewrite(program, flow);
        }
Beispiel #6
0
        /// <summary>
        /// Finds all interprocedural register dependencies (in- and out-parameters) and
        /// abstracts them away by rewriting as calls.
        /// </summary>
        /// <returns>A RegisterLiveness object that summarizes the interprocedural register
        /// liveness analysis. This information can be used to generate SSA form.
        /// </returns>
        public void UntangleProcedures()
        {
            eventListener.ShowStatus("Eliminating intra-block dead registers.");
            var usb = new UserSignatureBuilder(program);

            usb.BuildSignatures(eventListener);
            CallRewriter.Rewrite(program, eventListener);
            IntraBlockDeadRegisters.Apply(program, eventListener);
            AdjacentBranchCollector.Transform(program, eventListener);
            eventListener.ShowStatus("Finding terminating procedures.");
            var term = new TerminationAnalysis(flow, eventListener);

            term.Analyze(program);
            eventListener.ShowStatus("Finding trashed registers.");
            var trf = new TrashedRegisterFinder(program, program.Procedures.Values, flow, eventListener);

            trf.Compute();
            eventListener.ShowStatus("Rewriting affine expressions.");
            trf.RewriteBasicBlocks();
            eventListener.ShowStatus("Computing register liveness.");
            RegisterLiveness.Compute(program, flow, eventListener);
            eventListener.ShowStatus("Rewriting calls.");
            GlobalCallRewriter.Rewrite(program, flow, eventListener);
        }
Beispiel #7
0
 public ExpVisitor(IntraBlockDeadRegisters outer)
 {
     this.outer = outer;
 }