Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SVF::Andersen Class Reference

#include <Andersen.h>

Inheritance diagram for SVF::Andersen:
SVF::AndersenBase SVF::WPASolver< GraphType > 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 *, NodeIDCallSite2DummyValPN
 
- Public Types inherited from SVF::WPASolver< GraphType >
typedef SVF::GenericGraphTraits< GraphTypeGTraits
 Define the GTraits and node iterator for printing.
 
typedef GTraits::NodeRef GNODE
 
typedef GTraits::EdgeType GEDGE
 
typedef GTraits::ChildIteratorType child_iterator
 
typedef SCCDetection< GraphTypeSCC
 
typedef FIFOWorkList< NodeIDWorkList
 
- Public Types inherited from SVF::BVDataPTAImpl
typedef PTData< NodeID, NodeSet, NodeID, PointsToPTDataTy
 
typedef DiffPTData< NodeID, NodeSet, NodeID, PointsToDiffPTDataTy
 
typedef DFPTData< NodeID, NodeSet, NodeID, PointsToDFPTDataTy
 
typedef VersionedPTData< NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set< VersionedVar > > VersionedPTDataTy
 
typedef MutablePTData< NodeID, NodeSet, NodeID, PointsToMutPTDataTy
 
typedef MutableDiffPTData< NodeID, NodeSet, NodeID, PointsToMutDiffPTDataTy
 
typedef MutableDFPTData< NodeID, NodeSet, NodeID, PointsToMutDFPTDataTy
 
typedef MutableIncDFPTData< NodeID, NodeSet, NodeID, PointsToMutIncDFPTDataTy
 
typedef MutableVersionedPTData< NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set< VersionedVar > > MutVersionedPTDataTy
 
typedef PersistentPTData< NodeID, NodeSet, NodeID, PointsToPersPTDataTy
 
typedef PersistentDiffPTData< NodeID, NodeSet, NodeID, PointsToPersDiffPTDataTy
 
typedef PersistentDFPTData< NodeID, NodeSet, NodeID, PointsToPersDFPTDataTy
 
typedef PersistentIncDFPTData< NodeID, NodeSet, NodeID, PointsToPersIncDFPTDataTy
 
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 SVFIR::CallSiteToFunPtrMap CallSiteToFunPtrMap
 
typedef Set< const FunObjVar * > FunctionSet
 
typedef OrderedMap< const CallICFGNode *, FunctionSetCallEdgeMap
 
typedef SCCDetection< CallGraph * > CallGraphSCC
 
typedef Set< const GlobalObjVar * > VTableSet
 
typedef Set< const FunObjVar * > VFunSet
 

