use of soot.jimple.internal.JSubExpr in project soot by Sable.
the class ArrayIndexLivenessAnalysis method getGenAndKillSetForDefnStmt.
private void getGenAndKillSetForDefnStmt(DefinitionStmt asstmt, HashMap<Stmt, HashSet<Value>> absgen, HashSet<Object> genset, HashSet<Value> absgenset, HashSet<Value> killset, HashSet<Value> condset) {
/* kill left hand side */
Value lhs = asstmt.getLeftOp();
Value rhs = asstmt.getRightOp();
boolean killarrayrelated = false;
boolean killallarrayref = false;
if (fieldin) {
if (lhs instanceof Local) {
HashSet<Value> related = localToFieldRef.get(lhs);
if (related != null)
killset.addAll(related);
} else if (lhs instanceof StaticFieldRef) {
killset.add(lhs);
condset.add(lhs);
} else if (lhs instanceof InstanceFieldRef) {
SootField field = ((InstanceFieldRef) lhs).getField();
HashSet<Value> related = fieldToFieldRef.get(field);
if (related != null)
killset.addAll(related);
condset.add(lhs);
}
if (asstmt.containsInvokeExpr()) {
/*
Value expr = asstmt.getInvokeExpr();
List parameters = ((InvokeExpr)expr).getArgs();
// add the method invocation
boolean killall = false;
if (expr instanceof InstanceInvokeExpr)
killall = true;
else
{
for (int i=0; i<parameters.size(); i++)
{
Value para = (Value)parameters.get(i);
if (para.getType() instanceof RefType)
{
killall = true;
break;
}
}
}
if (killall)
{
killset.addAll(allInstFieldRefs);
}
*/
killset.addAll(allFieldRefs);
}
}
if (arrayin) {
// a = ... or i = ...
if (lhs instanceof Local) {
killarrayrelated = true;
} else // a[i] = ...
if (lhs instanceof ArrayRef) {
killallarrayref = true;
condset.add(lhs);
}
// invokeexpr kills all array references.
if (asstmt.containsInvokeExpr()) {
killallarrayref = true;
}
}
if (csin) {
HashSet<Value> exprs = localToExpr.get(lhs);
if (exprs != null)
killset.addAll(exprs);
if (rhs instanceof BinopExpr) {
Value op1 = ((BinopExpr) rhs).getOp1();
Value op2 = ((BinopExpr) rhs).getOp2();
if (rhs instanceof AddExpr) {
if ((op1 instanceof Local) && (op2 instanceof Local))
genset.add(rhs);
} else if (rhs instanceof MulExpr) {
if ((op1 instanceof Local) || (op2 instanceof Local))
genset.add(rhs);
} else if (rhs instanceof SubExpr) {
if (op2 instanceof Local)
genset.add(rhs);
}
}
}
if ((lhs instanceof Local) && (fullSet.contains(lhs))) {
killset.add(lhs);
/* speculatively add lhs as live condition. */
condset.add(lhs);
} else if (lhs instanceof ArrayRef) {
/* a[i] generate a and i. */
Value base = ((ArrayRef) lhs).getBase();
Value index = ((ArrayRef) lhs).getIndex();
absgenset.add(base);
if (index instanceof Local) {
absgenset.add(index);
}
}
if (rhs instanceof Local) {
/*
if (lhs instanceof Local && fullSet.contains(rhs))
genset.add(rhs);
*/
if (fullSet.contains(rhs))
genset.add(rhs);
/*
if (fieldin && (lhs instanceof FieldRef))
genset.add(rhs);
*/
} else if (rhs instanceof FieldRef) {
if (fieldin)
genset.add(rhs);
} else if (rhs instanceof ArrayRef) {
/* lhs=a[i]. */
Value base = ((ArrayRef) rhs).getBase();
Value index = ((ArrayRef) rhs).getIndex();
absgenset.add(base);
if (index instanceof Local) {
absgenset.add(index);
}
if (arrayin) {
genset.add(rhs);
if (rectarray)
genset.add(Array2ndDimensionSymbol.v(base));
}
} else if (rhs instanceof NewArrayExpr) {
/* a = new A[i]; */
Value size = ((NewArrayExpr) rhs).getSize();
if (size instanceof Local)
genset.add(size);
} else if (rhs instanceof NewMultiArrayExpr) {
/* a = new A[i][]...;*/
/* More precisely, we should track other dimensions. */
List sizes = ((NewMultiArrayExpr) rhs).getSizes();
Iterator sizeIt = sizes.iterator();
while (sizeIt.hasNext()) {
Value size = (Value) sizeIt.next();
if (size instanceof Local)
genset.add(size);
}
} else if (rhs instanceof LengthExpr) {
/* lhs = lengthof rhs */
Value op = ((LengthExpr) rhs).getOp();
genset.add(op);
} else if (rhs instanceof JAddExpr) {
/* lhs = rhs+c, lhs=c+rhs */
Value op1 = ((JAddExpr) rhs).getOp1();
Value op2 = ((JAddExpr) rhs).getOp2();
if ((op1 instanceof IntConstant) && (op2 instanceof Local)) {
genset.add(op2);
} else if ((op2 instanceof IntConstant) && (op1 instanceof Local)) {
genset.add(op1);
}
} else if (rhs instanceof JSubExpr) {
Value op1 = ((JSubExpr) rhs).getOp1();
Value op2 = ((JSubExpr) rhs).getOp2();
if ((op1 instanceof Local) && (op2 instanceof IntConstant)) {
genset.add(op1);
}
}
if (arrayin) {
if (killarrayrelated)
killArrayRelated.put(asstmt, lhs);
if (killallarrayref)
killAllArrayRef.put(asstmt, new Boolean(true));
}
}
Aggregations