use of org.mapleir.ir.code.Stmt 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.code.Stmt 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.code.Stmt in project maple-ir by LLVM-but-worse.
the class BasicBlock method clear.
@Override
public void clear() {
Iterator<Stmt> it = statements.iterator();
while (it.hasNext()) {
Stmt s = it.next();
s.setBlock(null);
it.remove();
}
}
use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class BasicBlock method transfer.
public void transfer(BasicBlock to) {
Iterator<Stmt> it = statements.iterator();
while (it.hasNext()) {
Stmt s = it.next();
to.statements.add(s);
s.setBlock(to);
it.remove();
}
}
use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class BasicBlock method transferUp.
public void transferUp(BasicBlock dst, int to) {
// FIXME: faster
for (int i = to - 1; i >= 0; i--) {
Stmt s = statements.remove(0);
dst.add(s);
s.setBlock(dst);
}
}
Aggregations