Public Member Functions

 Andersen (SVFIR *_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 PointsTogetPts (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 SVFIR nodes q for which mayAlias(node, q) holds.
 
void dumpTopLevelPtsTo ()
 
void setDetectPWC (bool flag)
 
- Public Member Functions inherited from SVF::AndersenBase
 AndersenBase (SVFIR *_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.
 
ConstraintGraphgetConstraintGraph ()
 Get constraint graph.
 
NodeID sccRepNode (NodeID id) const override
 SCC methods.
 
NodeBSsccSubNodes (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 (SVFIR *pag, PTATY type, bool alias_check=true)
 Constructor.
 
 ~BVDataPTAImpl () override=default
 Destructor.
 
PersistentPointsToCache< PointsTo > & getPtCache ()
 
const PointsTogetPts (NodeID id) override
 
const NodeSetgetRevPts (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
ICFGgetICFG () const
 Get ICFG.
 
u32_t getNumOfResolvedIndCallEdge () const
 Return number of resolved indirect call edges.
 
CallGraphgetCallGraph () const
 Return call graph.
 
CallGraphSCCgetCallGraphSCC () const
 Return call graph SCC.
 
 PointerAnalysis (SVFIR *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.
 
CallEdgeMapgetIndCallMap ()
 Get callees from an indirect callsite.
 
bool hasIndCSCallees (const CallICFGNode *cs) const
 
const FunctionSetgetIndCSCallees (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.
 
CommonCHGraphgetCHGraph () 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.
 
SVFIRgetPAG () const
 
PTAStatgetStat () const
 Get PTA stat.
 
OrderedNodeSetgetAllValidPtrs ()
 Get all Valid Pointers for resolution.
 
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 NodeBSgetAllFieldsObjVars (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 PointsTogetDiffPts (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 NodeStackSCCDetect ()
 SCC detection.
 
NodeBS getMayAliasCandidates (NodeID node)
 
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< GraphType >
 WPASolver ()
 Constructor.
 
virtual ~WPASolver ()=default
 Destructor.
 
SCCgetSCCDetector () const
 Get SCC detector.
 
const GraphType graph ()
 Get/Set graph methods.
 
void setGraph (GraphType g)
 
virtual NodeStackSCCDetect (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)
 
GNODENode (NodeID id)
 Get node on the graph.
 
NodeID Node_Index (GNODE node)
 Get node ID.
 
- Protected Member Functions inherited from SVF::BVDataPTAImpl
PTDataTygetPTDataTy () const
 Get points-to data structure.
 
void finalize () override
 Finalization of pointer analysis, and normalize points-to information to Bit Vector representation.
 
DiffPTDataTygetDiffPTDataTy () const
 
DFPTDataTygetDFPTDataTy () const
 
MutDFPTDataTygetMutDFPTDataTy () const
 
VersionedPTDataTygetVersionedPTDataTy () 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.
 
- Protected Member Functions inherited from SVF::PointerAnalysis
const CallSiteToFunPtrMapgetIndirectCallsites () 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
ConstraintGraphconsCG
 Constraint Graph.
 
CallSite2DummyValPN callsite2DummyValPN
 
- Protected Attributes inherited from SVF::WPASolver< GraphType >
bool reanalyze
 Reanalyze if any constraint value changed.
 
u32_t iterationForPrintStat
 print out statistics for i-th iteration
 
GraphType _graph
 Graph.
 
std::unique_ptr< SCCscc
 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.
 
PTAStatstat
 Statistics.
 
CallGraphcallgraph
 Call graph used for pointer analysis.
 
CallGraphSCCcallGraphSCC
 SCC for PTACallGraph.
 
ICFGicfg
 Interprocedural control-flow graph.
 
CommonCHGraphchgraph
 CHGraph.
 

Additional Inherited Members

- Public Attributes inherited from SVF::AndersenBase
NodeBS redundantGepNodes
 
- Public Attributes inherited from SVF::WPASolver< GraphType >
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 SVFIRpag = nullptr
 SVFIR.
 

Detailed Description

Inclusion-based Pointer Analysis

Definition at line 189 of file Andersen.h.

Member Typedef Documentation

◆ CGSCC

Definition at line 194 of file Andersen.h.

Constructor & Destructor Documentation

◆ Andersen()

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

Constructor.

Definition at line 197 of file Andersen.h.

199 {
200 }
newitem type
Definition cJSON.cpp:2739
AndersenBase(SVFIR *_pag, PTATY type=PTATY::Andersen_BASE, bool alias_check=true)
Constructor.
Definition Andersen.h:65
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ ~Andersen()

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

Destructor.

Definition at line 203 of file Andersen.h.

204 {
205
206 }

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 326 of file Andersen.h.

327 {
328 if (consCG->addCopyCGEdge(src, dst))
329 {
330 updatePropaPts(src, dst);
331 return true;
332 }
333 return false;
334 }
ConstraintGraph * consCG
Constraint Graph.
Definition Andersen.h:178
void updatePropaPts(NodeID dstId, NodeID srcId)
Handle propagated points-to set.
Definition Andersen.h:289
CopyCGEdge * addCopyCGEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition ConsG.cpp:226

◆ classof() [1/2]

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

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

Definition at line 225 of file Andersen.h.

226 {
227 return true;
228 }

◆ classof() [2/2]

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

Definition at line 229 of file Andersen.h.

230 {
231 return (pta->getAnalysisTy() == PTATY::Andersen_WPA
232 || pta->getAnalysisTy() == PTATY::AndersenWaveDiff_WPA
233 || pta->getAnalysisTy() == PTATY::AndersenSCD_WPA
234 || pta->getAnalysisTy() == PTATY::AndersenSFR_WPA);
235 }
@ 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 297 of file Andersen.h.

298 {
299 if (Options::DiffPts())
300 {
301 NodeID rep = sccRepNode(src);
302 getDiffPTDataTy()->clearPropaPts(rep);
303 }
304 }
NodeID sccRepNode(NodeID id) const override
SCC methods.
Definition Andersen.h:129
DiffPTDataTy * getDiffPTDataTy() const
static const Option< bool > DiffPts
Definition Options.h:205
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 1028 of file Andersen.cpp.

1029{
1030 assert(Options::MaxFieldLimit() == 0 && "Andersen::cluster: clustering for Andersen's is currently only supported in field-insensitive analysis");
1032 std::vector<std::pair<unsigned, unsigned>> keys;
1033 for (SVFIR::iterator pit = pag->begin(); pit != pag->end(); ++pit)
1034 {
1035 keys.push_back(std::make_pair(pit->first, 1));
1036 }
1037
1038 std::vector<std::pair<hclust_fast_methods, std::vector<NodeID>>> candidates;
1039 PointsTo::MappingPtr nodeMapping =
1040 std::make_shared<std::vector<NodeID>>(
1041 NodeIDAllocator::Clusterer::cluster(steens, keys, candidates, "aux-steens", print_stat)
1042 );
1043 PointsTo::MappingPtr reverseNodeMapping =
1044 std::make_shared<std::vector<NodeID>>(NodeIDAllocator::Clusterer::getReverseNodeMapping(*nodeMapping));
1045
1046 PointsTo::setCurrentBestNodeMapping(nodeMapping, reverseNodeMapping);
1047}
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
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 SVFIR * pag
SVFIR.
std::shared_ptr< std::vector< NodeID > > MappingPtr
Definition PointsTo.h:43
static void setCurrentBestNodeMapping(MappingPtr newCurrentBestNodeMapping, MappingPtr newCurrentBestReverseNodeMapping)
Definition PointsTo.cpp:371
static Steensgaard * createSteensgaard(SVFIR *_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 776 of file Andersen.cpp.

777{
783 return false;
784
785 bool changed = false;
786
787 double start = stat->getClk();
788
789 // set base node field-insensitive.
791
792 // replace all occurrences of each field with the field-insensitive node
797 {
799 if (fieldId != baseId)
800 {
801 // use the reverse pts of this field node to find all pointers point to it
803 for (const NodeID o : revPts)
804 {
805 // change the points-to target from field to base node
807 addPts(o, baseId);
809
810 changed = true;
811 }
812 // merge field node into base node, including edges and pts.
815 if (fieldId != baseRepNodeId)
816 {
817 // gep node fieldId becomes redundant if it is merged to its base node who is set as field-insensitive
818 // two node IDs should be different otherwise this field is actually the base and should not be removed.
820 }
821 }
822 }
823
826 changed = true;
827
828 double end = stat->getClk();
829 timeOfCollapse += (end - start) / TIMEINTERVAL;
830
831 return changed;
832}
#define TIMEINTERVAL
Definition SVFType.h:604
NodeBS redundantGepNodes
Definition Andersen.h:153
static double timeOfCollapse
Definition Andersen.h:168
virtual void mergeNodeToRep(NodeID nodeId, NodeID newRepId)
Merge sub node to its rep.
Definition Andersen.cpp:892
bool collapseNodePts(NodeID nodeId)
Definition Andersen.cpp:756
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)
NodeID sccRepNode(NodeID id) const
SCC rep/sub nodes methods.
Definition ConsG.h:230
NodeID getFIObjVar(NodeID id)
Get a field-insensitive node of a memory object.
Definition ConsG.h:334
bool isPWCNode(NodeID nodeId)
Check/Set PWC (positive weight cycle) flag.
Definition ConsG.h:345
bool isBlkObjOrConstantObj(NodeID id)
Definition ConsG.h:307
NodeBS & getAllFieldsObjVars(NodeID id)
Definition ConsG.h:311
PTAStat * stat
Statistics.
void setObjFieldInsensitive(NodeID id)
static double getClk(bool mark=false)
Definition SVFStat.cpp:51
void set(unsigned Idx)
virtual void pushIntoWorklist(NodeID id)
Definition WPASolver.h:157
Set< NodeID > NodeSet
Definition GeneralType.h:87

◆ collapseFields()

void Andersen::collapseFields ( )
inlineprotectedvirtual

collapse positive weight cycles of a graph

Reimplemented from SVF::WPASolver< GraphType >.

Definition at line 702 of file Andersen.cpp.

703{
705 {
707 // collapseField() may change the points-to set of the nodes which have been processed
708 // before, in this case, we may need to re-do the analysis.
709 if (collapseField(node))
710 reanalyze = true;
711 }
712}
bool collapseField(NodeID nodeId)
Definition Andersen.cpp:776
NodeID getNextCollapseNode()
Definition ConsG.h:365
bool hasNodesToBeCollapsed() const
Add/get nodes to be collapsed.
Definition ConsG.h:357
bool reanalyze
Reanalyze if any constraint value changed.
Definition WPASolver.h:172

◆ 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 756 of file Andersen.cpp.

757{
758 bool changed = false;
759 const PointsTo& nodePts = getPts(nodeId);
762 for (PointsTo::iterator ptsIt = ptsClone.begin(), ptsEit = ptsClone.end(); ptsIt != ptsEit; ptsIt++)
763 {
765 continue;
766
767 if (collapseField(*ptsIt))
768 changed = true;
769 }
770 return changed;
771}
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:239
bool isFieldInsensitive(NodeID id) const

◆ collapsePWCNode()

void Andersen::collapsePWCNode ( NodeID  nodeId)
inlineprotectedvirtual

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 693 of file Andersen.cpp.

694{
695 // If a node is a PWC node, collapse all its points-to target.
696 // collapseNodePts() may change the points-to set of the nodes which have been processed
697 // before, in this case, we may need to re-do the analysis.
699 reanalyze = true;
700}

◆ computeDiffPts()

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

Handle diff points-to set.

Definition at line 271 of file Andersen.h.

272 {
273 if (Options::DiffPts())
274 {
275 NodeID rep = sccRepNode(id);
276 getDiffPTDataTy()->computeDiffPts(rep, getDiffPTDataTy()->getPts(rep));
277 }
278 }

◆ dumpTopLevelPtsTo()

void Andersen::dumpTopLevelPtsTo ( )
virtual

Print pag nodes' pts by an ascending order

Reimplemented from SVF::PointerAnalysis.

Definition at line 1052 of file Andersen.cpp.

1053{
1054 for (OrderedNodeSet::iterator nIter = this->getAllValidPtrs().begin();
1055 nIter != this->getAllValidPtrs().end(); ++nIter)
1056 {
1057 const SVFVar* node = getPAG()->getSVFVar(*nIter);
1058 if (getPAG()->isValidTopLevelPtr(node))
1059 {
1060 const PointsTo& pts = this->getPts(node->getId());
1061 outs() << "\nNodeID " << node->getId() << " ";
1062
1063 if (pts.empty())
1064 {
1065 outs() << "\t\tPointsTo: {empty}\n";
1066 }
1067 else
1068 {
1069 outs() << "\t\tPointsTo: { ";
1070
1072 for (PointsTo::iterator it = pts.begin(), eit = pts.end();
1073 it != eit; ++it)
1074 {
1075 line.insert(*it);
1076 }
1077 for (multiset<u32_t>::const_iterator it = line.begin(); it != line.end(); ++it)
1078 {
1080 if (auto gepNode = pag->getGepObjVar(*it))
1081 outs() << gepNode->getBaseNode() << "_" << gepNode->getConstantFieldIdx() << " ";
1082 else
1083 outs() << *it << " ";
1084 else
1085 outs() << *it << " ";
1086 }
1087 outs() << "}\n";
1088 }
1089 }
1090 }
1091
1092 outs().flush();
1093}
static const Option< bool > PrintFieldWithBasePrefix
Definition Options.h:114
SVFIR * getPAG() const
OrderedNodeSet & getAllValidPtrs()
Get all Valid Pointers for resolution.
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:135
const GepObjVar * getGepObjVar(NodeID id) const
Definition SVFIR.h:169
NodeID getId() const
Get ID.
Definition SVFValue.h:158
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ 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.

Definition at line 437 of file Andersen.cpp.

438{
439 // TODO: broken
441 {
443 const PTDataTy *ptd = getPTDataTy();
444 // TODO: should we use liveOnly?
445 // TODO: parameterise final arg.
447 if (print_stat)
448 {
450 }
451 }
452
455 // sanitizePts();
457}
virtual void finalize() override
Finalize analysis.
Definition Andersen.cpp:91
PTData< NodeID, NodeSet, NodeID, PointsTo > PTDataTy
PTDataTy * getPTDataTy() const
Get points-to data structure.
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:361

◆ getDiffPts()

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

Definition at line 279 of file Andersen.h.

280 {
281 NodeID rep = sccRepNode(id);
282 if (Options::DiffPts())
283 return getDiffPTDataTy()->getDiffPts(rep);
284 else
285 return getPTDataTy()->getPts(rep);
286 }

◆ getMayAliasCandidates()

NodeBS Andersen::getMayAliasCandidates ( NodeID  node)
protected

Collect may-alias candidates. Attempts to do so from reverse points-to sets (cheaper), and if not possible, falls back to trying every node (costlier).

Collect a superset of the may-aliases of a node. Attempts to do so from reverse points-to sets (cheaper), and if not possible, falls back to trying every node (costlier).

Definition at line 942 of file Andersen.cpp.

943{
944 NodeBS candidates;
947
948 // A node that may point to the black hole aliases every node
949 if (getPTDataTy()->hasReversePts() && !containBlackHoleNode(expandedPts))
950 {
951 // Expansion only adds fields of an object's own base, so another node's expanded
952 // points-to set can only meet this one on these bases and their fields. Dummy
953 // objects are not listed among their own fields, hence the bases themselves.
954 NodeBS objs;
955 for (NodeID obj : expandedPts)
956 {
957 NodeID base = pag->getBaseObjVarID(obj);
958 objs.set(base);
959 objs |= pag->getAllFieldsObjVars(base);
960 }
961 // Nodes that may point to the black hole alias this node too
963
964 // Heavily shared objects can make the reverse walk longer than trying every node
965 size_t entries = 0;
966 for (NodeID obj : objs)
967 entries += getRevPts(obj).size();
968 if (entries <= pag->getTotalNodeNum())
969 {
970 // Andersen keeps an SCC's points-to set under its representative, so a reverse
971 // points-to key stands for its whole SCC. Collecting representatives first adds
972 // each SCC once.
973 NodeBS reps;
974 for (NodeID obj : objs)
975 {
976 for (NodeID key : getRevPts(obj))
977 reps.set(sccRepNode(key));
978 }
979 for (NodeID rep : reps)
980 candidates |= sccSubNodes(rep);
981 return candidates;
982 }
983 }
984
985 for (SVFIR::iterator it = pag->begin(), eit = pag->end(); it != eit; ++it)
986 candidates.set(it->first);
987 return candidates;
988}
NodeBS & sccSubNodes(NodeID repId)
Definition Andersen.h:133
virtual void expandFIObjs(const PointsTo &pts, PointsTo &expandedPts)
Expand FI objects.
NodeID getBlackHoleNode() const
Definition IRGraph.h:246
bool containBlackHoleNode(const PointsTo &pts)
Determine whether a points-to contains a black hole or constant node.
NodeID getBaseObjVarID(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:554
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:573

◆ getMayAliases()

NodeBS Andersen::getMayAliases ( NodeID  node)
virtual

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

Collect every SVFIR node that may alias the given node. Each candidate is confirmed with mayAlias, so the result is exactly the nodes q for which mayAlias(node, q) holds.

Reimplemented from SVF::PointerAnalysis.

Definition at line 924 of file Andersen.cpp.

925{
928 {
929 // Check the candidate still exists, because field nodes removed by
930 // normalizePointsTo keep stale points-to entries
931 if (pag->hasGNode(candidate) && mayAlias(node, candidate))
933 }
934 return aliases;
935}
NodeBS getMayAliasCandidates(NodeID node)
Definition Andersen.cpp:942
bool mayAlias(const PointsTo &pts1, const PointsTo &pts2)
Convenience bool wrappers: return true if the two operands may/must/partial alias.
bool hasGNode(NodeID id) const
Has a node.

◆ getPts()

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

Operation of points-to set.

Implements SVF::PointerAnalysis.

Definition at line 239 of file Andersen.h.

240 {
241 return getPTDataTy()->getPts(sccRepNode(id));
242 }

◆ handleCopyGep()

void Andersen::handleCopyGep ( ConstraintNode node)
protectedvirtual

Process copy and gep edges

Reimplemented in SVF::AndersenSCD.

Definition at line 483 of file Andersen.cpp.

484{
485 NodeID nodeId = node->getId();
487
488 if (!getDiffPts(nodeId).empty())
489 {
490 for (ConstraintEdge* edge : node->getCopyOutEdges())
492 for (ConstraintEdge* edge : node->getGepOutEdges())
493 {
494 if (GepCGEdge* gepEdge = SVFUtil::dyn_cast<GepCGEdge>(edge))
496 }
497 }
498}
virtual void computeDiffPts(NodeID id)
Handle diff points-to set.
Definition Andersen.h:271
virtual const PointsTo & getDiffPts(NodeID id)
Definition Andersen.h:279
virtual bool processGep(NodeID node, const GepCGEdge *edge)
Definition Andersen.cpp:620
virtual bool processCopy(NodeID node, const ConstraintEdge *edge)
Definition Andersen.cpp:600

◆ handleLoadStore()

void Andersen::handleLoadStore ( ConstraintNode node)
protectedvirtual

Process load and store edges

Reimplemented in SVF::AndersenSCD.

Definition at line 503 of file Andersen.cpp.

504{
505 NodeID nodeId = node->getId();
506 for (PointsTo::iterator piter = getPts(nodeId).begin(), epiter =
507 getPts(nodeId).end(); piter != epiter; ++piter)
508 {
509 NodeID ptd = *piter;
510 // handle load
512 eit = node->outgoingLoadsEnd(); it != eit; ++it)
513 {
514 if (processLoad(ptd, *it))
516 }
517
518 // handle store
520 eit = node->incomingStoresEnd(); it != eit; ++it)
521 {
522 if (processStore(ptd, *it))
523 pushIntoWorklist((*it)->getSrcID());
524 }
525 }
526}
virtual bool processLoad(NodeID node, const ConstraintEdge *load)
Definition Andersen.cpp:560
virtual bool processStore(NodeID node, const ConstraintEdge *load)
Definition Andersen.cpp:580
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.

 Connect formal and actual parameters for indirect callsites
&zwj;/

void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, const FunObjVar* F, NodePairSet &cpySrcNodes) { assert(F);

DBOUT(DAndersen, outs() << "connect parameters from indirect callsite " << cs->valueOnlyToString() << " to callee " << *F << "\n");

const CallICFGNode* callBlockNode = cs; const RetICFGNode* retBlockNode = cs->getRetICFGNode();

if(SVFUtil::isHeapAllocExtFunViaRet(F) && pag->callsiteHasRet(retBlockNode)) { heapAllocatorViaIndCall(cs,cpySrcNodes); }

if (pag->funHasRet(F) && pag->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retBlockNode); const PAGNode* fun_return = pag->getFunRet(F); if (cs_return->isPointer() && fun_return->isPointer()) { NodeID dstrec = sccRepNode(cs_return->getId()); NodeID srcret = sccRepNode(fun_return->getId()); if(addCopyEdge(srcret, dstrec)) { cpySrcNodes.insert(std::make_pair(srcret,dstrec)); } } else { DBOUT(DAndersen, outs() << "not a pointer ignored\n"); } }

if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(F)) {

connect actual and formal param const SVFIR::ValVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); const SVFIR::ValVarList& funArgList = pag->getFunArgsList(F); Go through the fixed parameters. DBOUT(DPAGBuild, outs() << " args:"); SVFIR::ValVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); SVFIR::ValVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end(); for (; funArgIt != funArgEit; ++csArgIt, ++funArgIt) { Some programs (e.g. Linux kernel) leave unneeded parameters empty. if (csArgIt == csArgEit) { DBOUT(DAndersen, outs() << " !! not enough args\n"); break; } const PAGNode *cs_arg = *csArgIt ; const PAGNode *fun_arg = *funArgIt;

if (cs_arg->isPointer() && fun_arg->isPointer()) { DBOUT(DAndersen, outs() << "process actual parm " << cs_arg->toString() << " \n"); NodeID srcAA = sccRepNode(cs_arg->getId()); NodeID dstFA = sccRepNode(fun_arg->getId()); if(addCopyEdge(srcAA, dstFA)) { cpySrcNodes.insert(std::make_pair(srcAA,dstFA)); } } }

Any remaining actual args must be varargs. if (F->isVarArg()) { NodeID vaF = sccRepNode(pag->getVarargNode(F)); DBOUT(DPAGBuild, outs() << "\n varargs:"); for (; csArgIt != csArgEit; ++csArgIt) { const PAGNode *cs_arg = *csArgIt; if (cs_arg->isPointer()) { NodeID vnAA = sccRepNode(cs_arg->getId()); if (addCopyEdge(vnAA,vaF)) { cpySrcNodes.insert(std::make_pair(vnAA,vaF)); } } } } if(csArgIt != csArgEit) { writeWrnMsg("too many args to non-vararg func."); writeWrnMsg("(" + cs->getSourceLoc() + ")"); } } }

void AndersenBase::heapAllocatorViaIndCall(const CallICFGNode* cs, NodePairSet &cpySrcNodes) { assert(cs->getCalledFunction() == nullptr && "not an indirect callsite?"); const RetICFGNode* retBlockNode = cs->getRetICFGNode(); const PAGNode* cs_return = pag->getCallSiteRet(retBlockNode); NodeID srcret; CallSite2DummyValPN::const_iterator it = callsite2DummyValPN.find(cs); if(it != callsite2DummyValPN.end()) { srcret = sccRepNode(it->second); } else { NodeID valNode = pag->addDummyValNode(); NodeID objNode = pag->addDummyObjNode(cs->getType()); addPts(valNode,objNode); callsite2DummyValPN.insert(std::make_pair(cs,valNode)); consCG->addConstraintNode(new ConstraintNode(valNode),valNode); consCG->addConstraintNode(new ConstraintNode(objNode),objNode); srcret = valNode; }

NodeID dstrec = sccRepNode(cs_return->getId()); if(addCopyEdge(srcret, dstrec)) cpySrcNodes.insert(std::make_pair(srcret,dstrec)); }

void AndersenBase::normalizePointsTo() { SVFIR::MemObjToFieldsMap &memToFieldsMap = pag->getMemToFieldsMap(); SVFIR::OffsetToGepVarMap &GepObjVarMap = pag->getGepObjNodeMap();

clear GepObjVarMap/memToFieldsMap/nodeToSubsMap/nodeToRepMap for redundant gepnodes and remove those nodes from pag for (NodeID n: redundantGepNodes) { NodeID base = pag->getBaseObjVarID(n); const GepObjVar* gepNode = pag->getGepObjVar(n); assert(gepNode && "Not a gep node in redundantGepNodes set"); const APOffset apOffset = gepNode->getConstantFieldIdx(); GepObjVarMap.erase(std::make_pair(base, apOffset)); memToFieldsMap[base].reset(n); cleanConsCG(n);

pag->removeGNode(const_cast<GepObjVar*>(gepNode)); } }

/*! Initialize analysis

Initialize worklist

Reimplemented from SVF::AndersenBase.

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

Definition at line 423 of file Andersen.cpp.

424{
425 resetData();
427
429
432}
virtual void initialize() override
Initialize analysis.
Definition Andersen.cpp:75
void resetData()
Reset data.
Definition Andersen.h:215
void processAllAddr()
handling various constraints
Definition Andersen.cpp:531
virtual void cluster(void) const

◆ initWorklist()

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

Reimplemented from SVF::WPASolver< GraphType >.

Definition at line 306 of file Andersen.h.

306{}

◆ mergeNodeToRep()

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

Merge sub node to its rep.

Definition at line 892 of file Andersen.cpp.

893{
894
897}
virtual bool mergeSrcToTgt(NodeID srcId, NodeID tgtId)
Definition Andersen.cpp:861
void setPWCNode(NodeID nodeId)
Definition ConsG.h:349

◆ mergeSccCycle()

void Andersen::mergeSccCycle ( )
protected

Definition at line 717 of file Andersen.cpp.

718{
719 NodeStack topoOrder = getSCCDetector()->topoNodeStack();
720
721 while (!topoOrder.empty())
722 {
723 NodeID repNodeId = topoOrder.top();
724 topoOrder.pop();
725 const NodeBS& subNodes = getSCCDetector()->subNodes(repNodeId);
726 // merge sub nodes to rep node
727 mergeSccNodes(repNodeId, subNodes);
728 if (subNodes.count() > 1)
729 {
731 reanalyze = true;
732 }
733 }
734}
void mergeSccNodes(NodeID repNodeId, const NodeBS &subNodes)
Merge sub node in a SCC cycle to their rep node.
Definition Andersen.cpp:741
unsigned count() const
SCC * getSCCDetector() const
Get SCC detector.
Definition WPASolver.h:68
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 741 of file Andersen.cpp.

742{
743 for (NodeBS::iterator nodeIt = subNodes.begin(); nodeIt != subNodes.end(); nodeIt++)
744 {
746 if (subNodeId != repNodeId)
747 {
749 }
750 }
751}
iterator begin() const

◆ 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 861 of file Andersen.cpp.

862{
863
864 if(nodeId==newRepId)
865 return false;
866
870
874
879 if(node->isPWCNode())
880 pwc = true;
881
884
886
887 return pwc;
888}
virtual bool unionPts(NodeID id, const PointsTo &target)
Definition Andersen.h:243
void updateNodeRepAndSubs(NodeID nodeId, NodeID newRepId)
Updates subnodes of its rep, and rep node of its subs.
Definition Andersen.cpp:902
void removeConstraintNode(ConstraintNode *node)
Definition ConsG.h:118
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition ConsG.h:104
bool moveEdgesToRepNode(ConstraintNode *node, ConstraintNode *rep)
Definition ConsG.h:281
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 545 of file Andersen.cpp.

546{
548
549 NodeID dst = addr->getDstID();
550 NodeID src = addr->getSrcID();
551 if(addPts(dst,src))
552 pushIntoWorklist(dst);
553}
static u32_t numOfProcessedAddr
Statistics.
Definition Andersen.h:157

◆ processAllAddr()

void Andersen::processAllAddr ( )
protected

handling various constraints

Process address edges

Definition at line 531 of file Andersen.cpp.

532{
534 {
535 ConstraintNode * cgNode = nodeIt->second;
537 it != eit; ++it)
538 processAddr(SVFUtil::cast<AddrCGEdge>(*it));
539 }
540}
virtual void processAddr(const AddrCGEdge *addr)
Definition Andersen.cpp:545
const_iterator incomingAddrsBegin() const
Definition ConsGNode.h:181
const_iterator incomingAddrsEnd() const
Definition ConsGNode.h:185

◆ 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 600 of file Andersen.cpp.

601{
603
604 assert((SVFUtil::isa<CopyCGEdge>(edge)) && "not copy/call/ret ??");
605 NodeID dst = edge->getDstID();
606 const PointsTo& srcPts = getDiffPts(node);
607
608 bool changed = unionPts(dst, srcPts);
609 if (changed)
610 pushIntoWorklist(dst);
611 return changed;
612}
static u32_t numOfProcessedCopy
Number of processed Addr edge.
Definition Andersen.h:158

◆ 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 620 of file Andersen.cpp.

621{
622 const PointsTo& srcPts = getDiffPts(edge->getSrcID());
623 return processGepPts(srcPts, edge);
624}
virtual bool processGepPts(const PointsTo &pts, const GepCGEdge *edge)
Definition Andersen.cpp:629

◆ processGepPts()

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

Compute points-to for gep edges

Reimplemented in SVF::AndersenSFR.

Definition at line 629 of file Andersen.cpp.

630{
632
634 if (SVFUtil::isa<VariantGepCGEdge>(edge))
635 {
636 // If a pointer is connected by a variant gep edge,
637 // then set this memory object to be field insensitive,
638 // unless the object is a black hole/constant.
639 for (NodeID o : pts)
640 {
642 {
643 tmpDstPts.set(o);
644 continue;
645 }
646
647 if (!isFieldInsensitive(o))
648 {
651 }
652
653 // Add the field-insensitive node into pts.
655 tmpDstPts.set(baseId);
656 }
657 }
658 else if (const NormalGepCGEdge* normalGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge))
659 {
660 // TODO: after the node is set to field insensitive, handling invariant
661 // gep edge may lose precision because offsets here are ignored, and the
662 // base object is always returned.
663 for (NodeID o : pts)
664 {
666 {
667 tmpDstPts.set(o);
668 continue;
669 }
670
671 NodeID fieldSrcPtdNode = consCG->getGepObjVar(o, normalGepEdge->getAccessPath().getConstantStructFldIdx());
673 }
674 }
675 else
676 {
677 assert(false && "Andersen::processGepPts: New type GEP edge type?");
678 }
679
680 NodeID dstId = edge->getDstID();
682 {
684 return true;
685 }
686
687 return false;
688}
static u32_t numOfProcessedGep
Number of processed Copy edge.
Definition Andersen.h:159
void addNodeToBeCollapsed(NodeID id)
Definition ConsG.h:361
NodeID getBaseObjVarID(NodeID id)
Definition ConsG.h:315
NodeID getGepObjVar(NodeID id, const APOffset &apOffset)
Get a field of a memory object.
Definition ConsG.h:325
void set(u32_t n)
Inserts n in the set.
Definition PointsTo.cpp:157

◆ 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 560 of file Andersen.cpp.

561{
565// if (pag->isBlkObjOrConstantObj(node))
566 if (pag->isConstantObj(node) || pag->getSVFVar(load->getDstID())->isPointer() == false)
567 return false;
568
570
571 NodeID dst = load->getDstID();
572 return addCopyEdge(node, dst);
573}
static u32_t numOfProcessedLoad
Number of processed Gep edge.
Definition Andersen.h:160
virtual bool addCopyEdge(NodeID src, NodeID dst)
Add copy edge on constraint graph.
Definition Andersen.h:326
NodeID getDstID() const
bool isConstantObj(NodeID id) const
Definition SVFIR.h:542
virtual bool isPointer() const
Check if this variable represents a pointer.

◆ processNode()

void Andersen::processNode ( NodeID  nodeId)
protectedvirtual

Override WPASolver function in order to use the default solver.

Start constraint solving

Reimplemented from SVF::WPASolver< GraphType >.

Reimplemented in SVF::AndersenWaveDiff.

Definition at line 462 of file Andersen.cpp.

463{
464 // sub nodes do not need to be processed
465 if (sccRepNode(nodeId) != nodeId)
466 return;
467
469 double insertStart = stat->getClk();
470 handleLoadStore(node);
471 double insertEnd = stat->getClk();
473
474 double propStart = stat->getClk();
475 handleCopyGep(node);
476 double propEnd = stat->getClk();
478}
static double timeOfProcessLoadStore
Definition Andersen.h:172
static double timeOfProcessCopyGep
Definition Andersen.h:171
virtual void handleLoadStore(ConstraintNode *node)
Definition Andersen.cpp:503
virtual void handleCopyGep(ConstraintNode *node)
Definition Andersen.cpp:483

◆ 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 580 of file Andersen.cpp.

581{
585// if (pag->isBlkObjOrConstantObj(node))
586 if (pag->isConstantObj(node) || pag->getSVFVar(store->getSrcID())->isPointer() == false)
587 return false;
588
590
591 NodeID src = store->getSrcID();
592 return addCopyEdge(src, node);
593}
static u32_t numOfProcessedStore
Number of processed Load edge.
Definition Andersen.h:161
NodeID getSrcID() const
get methods of the components

◆ PTAName()

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

Get PTA name.

Reimplemented from SVF::PointerAnalysis.

Definition at line 392 of file Andersen.h.

393 {
394 return "AndersenWPA";
395 }

◆ resetData()

void SVF::Andersen::resetData ( )
inline

Reset data.

Definition at line 215 of file Andersen.h.

216 {
221 }
static u32_t MaxPointsToSetSize
Definition Andersen.h:170
static u32_t AveragePointsToSetSize
Definition Andersen.h:169

◆ sanitizePts()

void SVF::Andersen::sanitizePts ( )
inlineprotected

Sanitize pts for field insensitive objects.

Definition at line 370 of file Andersen.h.

371 {
372 for(ConstraintGraph::iterator it = consCG->begin(), eit = consCG->end(); it!=eit; ++it)
373 {
374 const PointsTo& pts = getPts(it->first);
376
377 for (NodeID o : pts)
378 {
381 }
382
383 for (NodeID o : fldInsenObjs)
384 {
386 for (NodeID f : allFields) addPts(it->first, f);
387 }
388 }
389 }
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ SCCDetect()

NodeStack & Andersen::SCCDetect ( )
protectedvirtual

SCC detection.

SCC detection on constraint graph

Reimplemented from SVF::WPASolver< GraphType >.

Reimplemented in SVF::AndersenSCD.

Definition at line 837 of file Andersen.cpp.

838{
840
841 double sccStart = stat->getClk();
843 double sccEnd = stat->getClk();
844
846
847 double mergeStart = stat->getClk();
848
850
851 double mergeEnd = stat->getClk();
852
854
855 return getSCCDetector()->topoNodeStack();
856}
static double timeOfSCCMerges
Definition Andersen.h:167
static u32_t numOfSCCDetection
Definition Andersen.h:165
static double timeOfSCCDetection
Definition Andersen.h:166
void mergeSccCycle()
Definition Andersen.cpp:717
virtual NodeStack & SCCDetect()
SCC detection.
Definition WPASolver.h:87

◆ setDetectPWC()

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

Definition at line 261 of file Andersen.h.

262 {
264 }
void setValue(T v)
static Option< bool > DetectPWC
Definition Options.h:206

◆ 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 243 of file Andersen.h.

244 {
245 id = sccRepNode(id);
246 return getPTDataTy()->unionPts(id, target);
247 }

◆ unionPts() [2/2]

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

Reimplemented from SVF::BVDataPTAImpl.

Definition at line 248 of file Andersen.h.

249 {
250 id = sccRepNode(id);
251 ptd = sccRepNode(ptd);
252 return getPTDataTy()->unionPts(id,ptd);
253 }

◆ 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 902 of file Andersen.cpp.

903{
908 // update nodeToSubsMap, union its subs with its rep Subs
910 for(NodeBS::iterator sit = nodeSubs.begin(), esit = nodeSubs.end(); sit!=esit; ++sit)
911 {
912 NodeID subId = *sit;
914 }
915 repSubs |= nodeSubs;
918}
void setSubs(NodeID node, NodeBS &subs)
Definition ConsG.h:247
void resetSubs(NodeID node)
Definition ConsG.h:251
NodeBS & sccSubNodes(NodeID id)
Definition ConsG.h:238
void setRep(NodeID node, NodeID rep)
Definition ConsG.h:243

◆ updatePropaPts()

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

Handle propagated points-to set.

Definition at line 289 of file Andersen.h.

290 {
291 if (!Options::DiffPts())
292 return;
295 getDiffPTDataTy()->updatePropaPtsMap(srcRep, dstRep);
296 }

◆ 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 994 of file Andersen.cpp.

995{
997
998 PointerAnalysis* pta = this;
999 const FunObjVar* checkFun = pag->getFunObjVar(fun);
1000 if (!checkFun)
1001 return;
1002 for (const CallICFGNode* callNode : pag->getCallSiteSet())
1003 {
1004 if (callNode->getCalledFunction() != checkFun)
1005 continue;
1006 for (u32_t i = 0; i < callNode->arg_size(); ++i)
1007 {
1008 NodeID ptr = callNode->getArgument(i)->getId();
1010 for (SVFIR::iterator it = pag->begin(), eit = pag->end(); it != eit; ++it)
1011 {
1012 if (mayAlias(ptr, it->first))
1013 expected.set(it->first);
1014 }
1015 if (pta->getMayAliases(ptr) == expected)
1016 outs() << sucMsg("\t SUCCESS :") << "getMayAliases check <id:" << ptr << "> at ("
1017 << callNode->getSourceLoc() << ")\n";
1018 else
1019 {
1020 SVFUtil::errs() << errMsg("\t FAILURE :") << "getMayAliases check <id:" << ptr
1021 << "> at (" << callNode->getSourceLoc() << ")\n";
1022 assert(false && "getMayAliases disagrees with mayAlias!");
1023 }
1024 }
1025 }
1026}
unsigned u32_t
Definition CommandLine.h:18
NodeID getId() const
Get the memory object id.
virtual NodeBS getMayAliases(NodeID node)
virtual void validateSuccessTests(std::string fun)
const FunObjVar * getFunObjVar(const std::string &name)
Definition SVFIR.cpp:48
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
Definition SVFUtil.cpp:59
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
Definition SVFUtil.cpp:82
std::ostream & errs()
Overwrite llvm::errs()
Definition SVFUtil.h:58

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 268 of file Andersen.h.


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