private OrdinalSet<InstanceKey> computeImplicitPointsToSetAtCall(LocalPointerKey lpk, CGNode node, SSAInvokeInstruction call) { int exc = call.getException(); if (lpk.getValueNumber() == exc) { return computeImplicitExceptionsForCall(node, call); } else { Assertions.UNREACHABLE("time to implement me."); return null; } }
private OrdinalSet<InstanceKey> computeImplicitPointsToSetAtCall(LocalPointerKey lpk, CGNode node, SSAInvokeInstruction call) { int exc = call.getException(); if (lpk.getValueNumber() == exc) { return computeImplicitExceptionsForCall(node, call); } else { Assertions.UNREACHABLE("time to implement me."); return null; } }
private static int compareLocalKey(LocalPointerKey key1, Object key2) { if (key2 instanceof LocalPointerKey) { int l1 = key1.getValueNumber(); int l2 = ((LocalPointerKey)key2).getValueNumber(); if (l1 != l2) return l1-l2; else { int n1 = key1.getNode().getGraphNodeId(); int n2 = ((LocalPointerKey)key2).getNode().getGraphNodeId(); if (n1 != n2) return n1-n2; else { assert key1.equals(key2); return 0; } } } else return -1; }
private static int compareLocalKey(LocalPointerKey key1, Object key2) { if (key2 instanceof LocalPointerKey) { int l1 = key1.getValueNumber(); int l2 = ((LocalPointerKey)key2).getValueNumber(); if (l1 != l2) return l1-l2; else { int n1 = key1.getNode().getGraphNodeId(); int n2 = ((LocalPointerKey)key2).getNode().getGraphNodeId(); if (n1 != n2) return n1-n2; else { assert key1.equals(key2); return 0; } } } else return -1; }
/** * record that a particular points-to-set is represented implicitly. */ public void recordImplicitPointsToSet(PointerKey key) { if (key == null) { throw new IllegalArgumentException("null key"); } if (key instanceof LocalPointerKey) { LocalPointerKey lpk = (LocalPointerKey) key; if (lpk.isParameter()) { System.err.println("------------------ ERROR:"); System.err.println("LocalPointerKey: " + lpk); System.err.println("Constant? " + lpk.getNode().getIR().getSymbolTable().isConstant(lpk.getValueNumber())); System.err.println(" -- IR:"); System.err.println(lpk.getNode().getIR()); Assertions.UNREACHABLE("How can parameter be implicit?"); } } pointsToMap.recordImplicit(key); }
public GlobalReturnToNodeFunction(IFDSTaintDomain<E> domain, PointerAnalysis<InstanceKey> pa, CGNode node) { this.domain = domain; this.ikMap = HashMapFactory.make(); for (PointerKey pk : pa.getPointerKeys()) { if (!(pk instanceof LocalPointerKey)) { continue; } LocalPointerKey lpk = (LocalPointerKey) pk; if (!lpk.getNode().equals(node)) { continue; } for (InstanceKey ik : pa.getPointsToSet(lpk)) { Set<CodeElement> elts = ikMap.get(ik); if (null == elts) { elts = HashSetFactory.make(); ikMap.put(ik, elts); } elts.add(new LocalElement(lpk.getValueNumber())); } } }
/** * record that a particular points-to-set is represented implicitly. */ public void recordImplicitPointsToSet(PointerKey key) { if (key == null) { throw new IllegalArgumentException("null key"); } if (key instanceof LocalPointerKey) { LocalPointerKey lpk = (LocalPointerKey) key; if (lpk.isParameter()) { System.err.println("------------------ ERROR:"); System.err.println("LocalPointerKey: " + lpk); System.err.println("Constant? " + lpk.getNode().getIR().getSymbolTable().isConstant(lpk.getValueNumber())); System.err.println(" -- IR:"); System.err.println(lpk.getNode().getIR()); Assertions.UNREACHABLE("How can parameter be implicit?"); } } pointsToMap.recordImplicit(key); }
public Iterator<PointerKeyAndCallSite> getReturnSuccs(LocalPointerKey pk) { SSAAbstractInvokeInstruction callInstr = callDefs.get(pk); if (callInstr == null) return EmptyIterator.instance(); ArrayList<PointerKeyAndCallSite> returnSuccs = new ArrayList<>(); boolean isExceptional = pk.getValueNumber() == callInstr.getException(); CallSiteReference callSiteRef = callInstr.getCallSite(); // get call targets Collection<CGNode> possibleCallees = cg.getPossibleTargets(pk.getNode(), callSiteRef); // construct graph for each target for (CGNode callee : possibleCallees) { addSubgraphForNode(callee); PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel .getPointerKeyForReturnValue(callee); assert containsNode(retVal); returnSuccs.add(new PointerKeyAndCallSite(retVal, callSiteRef)); } return returnSuccs.iterator(); }
public Iterator<PointerKeyAndCallSite> getReturnSuccs(LocalPointerKey pk) { SSAAbstractInvokeInstruction callInstr = callDefs.get(pk); if (callInstr == null) return EmptyIterator.instance(); ArrayList<PointerKeyAndCallSite> returnSuccs = new ArrayList<>(); boolean isExceptional = pk.getValueNumber() == callInstr.getException(); CallSiteReference callSiteRef = callInstr.getCallSite(); // get call targets Collection<CGNode> possibleCallees = cg.getPossibleTargets(pk.getNode(), callSiteRef); // construct graph for each target for (CGNode callee : possibleCallees) { addSubgraphForNode(callee); PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel .getPointerKeyForReturnValue(callee); assert containsNode(retVal); returnSuccs.add(new PointerKeyAndCallSite(retVal, callSiteRef)); } return returnSuccs.iterator(); }
public Iterator<PointerKeyAndCallSite> getParamPreds(LocalPointerKey pk) { // TODO Set<SSAAbstractInvokeInstruction> instrs = callParams.get(pk); if (instrs == null) { return EmptyIterator.instance(); } ArrayList<PointerKeyAndCallSite> paramPreds = new ArrayList<>(); for (SSAAbstractInvokeInstruction callInstr : instrs) { for (int i = 0; i < callInstr.getNumberOfUses(); i++) { if (pk.getValueNumber() != callInstr.getUse(i)) continue; CallSiteReference callSiteRef = callInstr.getCallSite(); // get call targets Collection<CGNode> possibleCallees = cg.getPossibleTargets(pk.getNode(), callSiteRef); // construct graph for each target for (CGNode callee : possibleCallees) { addSubgraphForNode(callee); // TODO test this!!! // TODO test passing null as an argument PointerKey paramVal = heapModel.getPointerKeyForLocal(callee, i + 1); assert containsNode(paramVal); paramPreds.add(new PointerKeyAndCallSite(paramVal, callSiteRef)); } } } return paramPreds.iterator(); }
/** * precondition: !mayBeLiveInSomeCaller(ik, m) * * @param instructionIndex index of an SSA instruction */ private boolean mayBeLiveIntraprocedural(InstanceKey ik, CGNode m, int instructionIndex) { IR ir = m.getIR(); DefUse du = m.getDU(); for (Object p : Iterator2Iterable.make(DFS.iterateDiscoverTime(GraphInverter.invert(heapGraph), ik))) { if (p instanceof LocalPointerKey) { LocalPointerKey lpk = (LocalPointerKey) p; if (lpk.getNode().equals(m)) { if (LocalLiveRangeAnalysis.isLive(lpk.getValueNumber(), instructionIndex, ir, du)) { return true; } } } } return false; }
/** * precondition: !mayBeLiveInSomeCaller(ik, m) * * @param instructionIndex index of an SSA instruction */ private boolean mayBeLiveIntraprocedural(InstanceKey ik, CGNode m, int instructionIndex) { IR ir = m.getIR(); DefUse du = m.getDU(); for (Object p : Iterator2Iterable.make(DFS.iterateDiscoverTime(GraphInverter.invert(heapGraph), ik))) { if (p instanceof LocalPointerKey) { LocalPointerKey lpk = (LocalPointerKey) p; if (lpk.getNode().equals(m)) { if (LocalLiveRangeAnalysis.isLive(lpk.getValueNumber(), instructionIndex, ir, du)) { return true; } } } } return false; }
private void upgradeToFilter(PointsToSetVariable p, FilteredPointerKey.TypeFilter typeFilter) { if (p.getPointerKey() instanceof LocalPointerKey) { LocalPointerKey lpk = (LocalPointerKey) p.getPointerKey(); LocalPointerKeyWithFilter f = new LocalPointerKeyWithFilter(lpk.getNode(), lpk.getValueNumber(), typeFilter); p.setPointerKey(f); pointerKeys.replace(lpk, f); } else if (p.getPointerKey() instanceof ReturnValueKey) { ReturnValueKey r = (ReturnValueKey) p.getPointerKey(); ReturnValueKeyWithFilter f = new ReturnValueKeyWithFilter(r.getNode(), typeFilter); p.setPointerKey(f); pointerKeys.replace(r, f); } else { Assertions.UNREACHABLE(p.getPointerKey().getClass().toString()); } }
private void upgradeToFilter(PointsToSetVariable p, FilteredPointerKey.TypeFilter typeFilter) { if (p.getPointerKey() instanceof LocalPointerKey) { LocalPointerKey lpk = (LocalPointerKey) p.getPointerKey(); LocalPointerKeyWithFilter f = new LocalPointerKeyWithFilter(lpk.getNode(), lpk.getValueNumber(), typeFilter); p.setPointerKey(f); pointerKeys.replace(lpk, f); } else if (p.getPointerKey() instanceof ReturnValueKey) { ReturnValueKey r = (ReturnValueKey) p.getPointerKey(); ReturnValueKeyWithFilter f = new ReturnValueKeyWithFilter(r.getNode(), typeFilter); p.setPointerKey(f); pointerKeys.replace(r, f); } else { Assertions.UNREACHABLE(p.getPointerKey().getClass().toString()); } }
private void addParamEdges(LocalPointerKey pk, CGNode node) { // get parameter position: value number - 1? int paramPos = pk.getValueNumber() - 1; // iterate over callers for (CGNode caller : cg) { // TODO we don't need to add the graph if null is passed // as the argument addSubgraphForNode(caller); IR ir = caller.getIR(); for (CallSiteReference call : Iterator2Iterable.make(ir.iterateCallSites())) { if (cg.getPossibleTargets(caller, call).contains(node)) { SSAAbstractInvokeInstruction[] callInstrs = ir.getCalls(call); for (SSAAbstractInvokeInstruction callInstr : callInstrs) { PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos)); assert containsNode(actualPk); assert containsNode(pk); addEdge(pk, actualPk); } } } } }
private void addParamEdges(LocalPointerKey pk, CGNode node) { // get parameter position: value number - 1? int paramPos = pk.getValueNumber() - 1; // iterate over callers for (CGNode caller : cg) { // TODO we don't need to add the graph if null is passed // as the argument addSubgraphForNode(caller); IR ir = caller.getIR(); for (CallSiteReference call : Iterator2Iterable.make(ir.iterateCallSites())) { if (cg.getPossibleTargets(caller, call).contains(node)) { SSAAbstractInvokeInstruction[] callInstrs = ir.getCalls(call); for (SSAAbstractInvokeInstruction callInstr : callInstrs) { PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos)); assert containsNode(actualPk); assert containsNode(pk); addEdge(pk, actualPk); } } } } }
/** * @param pk value being def'fed by a call instruction (either normal or exceptional) */ private void addReturnEdges(LocalPointerKey pk, SSAInvokeInstruction callInstr) { boolean isExceptional = pk.getValueNumber() == callInstr.getException(); // get call targets Collection<CGNode> possibleCallees = cg.getPossibleTargets(pk.getNode(), callInstr.getCallSite()); // construct graph for each target for (CGNode callee : possibleCallees) { addSubgraphForNode(callee); PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel .getPointerKeyForReturnValue(callee); assert containsNode(retVal); addEdge(pk, retVal); } }
/** * @param pk value being def'fed by a call instruction (either normal or exceptional) */ private void addReturnEdges(LocalPointerKey pk, SSAInvokeInstruction callInstr) { boolean isExceptional = pk.getValueNumber() == callInstr.getException(); // get call targets Collection<CGNode> possibleCallees = cg.getPossibleTargets(pk.getNode(), callInstr.getCallSite()); // construct graph for each target for (CGNode callee : possibleCallees) { addSubgraphForNode(callee); PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel .getPointerKeyForReturnValue(callee); assert containsNode(retVal); addEdge(pk, retVal); } }
@Override protected void action(PointerKey lexicalKey, int vn) { PointerKey lval = getPointerKeyForLocal(vn); if (lexicalKey instanceof LocalPointerKey) { CGNode lnode = ((LocalPointerKey) lexicalKey).getNode(); int lvn = ((LocalPointerKey) lexicalKey).getValueNumber(); IRView lir = getBuilder().getCFAContextInterpreter().getIRView(lnode); SymbolTable lsymtab = lir.getSymbolTable(); DefUse ldu = getBuilder().getCFAContextInterpreter().getDU(lnode); // DefUse ldu = getAnalysisCache().getDefUse(lir); if (contentsAreInvariant(lsymtab, ldu, lvn)) { InstanceKey[] ik = getInvariantContents(lsymtab, ldu, lnode, lvn); system.recordImplicitPointsToSet(lexicalKey); for (InstanceKey element : ik) { system.findOrCreateIndexForInstanceKey(element); system.newConstraint(lval, element); } return; } } system.newConstraint(lval, assignOperator, lexicalKey); } });
@Override protected void action(PointerKey lexicalKey, int vn) { PointerKey lval = getPointerKeyForLocal(vn); if (lexicalKey instanceof LocalPointerKey) { CGNode lnode = ((LocalPointerKey) lexicalKey).getNode(); int lvn = ((LocalPointerKey) lexicalKey).getValueNumber(); IRView lir = getBuilder().getCFAContextInterpreter().getIRView(lnode); SymbolTable lsymtab = lir.getSymbolTable(); DefUse ldu = getBuilder().getCFAContextInterpreter().getDU(lnode); // DefUse ldu = getAnalysisCache().getDefUse(lir); if (contentsAreInvariant(lsymtab, ldu, lvn)) { InstanceKey[] ik = getInvariantContents(lsymtab, ldu, lnode, lvn); system.recordImplicitPointsToSet(lexicalKey); for (InstanceKey element : ik) { system.findOrCreateIndexForInstanceKey(element); system.newConstraint(lval, element); } return; } } system.newConstraint(lval, assignOperator, lexicalKey); } });