Search in sources :

Example 11 with VersionedLocal

use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.

the class SSAGenPass method generate.

private VersionedLocal generate(AbstractCopyStmt copy) {
    VarExpr v = copy.getVariable();
    Local oldLocal = v.getLocal();
    int index = oldLocal.getIndex();
    boolean isStack = oldLocal.isStack();
    LocalsPool handler = builder.graph.getLocals();
    Local l = handler.get(index, isStack);
    int subscript = counters.get(l);
    stacks.get(l).push(subscript);
    counters.put(l, subscript + 1);
    VersionedLocal ssaL = handler.get(index, subscript, isStack);
    if (OPTIMISE) {
        makeValue(copy, ssaL);
    }
    v.setLocal(ssaL);
    pool.defs.put(ssaL, copy);
    types.put(ssaL, copy.getExpression().getType());
    pool.uses.put(ssaL, new HashSet<>());
    return ssaL;
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) LocalsPool(org.mapleir.ir.locals.LocalsPool) VarExpr(org.mapleir.ir.code.expr.VarExpr) BasicLocal(org.mapleir.ir.locals.impl.BasicLocal) Local(org.mapleir.ir.locals.Local) VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) Constraint(org.mapleir.ir.cfg.builder.ssaopt.Constraint)

Example 12 with VersionedLocal

use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.

the class SSAGenPass method fixPhiArgs.

private void fixPhiArgs(BasicBlock b, BasicBlock succ) {
    for (Stmt stmt : succ) {
        if (stmt.getOpcode() == Opcode.PHI_STORE) {
            CopyPhiStmt copy = (CopyPhiStmt) stmt;
            PhiExpr phi = copy.getExpression();
            Expr e = phi.getArgument(b);
            if (e.getOpcode() == Opcode.LOCAL_LOAD) {
                VarExpr v = (VarExpr) e;
                translate(v, true, true);
                VersionedLocal ssaL = (VersionedLocal) v.getLocal();
                Type t = types.get(ssaL);
                copy.getVariable().setType(t);
                phi.setType(t);
            } else {
                throw new IllegalArgumentException(phi + ", " + e);
            }
        } else {
            /* No need to search the rest of the block
				 * after we have visited the phis as they
				 * precede all other statements.
				 */
            break;
        }
    }
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) Type(org.objectweb.asm.Type) ConstantExpr(org.mapleir.ir.code.expr.ConstantExpr) InitialisedObjectExpr(org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) SwitchStmt(org.mapleir.ir.code.stmt.SwitchStmt) CopyVarStmt(org.mapleir.ir.code.stmt.copy.CopyVarStmt) PopStmt(org.mapleir.ir.code.stmt.PopStmt) ThrowStmt(org.mapleir.ir.code.stmt.ThrowStmt) UnconditionalJumpStmt(org.mapleir.ir.code.stmt.UnconditionalJumpStmt) Stmt(org.mapleir.ir.code.Stmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt) ConditionalJumpStmt(org.mapleir.ir.code.stmt.ConditionalJumpStmt) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt)

Example 13 with VersionedLocal

use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.

the class SSAGenPass method processDeferredTranslations.

