Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::Andersen Class Reference

#include <Andersen.h>

Inheritance diagram for SVF::Andersen:
SVF::AndersenBase SVF::WPASolver< ConstraintGraph * > SVF::BVDataPTAImpl SVF::PointerAnalysis SVF::AndersenSCD SVF::AndersenWaveDiff SVF::AndersenSFR

Public Types

typedef SCCDetection< ConstraintGraph * > CGSCC
Public Types inherited from SVF::AndersenBase
typedef OrderedMap< const CallICFGNode *, NodeID > CallSite2DummyValPN
Public Types inherited from SVF::WPASolver< ConstraintGraph * >
typedef SVF::GenericGraphTraits< ConstraintGraph * > GTraits
 Define the GTraits and node iterator for printing.
typedef GTraits::NodeRef GNODE
typedef GTraits::EdgeType GEDGE
typedef GTraits::ChildIteratorType child_iterator
typedef SCCDetection< ConstraintGraph * > SCC
typedef FIFOWorkList< NodeID > WorkList
Public Types inherited from SVF::BVDataPTAImpl
typedef PTData< NodeID, NodeSet, NodeID, PointsTo > PTDataTy
typedef DiffPTData< NodeID, NodeSet, NodeID, PointsTo > DiffPTDataTy
typedef DFPTData< NodeID, NodeSet, NodeID, PointsTo > DFPTDataTy
typedef VersionedPTData< NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set< VersionedVar > > VersionedPTDataTy
typedef MutablePTData< NodeID, NodeSet, NodeID, PointsTo > MutPTDataTy
typedef MutableDiffPTData< NodeID, NodeSet, NodeID, PointsTo > MutDiffPTDataTy
typedef MutableDFPTData< NodeID, NodeSet, NodeID, PointsTo > MutDFPTDataTy
typedef MutableIncDFPTData< NodeID, NodeSet, NodeID, PointsTo > MutIncDFPTDataTy
typedef MutableVersionedPTData< NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set< VersionedVar > > MutVersionedPTDataTy
typedef PersistentPTData< NodeID, NodeSet, NodeID, PointsTo > PersPTDataTy
typedef PersistentDiffPTData< NodeID, NodeSet, NodeID, PointsTo > PersDiffPTDataTy
typedef PersistentDFPTData< NodeID, NodeSet, NodeID, PointsTo > PersDFPTDataTy
typedef PersistentIncDFPTData< NodeID, NodeSet, NodeID, PointsTo > PersIncDFPTDataTy
typedef PersistentVersionedPTData< NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set< VersionedVar > > PersVersionedPTDataTy
Public Types inherited from SVF::PointerAnalysis
typedef Set< const CallICFGNode * > CallSiteSet
 Indirect call edges type, map a callsite to a set of callees.
typedef PAG::CallSiteToFunPtrMap CallSiteToFunPtrMap
typedef Set< const FunObjVar * > FunctionSet
typedef OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
typedef SCCDetection< CallGraph * > CallGraphSCC
typedef Set< const GlobalObjVar * > VTableSet
typedef Set< const FunObjVar * > VFunSet

Public Member Functions

 Andersen (PAG *_pag, PTATY type=PTATY::Andersen_WPA, bool alias_check=true)
 Constructor.
virtual ~Andersen ()
 Destructor.
virtual void initialize ()
 Initialize analysis.
virtual void finalize ()
 Finalize analysis.
void resetData ()
 Reset data.
virtual const PointsTo & getPts (NodeID id)
 Operation of points-to set.
virtual bool unionPts (NodeID id, const PointsTo &target)
virtual bool unionPts (NodeID id, NodeID ptd)
virtual NodeBS getMayAliases (NodeID node)
 Collect exactly the PAG nodes q for which mayAlias(node, q) holds.
std::vector< NodeBS > getMayAliasesBatch (const std::vector< NodeID > &nodes)
void dumpTopLevelPtsTo ()
void setDetectPWC (bool flag)
Public Member Functions inherited from SVF::AndersenBase
 AndersenBase (PAG *_pag, PTATY type=PTATY::Andersen_BASE, bool alias_check=true)
 Constructor.
 ~AndersenBase () override
 Destructor.
virtual void analyze () override
 Andersen analysis.
virtual void solveAndwritePtsToFile (const std::string &filename)
virtual void readPtsFromFile (const std::string &filename)
virtual void solveConstraints ()
virtual bool updateCallGraph (const CallSiteToFunPtrMap &) override
 Update call graph.
virtual bool updateThreadCallGraph (const CallSiteToFunPtrMap &, NodePairSet &)
 Update thread call graph.
virtual void connectCaller2ForkedFunParams (const CallICFGNode *cs, const FunObjVar *F, NodePairSet &cpySrcNodes)
 Connect formal and actual parameters for indirect forksites.
virtual void connectCaller2CalleeParams (const CallICFGNode *cs, const FunObjVar *F, NodePairSet &cpySrcNodes)
 Connect formal and actual parameters for indirect callsites.
ConstraintGraph * getConstraintGraph ()
 Get constraint graph.
NodeID sccRepNode (NodeID id) const override
 SCC methods.
NodeBS & sccSubNodes (NodeID repId)
void printStat ()
 dump statistics
virtual void normalizePointsTo () override
void cleanConsCG (NodeID id)
 remove redundant gepnodes in constraint graph
Public Member Functions inherited from SVF::BVDataPTAImpl
 BVDataPTAImpl (PAG *pag, PTATY type, bool alias_check=true)
 Constructor.
 ~BVDataPTAImpl () override=default
 Destructor.
PersistentPointsToCache< PointsTo > & getPtCache ()
const PointsTo & getPts (NodeID id) override
const NodeSet & getRevPts (NodeID nodeId) override
virtual void clearPts (NodeID id, NodeID element)
 Remove element from the points-to set of id.
virtual void clearFullPts (NodeID id)
 Clear points-to set of id.
virtual bool addPts (NodeID id, NodeID ptd)
virtual void clearAllPts ()
 Clear all data.
virtual void expandFIObjs (const PointsTo &pts, PointsTo &expandedPts)
 Expand FI objects.
virtual void expandFIObjs (const NodeBS &pts, NodeBS &expandedPts)
 TODO: remove repetition.
void remapPointsToSets (void)
 Remap all points-to sets to use the current mapping.
virtual void writeToFile (const std::string &filename)
 Interface for analysis result storage on filesystem.
virtual void writeObjVarToFile (const std::string &filename)
virtual void writePtsResultToFile (std::fstream &f)
virtual void writeGepObjVarMapToFile (std::fstream &f)
virtual bool readFromFile (const std::string &filename)
virtual void readPtsResultFromFile (std::ifstream &f)
virtual void readGepObjVarMapFromFile (std::ifstream &f)
virtual void readAndSetObjFieldSensitivity (std::ifstream &f, const std::string &delimiterStr)
AliasResult alias (const SVFVar *V1, const SVFVar *V2) override
 Interface expose to users of our pointer analysis, given Value infos.
AliasResult alias (NodeID node1, NodeID node2) override
 Interface expose to users of our pointer analysis, given PAGNodeID.
virtual AliasResult alias (const PointsTo &pts1, const PointsTo &pts2)
 Interface expose to users of our pointer analysis, given two pts.
bool mayAlias (const PointsTo &pts1, const PointsTo &pts2)
 Convenience bool wrappers: return true if the two operands may/must/partial alias.
void dumpCPts () override
 dump and debug, print out conditional pts
void dumpTopLevelPtsTo () override
void dumpAllPts () override
bool mayAlias (const SVFVar *V1, const SVFVar *V2)
bool mayAlias (NodeID node1, NodeID node2)
Public Member Functions inherited from SVF::PointerAnalysis
ICFG * getICFG () const
 Get ICFG.
u32_t getNumOfResolvedIndCallEdge () const
 Return number of resolved indirect call edges.
CallGraph * getCallGraph () const
 Return call graph.
CallGraphSCC * getCallGraphSCC () const
 Return call graph SCC.
 PointerAnalysis (PAG *pag, PTATY ty=PTATY::Default_PTA, bool alias_check=true)
 Constructor.
PTATY getAnalysisTy () const
 Type of pointer analysis.
PTAImplTy getImplTy () const
 Return implementation type of the pointer analysis.
bool printStat ()
 Whether print statistics.
void disablePrintStat ()
 Whether print statistics.
