@Override public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) { if (valueNumber <= 0) { throw new IllegalArgumentException("illegal value number: " + valueNumber + " in " + node); } return new LocalPointerKey(node, valueNumber); }
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())); } } }
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); }
protected ImplicitPointsToSetVisitor(PointerAnalysisImpl analysis, LocalPointerKey lpk) { this.lpk = lpk; this.node = lpk.getNode(); this.analysis = analysis; }
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 void handleUriWitAppendPath(final LocalPointerKey lpk, final PointerAnalysis<InstanceKey> pa, final OrdinalSetMapping<InstanceKey> mapping, final Map<InstanceKeySite, Set<InstanceKey>> unresolvedDependencies) { final Context context = lpk.getNode().getContext(); final CGNode caller = (CGNode) context.get(ContextKey.CALLER); (SSAInvokeInstruction) caller.getIR().getBasicBlocksForCall(csr)[0].getLastInstruction(); final OrdinalSet<InstanceKey> ptsUri = pa.getPointsToSet(new LocalPointerKey(caller, invoke.getUse(0))); pa.getPointsToSet(new LocalPointerKey(caller, invoke.getUse(1))); pa.getPointsToSet(new LocalPointerKey(caller, invoke.getReturnValue(0)));
protected ImplicitPointsToSetVisitor(PointerAnalysisImpl analysis, LocalPointerKey lpk) { this.lpk = lpk; this.node = lpk.getNode(); this.analysis = analysis; }
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; } }
/** * 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); }
/** * 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; }
@Override public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) { if (valueNumber <= 0) { throw new IllegalArgumentException("illegal value number: " + valueNumber + " in " + node); } return new LocalPointerKey(node, valueNumber); }
private static boolean hasSignature(final LocalPointerKey pk, final String signature) { return hasSignature(pk.getNode(), signature); }
public Iterator<PointerKeyAndCallSite> getParamSuccs(LocalPointerKey pk) { // TODO cache this result // TODO take some cgnode as parameter if we have calling context? CGNode cgNode = params.get(pk); if (cgNode == null) { return EmptyIterator.instance(); } int paramPos = pk.getValueNumber() - 1; ArrayList<PointerKeyAndCallSite> paramSuccs = new ArrayList<>(); // iterate over callers for (CGNode caller : cg) { // TODO optimization: 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(cgNode)) { SSAAbstractInvokeInstruction[] callInstrs = ir.getCalls(call); for (SSAAbstractInvokeInstruction callInstr : callInstrs) { PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos)); assert containsNode(actualPk); assert containsNode(pk); paramSuccs.add(new PointerKeyAndCallSite(actualPk, call)); } } } } return paramSuccs.iterator(); }
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; }
/** * 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 List<SSAInstruction> findInstructions() { List<SSAInstruction> instructions = new ArrayList<>(); if (node != null) { for (SSAInstruction inst: node.getIR().getInstructions()) { if (inst instanceof SSAInvokeInstruction) { if (localPointerKeys.contains(new LocalPointerKey(node,inst.getUse(0)))) { instructions.add(inst); } } } } return instructions; }
@Override protected ImplicitPointsToSetVisitor makeImplicitPointsToVisitor(LocalPointerKey lpk) { return implicitVisitors.get(getLanguage(lpk.getNode()), lpk); } }
public Iterator<PointerKeyAndCallSite> getParamSuccs(LocalPointerKey pk) { // TODO cache this result // TODO take some cgnode as parameter if we have calling context? CGNode cgNode = params.get(pk); if (cgNode == null) { return EmptyIterator.instance(); } int paramPos = pk.getValueNumber() - 1; ArrayList<PointerKeyAndCallSite> paramSuccs = new ArrayList<>(); // iterate over callers for (CGNode caller : cg) { // TODO optimization: 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(cgNode)) { SSAAbstractInvokeInstruction[] callInstrs = ir.getCalls(call); for (SSAAbstractInvokeInstruction callInstr : callInstrs) { PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos)); assert containsNode(actualPk); assert containsNode(pk); paramSuccs.add(new PointerKeyAndCallSite(actualPk, call)); } } } } return paramSuccs.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(); }