use of org.mapleir.stdlib.collections.bitset.GenericBitSet in project maple-ir by LLVM-but-worse.
the class SSABlockLivenessAnalyser method compute.
public void compute() {
// negative handling always goes after positive and any adds
while (!queue.isEmpty()) {
BasicBlock b = queue.remove();
// System.out.println("\n\nProcessing " + b.getId());
GenericBitSet<Local> oldIn = new GenericBitSet<>(in.get(b));
GenericBitSet<Local> curIn = new GenericBitSet<>(use.get(b));
GenericBitSet<Local> curOut = locals.createBitSet();
// out[n] = U(s in succ[n])(in[s])
for (FlowEdge<BasicBlock> succEdge : cfg.getEdges(b)) curOut.addAll(in.get(succEdge.dst()));
// negative phi handling for defs
for (FlowEdge<BasicBlock> succEdge : cfg.getEdges(b)) curOut.removeAll(phiDef.get(succEdge.dst()));
// positive phi handling for uses, see ยง5.4.2 "Meaning of copy statements in Sreedhar's method"
for (FlowEdge<BasicBlock> succEdge : cfg.getEdges(b)) curOut.addAll(phiUse.get(succEdge.dst()).getNonNull(b));
// negative phi handling for uses
for (FlowEdge<BasicBlock> predEdge : cfg.getReverseEdges(b)) curIn.removeAll(phiUse.get(b).getNonNull(predEdge.src()).relativeComplement(use.get(b)));
// positive phi handling for defs
curIn.addAll(phiDef.get(b));
oldIn.addAll(phiDef.get(b));
// in[n] = use[n] U(out[n] - def[n])
curIn.addAll(curOut.relativeComplement(def.get(b)));
in.put(b, curIn);
out.put(b, curOut);
// queue preds if dataflow state changed
if (!oldIn.equals(curIn)) {
cfg.getReverseEdges(b).stream().map(e -> e.src()).forEach(this::enqueue);
// for (BasicBlock b2 : cfg.vertices())
// System.out.println(b2.getId() + " |||| IN: " + in.get(b2) + " ||||| OUT: " + out.get(b2));
}
}
}
use of org.mapleir.stdlib.collections.bitset.GenericBitSet in project maple-ir by LLVM-but-worse.
the class SreedharDestructor method leaveSSA.
// ============================================================================================================= //
// ================================================== Leave SSA ================================================ //
// ============================================================================================================= //
private void leaveSSA() {
// Flatten pccs into one variable through remapping
// System.out.println("remap:");
Map<Local, Local> remap = new HashMap<>();
for (Entry<Local, GenericBitSet<Local>> entry : pccs.entrySet()) {
GenericBitSet<Local> pcc = entry.getValue();
if (pcc.isEmpty())
continue;
Local local = entry.getKey();
if (remap.containsKey(local))
continue;
Local newLocal = locals.makeLatestVersion(local);
remap.put(local, newLocal);
// System.out.println(" " + local + " -> " + newLocal);
for (Local pccLocal : pcc) {
remap.put(pccLocal, newLocal);
// System.out.println(" " + pccLocal + " -> " + newLocal);
}
}
for (BasicBlock b : cfg.vertices()) {
for (Iterator<Stmt> it = b.iterator(); it.hasNext(); ) {
Stmt stmt = it.next();
// We can now simply drop all phi statements.
if (stmt instanceof CopyPhiStmt) {
it.remove();
continue;
}
// Apply remappings
if (stmt instanceof CopyVarStmt) {
VarExpr lhs = ((CopyVarStmt) stmt).getVariable();
Local copyTarget = lhs.getLocal();
lhs.setLocal(remap.getOrDefault(copyTarget, copyTarget));
}
for (Expr child : stmt.enumerateOnlyChildren()) {
if (child.getOpcode() == LOCAL_LOAD) {
VarExpr var = (VarExpr) child;
Local loadSource = var.getLocal();
var.setLocal(remap.getOrDefault(loadSource, loadSource));
}
}
}
}
// System.out.println();
}
Aggregations