use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class UnSSATransformer method genRegGraph.
private void genRegGraph(IrMethod method, LiveA liveA) {
for (Local local : method.locals) {
local.tag = new RegAssign();
}
Set<Stmt> tos = new HashSet<>();
for (Stmt stmt : method.stmts) {
if ((stmt.st == ST.ASSIGN || stmt.st == ST.IDENTITY) && stmt.getOp1().vt == VT.LOCAL) {
Local localAssignTo = (Local) stmt.getOp1();
RegAssign regAssignTo = (RegAssign) localAssignTo.tag;
Set<Integer> excludeIdx = new HashSet<>();
Cfg.collectTos(stmt, tos);
for (Stmt target : tos) {
LiveV[] frame = (LiveV[]) target.frame;
if (frame == null) {
continue;
}
// exclude thisReg and phiReg
excludeIdx.clear();
excludeIdx.add(localAssignTo._ls_index);
if (target.st == ST.LABEL) {
LabelStmt label = (LabelStmt) target;
if (label.phis != null) {
for (AssignStmt phiAssignStmt : (List<AssignStmt>) label.phis) {
Local phiLocal = (Local) phiAssignStmt.getOp1();
excludeIdx.add(phiLocal._ls_index);
}
}
}
for (int i = 0; i < frame.length; i++) {
if (excludeIdx.contains(i)) {
continue;
}
LiveV v = frame[i];
if (v != null && v.used) {
RegAssign b = (RegAssign) v.local.tag;
regAssignTo.excludes.add(b);
b.excludes.add(regAssignTo);
}
}
}
tos.clear();
} else if (stmt.st == ST.LABEL) {
//
LabelStmt label = (LabelStmt) stmt;
if (label.phis != null) {
for (AssignStmt phiAssignStmt : (List<AssignStmt>) label.phis) {
Local phiLocal = (Local) phiAssignStmt.getOp1();
RegAssign a = (RegAssign) phiLocal.tag;
LiveV[] frame = (LiveV[]) stmt.frame;
for (LiveV v : frame) {
if (v != null && v.used) {
RegAssign b = (RegAssign) v.local.tag;
a.excludes.add(b);
b.excludes.add(a);
}
}
}
}
}
}
if (DEBUG) {
System.out.println(liveA.toString());
}
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class VoidInvokeTransformer method transformReportChanged.
@Override
public boolean transformReportChanged(IrMethod method) {
if (method.locals.size() == 0) {
return false;
}
int[] reads = Cfg.countLocalReads(method);
boolean changed = false;
for (Stmt p = method.stmts.getFirst(); p != null; p = p.getNext()) {
if (p.st == Stmt.ST.ASSIGN && p.getOp1().vt == Value.VT.LOCAL) {
Local left = (Local) p.getOp1();
if (reads[left._ls_index] == 0) {
switch(p.getOp2().vt) {
case INVOKE_INTERFACE:
case INVOKE_NEW:
case INVOKE_SPECIAL:
case INVOKE_STATIC:
case INVOKE_VIRTUAL:
method.locals.remove(left);
Stmt nVoidInvoke = Stmts.nVoidInvoke(p.getOp2());
method.stmts.replace(p, nVoidInvoke);
p = nVoidInvoke;
changed = true;
break;
default:
break;
}
}
}
}
return changed;
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class BaseAnalyze method init.
protected void init() {
if (reindexLocal) {
int index = 0;
for (Local local : method.locals) {
local._ls_index = index;
index++;
}
}
if (DEBUG) {
int idx = 0;
for (Stmt s : method.stmts) {
if (s.st == Stmt.ST.LABEL) {
LabelStmt label = (LabelStmt) s;
label.displayName = "L" + idx++;
}
}
}
initCFG();
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class UnSSATransformerTransformerTest method test01SSAProblem.
@Test
public void test01SSAProblem() {
initMethod(true, "I");
Local a = addLocal("a");
Local b = addLocal("b");
Local phi = addLocal("p");
LabelStmt L0 = newLabel();
addStmt(nAssign(a, nInt(2)));
addStmt(L0);
attachPhi(L0, nAssign(phi, nPhi(a, b)));
Stmt stmt = addStmt(nAssign(b, niAdd(phi, nInt(0))));
addStmt(nIf(niGt(nInt(100), nInt(0)), L0));
addStmt(nReturn(phi));
transform();
Assert.assertTrue("a new local should introduced to solve the problem", stmt.getPre() != L0);
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class SSATransformerTest method test11NotDeleteAssignWherePhiIsConfused.
/**
* for
*
* <pre>
* a=12;
* b=34;
* c=a;
* if c1=0 goto L1:
* c=b;
* L1:
* return c;
*
* </pre>
*
*/
@Test
public void test11NotDeleteAssignWherePhiIsConfused() {
Local a = addLocal("a");
Local b = addLocal("b");
Local c = addLocal("c");
LabelStmt L1 = nLabel();
addStmt(nAssign(a, nString("12")));
addStmt(nAssign(b, nString("34")));
addStmt(nAssign(c, a));
Stmt jmp = addStmt(nIf(njGt(c, nInt(0)), L1));
addStmt(nAssign(c, b));
addStmt(L1);
addStmt(Stmts.nReturn(c));
transform();
Assert.assertNotSame("the c=b should not deleted", jmp.getNext(), L1);
}
Aggregations