Search in sources :

Example 1 with RefExpr

use of com.googlecode.dex2jar.ir.expr.RefExpr in project dex2jar by pxb1988.

the class Ir2JRegAssignTransformer method genGraph.

private Reg[] genGraph(IrMethod method, final Reg[] regs) {
    Reg[] args;
    if (method.isStatic) {
        args = new Reg[method.args.length];
    } else {
        args = new Reg[method.args.length + 1];
    }
    Set<Stmt> tos = new HashSet<>();
    for (Stmt stmt : method.stmts) {
        if (stmt.st == ST.ASSIGN || stmt.st == ST.IDENTITY) {
            if (stmt.getOp1().vt == VT.LOCAL) {
                Local left = (Local) stmt.getOp1();
                Value op2 = stmt.getOp2();
                int idx = left._ls_index;
                Reg leftReg = regs[idx];
                // a new local can't effect next value live in next frame
                Cfg.collectTos(stmt, tos);
                for (Stmt next : tos) {
                    SimpleLiveValue[] frame = (SimpleLiveValue[]) next.frame;
                    if (frame == null) {
                        continue;
                    }
                    for (int i = 0; i < frame.length; i++) {
                        if (i == idx) {
                            continue;
                        }
                        SimpleLiveValue v = frame[i];
                        if (v != null && v.used) {
                            Reg rightReg = regs[i];
                            leftReg.excludes.add(rightReg);
                            rightReg.excludes.add(leftReg);
                        }
                    }
                }
                tos.clear();
                // Preferred same reg can save load-store
                if (op2.vt == VT.LOCAL) {
                    Reg rightReg = regs[((Local) op2)._ls_index];
                    leftReg.prefers.add(rightReg);
                    rightReg.prefers.add(leftReg);
                }
                // record @this @parameter_x
                if (op2.vt == VT.THIS_REF) {
                    args[0] = leftReg;
                } else if (op2.vt == VT.PARAMETER_REF) {
                    RefExpr refExpr = (RefExpr) op2;
                    if (method.isStatic) {
                        args[refExpr.parameterIndex] = leftReg;
                    } else {
                        args[refExpr.parameterIndex + 1] = leftReg;
                    }
                }
            }
        }
    }
    // remove the link between itself
    for (Reg reg : regs) {
        reg.excludes.remove(reg);
        reg.prefers.remove(reg);
    }
    return args;
}
Also used : SimpleLiveValue(com.googlecode.dex2jar.ir.ts.an.SimpleLiveValue) Value(com.googlecode.dex2jar.ir.expr.Value) SimpleLiveValue(com.googlecode.dex2jar.ir.ts.an.SimpleLiveValue) Local(com.googlecode.dex2jar.ir.expr.Local) RefExpr(com.googlecode.dex2jar.ir.expr.RefExpr) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt)

Aggregations

Local (com.googlecode.dex2jar.ir.expr.Local)1 RefExpr (com.googlecode.dex2jar.ir.expr.RefExpr)1 Value (com.googlecode.dex2jar.ir.expr.Value)1 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)1 SimpleLiveValue (com.googlecode.dex2jar.ir.ts.an.SimpleLiveValue)1