CallEdgeMap & getIndCallMap ()
 Get callees from an indirect callsite.
bool hasIndCSCallees (const CallICFGNode *cs) const
const FunctionSet & getIndCSCallees (const CallICFGNode *cs) const
virtual void resolveIndCalls (const CallICFGNode *cs, const PointsTo &target, CallEdgeMap &newEdges)
 Resolve indirect call edges.
void callGraphSCCDetection ()
 PTACallGraph SCC related methods.
NodeID getCallGraphSCCRepNode (NodeID id) const
 Get SCC rep node of a SVFG node.
bool inSameCallGraphSCC (const FunObjVar *fun1, const FunObjVar *fun2)
 Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SCC on the SVFG.
bool isInRecursion (const FunObjVar *fun) const
bool isLocalVarInRecursiveFun (NodeID id) const
 Whether a local variable is in function recursions.
CommonCHGraph * getCHGraph () const
 get CHGraph
void getVFnsFromCHA (const CallICFGNode *cs, VFunSet &vfns)
void getVFnsFromPts (const CallICFGNode *cs, const PointsTo &target, VFunSet &vfns)
void connectVCallToVFns (const CallICFGNode *cs, const VFunSet &vfns, CallEdgeMap &newEdges)
virtual void resolveCPPIndCalls (const CallICFGNode *cs, const PointsTo &target, CallEdgeMap &newEdges)
 Resolve cpp indirect call edges.
PAG * getPAG () const
PTAStat * getStat () const
 Get PTA stat.
OrderedNodeSet & getAllValidPtrs ()
 Get all Valid Pointers for resolution.
virtual ~PointerAnalysis ()
 Destructor.
virtual void computeDDAPts (NodeID)
 Compute points-to results on-demand, overridden by derived classes.
bool mayAlias (const SVFVar *V1, const SVFVar *V2)
 Convenience bool wrappers: return true if the two operands may/must/partial alias.
bool mayAlias (NodeID node1, NodeID node2)
void printIndCSTargets (const CallICFGNode *cs, const FunctionSet &targets)
 Print targets of a function pointer.
virtual void dumpPts (NodeID ptr, const PointsTo &pts)
void printIndCSTargets ()
void dumpAllTypes ()
void dumpStat ()
 Dump the statistics.
bool containBlackHoleNode (const PointsTo &pts)
 Determine whether a points-to contains a black hole or constant node.
bool containConstantNode (const PointsTo &pts)
virtual bool isBlkObjOrConstantObj (NodeID ptd) const
bool isHeapMemObj (NodeID id) const
 Whether this object is heap or array.
bool isArrayMemObj (NodeID id) const
bool isFIObjNode (NodeID id) const
NodeID getBaseObjVarID (NodeID id)
NodeID getFIObjVar (NodeID id)
NodeID getGepObjVar (NodeID id, const APOffset &ap)
virtual const NodeBS & getAllFieldsObjVars (NodeID id)
void setObjFieldInsensitive (NodeID id)
bool isFieldInsensitive (NodeID id) const

Static Public Member Functions

static bool classof (const Andersen *)
 Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof (const PointerAnalysis *pta)
Static Public Member Functions inherited from SVF::AndersenBase
static bool classof (const AndersenBase *)
 Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof (const PointerAnalysis *pta)
Static Public Member Functions inherited from SVF::BVDataPTAImpl
static bool classof (const PointerAnalysis *pta)

Protected Member Functions

virtual void computeDiffPts (NodeID id)
 Handle diff points-to set.
virtual const PointsTo & getDiffPts (NodeID id)
void updatePropaPts (NodeID dstId, NodeID srcId)
 Handle propagated points-to set.
void clearPropaPts (NodeID src)
virtual void initWorklist ()
virtual void processNode (NodeID nodeId)
 Override WPASolver function in order to use the default solver.
void processAllAddr ()
 handling various constraints
virtual bool processLoad (NodeID node, const ConstraintEdge *load)
virtual bool processStore (NodeID node, const ConstraintEdge *load)
virtual bool processCopy (NodeID node, const ConstraintEdge *edge)
virtual bool processGep (NodeID node, const GepCGEdge *edge)
virtual void handleCopyGep (ConstraintNode *node)
virtual void handleLoadStore (ConstraintNode *node)
virtual void processAddr (const AddrCGEdge *addr)
virtual bool processGepPts (const PointsTo &pts, const GepCGEdge *edge)
virtual bool addCopyEdge (NodeID src, NodeID dst)
 Add copy edge on constraint graph.
virtual void mergeNodeToRep (NodeID nodeId, NodeID newRepId)
 Merge sub node to its rep.
virtual bool mergeSrcToTgt (NodeID srcId, NodeID tgtId)
void mergeSccNodes (NodeID repNodeId, const NodeBS &subNodes)
 Merge sub node in a SCC cycle to their rep node.
void mergeSccCycle ()
virtual void collapsePWCNode (NodeID nodeId)
 Collapse a field object into its base for field insensitive analysis.
void collapseFields ()
 collapse positive weight cycles of a graph
bool collapseNodePts (NodeID nodeId)
bool collapseField (NodeID nodeId)
void updateNodeRepAndSubs (NodeID nodeId, NodeID newRepId)
 Updates subnodes of its rep, and rep node of its subs.
virtual NodeStack & SCCDetect ()
 SCC detection.
std::optional< NodeBS > collectMayAliasesFromIndex (const PointsTo &expandedPts)
virtual void validateSuccessTests (std::string fun)
 Also check getMayAliases on the pointers that the alias tests use.
void sanitizePts ()
 Sanitize pts for field insensitive objects.
virtual const std::string PTAName () const
 Get PTA name.
virtual void cluster (void) const
Protected Member Functions inherited from SVF::AndersenBase
void heapAllocatorViaIndCall (const CallICFGNode *cs, NodePairSet &cpySrcNodes)
Protected Member Functions inherited from SVF::WPASolver< ConstraintGraph * >
 WPASolver ()
 Constructor.
virtual ~WPASolver ()=default
 Destructor.
SCC * getSCCDetector () const
 Get SCC detector.
const ConstraintGraph * graph ()
 Get/Set graph methods.
void setGraph (ConstraintGraph *g)
virtual NodeStack & SCCDetect (NodeSet &candidates)
virtual void solveWorklist ()
virtual void propagate (GNODE *v)
virtual bool propFromSrcToDst (GEDGE *)
 Propagate information from source to destination node, to be implemented in the child class.
NodeID popFromWorklist ()
 Worklist operations.
virtual void pushIntoWorklist (NodeID id)
bool isWorklistEmpty ()
bool isInWorklist (NodeID id)
GNODE * Node (NodeID id)
 Get node on the graph.
NodeID Node_Index (GNODE node)
 Get node ID.
PTDataTy * getPTDataTy () const
 Get points-to data structure.
void finalize () override
 Finalization of pointer analysis, and normalize points-to information to Bit Vector representation.
DiffPTDataTy * getDiffPTDataTy () const
DFPTDataTy * getDFPTDataTy () const
MutDFPTDataTy * getMutDFPTDataTy () const
VersionedPTDataTy * getVersionedPTDataTy () const
virtual void onTheFlyCallGraphSolve (const CallSiteToFunPtrMap &callsites, CallEdgeMap &newEdges)
 On the fly call graph construction.
virtual void onTheFlyThreadCallGraphSolve (const CallSiteToFunPtrMap &callsites, CallEdgeMap &newForkEdges)
 On the fly thread call graph construction respecting forksite.
const CallSiteToFunPtrMap & getIndirectCallsites () const
 Return all indirect callsites.
NodeID getFunPtr (const CallICFGNode *cs) const
 Return function pointer PAGNode at a callsite cs.
virtual void validateTests ()
 Alias check functions to verify correctness of pointer analysis.
virtual void validateExpectedFailureTests (std::string fun)
void resetObjFieldSensitive ()
 Reset all object node as field-sensitive.

Protected Attributes

CallSite2DummyValPN callsite2DummyValPN
 Map an instruction to a dummy obj which created at an indirect callsite, which invokes a heap allocator.
Protected Attributes inherited from SVF::AndersenBase
ConstraintGraph * consCG
 Constraint Graph.
CallSite2DummyValPN callsite2DummyValPN
Protected Attributes inherited from SVF::WPASolver< ConstraintGraph * >
bool reanalyze
 Reanalyze if any constraint value changed.
u32_t iterationForPrintStat
 print out statistics for i-th iteration
