Skip to content

Commit

Permalink
Refactor: adapt DataFlowAnalysis to use SccWorkerCoordinator (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Aug 4, 2023
1 parent b48a4de commit f9ff640
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Decompiler/Analysis/CallRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CallRewriter(IPlatform platform, ProgramDataFlow mpprocflow, IDecompilerE

public static void Rewrite(
IPlatform platform,
List<SsaTransform> ssts,
IReadOnlyCollection<SsaTransform> ssts,
ProgramDataFlow summaries,
IDecompilerEventListener eventListener)
{
Expand Down
33 changes: 27 additions & 6 deletions src/Decompiler/Analysis/DataFlowAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
*/
#endregion

using Reko.Concurrent;
using Reko.Core;
using Reko.Core.Code;
using Reko.Core.Expressions;
using Reko.Core.Graphs;
using Reko.Core.Hll.C;
using Reko.Core.Output;
using Reko.Core.Services;
using Reko.Core.Types;
using Reko.Services;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -112,11 +112,11 @@ public void AnalyzeProgram()
/// Summarizes the net effect each procedure has on registers,
/// then removes trashed registers that aren't live-out.
/// </summary>
public List<SsaTransform> UntangleProcedures()
public IReadOnlyCollection<SsaTransform> UntangleProcedures()
{
eventListener.Progress.ShowProgress("Rewriting procedures.", 0, Program.Procedures.Count);

var ssts = new List<SsaTransform>();
IReadOnlyCollection<SsaTransform> ssts = Array.Empty<SsaTransform>();
IntraBlockDeadRegisters.Apply(Program, eventListener);
if (eventListener.IsCanceled())
return ssts;
Expand Down Expand Up @@ -171,7 +171,6 @@ public List<SsaTransform> RewriteProceduresToSsa()
var ssts = new List<SsaTransform>();
var sccs = SccFinder.Condense(new ProcedureGraph(Program));
var sccWorkers = sccs.Members.Values.Select(CreateSccWorker);
//$TODO: make a TaskTree out of this.
foreach (var worker in sccWorkers)
{
if (eventListener.IsCanceled())
Expand All @@ -182,6 +181,28 @@ public List<SsaTransform> RewriteProceduresToSsa()
return ssts;
}

public IReadOnlyCollection<SsaTransform> RewriteProceduresToSsa_Concurrent()
{
var ssts = new ConcurrentQueue<SsaTransform>();
var sccs = SccFinder.Condense(new ProcedureGraph(Program));
var coordinator = new SccWorkerCoordinator<Procedure>(sccs, eventListener, procs =>
{
Debug.Print("== Working on {0}", string.Join(",", procs.Select(p => p.Name)));
if (eventListener.IsCanceled())
return;
var worker = CreateSccWorker(procs);
var sccSsts = worker.Transform();
foreach (var sccSst in sccSsts)
{
ssts.Enqueue(sccSst);
}
Debug.Print("== Done with {0}", string.Join(",", procs.Select(p => p.Name)));
});
coordinator.RunAsync().Wait();
return ssts;
}

private SccWorker CreateSccWorker(Procedure[] scc)
{
return new SccWorker(this, scc, this.dynamicLinker, this.services);
Expand All @@ -193,7 +214,7 @@ private SccWorker CreateSccWorker(Procedure[] scc)
/// trees out of the simple, close-to-the-machine code generated by
/// the disassembly.
/// </summary>
public void BuildExpressionTrees(List<SsaTransform> ssts)
public void BuildExpressionTrees(IReadOnlyCollection<SsaTransform> ssts)
{
eventListener.Progress.ShowProgress("Building expressions.", 0, Program.Procedures.Count);
foreach (var sst in ssts)
Expand Down
2 changes: 1 addition & 1 deletion src/Decompiler/Decompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public virtual void AnalyzeDataFlow()
var ir = new DynamicLinker(project, program, eventListener);
var dfa = new DataFlowAnalysis(program, ir, services);
dfa.ClearTestFiles();
var ssas = new List<SsaTransform>();
IReadOnlyCollection<SsaTransform> ssas = new List<SsaTransform>();
if (program.NeedsSsaTransform)
{
eventListener.Progress.ShowStatus("Performing interprocedural analysis.");
Expand Down

0 comments on commit f9ff640

Please sign in to comment.