use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.
the class SSAGenPass method generate.
private VersionedLocal generate(AbstractCopyStmt copy) {
VarExpr v = copy.getVariable();
Local oldLocal = v.getLocal();
int index = oldLocal.getIndex();
boolean isStack = oldLocal.isStack();
LocalsPool handler = builder.graph.getLocals();
Local l = handler.get(index, isStack);
int subscript = counters.get(l);
stacks.get(l).push(subscript);
counters.put(l, subscript + 1);
VersionedLocal ssaL = handler.get(index, subscript, isStack);
if (OPTIMISE) {
makeValue(copy, ssaL);
}
v.setLocal(ssaL);
pool.defs.put(ssaL, copy);
types.put(ssaL, copy.getExpression().getType());
pool.uses.put(ssaL, new HashSet<>());
return ssaL;
}
use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.
the class SSAGenPass method fixPhiArgs.
private void fixPhiArgs(BasicBlock b, BasicBlock succ) {
for (Stmt stmt : succ) {
if (stmt.getOpcode() == Opcode.PHI_STORE) {
CopyPhiStmt copy = (CopyPhiStmt) stmt;
PhiExpr phi = copy.getExpression();
Expr e = phi.getArgument(b);
if (e.getOpcode() == Opcode.LOCAL_LOAD) {
VarExpr v = (VarExpr) e;
translate(v, true, true);
VersionedLocal ssaL = (VersionedLocal) v.getLocal();
Type t = types.get(ssaL);
copy.getVariable().setType(t);
phi.setType(t);
} else {
throw new IllegalArgumentException(phi + ", " + e);
}
} else {
/* No need to search the rest of the block
* after we have visited the phis as they
* precede all other statements.
*/
break;
}
}
}
use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.
the class SSAGenPass method processDeferredTranslations.
private int processDeferredTranslations() {
int i = 0;
Iterator<Entry<VersionedLocal, Set<VarExpr>>> it = pool.uses.entrySet().iterator();
while (it.hasNext()) {
Entry<VersionedLocal, Set<VarExpr>> e = it.next();
VersionedLocal vl = e.getKey();
if (deferred.contains(vl) || vl.isStack()) {
Set<VarExpr> useSet = e.getValue();
AbstractCopyStmt def = pool.defs.get(vl);
if (def != null && useSet.size() == 1) {
/* In this case, the only place that the value
* of this assignment will be used is at the use site.
* Since that value can not be spread until this one
* is, we can propagate it.*/
if (def.getOpcode() != Opcode.PHI_STORE) {
VarExpr use = useSet.iterator().next();
LatestValue val = latest.get(vl);
// System.out.println();
// System.out.println();
// System.out.println(def);
// System.out.println(use);
/* phi var*/
Expr rhs = def.getExpression();
if (use.getParent() != null) {
if (canTransferHandlers(def.getBlock(), use.getBlock()) && val.canPropagate(def, use.getRootParent(), use, false)) {
CodeUnit parent = use.getParent();
if (rhs.getOpcode() == Opcode.CATCH) {
// CodeUnit rp = use.getRootParent();
// System.out.println("DENIED NIGGA");
// System.out.println("replace " + vl + " with " + rhs);
// System.out.println(" in " + parent);
// System.out.println(" kill def: " + def);
// System.out.println();
deferred.remove(vl);
continue;
// check to see if we're moving it to the
// first expression in the block, if we aren't
// then deny, otherwise we can get rid of the local.
// if(rp.getBlock().indexOf(rp) != 1 || rp.enumerateExecutionOrder().indexOf(use) != 0) {
//
// }
}
rhs.unlink();
def.delete();
pool.defs.remove(vl);
useSet.clear();
parent.overwrite(rhs, parent.indexOf(use));
i++;
it.remove();
}
}
}
}
}
}
return i;
}
use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.
the class SSAGenPass method prune.
private boolean prune(AbstractCopyStmt def) {
if (def.isSynthetic()) {
return false;
}
Expr e = def.getExpression();
if (canPrune(e)) {
for (Expr s : e.enumerateWithSelf()) {
if (s.getOpcode() == Opcode.LOCAL_LOAD) {
VarExpr v = (VarExpr) s;
VersionedLocal vl = (VersionedLocal) v.getLocal();
pool.uses.get(vl).remove(v);
}
}
def.delete();
return true;
}
return false;
}
use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.
the class SSAGenPass method latest.
private VersionedLocal latest(int index, boolean isStack) {
LocalsPool handler = builder.graph.getLocals();
Local l = handler.get(index, isStack);
Stack<Integer> stack = stacks.get(l);
if (stack == null || stack.isEmpty()) {
System.err.println(builder.method.owner.name + "#" + builder.method.name);
System.err.println(builder.graph);
System.err.println(stacks);
throw new NullPointerException(l.toString());
}
return handler.get(index, stack.peek(), /*subscript*/
isStack);
}
Aggregations