ConstraintGraph * _graph
 Graph.
std::unique_ptr< SCC > scc
 SCC.
WorkList worklist
 Worklist for resolution.
Protected Attributes inherited from SVF::PointerAnalysis
bool print_stat
 User input flags.
bool alias_validation
 Flag for validating points-to/alias results.
u32_t OnTheFlyIterBudgetForStat
 Flag for iteration budget for on-the-fly statistics.
PTATY ptaTy
 Pointer analysis Type.
PTAImplTy ptaImplTy
 PTA implementation type.
PTAStat * stat
 Statistics.
CallGraph * callgraph
 Call graph used for pointer analysis.
CallGraphSCC * callGraphSCC
 SCC for PTACallGraph.
ICFG * icfg
 Interprocedural control-flow graph.
CommonCHGraph * chgraph
 CHGraph.

Additional Inherited Members

Public Attributes inherited from SVF::AndersenBase
NodeBS redundantGepNodes
Public Attributes inherited from SVF::WPASolver< ConstraintGraph * >
u32_t numOfIteration
 num of iterations during constraint solving
Static Public Attributes inherited from SVF::AndersenBase
static u32_t numOfProcessedAddr = 0
 Statistics.
static u32_t numOfProcessedCopy = 0
 Number of processed Addr edge.
static u32_t numOfProcessedGep = 0
 Number of processed Copy edge.
static u32_t numOfProcessedLoad = 0
 Number of processed Gep edge.
static u32_t numOfProcessedStore = 0
 Number of processed Load edge.
static u32_t numOfSfrs = 0
 Number of processed Store edge.
static u32_t numOfFieldExpand = 0
static u32_t numOfSCCDetection = 0
static double timeOfSCCDetection = 0
static double timeOfSCCMerges = 0
static double timeOfCollapse = 0
static u32_t AveragePointsToSetSize = 0
static u32_t MaxPointsToSetSize = 0
static double timeOfProcessCopyGep = 0
static double timeOfProcessLoadStore = 0
static double timeOfUpdateCallGraph = 0
Static Public Attributes inherited from SVF::PointerAnalysis
static const std::string aliasTestMayAlias = "MAYALIAS"
static const std::string aliasTestMayAliasMangled = "_Z8MAYALIASPvS_"
static const std::string aliasTestNoAlias = "NOALIAS"
static const std::string aliasTestNoAliasMangled = "_Z7NOALIASPvS_"
static const std::string aliasTestPartialAlias = "PARTIALALIAS"
static const std::string aliasTestPartialAliasMangled = "_Z12PARTIALALIASPvS_"
static const std::string aliasTestMustAlias = "MUSTALIAS"
static const std::string aliasTestMustAliasMangled = "_Z9MUSTALIASPvS_"
static const std::string aliasTestFailMayAlias = "EXPECTEDFAIL_MAYALIAS"
static const std::string aliasTestFailMayAliasMangled = "_Z21EXPECTEDFAIL_MAYALIASPvS_"
static const std::string aliasTestFailNoAlias = "EXPECTEDFAIL_NOALIAS"
static const std::string aliasTestFailNoAliasMangled = "_Z20EXPECTEDFAIL_NOALIASPvS_"
Static Protected Attributes inherited from SVF::PointerAnalysis
static PAG * pag = nullptr
 PAG.

Detailed Description

Inclusion-based Pointer Analysis

Definition at line 192 of file Andersen.h.

Member Typedef Documentation

◆ CGSCC

Definition at line 197 of file Andersen.h.

Constructor & Destructor Documentation

◆ Andersen()

SVF::Andersen::Andersen ( PAG * _pag,
PTATY type = PTATY::Andersen_WPA,
bool alias_check = true )
inline

Constructor.

Definition at line 200 of file Andersen.h.

201 : AndersenBase(_pag, type, alias_check)
202 {
203 }
newitem type
Definition cJSON.cpp:2739
AndersenBase(PAG *_pag, PTATY type=PTATY::Andersen_BASE, bool alias_check=true)
Constructor.
Definition Andersen.h:68

◆ ~Andersen()

virtual SVF::Andersen::~Andersen ( )
inlinevirtual

Destructor.

Definition at line 206 of file Andersen.h.

207 {
208
209 }

Member Function Documentation

◆ addCopyEdge()

virtual bool SVF::Andersen::addCopyEdge ( NodeID src,
NodeID dst )
inlineprotectedvirtual

Add copy edge on constraint graph.

Implements SVF::AndersenBase.

Reimplemented in SVF::AndersenSCD.

Definition at line 338 of file Andersen.h.

339 {
340 if (consCG->addCopyCGEdge(src, dst))
341 {
342 updatePropaPts(src, dst);
343 return true;
344 }
345 return false;
346 }
ConstraintGraph * consCG
Constraint Graph.
Definition Andersen.h:181
void updatePropaPts(NodeID dstId, NodeID srcId)
Handle propagated points-to set.
Definition Andersen.h:301

◆ classof() [1/2]

bool SVF::Andersen::classof ( const Andersen * )
inlinestatic

Methods for support type inquiry through isa, cast, and dyn_cast:

Definition at line 228 of file Andersen.h.

229 {
230 return true;
231 }

◆ classof() [2/2]

bool SVF::Andersen::classof ( const PointerAnalysis * pta)
inlinestatic

Definition at line 232 of file Andersen.h.

233 {
234 return (pta->getAnalysisTy() == PTATY::Andersen_WPA
235 || pta->getAnalysisTy() == PTATY::AndersenWaveDiff_WPA
236 || pta->getAnalysisTy() == PTATY::AndersenSCD_WPA
237 || pta->getAnalysisTy() == PTATY::AndersenSFR_WPA);
238 }
@ Andersen_WPA
Andersen PTA.
Definition PTATY.h:12
@ AndersenSFR_WPA
Stride-based field representation.
Definition PTATY.h:14
@ AndersenWaveDiff_WPA
Diff wave propagation andersen-style WPA.
Definition PTATY.h:15
@ AndersenSCD_WPA
Selective cycle detection andersen-style WPA.
Definition PTATY.h:13

◆ clearPropaPts()

void SVF::Andersen::clearPropaPts ( NodeID src)
inlineprotected

Definition at line 309 of file Andersen.h.

310 {
311 if (Options::DiffPts())
312 {
313 NodeID rep = sccRepNode(src);
315 }
316 }
NodeID sccRepNode(NodeID id) const override
SCC methods.
Definition Andersen.h:132
DiffPTDataTy * getDiffPTDataTy() const
virtual void clearPropaPts(Key &var)=0
Clear propagated points-to set of var.
static const Option< bool > DiffPts
Definition Options.h:207
u32_t NodeID
Definition GeneralType.h:76

◆ cluster()

void Andersen::cluster ( void ) const
protectedvirtual

Runs a Steensgaard analysis and performs clustering based on those results set the global best mapping.

Definition at line 1128 of file Andersen.cpp.

1129{
1130 assert(Options::MaxFieldLimit() == 0 && "Andersen::cluster: clustering for Andersen's is currently only supported in field-insensitive analysis");
1131 Steensgaard *steens = Steensgaard::createSteensgaard(pag);
1132 std::vector<std::pair<unsigned, unsigned>> keys;
1133 for (PAG::iterator pit = pag->begin(); pit != pag->end(); ++pit)
1134 {
1135 keys.push_back(std::make_pair(pit->first, 1));
1136 }
1137
1138 std::vector<std::pair<hclust_fast_methods, std::vector<NodeID>>> candidates;
1139 PointsTo::MappingPtr nodeMapping =
1140 std::make_shared<std::vector<NodeID>>(
1141 NodeIDAllocator::Clusterer::cluster(steens, keys, candidates, "aux-steens", print_stat)
1142 );
1143 PointsTo::MappingPtr reverseNodeMapping =
1144 std::make_shared<std::vector<NodeID>>(NodeIDAllocator::Clusterer::getReverseNodeMapping(*nodeMapping));
1145
1146 PointsTo::setCurrentBestNodeMapping(nodeMapping, reverseNodeMapping);
1147}
IDToNodeMapTy::iterator iterator
static std::vector< NodeID > getReverseNodeMapping(const std::vector< NodeID > &nodeMapping)
static std::vector< NodeID > cluster(BVDataPTAImpl *pta, const std::vector< std::pair< NodeID, unsigned > > keys, std::vector< std::pair< hclust_fast_methods, std::vector< NodeID > > > &candidates, std::string evalSubtitle="", bool printStat=true)
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
Definition Options.h:34
bool print_stat
User input flags.
static PAG * pag
PAG.
std::shared_ptr< std::vector< NodeID > > MappingPtr
Definition PointsTo.h:43
static void setCurrentBestNodeMapping(MappingPtr newCurrentBestNodeMapping, MappingPtr newCurrentBestReverseNodeMapping)
Definition PointsTo.cpp:383
static Steensgaard * createSteensgaard(PAG *_pag)
Create an singleton instance.
Definition Steensgaard.h:36

