use of org.mapleir.ir.code.expr.PhiExpr in project maple-ir by LLVM-but-worse.
the class BoissinotDestructor method copyPhiOperands.
private void copyPhiOperands(BasicBlock b) {
NullPermeableHashMap<BasicBlock, List<PhiRes>> wl = new NullPermeableHashMap<>(new ListCreator<>());
ParallelCopyVarStmt dst_copy = new ParallelCopyVarStmt();
for (Stmt stmt : b) {
// phis only appear at the start of a block.
if (stmt.getOpcode() != Opcode.PHI_STORE) {
break;
}
CopyPhiStmt copy = (CopyPhiStmt) stmt;
PhiExpr phi = copy.getExpression();
// so that we can parallelise the copy when we insert it.
for (Entry<BasicBlock, Expr> e : phi.getArguments().entrySet()) {
BasicBlock h = e.getKey();
// these are validated in init().
VarExpr v = (VarExpr) e.getValue();
PhiRes r = new PhiRes(copy.getVariable().getLocal(), phi, h, v.getLocal(), v.getType());
wl.getNonNull(h).add(r);
}
// for each x0, where x0 is a phi copy target, create a new variable z0 for
// a copy x0 = z0 and replace the phi copy target to z0.
Local x0 = copy.getVariable().getLocal();
Local z0 = locals.makeLatestVersion(x0);
// x0 = z0
dst_copy.pairs.add(new CopyPair(x0, z0, copy.getVariable().getType()));
// z0 = phi(...)
copy.getVariable().setLocal(z0);
}
// resolve
if (dst_copy.pairs.size() > 0)
insertStart(b, dst_copy);
for (Entry<BasicBlock, List<PhiRes>> e : wl.entrySet()) {
BasicBlock p = e.getKey();
ParallelCopyVarStmt copy = new ParallelCopyVarStmt();
for (PhiRes r : e.getValue()) {
// for each xi source in a phi, create a new variable zi, and insert the copy
// zi = xi in the pred Li. then replace the phi arg from Li with zi.
Local xi = r.l;
Local zi = locals.makeLatestVersion(xi);
copy.pairs.add(new CopyPair(zi, xi, r.type));
// we consider phi args to be used in the pred instead of the block
// where the phi is, so we need to update the def/use maps here.
r.phi.setArgument(r.pred, new VarExpr(zi, r.type));
}
insertEnd(p, copy);
}
}
use of org.mapleir.ir.code.expr.PhiExpr in project maple-ir by LLVM-but-worse.
the class SSADefUseMap method buildIndex.
protected void buildIndex(BasicBlock b, Stmt stmt, int index, Set<Local> usedLocals) {
if (stmt instanceof AbstractCopyStmt) {
AbstractCopyStmt copy = (AbstractCopyStmt) stmt;
defIndex.put(copy.getVariable().getLocal(), index);
if (copy instanceof CopyPhiStmt) {
PhiExpr phi = ((CopyPhiStmt) copy).getExpression();
for (Entry<BasicBlock, Expr> en : phi.getArguments().entrySet()) {
lastUseIndex.getNonNull(((VarExpr) en.getValue()).getLocal()).put(en.getKey(), en.getKey().size());
// lastUseIndex.get(ul).put(b, -1);
}
return;
}
}
for (Local usedLocal : usedLocals) lastUseIndex.getNonNull(usedLocal).put(b, index);
}
Aggregations