use of org.mapleir.ir.code.expr.PhiExpr 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.code.expr.PhiExpr in project maple-ir by LLVM-but-worse.
the class CodeUnit method _enumerate.
protected Set<Expr> _enumerate() {
Set<Expr> set = new HashSet<>();
if (opcode == Opcode.PHI) {
/*CopyPhiStmt phi = (CopyPhiStmt) this;
for(Expr e : phi.getExpression().getArguments().values()) {
set.add(e);
set.addAll(e._enumerate());
}*/
PhiExpr phi = (PhiExpr) this;
for (Expr e : phi.getArguments().values()) {
set.add(e);
set.addAll(e._enumerate());
}
} else {
for (Expr c : children) {
if (c != null) {
set.add(c);
set.addAll(c._enumerate());
}
}
}
return set;
}
use of org.mapleir.ir.code.expr.PhiExpr in project maple-ir by LLVM-but-worse.
the class PoolLocalValueResolver method getValues.
@Override
public TaintableSet<Expr> getValues(ControlFlowGraph cfg, Local l) {
if (cfg.getLocals() != pool) {
throw new UnsupportedOperationException();
}
AbstractCopyStmt copy = pool.defs.get(l);
TaintableSet<Expr> set = new TaintableSet<>();
if (copy.getOpcode() == Opcode.PHI_STORE) {
// checkRecursive(l);
// PhiExpr phi = ((CopyPhiStmt) copy).getExpression();
/*for(Expr e : phi.getArguments().values()) {
if(e.getOpcode() == Opcode.LOCAL_LOAD) {
Local l2 = ((VarExpr) e).getLocal();
if(l2 == l) {
throw new RuntimeException(copy.toString());
}
}
}*/
// set.addAll(phi.getArguments().values());
} else {
// set.add(copy.getExpression());
}
set.add(copy.getExpression());
return set;
}
use of org.mapleir.ir.code.expr.PhiExpr in project maple-ir by LLVM-but-worse.
the class SSAGenPass method insertPhis.
private void insertPhis(BasicBlock b, Local l, int i, LinkedList<BasicBlock> queue) {
if (b == null || b == builder.head) {
// exit
return;
}
Local newl = builder.graph.getLocals().get(l.getIndex(), 0, l.isStack());
for (BasicBlock x : doms.iteratedFrontier(b)) {
if (insertion.get(x) < i) {
// pruned SSA
if (liveness.in(x).contains(l)) {
if ((l == svar0) && handlers.contains(x)) /* == faster than contains. */
{
/* Note: this is quite subtle. Since there is a
* copy, (svar0 = catch()) at the start of each
* handler block, technically any natural flowing
* svar0 definition is killed upon entry to the
* block, so it is not considered live. One way to
* check if the variable is live-in, therefore, is
* by checking whether svar0 is live-out of the
* catch() definition. We handle it here, since
* the previous liveness check which is used for
* pruned SSA will fail in this case. */
/* Ok fuck that that, it's considered live-in
* even if there is a catch()::
* #see SSaBlockLivenessAnalyser.precomputeBlock*/
boolean naturalFlow = false;
for (FlowEdge<BasicBlock> e : builder.graph.getReverseEdges(x)) {
if (e.getType() != FlowEdges.TRYCATCH) {
naturalFlow = true;
break;
}
}
if (naturalFlow) {
CopyVarStmt catcher = null;
for (Stmt stmt : x) {
if (stmt.getOpcode() == Opcode.LOCAL_STORE) {
CopyVarStmt copy = (CopyVarStmt) stmt;
Expr e = copy.getExpression();
if (e.getOpcode() == Opcode.CATCH) {
catcher = copy;
break;
}
}
}
if (catcher == null) {
/* Handler but no catch copy?
* This can't happen since svar0 is
* the only reserved register for
* catch copies, and this block cannot
* be visited twice to insert a phi or
* psi(ephi) node. */
throw new IllegalStateException(x.getDisplayName());
}
/* Map<BasicBlock, Expression> vls = new HashMap<>();
for(FlowEdge<BasicBlock> fe : builder.graph.getReverseEdges(x)) {
vls.put(fe.src, new VarExpr(newl, null));
}
vls.put(x, catcher.getExpression().copy());
catcher.delete();
PhiExpr phi = new PhiExceptionExpr(vls);
CopyPhiStmt assign = new CopyPhiStmt(new VarExpr(l, null), phi);
x.add(0, assign); */
throw new UnsupportedOperationException(builder.method.toString());
}
}
if (builder.graph.getReverseEdges(x).size() > 1) {
Map<BasicBlock, Expr> vls = new HashMap<>();
for (FlowEdge<BasicBlock> fe : builder.graph.getReverseEdges(x)) {
vls.put(fe.src(), new VarExpr(newl, null));
}
PhiExpr phi = new PhiExpr(vls);
CopyPhiStmt assign = new CopyPhiStmt(new VarExpr(l, null), phi);
x.add(0, assign);
}
}
insertion.put(x, i);
if (process.get(x) < i) {
process.put(x, i);
queue.add(x);
}
}
}
}
use of org.mapleir.ir.code.expr.PhiExpr in project maple-ir by LLVM-but-worse.
the class PoolLocalValueResolver method checkRecursive.
private void checkRecursive(Local l) {
Set<Local> visited = new HashSet<>();
Queue<Local> worklist = new LinkedList<>();
worklist.add(l);
while (!worklist.isEmpty()) {
l = worklist.poll();
AbstractCopyStmt copy = pool.defs.get(l);
Set<Local> set = new HashSet<>();
Expr rhs = copy.getExpression();
if (rhs.getOpcode() == Opcode.LOCAL_LOAD) {
set.add(((VarExpr) rhs).getLocal());
} else if (rhs.getOpcode() == Opcode.PHI) {
for (Expr e : ((PhiExpr) rhs).getArguments().values()) {
set.add(((VarExpr) e).getLocal());
}
}
for (Local v : set) {
if (visited.contains(v)) {
System.err.println(copy.getBlock().getGraph());
System.err.printf("visited: %s%n", visited);
System.err.printf(" copy: %s%n", copy);
System.err.printf(" dup: %s%n", v);
throw new RuntimeException();
}
}
worklist.addAll(set);
visited.addAll(set);
}
}
Aggregations