Re-enable simpleMerge with additional scoping restrictions

I've changed it to only merge variables within the same basic block,
which improves the output significantly.
master
Graham 4 years ago
parent fda8f42dd0
commit 74c7174bbf
  1. 37
      src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java

@ -4,10 +4,12 @@ package org.jetbrains.java.decompiler.modules.decompiler.vars;
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.collectors.CounterContainer;
import org.jetbrains.java.decompiler.modules.decompiler.exps.AssignmentExprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.ConstExprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
import org.jetbrains.java.decompiler.modules.decompiler.sforms.DirectGraph;
import org.jetbrains.java.decompiler.modules.decompiler.sforms.DirectNode;
import org.jetbrains.java.decompiler.modules.decompiler.sforms.FlattenStatementsHelper;
import org.jetbrains.java.decompiler.modules.decompiler.sforms.SSAConstructorSparseEx;
import org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement;
@ -40,7 +42,7 @@ public class VarVersionsProcessor {
typeProcessor.calculateVarTypes(root, graph);
//simpleMerge(typeProcessor, graph, method);
simpleMerge(typeProcessor, graph, method);
// FIXME: advanced merging
@ -166,6 +168,39 @@ public class VarVersionsProcessor {
for (int j = i + 1; j < lstVersions.size(); j++) {
VarVersionPair secondPair = new VarVersionPair(ent.getKey(), lstVersions.get(j));
// find all scopes the two variable versions are assigned in
Set<DirectNode> nodes = new HashSet<>();
for (DirectNode node : graph.nodes) {
for (Exprent expr : node.exprents) {
if (expr.type != Exprent.EXPRENT_ASSIGNMENT) {
continue;
}
AssignmentExprent assignExpr = (AssignmentExprent) expr;
Exprent leftExpr = assignExpr.getLeft();
if (leftExpr.type != Exprent.EXPRENT_VAR) {
continue;
}
VarExprent varExpr = (VarExprent) leftExpr;
int index = varExpr.getIndex();
int version = varExpr.getVersion();
if (index == firstPair.var && version == firstPair.version) {
nodes.add(node);
} else if (index == secondPair.var && version == secondPair.version) {
nodes.add(node);
}
}
}
// only merge variables if they're assigned in the same scope
if (nodes.size() > 1) {
continue;
}
VarType secondType = mapExprentMinTypes.get(secondPair);
if (firstType.equals(secondType) ||

Loading…
Cancel
Save