Search in sources :

Example 46 with Stmt

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

Example 47 with Stmt

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

Example 48 with Stmt

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

Example 49 with Stmt

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

Example 50 with Stmt

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

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