◆ collapseField()

bool Andersen::collapseField ( NodeID nodeId)
protected

Collapse field. make struct with the same base as nodeId become field-insensitive.

Black hole doesn't have structures, no collapse is needed. In later versions, instead of using base node to represent the struct, we'll create new field-insensitive node. To avoid creating a new "black hole" node, do not collapse field for black hole node.

Definition at line 798 of file Andersen.cpp.

799{
804 if (consCG->isBlkObjOrConstantObj(nodeId))
805 return false;
806
807 bool changed = false;
808
809 double start = stat->getClk();
810
811 // set base node field-insensitive.
813
814 // replace all occurrences of each field with the field-insensitive node
815 NodeID baseId = consCG->getFIObjVar(nodeId);
816 NodeID baseRepNodeId = consCG->sccRepNode(baseId);
817 NodeBS & allFields = consCG->getAllFieldsObjVars(baseId);
818 for (NodeBS::iterator fieldIt = allFields.begin(), fieldEit = allFields.end(); fieldIt != fieldEit; fieldIt++)
819 {
820 NodeID fieldId = *fieldIt;
821 if (fieldId != baseId)
822 {
823 // use the reverse pts of this field node to find all pointers point to it
824 const NodeSet revPts = getRevPts(fieldId);
825 for (const NodeID o : revPts)
826 {
827 // change the points-to target from field to base node
828 clearPts(o, fieldId);
829 addPts(o, baseId);
831
832 changed = true;
833 }
834 // merge field node into base node, including edges and pts.
835 NodeID fieldRepNodeId = consCG->sccRepNode(fieldId);
836 mergeNodeToRep(fieldRepNodeId, baseRepNodeId);
837 if (fieldId != baseRepNodeId)
838 {
839 // gep node fieldId becomes redundant if it is merged to its base node who is set as field-insensitive
840 // two node IDs should be different otherwise this field is actually the base and should not be removed.
841 redundantGepNodes.set(fieldId);
842 }
843 }
844 }
845
846 if (consCG->isPWCNode(baseRepNodeId))
847 if (collapseNodePts(baseRepNodeId))
848 changed = true;
849
850 double end = stat->getClk();
851 timeOfCollapse += (end - start) / TIMEINTERVAL;
852
853 return changed;
854}
#define TIMEINTERVAL
Definition SVFType.h:604
NodeBS redundantGepNodes
Definition Andersen.h:156
static double timeOfCollapse
Definition Andersen.h:171
virtual void mergeNodeToRep(NodeID nodeId, NodeID newRepId)
Merge sub node to its rep.
Definition Andersen.cpp:914
bool collapseNodePts(NodeID nodeId)
Definition Andersen.cpp:778
const NodeSet & getRevPts(NodeID nodeId) override
virtual void clearPts(NodeID id, NodeID element)
Remove element from the points-to set of id.
virtual bool addPts(NodeID id, NodeID ptd)
PTAStat * stat
Statistics.
void setObjFieldInsensitive(NodeID id)
SparseBitVectorIterator iterator
iterator begin() const
virtual void pushIntoWorklist(NodeID id)
Definition WPASolver.h:157
Set< NodeID > NodeSet
Definition GeneralType.h:87
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ collapseFields()

void Andersen::collapseFields ( )
protectedvirtual

collapse positive weight cycles of a graph

Reimplemented from SVF::WPASolver< ConstraintGraph * >.

Definition at line 724 of file Andersen.cpp.

725{
726 while (consCG->hasNodesToBeCollapsed())
727 {
728 NodeID node = consCG->getNextCollapseNode();
729 // collapseField() may change the points-to set of the nodes which have been processed
730 // before, in this case, we may need to re-do the analysis.
731 if (collapseField(node))
732 reanalyze = true;
733 }
734}
bool collapseField(NodeID nodeId)
Definition Andersen.cpp:798

◆ collapseNodePts()

bool Andersen::collapseNodePts ( NodeID nodeId)
protected

Collapse node's points-to set. Change all points-to elements into field-insensitive.

Points to set may be changed during collapse, so use a clone instead.

Definition at line 778 of file Andersen.cpp.

779{
780 bool changed = false;
781 const PointsTo& nodePts = getPts(nodeId);
783 PointsTo ptsClone = nodePts;
784 for (PointsTo::iterator ptsIt = ptsClone.begin(), ptsEit = ptsClone.end(); ptsIt != ptsEit; ptsIt++)
785 {
786 if (isFieldInsensitive(*ptsIt))
787 continue;
788
789 if (collapseField(*ptsIt))
790 changed = true;
791 }
792 return changed;
793}
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:242
bool isFieldInsensitive(NodeID id) const
const_iterator end() const
Definition PointsTo.h:133
const_iterator iterator
Definition PointsTo.h:41
const_iterator begin() const
Definition PointsTo.h:129

◆ collapsePWCNode()

void Andersen::collapsePWCNode ( NodeID nodeId)
protectedvirtual

Collapse a field object into its base for field insensitive analysis.

Detect and collapse PWC nodes produced by processing gep edges, under the constraint of field limit.

Definition at line 715 of file Andersen.cpp.

716{
717 // If a node is a PWC node, collapse all its points-to target.
718 // collapseNodePts() may change the points-to set of the nodes which have been processed
719 // before, in this case, we may need to re-do the analysis.
720 if (consCG->isPWCNode(nodeId) && collapseNodePts(nodeId))
721 reanalyze = true;
722}

◆ collectMayAliasesFromIndex()

std::optional< NodeBS > Andersen::collectMayAliasesFromIndex ( const PointsTo & expandedPts)
protected

Answer a may-alias query from the reverse points-to sets. Returns nullopt when those sets cannot answer it, leaving the caller to try every node.

Answer a may-alias query from the reverse points-to sets, which say which nodes may point to a given object.

Two nodes may alias exactly when their expanded points-to sets share an object. For every object in this query's expanded set, collect all raw points-to objects whose expansion can contain it: the object itself, its base, and every field of a field-insensitive base. The reverse sets of those objects therefore name the complete answer. The black-hole reverse set supplies nodes that alias everything.

Returns nullopt when reverse points-to sets are unavailable or the query itself points to the black hole, leaving the caller to try every node.

Definition at line 1030 of file Andersen.cpp.

