Search in sources :

Example 1 with JSubExpr

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));
    }
}
Also used : MulExpr(soot.jimple.MulExpr) JSubExpr(soot.jimple.internal.JSubExpr) FieldRef(soot.jimple.FieldRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) StaticFieldRef(soot.jimple.StaticFieldRef) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) LengthExpr(soot.jimple.LengthExpr) JSubExpr(soot.jimple.internal.JSubExpr) SubExpr(soot.jimple.SubExpr) Local(soot.Local) JAddExpr(soot.jimple.internal.JAddExpr) AddExpr(soot.jimple.AddExpr) StaticFieldRef(soot.jimple.StaticFieldRef) ArrayRef(soot.jimple.ArrayRef) NewArrayExpr(soot.jimple.NewArrayExpr) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) Iterator(java.util.Iterator) IntConstant(soot.jimple.IntConstant) SootField(soot.SootField) ArrayList(java.util.ArrayList) List(java.util.List) JAddExpr(soot.jimple.internal.JAddExpr) BinopExpr(soot.jimple.BinopExpr)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Local (soot.Local)1 SootField (soot.SootField)1 Value (soot.Value)1 AddExpr (soot.jimple.AddExpr)1 ArrayRef (soot.jimple.ArrayRef)1 BinopExpr (soot.jimple.BinopExpr)1 FieldRef (soot.jimple.FieldRef)1 InstanceFieldRef (soot.jimple.InstanceFieldRef)1 IntConstant (soot.jimple.IntConstant)1 LengthExpr (soot.jimple.LengthExpr)1 MulExpr (soot.jimple.MulExpr)1 NewArrayExpr (soot.jimple.NewArrayExpr)1 NewMultiArrayExpr (soot.jimple.NewMultiArrayExpr)1 StaticFieldRef (soot.jimple.StaticFieldRef)1 SubExpr (soot.jimple.SubExpr)1 JAddExpr (soot.jimple.internal.JAddExpr)1 JSubExpr (soot.jimple.internal.JSubExpr)1