Search in sources :

Example 16 with Expr

use of org.mapleir.ir.code.Expr 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 17 with Expr

use of org.mapleir.ir.code.Expr 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 18 with Expr

use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.

the class LatestValue method makeConstraints.

public void makeConstraints(Expr e) {
    for (Expr s : e.enumerateWithSelf()) {
        int op = s.getOpcode();
        if (op == Opcode.FIELD_LOAD) {
            FieldConstraint c = new FieldConstraint((FieldLoadExpr) s);
            constraints.add(c);
        } else if (ConstraintUtil.isInvoke(op)) {
            constraints.add(new InvokeConstraint());
        } else if (op == Opcode.ARRAY_LOAD) {
            constraints.add(new ArrayConstraint());
        }
    }
}
Also used : VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) FieldLoadExpr(org.mapleir.ir.code.expr.FieldLoadExpr)

Example 19 with Expr

use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.

the class GenerationPass method _call.

protected void _call(int op, String owner, String name, String desc) {
    save_stack(false);
    int argLen = Type.getArgumentTypes(desc).length + (op == INVOKESTATIC ? 0 : 1);
    Expr[] args = new Expr[argLen];
    for (int i = args.length - 1; i >= 0; i--) {
        args[i] = pop();
    }
    InvocationExpr callExpr = new InvocationExpr(InvocationExpr.CallType.resolveCallType(op), args, owner, name, desc);
    if (callExpr.getType() == Type.VOID_TYPE) {
        addStmt(new PopStmt(callExpr));
    } else {
        int index = currentStack.height();
        Type type = assign_stack(index, callExpr);
        push(load_stack(index, type));
    }
}
Also used : Type(org.objectweb.asm.Type) ComparisonType(org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType) ValueComparisonType(org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType) ArrayType(org.mapleir.ir.TypeUtils.ArrayType) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr)

Example 20 with Expr

use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.

the class GenerationPass method _store_array.

protected void _store_array(ArrayType type) {
    save_stack(false);
    Expr value = pop();
    Expr index = pop();
    Expr array = pop();
    addStmt(new ArrayStoreStmt(array, index, value, type));
}
Also used : InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr)

Aggregations

Expr (org.mapleir.ir.code.Expr)87 VarExpr (org.mapleir.ir.code.expr.VarExpr)46 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)45 BasicBlock (org.mapleir.ir.cfg.BasicBlock)32 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)31 Stmt (org.mapleir.ir.code.Stmt)29 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)26 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)26 Local (org.mapleir.ir.locals.Local)22 Type (org.objectweb.asm.Type)21 VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)20 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)19 InitialisedObjectExpr (org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr)17 ComparisonType (org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType)14 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)14 ValueComparisonType (org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType)13 ArrayType (org.mapleir.ir.TypeUtils.ArrayType)12 HashSet (java.util.HashSet)11 ArithmeticExpr (org.mapleir.ir.code.expr.ArithmeticExpr)11 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)9