use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class SreedharDestructor method buildInterference.
private void buildInterference() {
for (BasicBlock b : cfg.vertices()) {
// not a copy!
GenericBitSet<Local> in = liveness.in(b);
// not a copy!
GenericBitSet<Local> out = liveness.out(b);
// in interfere in
for (Local l : in) interfere.getNonNull(l).addAll(in);
// out interfere out
for (Local l : out) interfere.getNonNull(l).addAll(out);
// backwards traverse for dealing with variables that are defined and used in the same block
GenericBitSet<Local> intraLive = out.copy();
ListIterator<Stmt> it = b.listIterator(b.size());
while (it.hasPrevious()) {
Stmt stmt = it.previous();
if (stmt instanceof CopyVarStmt) {
CopyVarStmt copy = (CopyVarStmt) stmt;
Local defLocal = copy.getVariable().getLocal();
intraLive.remove(defLocal);
}
for (Expr child : stmt.enumerateOnlyChildren()) {
if (stmt.getOpcode() == LOCAL_LOAD) {
Local usedLocal = ((VarExpr) child).getLocal();
if (intraLive.add(usedLocal)) {
interfere.getNonNull(usedLocal).addAll(intraLive);
for (Local l : intraLive) interfere.get(l).add(usedLocal);
}
}
}
}
}
// System.out.println("Interference:");
// for (Entry<Local, GenericBitSet<Local>> entry : interfere.entrySet())
// System.out.println(" " + entry.getKey() + " : " + entry.getValue());
// System.out.println();
}
use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class BasicBlock method retainAll.
@Override
public boolean retainAll(Collection<?> c) {
boolean ret = false;
Iterator<Stmt> it = iterator();
while (it.hasNext()) {
Stmt stmt = it.next();
if (!c.contains(stmt)) {
it.remove();
stmt.setBlock(null);
ret = true;
}
}
return ret;
}
use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class BasicBlock method remove.
@Override
public Stmt remove(int index) {
Stmt stmt = statements.remove(index);
stmt.setBlock(null);
return stmt;
}
use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class ControlFlowGraph method blockToString.
public static void blockToString(TabbedStringWriter sw, ControlFlowGraph cfg, BasicBlock b, int insn) {
// sw.print("===#Block " + b.getId() + "(size=" + (b.size()) + ")===");
sw.print(String.format("===#Block %s(size=%d, ident=%s, flags=%s)===", b.getDisplayName(), b.size(), /*(b.getLabelNode() != null && b.getLabel() != null ? b.getLabel().hashCode() : "null")*/
"x", Integer.toBinaryString(b.getFlags())));
sw.tab();
Iterator<Stmt> it = b.iterator();
if (!it.hasNext()) {
sw.untab();
} else {
sw.print("\n");
}
while (it.hasNext()) {
Stmt stmt = it.next();
// sw.print(stmt.getId() + ". ");
sw.print(insn++ + ". ");
stmt.toString(sw);
if (!it.hasNext()) {
sw.untab();
} else {
sw.print("\n");
}
}
sw.tab();
sw.tab();
if (cfg.containsVertex(b)) {
for (FlowEdge<BasicBlock> e : cfg.getEdges(b)) {
// if(e.getType() != FlowEdges.TRYCATCH) {
sw.print("\n-> " + e.toString());
// }
}
for (FlowEdge<BasicBlock> p : cfg.getReverseEdges(b)) {
// if(p.getType() != FlowEdges.TRYCATCH) {
sw.print("\n<- " + p.toString());
// }
}
}
sw.untab();
sw.untab();
sw.print("\n");
}
use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.
the class ControlFlowGraph method exciseEdge.
/**
* Properly removes the edge, and cleans up phi uses in fe.dst of phi arguments from fe.src.
* @param fe Edge to excise phi uses.
*/
public void exciseEdge(FlowEdge<BasicBlock> fe) {
if (!this.containsEdge(fe.src(), fe))
throw new IllegalArgumentException("Graph does not contain the specified edge");
removeEdge(fe.src(), fe);
for (Stmt stmt : fe.dst()) {
if (stmt.getOpcode() == PHI_STORE) {
CopyPhiStmt phs = (CopyPhiStmt) stmt;
PhiExpr phi = phs.getExpression();
BasicBlock pred = fe.src();
VarExpr arg = (VarExpr) phi.getArgument(pred);
VersionedLocal l = (VersionedLocal) arg.getLocal();
locals.uses.get(l).remove(arg);
phi.removeArgument(pred);
} else {
return;
}
}
}
Aggregations