private int processDeferredTranslations() {
    int i = 0;
    Iterator<Entry<VersionedLocal, Set<VarExpr>>> it = pool.uses.entrySet().iterator();
    while (it.hasNext()) {
        Entry<VersionedLocal, Set<VarExpr>> e = it.next();
        VersionedLocal vl = e.getKey();
        if (deferred.contains(vl) || vl.isStack()) {
            Set<VarExpr> useSet = e.getValue();
            AbstractCopyStmt def = pool.defs.get(vl);
            if (def != null && useSet.size() == 1) {
                /* In this case, the only place that the value
					 * of this assignment will be used is at the use site.
					 * Since that value can not be spread until this one
					 * is, we can propagate it.*/
                if (def.getOpcode() != Opcode.PHI_STORE) {
                    VarExpr use = useSet.iterator().next();
                    LatestValue val = latest.get(vl);
                    // System.out.println();
                    // System.out.println();
                    // System.out.println(def);
                    // System.out.println(use);
                    /* phi var*/
                    Expr rhs = def.getExpression();
                    if (use.getParent() != null) {
                        if (canTransferHandlers(def.getBlock(), use.getBlock()) && val.canPropagate(def, use.getRootParent(), use, false)) {
                            CodeUnit parent = use.getParent();
                            if (rhs.getOpcode() == Opcode.CATCH) {
                                // CodeUnit rp = use.getRootParent();
                                // System.out.println("DENIED NIGGA");
                                // System.out.println("replace " + vl + " with " + rhs);
                                // System.out.println(" in " + parent);
                                // System.out.println(" kill def: " + def);
                                // System.out.println();
                                deferred.remove(vl);
                                continue;
                            // check to see if we're moving it to the
                            // first expression in the block, if we aren't
                            // then deny, otherwise we can get rid of the local.
                            // if(rp.getBlock().indexOf(rp) != 1 || rp.enumerateExecutionOrder().indexOf(use) != 0) {
                            // 
                            // }
                            }
                            rhs.unlink();
                            def.delete();
                            pool.defs.remove(vl);
                            useSet.clear();
                            parent.overwrite(rhs, parent.indexOf(use));
                            i++;
                            it.remove();
                        }
                    }
                }
            }
        }
    }
    return i;
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) LatestValue(org.mapleir.ir.cfg.builder.ssaopt.LatestValue) Entry(java.util.Map.Entry) ConstantExpr(org.mapleir.ir.code.expr.ConstantExpr) InitialisedObjectExpr(org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) Constraint(org.mapleir.ir.cfg.builder.ssaopt.Constraint) CodeUnit(org.mapleir.ir.code.CodeUnit)

Example 14 with VersionedLocal

use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.

the class SSAGenPass method prune.

private boolean prune(AbstractCopyStmt def) {
    if (def.isSynthetic()) {
        return false;
    }
    Expr e = def.getExpression();
    if (canPrune(e)) {
        for (Expr s : e.enumerateWithSelf()) {
            if (s.getOpcode() == Opcode.LOCAL_LOAD) {
                VarExpr v = (VarExpr) s;
                VersionedLocal vl = (VersionedLocal) v.getLocal();
                pool.uses.get(vl).remove(v);
            }
        }
        def.delete();
        return true;
    }
    return false;
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) ConstantExpr(org.mapleir.ir.code.expr.ConstantExpr) InitialisedObjectExpr(org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr)

Example 15 with VersionedLocal

use of org.mapleir.ir.locals.impl.VersionedLocal in project maple-ir by LLVM-but-worse.

the class SSAGenPass method latest.

private VersionedLocal latest(int index, boolean isStack) {
    LocalsPool handler = builder.graph.getLocals();
    Local l = handler.get(index, isStack);
    Stack<Integer> stack = stacks.get(l);
    if (stack == null || stack.isEmpty()) {
        System.err.println(builder.method.owner.name + "#" + builder.method.name);
        System.err.println(builder.graph);
        System.err.println(stacks);
        throw new NullPointerException(l.toString());
    }
    return handler.get(index, stack.peek(), /*subscript*/
    isStack);
}
Also used : LocalsPool(org.mapleir.ir.locals.LocalsPool) BasicLocal(org.mapleir.ir.locals.impl.BasicLocal) Local(org.mapleir.ir.locals.Local) VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal)

Aggregations

VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)21 VarExpr (org.mapleir.ir.code.expr.VarExpr)18 Expr (org.mapleir.ir.code.Expr)12 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)12 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)11 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)9 InitialisedObjectExpr (org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr)8 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)8 Stmt (org.mapleir.ir.code.Stmt)6 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)6 BasicBlock (org.mapleir.ir.cfg.BasicBlock)5 Constraint (org.mapleir.ir.cfg.builder.ssaopt.Constraint)5 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)5 Local (org.mapleir.ir.locals.Local)5 LocalsPool (org.mapleir.ir.locals.LocalsPool)5 LatestValue (org.mapleir.ir.cfg.builder.ssaopt.LatestValue)4 CodeUnit (org.mapleir.ir.code.CodeUnit)3 BasicLocal (org.mapleir.ir.locals.impl.BasicLocal)3 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2