use of org.mapleir.ir.locals.Local in project maple-ir by LLVM-but-worse.
the class BoissinotDestructor method sequentialize.
private void sequentialize(BasicBlock b) {
// TODO: just rebuild the instruction list
LinkedHashMap<ParallelCopyVarStmt, Integer> p = new LinkedHashMap<>();
for (int i = 0; i < b.size(); i++) {
Stmt stmt = b.get(i);
if (stmt instanceof ParallelCopyVarStmt)
p.put((ParallelCopyVarStmt) stmt, i);
}
if (p.isEmpty())
return;
int indexOffset = 0;
Local spill = locals.makeLatestVersion(p.entrySet().iterator().next().getKey().pairs.get(0).targ);
for (Entry<ParallelCopyVarStmt, Integer> e : p.entrySet()) {
ParallelCopyVarStmt pcvs = e.getKey();
int index = e.getValue();
if (pcvs.pairs.size() == 0)
throw new IllegalArgumentException("pcvs is empty");
else if (pcvs.pairs.size() == 1) {
// constant sequentialize for trivial parallel copies
CopyPair pair = pcvs.pairs.get(0);
CopyVarStmt newCopy = new CopyVarStmt(new VarExpr(pair.targ, pair.type), new VarExpr(pair.source, pair.type));
b.set(index + indexOffset, newCopy);
} else {
List<CopyVarStmt> sequentialized = pcvs.sequentialize(spill);
b.remove(index + indexOffset--);
for (CopyVarStmt cvs : sequentialized) {
// warning: O(N^2) operation
b.add(index + ++indexOffset, cvs);
}
}
}
}
use of org.mapleir.ir.locals.Local 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);
}
use of org.mapleir.ir.locals.Local in project maple-ir by LLVM-but-worse.
the class SSADefUseMap method compute.
public void compute() {
defs.clear();
uses.clear();
phiDefs.clear();
phiUses.clear();
Set<Local> usedLocals = new HashSet<>();
for (BasicBlock b : cfg.vertices()) {
for (Stmt stmt : b) {
phiUses.getNonNull(b);
usedLocals.clear();
for (Expr s : stmt.enumerateOnlyChildren()) if (s.getOpcode() == Opcode.LOCAL_LOAD)
usedLocals.add(((VarExpr) s).getLocal());
build(b, stmt, usedLocals);
}
}
}
use of org.mapleir.ir.locals.Local in project maple-ir by LLVM-but-worse.
the class SreedharDestructor method init.
// ============================================================================================================= //
// =============================================== Initialization ============================================== //
// ============================================================================================================= //
private void init() {
// init pccs
for (CopyPhiStmt copyPhi : defuse.phiDefs.values()) {
Local phiTarget = copyPhi.getVariable().getLocal();
pccs.getNonNull(phiTarget).add(phiTarget);
// System.out.println("Initphi " + phiTarget);
for (Entry<BasicBlock, Expr> phiEntry : copyPhi.getExpression().getArguments().entrySet()) {
if (phiEntry.getValue().getOpcode() != LOCAL_LOAD)
throw new IllegalArgumentException("Phi arg is not local; instead is " + phiEntry.getValue().getClass().getSimpleName());
Local phiSource = ((VarExpr) phiEntry.getValue()).getLocal();
pccs.getNonNull(phiSource).add(phiSource);
// System.out.println("Initphi " + phiSource);
}
}
// System.out.println();
// compute liveness
(liveness = new SSABlockLivenessAnalyser(cfg)).compute();
// writer.add("liveness", new LivenessDecorator<ControlFlowGraph, BasicBlock, FlowEdge<BasicBlock>>().setLiveness(liveness));
buildInterference();
}
use of org.mapleir.ir.locals.Local in project maple-ir by LLVM-but-worse.
the class SreedharDestructor method resolvePhiSource.
private Local resolvePhiSource(Local xi, BasicBlock lk, Type phiType) {
// Insert spill copy
Local spill = insertEnd(xi, lk, phiType);
// Update liveness
GenericBitSet<Local> liveOut = liveness.out(lk);
liveOut.add(spill);
// xi can be removed from liveOut iff it isn't live into any succ or used in any succ phi.
for (BasicBlock lj : succsCache.getNonNull(lk)) {
if (!liveness.in(lj).contains(xi))
removeFromOut: {
for (int i = 0; i < lj.size() && lj.get(i).getOpcode() == Opcode.PHI_STORE; i++) if (((VarExpr) ((CopyPhiStmt) lj.get(i)).getExpression().getArguments().get(lk)).getLocal() == xi)
break removeFromOut;
// poor man's for-else loop
liveOut.remove(xi);
}
}
// Reflexively update interference
interfere.getNonNull(spill).addAll(liveOut);
for (Local l : liveOut) interfere.get(l).add(spill);
return spill;
}
Aggregations