Search in sources :

Example 11 with Stmt

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();
}
Also used : VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) CopyVarStmt(org.mapleir.ir.code.stmt.copy.CopyVarStmt) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Local(org.mapleir.ir.locals.Local) VarExpr(org.mapleir.ir.code.expr.VarExpr) Stmt(org.mapleir.ir.code.Stmt) CopyVarStmt(org.mapleir.ir.code.stmt.copy.CopyVarStmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt)

Example 12 with Stmt

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;
}
Also used : Stmt(org.mapleir.ir.code.Stmt)

Example 13 with Stmt

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;
}
Also used : Stmt(org.mapleir.ir.code.Stmt)

Example 14 with 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");
}
Also used : Stmt(org.mapleir.ir.code.Stmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt)

Example 15 with Stmt

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;
        }
    }
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) Stmt(org.mapleir.ir.code.Stmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt)

Aggregations

Stmt (org.mapleir.ir.code.Stmt)53 BasicBlock (org.mapleir.ir.cfg.BasicBlock)35 Expr (org.mapleir.ir.code.Expr)29 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)28 VarExpr (org.mapleir.ir.code.expr.VarExpr)26 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)25 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)24 Local (org.mapleir.ir.locals.Local)21 VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)19 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)15 ConditionalJumpStmt (org.mapleir.ir.code.stmt.ConditionalJumpStmt)13 UnconditionalJumpStmt (org.mapleir.ir.code.stmt.UnconditionalJumpStmt)13 ThrowStmt (org.mapleir.ir.code.stmt.ThrowStmt)12 PopStmt (org.mapleir.ir.code.stmt.PopStmt)11 SwitchStmt (org.mapleir.ir.code.stmt.SwitchStmt)11 HashSet (java.util.HashSet)10 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)9 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)8 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)8 BasicLocal (org.mapleir.ir.locals.impl.BasicLocal)7