1031{
1032 if (!getPTDataTy()->hasReversePts() || containBlackHoleNode(expandedPts))
1033 return std::nullopt;
1034
1035 NodeBS objects;
1036 const u32_t nodeBound = pag->getTotalNodeNum();
1037 for (NodeID object : expandedPts)
1038 {
1039 objects.set(object);
1040 const NodeID base = pag->getBaseObjVarID(object);
1041 objects.set(base);
1042 if (isFieldInsensitive(base))
1043 objects |= pag->getAllFieldsObjVars(base);
1044 }
1045 objects.set(pag->getBlackHoleNode());
1046
1047 const size_t wordCount = (static_cast<size_t>(nodeBound) +
1049 CoreBitVector representatives(wordCount);
1050 for (NodeID object : objects)
1051 {
1052 for (NodeID key : getRevPts(object))
1053 {
1054 const NodeID representative = sccRepNode(key);
1055 // Reverse points-to sets can retain stale postings. Confirm the
1056 // posting with one current-set bit test before treating it as an
1057 // alias witness, unless an earlier object already confirmed it.
1058 if (!representatives.test(representative) &&
1059 getPts(representative).test(object))
1060 representatives.set(representative);
1061 }
1062 }
1063
1064 // SCC subnode sets are individually ordered, but their concatenation is
1065 // not globally ordered. Collect them densely before inserting into the
1066 // sparse result, where backward insertions would be costly.
1067 CoreBitVector answer(wordCount);
1068 for (NodeID representative : representatives)
1069 {
1070 for (NodeID subNode : sccSubNodes(representative))
1071 answer.set(subNode);
1072 }
1073
1074 // normalizePointsTo can remove field nodes while their ids remain in
1075 // points-to sets. Do not return those stale nodes.
1076 NodeBS aliases;
1077 for (NodeID id : answer)
1078 {
1079 if (pag->hasGNode(id))
1080 aliases.set(id);
1081 }
1082 return aliases;
1083}
NodeBS & sccSubNodes(NodeID repId)
Definition Andersen.h:136
PTDataTy * getPTDataTy() const
Get points-to data structure.
static const size_t WordSize
bool containBlackHoleNode(const PointsTo &pts)
Determine whether a points-to contains a black hole or constant node.
void set(unsigned Idx)
unsigned u32_t
Definition GeneralType.h:67

◆ computeDiffPts()

virtual void SVF::Andersen::computeDiffPts ( NodeID id)
inlineprotectedvirtual

Handle diff points-to set.

Definition at line 283 of file Andersen.h.

284 {
285 if (Options::DiffPts())
286 {
287 NodeID rep = sccRepNode(id);
289 }
290 }
virtual bool computeDiffPts(Key &var, const DataSet &all)=0

◆ dumpTopLevelPtsTo()

void Andersen::dumpTopLevelPtsTo ( )
virtual

Print pag nodes' pts by an ascending order

Reimplemented from SVF::PointerAnalysis.

Definition at line 1152 of file Andersen.cpp.

1153{
1154 for (OrderedNodeSet::iterator nIter = this->getAllValidPtrs().begin();
1155 nIter != this->getAllValidPtrs().end(); ++nIter)
1156 {
1157 const SVFVar* node = getPAG()->getSVFVar(*nIter);
1158 if (getPAG()->isValidTopLevelPtr(node))
1159 {
1160 const PointsTo& pts = this->getPts(node->getId());
1161 outs() << "\nNodeID " << node->getId() << " ";
1162
1163 if (pts.empty())
1164 {
1165 outs() << "\t\tPointsTo: {empty}\n";
1166 }
1167 else
1168 {
1169 outs() << "\t\tPointsTo: { ";
1170
1171 multiset<u32_t> line;
1172 for (PointsTo::iterator it = pts.begin(), eit = pts.end();
1173 it != eit; ++it)
1174 {
1175 line.insert(*it);
1176 }
1177 for (multiset<u32_t>::const_iterator it = line.begin(); it != line.end(); ++it)
1178 {
1180 if (auto gepNode = pag->getGepObjVar(*it))
1181 outs() << gepNode->getBaseNode() << "_" << gepNode->getConstantFieldIdx() << " ";
1182 else
1183 outs() << *it << " ";
1184 else
1185 outs() << *it << " ";
1186 }
1187 outs() << "}\n";
1188 }
1189 }
1190 }
1191
1192 outs().flush();
1193}
static const Option< bool > PrintFieldWithBasePrefix
Definition Options.h:116
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition PAG.h:136
OrderedNodeSet & getAllValidPtrs()
Get all Valid Pointers for resolution.
bool empty() const
Returns true if set is empty.
Definition PointsTo.cpp:110
NodeID getId() const
Get ID.
Definition SVFValue.h:158
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58

◆ finalize()

void Andersen::finalize ( )
virtual

Finalize analysis.

Finalize analysis

sanitize field insensitive obj TODO: Fields has been collapsed during Andersen::collapseField().

Reimplemented from SVF::AndersenBase.

Reimplemented in SVF::AndersenWaveDiff.

Definition at line 451 of file Andersen.cpp.

452{
453 // TODO: broken
455 {
457 const PTDataTy *ptd = getPTDataTy();
458 // TODO: should we use liveOnly?
459 // TODO: parameterise final arg.
461 if (print_stat)
462 {
463 NodeIDAllocator::Clusterer::printStats("post-main", stats);
464 }
465 }
466
469 // sanitizePts();
471}
virtual void finalize() override
Finalize analysis.
Definition Andersen.cpp:97
PTData< NodeID, NodeSet, NodeID, PointsTo > PTDataTy
static void printStats(std::string title, Map< std::string, std::string > &stats)
static void evaluate(const std::vector< NodeID > &nodeMap, const Map< PointsTo, unsigned > pointsToSets, Map< std::string, std::string > &stats, bool accountForOcc)
Fills in *NumWords statistics in stats..
static const Option< bool > ClusterAnder
Whether to stage Andersen's with Steensgaard and cluster based on that data.
Definition Options.h:37
static MappingPtr getCurrentBestNodeMapping()
Definition PointsTo.cpp:373
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition GeneralType.h:56

◆ getDiffPts()

virtual const PointsTo & SVF::Andersen::getDiffPts ( NodeID id)
inlineprotectedvirtual

Definition at line 291 of file Andersen.h.

292 {
293 NodeID rep = sccRepNode(id);
294 if (Options::DiffPts())
295 return getDiffPTDataTy()->getDiffPts(rep);
296 else
297 return getPTDataTy()->getPts(rep);
298 }
virtual const DataSet & getDiffPts(Key &var)=0
Get diff points to.
virtual const DataSet & getPts(const Key &var)=0
Get points-to set of var.

◆ getMayAliases()

NodeBS Andersen::getMayAliases ( NodeID node)
virtual

Collect exactly the PAG nodes q for which mayAlias(node, q) holds.

Collect every PAG node that may alias the given node.

Reimplemented from SVF::PointerAnalysis.

Definition at line 945 of file Andersen.cpp.

946{
947 // Reuse this expansion for the index lookup and, when necessary, every
948 // comparison in the exhaustive fallback.
949 PointsTo expandedPts;
950 expandFIObjs(getPts(node), expandedPts);
951 if (auto aliases = collectMayAliasesFromIndex(expandedPts))
952 return std::move(*aliases);
953
954 NodeBS aliases;
955 const bool queryPointsToBlackHole = containBlackHoleNode(expandedPts);
956 for (PAG::iterator it = pag->begin(), eit = pag->end(); it != eit; ++it)
957 {
958 const NodeID candidate = it->first;
959 if (queryPointsToBlackHole)
960 {
961 aliases.set(candidate);
962 continue;
963 }
964
965 PointsTo candidatePts;
966 expandFIObjs(getPts(candidate), candidatePts);
967 if (containBlackHoleNode(candidatePts) ||
968 expandedPts.intersects(candidatePts))
969 aliases.set(candidate);
970 }
971 return aliases;
972}
std::optional< NodeBS > collectMayAliasesFromIndex(const PointsTo &expandedPts)
virtual void expandFIObjs(const PointsTo &pts, PointsTo &expandedPts)
Expand FI objects.
bool intersects(const PointsTo &rhs) const
Returns true if this set and rhs share any elements.
Definition PointsTo.cpp:201

◆ getMayAliasesBatch()

std::vector< NodeBS > Andersen::getMayAliasesBatch ( const std::vector< NodeID > & nodes)

Query multiple pointers, reusing answers for equal points-to sets within this call.

Parameters
nodesInput PAG node IDs in query order.
Returns
One owned alias set per input: result[i] equals getMayAliases(nodes[i]). Duplicates are preserved; empty input returns an empty vector. The analysis, PAG, SCCs and points-to mapping must stay unchanged during the call. Equal points-to sets must imply equal answers, including in subclass overrides. Cache limits exclude the returned results; split large inputs to limit output storage.

Reuse answers only within a batch whose analysis state is unchanged. For example, queries for p and q with pts(p) = pts(q) = {o} need the same reverse-index walk. Keep the cache local so later batches and scalar queries observe current state.

Definition at line 979 of file Andersen.cpp.

980{
981 std::vector<NodeBS> results;
982 results.reserve(nodes.size());
983 Map<PointsTo, NodeBS> answers;
984 size_t cachedMembers = 0;
985 // Bound the reuse cache separately from the caller-owned results.
986 constexpr size_t maxCachedSets = 256;
987 constexpr size_t maxCachedMembers = 1 << 20;
988 for (NodeID node : nodes)
989 {
990 const PointsTo& pts = getPts(node);
991 auto cached = answers.find(pts);
992 if (cached != answers.end())
993 {
994 results.push_back(cached->second);
995 continue;
996 }
997
998 NodeBS aliases = getMayAliases(node);
999 const size_t members = static_cast<size_t>(pts.count()) + aliases.count();
1000 if (members > maxCachedMembers)
1001 {
1002 results.push_back(std::move(aliases));
1003 continue;
1004 }
1005 if (answers.size() == maxCachedSets || cachedMembers > maxCachedMembers - members)
1006 {
1007 answers.clear();
1008 cachedMembers = 0;
1009 }
1010 auto inserted = answers.emplace(pts, std::move(aliases));
1011 cachedMembers += members;
1012 results.push_back(inserted.first->second);
1013 }
1014 return results;
1015}
virtual NodeBS getMayAliases(NodeID node)
Collect exactly the PAG nodes q for which mayAlias(node, q) holds.
Definition Andersen.cpp:945
u32_t count() const
Returns number of elements.
Definition PointsTo.cpp:123
unsigned count() const
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)

