/** * How many value numbers does instruction s use? */ protected int getNumberOfUses(SSAInstruction s) { return s.getNumberOfUses(); }
/** * How many value numbers does instruction s use? */ protected int getNumberOfUses(SSAInstruction s) { return s.getNumberOfUses(); }
@Override protected int getNumberOfUses(SSAInstruction inst) { return inst.getNumberOfUses(); }
@Override protected int getNumberOfUses(SSAInstruction inst) { return inst.getNumberOfUses(); }
private static void updateForInstruction(Map<Integer, ConstantValue> constants, SymbolTable symbolTable, SSAInstruction s) { for (int j = 0; j < s.getNumberOfDefs(); j++) { symbolTable.ensureSymbol(s.getDef(j)); } for (int j = 0; j < s.getNumberOfUses(); j++) { int vn = s.getUse(j); symbolTable.ensureSymbol(vn); if (constants != null && constants.containsKey(Integer.valueOf(vn))) symbolTable.setConstantValue(vn, constants.get(Integer.valueOf(vn))); } }
private static void updateForInstruction(Map<Integer, ConstantValue> constants, SymbolTable symbolTable, SSAInstruction s) { for (int j = 0; j < s.getNumberOfDefs(); j++) { symbolTable.ensureSymbol(s.getDef(j)); } for (int j = 0; j < s.getNumberOfUses(); j++) { int vn = s.getUse(j); symbolTable.ensureSymbol(vn); if (constants != null && constants.containsKey(Integer.valueOf(vn))) symbolTable.setConstantValue(vn, constants.get(Integer.valueOf(vn))); } }
private Iterable<CodeElement> getInCodeElts(CGNode node, SSAInstruction inst) { int useNo = inst.getNumberOfUses(); Set<CodeElement> elts = HashSetFactory.make(); if (inst instanceof SSAGetInstruction) { elts.addAll(getFieldAccessCodeElts(node, (SSAGetInstruction) inst)); } if (inst instanceof SSAArrayLoadInstruction) { elts.addAll(getArrayRefCodeElts(node, (SSAArrayLoadInstruction) inst)); } for (int i = 0; i < useNo; i++) { int valNo = inst.getUse(i); // Constants have valuenumber 0, which is otherwise, illegal. // these need to be skipped: if (0 == valNo) { continue; } try { elts.addAll(CodeElement.valueElements(valNo)); } catch (IllegalArgumentException e) { throw e; } } return elts; }
private int addOriginalStatements(SummarizedMethod m) { SSAInstruction[] original = m.getStatements(options.getSSAOptions()); // local value number 1 is "this", so the next free value number is 2 int nextLocal = 2; for (SSAInstruction s : original) { allInstructions.add(s); if (s instanceof SSAInvokeInstruction) { calls.add(s); } if (s instanceof SSANewInstruction) { allocations.add(s); } for (int j = 0; j < s.getNumberOfDefs(); j++) { int def = s.getDef(j); if (def >= nextLocal) { nextLocal = def + 1; } } for (int j = 0; j < s.getNumberOfUses(); j++) { int use = s.getUse(j); if (use >= nextLocal) { nextLocal = use + 1; } } } return nextLocal; }
public static int getArgumentsArrayVn(IR ir) { for(int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction inst = ir.getInstructions()[i]; if (inst != null) { for(int v = 0; v < inst.getNumberOfUses(); v++) { String[] names = ir.getLocalNames(i, inst.getUse(v)); if (names != null && names.length == 1 && "arguments".equals(names[0])) { return inst.getUse(v); } } } } return -1; }
public static int getArgumentsArrayVn(IR ir) { for(int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction inst = ir.getInstructions()[i]; if (inst != null) { for(int v = 0; v < inst.getNumberOfUses(); v++) { String[] names = ir.getLocalNames(i, inst.getUse(v)); if (names != null && names.length == 1 && "arguments".equals(names[0])) { return inst.getUse(v); } } } } return -1; }
.append(call.getDeclaredTarget().getName()); result.append(" exc:").append(call.getException()); for (int i = 0; i < s.getNumberOfUses(); i++) { result.append(' ').append(s.getUse(i));
private int addOriginalStatements(SummarizedMethod m) { SSAInstruction[] original = m.getStatements(options.getSSAOptions()); // local value number 1 is "this", so the next free value number is 2 int nextLocal = 2; for (SSAInstruction s : original) { allInstructions.add(s); if (s instanceof SSAInvokeInstruction) { calls.add(s); } if (s instanceof SSANewInstruction) { allocations.add(s); } for (int j = 0; j < s.getNumberOfDefs(); j++) { int def = s.getDef(j); if (def >= nextLocal) { nextLocal = def + 1; } } for (int j = 0; j < s.getNumberOfUses(); j++) { int use = s.getUse(j); if (use >= nextLocal) { nextLocal = use + 1; } } } return nextLocal; }
SSAInstruction inst2 = du.getDef(i); if(inst2 instanceof SSAPhiInstruction) { for(int j=0;j<inst2.getNumberOfUses();++j) { int use = inst2.getUse(j); if(!done.contains(use)) for(int j=0;j<inst2.getNumberOfUses();++j) { int use = inst2.getUse(j); if(!done.contains(use))
private void handleNonHeapInstruction(SSAInstruction instruction) { for (int i = 0; i < instruction.getNumberOfDefs(); i++) { int def = instruction.getDef(i); PointerKey defPk = heapModel.getPointerKeyForLocal(node, def); addNode(defPk); for (int j = 0; j < instruction.getNumberOfUses(); j++) { int use = instruction.getUse(j); PointerKey usePk = heapModel.getPointerKeyForLocal(node, use); addNode(usePk); addEdge(defPk, usePk, AssignLabel.noFilter()); } } }
private void handleNonHeapInstruction(SSAInstruction instruction) { for (int i = 0; i < instruction.getNumberOfDefs(); i++) { int def = instruction.getDef(i); PointerKey defPk = heapModel.getPointerKeyForLocal(node, def); addNode(defPk); for (int j = 0; j < instruction.getNumberOfUses(); j++) { int use = instruction.getUse(j); PointerKey usePk = heapModel.getPointerKeyForLocal(node, use); addNode(usePk); addEdge(defPk, usePk, AssignLabel.noFilter()); } } }
/** * Create a dataflow equation induced by a given instruction */ private void makeEquationForInstruction(OperatorFactory<T> opFactory, SSAInstruction s) { if (s != null && s.hasDef()) { AbstractOperator<T> op = opFactory.get(s); if (op != null) { T def = getVariable(s.getDef()); if (op instanceof NullaryOperator) { newStatement(def, (NullaryOperator<T>) op, false, false); } else { int n = s.getNumberOfUses(); T[] uses = makeStmtRHS(n); for (int j = 0; j < n; j++) { if (s.getUse(j) > -1) { uses[j] = getVariable(s.getUse(j)); assert uses[j] != null; } } newStatement(def, op, uses, false, false); } } } }
/** * Create a dataflow equation induced by a given instruction */ private void makeEquationForInstruction(OperatorFactory<T> opFactory, SSAInstruction s) { if (s != null && s.hasDef()) { AbstractOperator<T> op = opFactory.get(s); if (op != null) { T def = getVariable(s.getDef()); if (op instanceof NullaryOperator) { newStatement(def, (NullaryOperator<T>) op, false, false); } else { int n = s.getNumberOfUses(); T[] uses = makeStmtRHS(n); for (int j = 0; j < n; j++) { if (s.getUse(j) > -1) { uses[j] = getVariable(s.getUse(j)); assert uses[j] != null; } } newStatement(def, op, uses, false, false); } } } }
@Override public void check(CallGraph cg) { IR ir = getIR(cg, typeName, "main", "[Ljava/lang/String;", "V"); AstJavaTypeInference inference = new AstJavaTypeInference(ir, true); for (SSAInstruction instr : Iterator2Iterable.make(ir.iterateAllInstructions())) { // Check defs for (int def = 0; def < instr.getNumberOfDefs(); def++) { int ssaVariable = instr.getDef(def); inference.getType(ssaVariable); } // Check uses for (int def = 0; def < instr.getNumberOfUses(); def++) { int ssaVariable = instr.getUse(def); inference.getType(ssaVariable); } } }
public static PointerKey getParam(CGNode n, String methodName, HeapModel heapModel) { IR ir = n.getIR(); for (SSAInstruction s : Iterator2Iterable.make(ir.iterateAllInstructions())) { if (s instanceof SSAInvokeInstruction) { SSAInvokeInstruction call = (SSAInvokeInstruction) s; if (call.getCallSite().getDeclaredTarget().getName().toString().equals(methodName)) { IntSet indices = ir.getCallInstructionIndices(((SSAInvokeInstruction) s).getCallSite()); Assertions.productionAssertion(indices.size() == 1, "expected 1 but got " + indices.size()); SSAInstruction callInstr = ir.getInstructions()[indices.intIterator().next()]; Assertions.productionAssertion(callInstr.getNumberOfUses() == 1, "multiple uses for call"); return heapModel.getPointerKeyForLocal(n, callInstr.getUse(0)); } } } Assertions.UNREACHABLE("failed to find call to " + methodName + " in " + n); return null; }
@Test public void testMultiNewArray1() throws IOException, ClassHierarchyException { AnalysisScope scope = null; scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, (new FileProvider()).getFile("J2SEClassHierarchyExclusions.txt"), MY_CLASSLOADER); ClassHierarchy cha = ClassHierarchyFactory.make(scope); IClass klass = cha.lookupClass(TypeReference.findOrCreate(ClassLoaderReference.Application, TestConstants.MULTI_DIM_MAIN)); Assert.assertTrue(klass != null); IMethod m = klass.getMethod(Selector.make(Language.JAVA, "testNewMultiArray()V")); Assert.assertTrue(m != null); IAnalysisCacheView cache = new AnalysisCacheImpl(); IR ir = cache.getIRFactory().makeIR(m, Everywhere.EVERYWHERE, new SSAOptions()); Assert.assertTrue(ir != null); SSAInstruction[] instructions = ir.getInstructions(); for (SSAInstruction instr : instructions) { if (instr instanceof SSANewInstruction) { System.err.println(instr.toString(ir.getSymbolTable())); Assert.assertTrue(instr.getNumberOfUses() == 2); Assert.assertTrue(ir.getSymbolTable().getIntValue(instr.getUse(0)) == 3); Assert.assertTrue(ir.getSymbolTable().getIntValue(instr.getUse(1)) == 4); } } } }