◆ getPts()

virtual const PointsTo & SVF::Andersen::getPts ( NodeID id)
inlinevirtual

Operation of points-to set.

Implements SVF::PointerAnalysis.

Definition at line 242 of file Andersen.h.

243 {
244 return getPTDataTy()->getPts(sccRepNode(id));
245 }

◆ handleCopyGep()

void Andersen::handleCopyGep ( ConstraintNode * node)
protectedvirtual

Process copy and gep edges

Reimplemented in SVF::AndersenSCD.

Definition at line 497 of file Andersen.cpp.

498{
499 NodeID nodeId = node->getId();
500 computeDiffPts(nodeId);
501
502 if (!getDiffPts(nodeId).empty())
503 {
504 for (ConstraintEdge* edge : node->getCopyOutEdges())
505 processCopy(nodeId, edge);
506 for (ConstraintEdge* edge : node->getGepOutEdges())
507 {
508 if (GepCGEdge* gepEdge = SVFUtil::dyn_cast<GepCGEdge>(edge))
509 processGep(nodeId, gepEdge);
510 }
511 }
512}
virtual void computeDiffPts(NodeID id)
Handle diff points-to set.
Definition Andersen.h:283
virtual const PointsTo & getDiffPts(NodeID id)
Definition Andersen.h:291
virtual bool processGep(NodeID node, const GepCGEdge *edge)
Definition Andersen.cpp:642
virtual bool processCopy(NodeID node, const ConstraintEdge *edge)
Definition Andersen.cpp:622
const ConstraintEdge::ConstraintEdgeSetTy & getGepOutEdges() const
Definition ConsGNode.h:123
const ConstraintEdge::ConstraintEdgeSetTy & getCopyOutEdges() const
Definition ConsGNode.h:115
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405

◆ handleLoadStore()

void Andersen::handleLoadStore ( ConstraintNode * node)
protectedvirtual

Process load and store edges

Reimplemented in SVF::AndersenSCD.

Definition at line 517 of file Andersen.cpp.

518{
519 NodeID nodeId = node->getId();
520 for (PointsTo::iterator piter = getPts(nodeId).begin(), epiter =
521 getPts(nodeId).end(); piter != epiter; ++piter)
522 {
523 NodeID ptd = *piter;
524 // handle load
526 eit = node->outgoingLoadsEnd(); it != eit; ++it)
527 {
528 if (processLoad(ptd, *it))
529 pushIntoWorklist(ptd);
530 }
531
532 // handle store
534 eit = node->incomingStoresEnd(); it != eit; ++it)
535 {
536 if (processStore(ptd, *it))
537 pushIntoWorklist((*it)->getSrcID());
538 }
539 }
540}
virtual bool processLoad(NodeID node, const ConstraintEdge *load)
Definition Andersen.cpp:574
virtual bool processStore(NodeID node, const ConstraintEdge *load)
Definition Andersen.cpp:598
const_iterator outgoingLoadsEnd() const
Definition ConsGNode.h:194
const_iterator incomingStoresBegin() const
Definition ConsGNode.h:215
const_iterator incomingStoresEnd() const
Definition ConsGNode.h:219
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition ConsGNode.h:45
const_iterator outgoingLoadsBegin() const
Definition ConsGNode.h:190

◆ initialize()

void Andersen::initialize ( )
virtual

Initialize analysis.

Initialize analysis

Initialize worklist

Reimplemented from SVF::AndersenBase.

Reimplemented in SVF::AndersenSFR, and SVF::AndersenWaveDiff.

Definition at line 437 of file Andersen.cpp.

438{
439 resetData();
441
443
446}
virtual void initialize() override
Initialize analysis.
Definition Andersen.cpp:81
void resetData()
Reset data.
Definition Andersen.h:218
void processAllAddr()
handling various constraints
Definition Andersen.cpp:545
virtual void cluster(void) const

◆ initWorklist()

virtual void SVF::Andersen::initWorklist ( )
inlineprotectedvirtual

Reimplemented from SVF::WPASolver< ConstraintGraph * >.

Definition at line 318 of file Andersen.h.

318{}

◆ mergeNodeToRep()

void Andersen::mergeNodeToRep ( NodeID nodeId,
NodeID newRepId )
protectedvirtual

Merge sub node to its rep.

Definition at line 914 of file Andersen.cpp.

915{
916
917 if (mergeSrcToTgt(nodeId,newRepId))
918 consCG->setPWCNode(newRepId);
919}
virtual bool mergeSrcToTgt(NodeID srcId, NodeID tgtId)
Definition Andersen.cpp:883

◆ mergeSccCycle()

void Andersen::mergeSccCycle ( )
protected

Definition at line 739 of file Andersen.cpp.

740{
741 NodeStack topoOrder = getSCCDetector()->topoNodeStack();
742
743 while (!topoOrder.empty())
744 {
745 NodeID repNodeId = topoOrder.top();
746 topoOrder.pop();
747 const NodeBS& subNodes = getSCCDetector()->subNodes(repNodeId);
748 // merge sub nodes to rep node
749 mergeSccNodes(repNodeId, subNodes);
750 if (subNodes.count() > 1)
751 {
752 pushIntoWorklist(repNodeId);
753 reanalyze = true;
754 }
755 }
756}
void mergeSccNodes(NodeID repNodeId, const NodeBS &subNodes)
Merge sub node in a SCC cycle to their rep node.
Definition Andersen.cpp:763
GNodeStack & topoNodeStack()
Definition SCC.h:130
const NodeBS & subNodes(NodeID n) const
get all subnodes in one scc, if size is empty insert itself into the set
Definition SCC.h:196
std::stack< NodeID > NodeStack
Definition GeneralType.h:92

◆ mergeSccNodes()

void Andersen::mergeSccNodes ( NodeID repNodeId,
const NodeBS & subNodes )
protected

Merge sub node in a SCC cycle to their rep node.

Union points-to of subscc nodes into its rep nodes Move incoming/outgoing direct edges of sub node to rep node

Definition at line 763 of file Andersen.cpp.

764{
765 for (NodeBS::iterator nodeIt = subNodes.begin(); nodeIt != subNodes.end(); nodeIt++)
766 {
767 NodeID subNodeId = *nodeIt;
768 if (subNodeId != repNodeId)
769 {
770 mergeNodeToRep(subNodeId, repNodeId);
771 }
772 }
773}

◆ mergeSrcToTgt()

bool Andersen::mergeSrcToTgt ( NodeID nodeId,
NodeID newRepId )
protectedvirtual

merge nodeId to newRepId. Return true if the newRepId is a PWC node

union pts of node to rep

move the edges from node to rep, and remove the node

  1. if find gep edges inside SCC cycle, the rep node will become a PWC node and its pts should be collapsed later.
  2. if the node to be merged is already a PWC node, the rep node will also become a PWC node as it will have a self-cycle gep edge.

set rep and sub relations

Reimplemented in SVF::AndersenSFR.

Definition at line 883 of file Andersen.cpp.

884{
885
886 if(nodeId==newRepId)
887 return false;
888
890 updatePropaPts(newRepId, nodeId);
891 unionPts(newRepId,nodeId);
892
894 ConstraintNode* node = consCG->getConstraintNode(nodeId);
895 bool pwc = consCG->moveEdgesToRepNode(node, consCG->getConstraintNode(newRepId));
896
901 if(node->isPWCNode())
902 pwc = true;
903
905 updateNodeRepAndSubs(node->getId(),newRepId);
906
907 consCG->removeConstraintNode(node);
908
909 return pwc;
910}
virtual bool unionPts(NodeID id, const PointsTo &target)
Definition Andersen.h:246
void updateNodeRepAndSubs(NodeID nodeId, NodeID newRepId)
Updates subnodes of its rep, and rep node of its subs.
Definition Andersen.cpp:924
bool isPWCNode() const
Whether a node involves in PWC, if so, all its points-to elements should become field-insensitive.
Definition ConsGNode.h:81

◆ processAddr()

void Andersen::processAddr ( const AddrCGEdge * addr)
protectedvirtual

Process address edges

Reimplemented in SVF::AndersenSCD.

Definition at line 559 of file Andersen.cpp.

560{
562
563 NodeID dst = addr->getDstID();
564 NodeID src = addr->getSrcID();
565 if(addPts(dst,src))
566 pushIntoWorklist(dst);
567}
static u32_t numOfProcessedAddr
Statistics.
Definition Andersen.h:160
NodeID getDstID() const
NodeID getSrcID() const
get methods of the components

◆ processAllAddr()

void Andersen::processAllAddr ( )
protected

handling various constraints

Process address edges

Definition at line 545 of file Andersen.cpp.

546{
547 for (ConstraintGraph::const_iterator nodeIt = consCG->begin(), nodeEit = consCG->end(); nodeIt != nodeEit; nodeIt++)
548 {
549 ConstraintNode * cgNode = nodeIt->second;
550 for (ConstraintNode::const_iterator it = cgNode->incomingAddrsBegin(), eit = cgNode->incomingAddrsEnd();
551 it != eit; ++it)
553 }
554}
virtual void processAddr(const AddrCGEdge *addr)
Definition Andersen.cpp:559
const_iterator incomingAddrsBegin() const
Definition ConsGNode.h:181
const_iterator incomingAddrsEnd() const
Definition ConsGNode.h:185
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360

◆ processCopy()

bool Andersen::processCopy ( NodeID node,
const ConstraintEdge * edge )
protectedvirtual

Process copy edges src –copy--> dst, union pts(dst) with pts(src)

Definition at line 622 of file Andersen.cpp.

623{
625
626 assert((SVFUtil::isa<CopyCGEdge>(edge)) && "not copy/call/ret ??");
627 NodeID dst = edge->getDstID();
628 const PointsTo& srcPts = getDiffPts(node);
629
630 bool changed = unionPts(dst, srcPts);
631 if (changed)
632 pushIntoWorklist(dst);
633 return changed;
634}
static u32_t numOfProcessedCopy
Number of processed Addr edge.
Definition Andersen.h:161
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241

◆ processGep()

bool Andersen::processGep ( NodeID node,
const GepCGEdge * edge )
protectedvirtual

Process gep edges src –gep--> dst, for each srcPtdNode \in pts(src) ==> add fieldSrcPtdNode into tmpDstPts union pts(dst) with tmpDstPts

Definition at line 642 of file Andersen.cpp.

643{
644 const PointsTo& srcPts = getDiffPts(edge->getSrcID());
645 return processGepPts(srcPts, edge);
646}
virtual bool processGepPts(const PointsTo &pts, const GepCGEdge *edge)
Definition Andersen.cpp:651

◆ processGepPts()

bool Andersen::processGepPts ( const PointsTo & pts,
const GepCGEdge * edge )
protectedvirtual

Compute points-to for gep edges

Reimplemented in SVF::AndersenSFR.

Definition at line 651 of file Andersen.cpp.

652{
654
655 PointsTo tmpDstPts;
657 {
658 // If a pointer is connected by a variant gep edge,
659 // then set this memory object to be field insensitive,
660 // unless the object is a black hole/constant.
661 for (NodeID o : pts)
662 {
663 if (consCG->isBlkObjOrConstantObj(o))
664 {
665 tmpDstPts.set(o);
666 continue;
667 }
668
669 if (!isFieldInsensitive(o))
670 {
672 consCG->addNodeToBeCollapsed(consCG->getBaseObjVarID(o));
673 }
674
675 // Add the field-insensitive node into pts.
676 NodeID baseId = consCG->getFIObjVar(o);
677 tmpDstPts.set(baseId);
678 }
679 }
680 else if (const NormalGepCGEdge* normalGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge))
681 {
682 // TODO: after the node is set to field insensitive, handling invariant
683 // gep edge may lose precision because offsets here are ignored, and the
684 // base object is always returned.
685 for (NodeID o : pts)
686 {
687 if (consCG->isBlkObjOrConstantObj(o) || isFieldInsensitive(o))
688 {
689 tmpDstPts.set(o);
690 continue;
691 }
692
693 NodeID fieldSrcPtdNode = consCG->getGepObjVar(o, normalGepEdge->getAccessPath().getConstantStructFldIdx());
694 tmpDstPts.set(fieldSrcPtdNode);
695 }
696 }
697 else
698 {
699 assert(false && "Andersen::processGepPts: New type GEP edge type?");
700 }
701
702 NodeID dstId = edge->getDstID();
703 if (unionPts(dstId, tmpDstPts))
704 {
705 pushIntoWorklist(dstId);
706 return true;
707 }
708
709 return false;
710}
static u32_t numOfProcessedGep
Number of processed Copy edge.
Definition Andersen.h:162
void set(u32_t n)
Inserts n in the set.
Definition PointsTo.cpp:169

◆ processLoad()

bool Andersen::processLoad ( NodeID node,
const ConstraintEdge * load )
protectedvirtual

Process load edges src –load--> dst, node \in pts(src) ==> node–copy-->dst

TODO: New copy edges are also added for black hole obj node to make gcc in spec 2000 pass the flow-sensitive analysis. Try to handle black hole obj in an appropriate way.

Definition at line 574 of file Andersen.cpp.

575{
579// if (pag->isBlkObjOrConstantObj(node))
580 // SCC merging can choose a non-pointer object as the representative of
581 // pointer values. Its original type must not discard inherited constraints.
582 if (pag->isConstantObj(node) ||
583 (!pag->getSVFVar(load->getDstID())->isPointer() &&
584 sccSubNodes(load->getDstID()).isSingleElement()))
585 return false;
586
588
589 NodeID dst = load->getDstID();
590 return addCopyEdge(node, dst);
591}
static u32_t numOfProcessedLoad
Number of processed Gep edge.
Definition Andersen.h:163
virtual bool addCopyEdge(NodeID src, NodeID dst)
Add copy edge on constraint graph.
Definition Andersen.h:338

◆ processNode()

void Andersen::processNode ( NodeID nodeId)
protectedvirtual

Override WPASolver function in order to use the default solver.

Start constraint solving

Reimplemented from SVF::WPASolver< ConstraintGraph * >.

Reimplemented in SVF::AndersenWaveDiff.

Definition at line 476 of file Andersen.cpp.

477{
478 // sub nodes do not need to be processed
479 if (sccRepNode(nodeId) != nodeId)
480 return;
481
482 ConstraintNode* node = consCG->getConstraintNode(nodeId);
483 double insertStart = stat->getClk();
484 handleLoadStore(node);
485 double insertEnd = stat->getClk();
486 timeOfProcessLoadStore += (insertEnd - insertStart) / TIMEINTERVAL;
487
488 double propStart = stat->getClk();
489 handleCopyGep(node);
490 double propEnd = stat->getClk();
491 timeOfProcessCopyGep += (propEnd - propStart) / TIMEINTERVAL;
492}
static double timeOfProcessLoadStore
Definition Andersen.h:175
static double timeOfProcessCopyGep
Definition Andersen.h:174
virtual void handleLoadStore(ConstraintNode *node)
Definition Andersen.cpp:517
virtual void handleCopyGep(ConstraintNode *node)
Definition Andersen.cpp:497

◆ processStore()

bool Andersen::processStore ( NodeID node,
const ConstraintEdge * store )
protectedvirtual

Process store edges src –store--> dst, node \in pts(dst) ==> src–copy-->node

TODO: New copy edges are also added for black hole obj node to make gcc in spec 2000 pass the flow-sensitive analysis. Try to handle black hole obj in an appropriate way

Definition at line 598 of file Andersen.cpp.

599{
603// if (pag->isBlkObjOrConstantObj(node))
604 // SCC merging can choose a non-pointer object as the representative of
605 // pointer values. Its original type must not discard inherited constraints.
606 if (pag->isConstantObj(node) ||
607 (!pag->getSVFVar(store->getSrcID())->isPointer() &&
608 sccSubNodes(store->getSrcID()).isSingleElement()))
609 return false;
610
612
613 NodeID src = store->getSrcID();
614 return addCopyEdge(src, node);
615}
static u32_t numOfProcessedStore
Number of processed Load edge.
Definition Andersen.h:164

◆ PTAName()

virtual const std::string SVF::Andersen::PTAName ( ) const
inlineprotectedvirtual

Get PTA name.

Reimplemented from SVF::PointerAnalysis.

Definition at line 404 of file Andersen.h.

405 {
406 return "AndersenWPA";
407 }

◆ resetData()

void SVF::Andersen::resetData ( )
inline

Reset data.

Definition at line 218 of file Andersen.h.

219 {
224 }
static u32_t MaxPointsToSetSize
Definition Andersen.h:173
static u32_t AveragePointsToSetSize
Definition Andersen.h:172

◆ sanitizePts()

void SVF::Andersen::sanitizePts ( )
inlineprotected

Sanitize pts for field insensitive objects.

Definition at line 382 of file Andersen.h.

383 {
384 for(ConstraintGraph::iterator it = consCG->begin(), eit = consCG->end(); it!=eit; ++it)
385 {
386 const PointsTo& pts = getPts(it->first);
387 NodeBS fldInsenObjs;
388
389 for (NodeID o : pts)
390 {
391 if(isFieldInsensitive(o))
392 fldInsenObjs.set(o);
393 }
394
395 for (NodeID o : fldInsenObjs)
396 {
397 const NodeBS &allFields = consCG->getAllFieldsObjVars(o);
398 for (NodeID f : allFields) addPts(it->first, f);
399 }
400 }
401 }

◆ SCCDetect()

NodeStack & Andersen::SCCDetect ( )
protectedvirtual

SCC detection.

SCC detection on constraint graph

Reimplemented from SVF::WPASolver< ConstraintGraph * >.

Reimplemented in SVF::AndersenSCD.

Definition at line 859 of file Andersen.cpp.

860{
862
863 double sccStart = stat->getClk();
865 double sccEnd = stat->getClk();
866
867 timeOfSCCDetection += (sccEnd - sccStart)/TIMEINTERVAL;
868
869 double mergeStart = stat->getClk();
870
872
873 double mergeEnd = stat->getClk();
874
875 timeOfSCCMerges += (mergeEnd - mergeStart)/TIMEINTERVAL;
876
877 return getSCCDetector()->topoNodeStack();
878}
static double timeOfSCCMerges
Definition Andersen.h:170
static u32_t numOfSCCDetection
Definition Andersen.h:168
static double timeOfSCCDetection
Definition Andersen.h:169
void mergeSccCycle()
Definition Andersen.cpp:739
virtual NodeStack & SCCDetect()
Definition WPASolver.h:87

◆ setDetectPWC()

void SVF::Andersen::setDetectPWC ( bool flag)
inline

Definition at line 273 of file Andersen.h.

274 {
276 }
void setValue(T v)
static Option< bool > DetectPWC
Definition Options.h:208

◆ unionPts() [1/2]

virtual bool SVF::Andersen::unionPts ( NodeID id,
const PointsTo & target )
inlinevirtual

Union/add points-to. Add the reverse points-to for node collapse purpose To be noted that adding reverse pts might incur 10% total overhead during solving

Reimplemented from SVF::BVDataPTAImpl.

Definition at line 246 of file Andersen.h.

247 {
248 id = sccRepNode(id);
249 return getPTDataTy()->unionPts(id, target);
250 }
virtual bool unionPts(const Key &dstVar, const Key &srcVar)=0
Performs pts(dstVar) = pts(dstVar) U pts(srcVar).

◆ unionPts() [2/2]

virtual bool SVF::Andersen::unionPts ( NodeID id,
NodeID ptd )
inlinevirtual

Reimplemented from SVF::BVDataPTAImpl.

Definition at line 251 of file Andersen.h.

252 {
253 id = sccRepNode(id);
254 ptd = sccRepNode(ptd);
255 return getPTDataTy()->unionPts(id,ptd);
256 }

◆ updateNodeRepAndSubs()

void Andersen::updateNodeRepAndSubs ( NodeID nodeId,
NodeID newRepId )
protected

Updates subnodes of its rep, and rep node of its subs.

update nodeToRepMap, for each subs of current node updates its rep to newRepId

Definition at line 924 of file Andersen.cpp.

925{
926 consCG->setRep(nodeId,newRepId);
927 NodeBS repSubs;
928 repSubs.set(nodeId);
930 // update nodeToSubsMap, union its subs with its rep Subs
931 NodeBS& nodeSubs = consCG->sccSubNodes(nodeId);
932 for(NodeBS::iterator sit = nodeSubs.begin(), esit = nodeSubs.end(); sit!=esit; ++sit)
933 {
934 NodeID subId = *sit;
935 consCG->setRep(subId,newRepId);
936 }
937 repSubs |= nodeSubs;
938 consCG->setSubs(newRepId,repSubs);
939 consCG->resetSubs(nodeId);
940}

◆ updatePropaPts()

void SVF::Andersen::updatePropaPts ( NodeID dstId,
NodeID srcId )
inlineprotected

Handle propagated points-to set.

Definition at line 301 of file Andersen.h.

302 {
303 if (!Options::DiffPts())
304 return;
305 NodeID srcRep = sccRepNode(srcId);
306 NodeID dstRep = sccRepNode(dstId);
307 getDiffPTDataTy()->updatePropaPtsMap(srcRep, dstRep);
308 }
virtual void updatePropaPtsMap(Key &src, Key &dst)=0

◆ validateSuccessTests()

void Andersen::validateSuccessTests ( std::string fun)
protectedvirtual

Also check getMayAliases on the pointers that the alias tests use.

Run the alias tests, then check getMayAliases on every pointer they use: it must return exactly the nodes that mayAlias reports

Reimplemented from SVF::PointerAnalysis.

Definition at line 1089 of file Andersen.cpp.

1090{
1092
1093 PointerAnalysis* pta = this;
1094 const FunObjVar* checkFun = pag->getFunObjVar(fun);
1095 if (!checkFun)
1096 return;
1097 for (const CallICFGNode* callNode : pag->getCallSiteSet())
1098 {
1099 if (callNode->getCalledFunction() != checkFun)
1100 continue;
1101 std::vector<NodeID> queries;
1102 for (u32_t i = 0; i < callNode->arg_size(); ++i)
1103 queries.push_back(callNode->getArgument(i)->getId());
1104 const std::vector<NodeBS> aliases = getMayAliasesBatch(queries);
1105 assert(aliases.size() == queries.size() && "getMayAliasesBatch result count mismatch!");
1106 for (size_t i = 0; i < queries.size(); ++i)
1107 {
1108 const NodeID ptr = queries[i];
1109 NodeBS expected;
1110 for (PAG::iterator it = pag->begin(), eit = pag->end(); it != eit; ++it)
1111 {
1112 if (mayAlias(ptr, it->first))
1113 expected.set(it->first);
1114 }
1115 if (aliases[i] == expected && pta->getMayAliases(ptr) == expected)
1116 outs() << sucMsg("\t SUCCESS :") << "getMayAliases check <id:" << ptr << "> at ("
1117 << callNode->getSourceLoc() << ")\n";
1118 else
1119 {
1120 SVFUtil::errs() << errMsg("\t FAILURE :") << "getMayAliases check <id:" << ptr
1121 << "> at (" << callNode->getSourceLoc() << ")\n";
1122 assert(false && "getMayAliases disagrees with mayAlias!");
1123 }
1124 }
1125 }
1126}
std::vector< NodeBS > getMayAliasesBatch(const std::vector< NodeID > &nodes)
Definition Andersen.cpp:979
bool mayAlias(const PointsTo &pts1, const PointsTo &pts2)
Convenience bool wrappers: return true if the two operands may/must/partial alias.
virtual NodeBS getMayAliases(NodeID node)
virtual void validateSuccessTests(std::string fun)
PointerAnalysis(PAG *pag, PTATY ty=PTATY::Default_PTA, bool alias_check=true)
Constructor.
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
Definition SVFUtil.cpp:75
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
Definition SVFUtil.cpp:98
std::ostream & errs()
Overwrite llvm::errs().
Definition SVFUtil.h:64

Member Data Documentation

◆ callsite2DummyValPN

CallSite2DummyValPN SVF::Andersen::callsite2DummyValPN
protected

Map an instruction to a dummy obj which created at an indirect callsite, which invokes a heap allocator.

Definition at line 280 of file Andersen.h.


The documentation for this class was generated from the following files: