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

#include <SVFGOPT.h>

Inheritance diagram for SVF::SVFGOPT:
SVF::SVFG SVF::VFG SVF::GenericGraph< NodeTy, EdgeTy >

Public Member Functions

 SVFGOPT (std::unique_ptr< MemSSA > mssa, VFGK kind)
 Constructor.
 
 ~SVFGOPT () override=default
 Destructor.
 
void setTokeepActualOutFormalIn ()
 
void setTokeepAllSelfCycle ()
 
void setTokeepContextSelfCycle ()
 
- Public Member Functions inherited from SVF::SVFG
virtual ~SVFG ()
 Destructor.
 
SVFGStatgetStat () const
 Return statistics.
 
void clearMSSA ()
 Clear MSSA.
 
MemSSAgetMSSA () const
 Get SVFG memory SSA.
 
PointerAnalysisgetPTA () const
 Get Pointer Analysis.
 
SVFGNodegetSVFGNode (NodeID id) const
 Get a SVFG node.
 
bool hasSVFGNode (NodeID id) const
 Whether has the SVFGNode.
 
void getInterVFEdgesForIndirectCallSite (const CallICFGNode *cs, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 Get all inter value flow edges of a indirect call site.
 
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file.
 
virtual void connectCallerAndCallee (const CallICFGNode *cs, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 Connect SVFG nodes between caller and callee for indirect call site.
 
const SVFGNodegetDefSVFGNode (const PAGNode *pagNode) const
 Given a pagNode, return its definition site.
 
bool hasDefSVFGNode (const PAGNode *pagNode) const
 Given a pagNode, return whether it has definition site.
 
void performStat ()
 Perform statistics.
 
bool hasActualINSVFGNodes (const CallICFGNode *cs) const
 Has a SVFGNode.
 
bool hasActualOUTSVFGNodes (const CallICFGNode *cs) const
 
bool hasFormalINSVFGNodes (const SVFFunction *fun) const
 
bool hasFormalOUTSVFGNodes (const SVFFunction *fun) const
 
ActualINSVFGNodeSetgetActualINSVFGNodes (const CallICFGNode *cs)
 Get SVFGNode set.
 
ActualOUTSVFGNodeSetgetActualOUTSVFGNodes (const CallICFGNode *cs)
 
FormalINSVFGNodeSetgetFormalINSVFGNodes (const SVFFunction *fun)
 
FormalOUTSVFGNodeSetgetFormalOUTSVFGNodes (const SVFFunction *fun)
 
const SVFFunctionisFunEntrySVFGNode (const SVFGNode *node) const
 Whether a node is function entry SVFGNode.
 
const CallICFGNodeisCallSiteRetSVFGNode (const SVFGNode *node) const
 Whether a node is callsite return SVFGNode.
 
void removeSVFGEdge (SVFGEdge *edge)
 Remove a SVFG edge.
 
void removeSVFGNode (SVFGNode *node)
 Remove a SVFGNode.
 
bool addSVFGEdge (SVFGEdge *edge)
 Add SVFG edge.
 
u32_t getSVFGNodeNum () const
 Return total SVFG node number.
 
const DummyVersionPropSVFGNodeaddDummyVersionPropSVFGNode (const NodeID object, const NodeID version)
 
virtual void writeToFile (const std::string &filename)
 
virtual void readFile (const std::string &filename)
 
virtual MRVergetMRVERFromString (const std::string &input)
 
- Public Member Functions inherited from SVF::VFG
 VFG (PTACallGraph *callgraph, VFGK k=FULLSVFG)
 Constructor.
 
virtual ~VFG ()
 Destructor.
 
VFGK getKind () const
 Get VFG kind.
 
bool isPtrOnlySVFG () const
 Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.
 
SVFIRgetPAG () const
 Return SVFIR.
 
PTACallGraphgetCallGraph () const
 Return PTACallGraph.
 
VFGNodegetVFGNode (NodeID id) const
 Get a VFG node.
 
bool hasVFGNode (NodeID id) const
 Whether has the VFGNode.
 
GlobalVFGNodeSetgetGlobalVFGNodes ()
 Return global stores.
 
VFGEdgegetIntraVFGEdge (const VFGNode *src, const VFGNode *dst, VFGEdge::VFGEdgeK kind)
 Get a SVFG edge according to src and dst.
 
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file.
 
void view ()
 Dump graph into dot file.
 
void updateCallGraph (PointerAnalysis *pta)
 Update VFG based on pointer analysis results.
 
CallSiteID getCallSiteID (const CallICFGNode *cs, const SVFFunction *func) const
 Get callsite given a callsiteID.
 
const CallICFGNodegetCallSite (CallSiteID id) const
 
const VFGNodegetDefVFGNode (const PAGNode *pagNode) const
 Given a pagNode, return its definition site.
 
const PAGNodegetLHSTopLevPtr (const VFGNode *node) const
 
StmtVFGNodegetStmtVFGNode (const PAGEdge *pagEdge) const
 Get an VFGNode.
 
IntraPHIVFGNodegetIntraPHIVFGNode (const PAGNode *pagNode) const
 
BinaryOPVFGNodegetBinaryOPVFGNode (const PAGNode *pagNode) const
 
UnaryOPVFGNodegetUnaryOPVFGNode (const PAGNode *pagNode) const
 
BranchVFGNodegetBranchVFGNode (const PAGNode *pagNode) const
 
CmpVFGNodegetCmpVFGNode (const PAGNode *pagNode) const
 
ActualParmVFGNodegetActualParmVFGNode (const PAGNode *aparm, const CallICFGNode *cs) const
 
ActualRetVFGNodegetActualRetVFGNode (const PAGNode *aret) const
 
FormalParmVFGNodegetFormalParmVFGNode (const PAGNode *fparm) const
 
FormalRetVFGNodegetFormalRetVFGNode (const PAGNode *fret) const
 
const SVFFunctionisFunEntryVFGNode (const VFGNode *node) const
 Whether a node is function entry VFGNode.
 
bool hasBlackHoleConstObjAddrAsDef (const PAGNode *pagNode) const
 Whether a PAGNode has a blackhole or const object as its definition.
 
VFGEdgeaddIntraDirectVFEdge (NodeID srcId, NodeID dstId)
 
VFGEdgeaddCallEdge (NodeID srcId, NodeID dstId, CallSiteID csId)
 
VFGEdgeaddRetEdge (NodeID srcId, NodeID dstId, CallSiteID csId)
 
void removeVFGEdge (VFGEdge *edge)
 Remove a SVFG edge.
 
void removeVFGNode (VFGNode *node)
 Remove a VFGNode.
 
VFGEdgehasIntraVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
 Whether we has a SVFG edge.
 
VFGEdgehasInterVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
 
VFGEdgehasThreadVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
 
bool addVFGEdge (VFGEdge *edge)
 Add VFG edge.
 
VFGNodeSetgetVFGNodes (const SVFFunction *fun)
 
bool hasVFGNodes (const SVFFunction *fun) const
 
bool VFGNodes (const SVFFunction *fun) const
 
VFGNodeSet::const_iterator getVFGNodeBegin (const SVFFunction *fun) const
 
VFGNodeSet::const_iterator getVFGNodeEnd (const SVFFunction *fun) const
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 GenericGraph ()
 Constructor.
 
virtual ~GenericGraph ()
 Destructor.
 
void destroy ()
 Release memory.
 
iterator begin ()
 Iterators.
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void addGNode (NodeID id, NodeType *node)
 Add a Node.
 
NodeTypegetGNode (NodeID id) const
 Get a node.
 
bool hasGNode (NodeID id) const
 Has a node.
 
void removeGNode (NodeType *node)
 Delete a node.
 
u32_t getTotalNodeNum () const
 Get total number of node/edge.
 
u32_t getTotalEdgeNum () const
 
void incNodeNum ()
 Increase number of node/edge.
 
void incEdgeNum ()
 

Protected Member Functions

void buildSVFG () override
 Start building SVFG.
 
void connectAParamAndFParam (const PAGNode *cs_arg, const PAGNode *fun_arg, const CallICFGNode *, CallSiteID csId, SVFGEdgeSetTy &edges) override
 Connect SVFG nodes between caller and callee for indirect call sites.
 
void connectFRetAndARet (const PAGNode *fun_ret, const PAGNode *cs_ret, CallSiteID csId, SVFGEdgeSetTy &edges) override
 Connect formal-ret and actual ret.
 
void connectAInAndFIn (const ActualINSVFGNode *actualIn, const FormalINSVFGNode *formalIn, CallSiteID csId, SVFGEdgeSetTy &edges) override
 Connect actual-in and formal-in.
 
void connectFOutAndAOut (const FormalOUTSVFGNode *formalOut, const ActualOUTSVFGNode *actualOut, CallSiteID csId, SVFGEdgeSetTy &edges) override
 Connect formal-out and actual-out.
 
NodeID getActualINDef (NodeID ai) const
 Get def-site of actual-in/formal-out.
 
NodeID getFormalOUTDef (NodeID fo) const
 
- Protected Member Functions inherited from SVF::SVFG
void destroy ()
 Clean up memory.
 
 SVFG (std::unique_ptr< MemSSA > mssa, VFGK k)
 Constructor.
 
SVFGEdgeaddIntraIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts)
 Add indirect def-use edges of a memory region between two statements,.
 
SVFGEdgeaddCallIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
 
SVFGEdgeaddRetIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
 
SVFGEdgeaddThreadMHPIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts)
 
SVFGEdgeaddInterIndirectVFCallEdge (const ActualINSVFGNode *src, const FormalINSVFGNode *dst, CallSiteID csId)
 Add inter VF edge from callsite mu to function entry chi.
 
SVFGEdgeaddInterIndirectVFRetEdge (const FormalOUTSVFGNode *src, const ActualOUTSVFGNode *dst, CallSiteID csId)
 Add inter VF edge from function exit mu to callsite chi.
 
virtual void getInterVFEdgeAtIndCSFromAPToFP (const PAGNode *cs_arg, const PAGNode *fun_arg, const CallICFGNode *, CallSiteID csId, SVFGEdgeSetTy &edges)
 Get inter value flow edges between indirect call site and callee.
 
virtual void getInterVFEdgeAtIndCSFromFRToAR (const PAGNode *fun_ret, const PAGNode *cs_ret, CallSiteID csId, SVFGEdgeSetTy &edges)
 
virtual void getInterVFEdgeAtIndCSFromAInToFIn (ActualINSVFGNode *actualIn, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 
virtual void getInterVFEdgeAtIndCSFromFOutToAOut (ActualOUTSVFGNode *actualOut, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 
void setDef (const PAGNode *pagNode, const SVFGNode *node)
 Given a PAGNode, set/get its def SVFG node (definition of top level pointers)
 
NodeID getDef (const PAGNode *pagNode) const
 
bool hasDef (const PAGNode *pagNode) const
 
void setDef (const MRVer *mvar, const SVFGNode *node)
 Given a MSSADef, set/get its def SVFG node (definition of address-taken variables)
 
NodeID getDef (const MRVer *mvar) const
 
void addSVFGNodesForAddrTakenVars ()
 Create SVFG nodes for address-taken variables.
 
void connectIndirectSVFGEdges ()
 Connect direct SVFG edges between two SVFG nodes (value-flow of top address-taken variables)
 
void connectFromGlobalToProgEntry ()
 Connect indirect SVFG edges from global initializers (store) to main function entry.
 
virtual void addSVFGNode (SVFGNode *node, ICFGNode *icfgNode)
 Add SVFG node.
 
void addFormalINSVFGNode (const FunEntryICFGNode *funEntry, const MRVer *resVer, const NodeID nodeId)
 Add memory Function entry chi SVFG node.
 
void addFormalOUTSVFGNode (const FunExitICFGNode *funExit, const MRVer *ver, const NodeID nodeId)
 Add memory Function return mu SVFG node.
 
void addActualINSVFGNode (const CallICFGNode *callsite, const MRVer *ver, const NodeID nodeId)
 Add memory callsite mu SVFG node.
 
void addActualOUTSVFGNode (const CallICFGNode *callsite, const MRVer *resVer, const NodeID nodeId)
 Add memory callsite chi SVFG node.
 
void addIntraMSSAPHISVFGNode (ICFGNode *BlockICFGNode, const Map< u32_t, const MRVer * >::const_iterator opVerBegin, const Map< u32_t, const MRVer * >::const_iterator opVerEnd, const MRVer *resVer, const NodeID nodeId)
 Add memory SSA PHI SVFG node.
 
bool hasFuncEntryChi (const SVFFunction *func) const
 Has function for EntryCHI/RetMU/CallCHI/CallMU.
 
bool hasFuncRetMu (const SVFFunction *func) const
 
bool hasCallSiteChi (const CallICFGNode *cs) const
 
bool hasCallSiteMu (const CallICFGNode *cs) const
 
- Protected Member Functions inherited from SVF::VFG
void destroy ()
 Clean up memory.
 
void checkIntraEdgeParents (const VFGNode *srcNode, const VFGNode *dstNode)
 sanitize Intra edges, verify that both nodes belong to the same function.
 
VFGEdgeaddInterEdgeFromAPToFP (ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
 Add inter VF edge from actual to formal parameters.
 
VFGEdgeaddInterEdgeFromFRToAR (FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
 Add inter VF edge from callee return to callsite receive parameter.
 
VFGEdgeaddInterEdgeFromAPToFP (NodeID src, NodeID dst, CallSiteID csId)
 Add inter VF edge from actual to formal parameters.
 
VFGEdgeaddInterEdgeFromFRToAR (NodeID src, NodeID dst, CallSiteID csId)
 Add inter VF edge from callee return to callsite receive parameter.
 
void setDef (const PAGNode *pagNode, const VFGNode *node)
 Given a PAGNode, set/get its def VFG node (definition of top level pointers)
 
NodeID getDef (const PAGNode *pagNode) const
 
bool hasDef (const PAGNode *pagNode) const
 
void addVFGNodes ()
 Create VFG nodes.
 
virtual SVFStmt::SVFStmtSetTygetPAGEdgeSet (SVFStmt::PEDGEK kind)
 Get PAGEdge set.
 
virtual bool isInterestedPAGNode (const SVFVar *node) const
 
void connectDirectVFGEdges ()
 Create edges between VFG nodes within a function.
 
void addVFGInterEdges (const CallICFGNode *cs, const SVFFunction *callee)
 Create edges between VFG nodes across functions.
 
bool isPhiCopyEdge (const PAGEdge *copy) const
 
virtual void addVFGNode (VFGNode *vfgNode, ICFGNode *icfgNode)
 Add a VFG node.
 
void addStmtVFGNode (StmtVFGNode *node, const PAGEdge *pagEdge)
 Add a VFG node for program statement.
 
void addNullPtrVFGNode (const PAGNode *pagNode)
 
void addAddrVFGNode (const AddrStmt *addr)
 Add an Address VFG node.
 
void addCopyVFGNode (const CopyStmt *copy)
 Add a Copy VFG node.
 
void addGepVFGNode (const GepStmt *gep)
 Add a Gep VFG node.
 
void addLoadVFGNode (const LoadStmt *load)
 Add a Load VFG node.
 
void addStoreVFGNode (const StoreStmt *store)
 
void addActualParmVFGNode (const PAGNode *aparm, const CallICFGNode *cs)
 
void addFormalParmVFGNode (const PAGNode *fparm, const SVFFunction *fun, CallPESet &callPEs)
 Add a formal parameter VFG node.
 
void addFormalRetVFGNode (const PAGNode *uniqueFunRet, const SVFFunction *fun, RetPESet &retPEs)
 
void addActualRetVFGNode (const PAGNode *ret, const CallICFGNode *cs)
 Add a callsite Receive VFG node.
 
void addIntraPHIVFGNode (const MultiOpndStmt *edge)
 Add an llvm PHI VFG node.
 
void addCmpVFGNode (const CmpStmt *edge)
 Add a Compare VFG node.
 
void addBinaryOPVFGNode (const BinaryOPStmt *edge)
 Add a BinaryOperator VFG node.
 
void addUnaryOPVFGNode (const UnaryOPStmt *edge)
 Add a UnaryOperator VFG node.
 
void addBranchVFGNode (const BranchStmt *edge)
 Add a BranchVFGNode.
 

Private Types

typedef Set< SVFGNode * > SVFGNodeSet
 
typedef Map< NodeID, NodeIDNodeIDToNodeIDMap
 
typedef FIFOWorkList< const MSSAPHISVFGNode * > WorkList
 

Private Member Functions

void parseSelfCycleHandleOption ()
 
SVFGEdgeaddCallIndirectSVFGEdge (NodeID srcId, NodeID dstId, CallSiteID csid, const NodeBS &cpts)
 Add inter-procedural value flow edge.
 
SVFGEdgeaddRetIndirectSVFGEdge (NodeID srcId, NodeID dstId, CallSiteID csid, const NodeBS &cpts)
 Add indirect ret edge from src to dst with one call site ID.
 
void handleInterValueFlow ()
 
void replaceFParamARetWithPHI (PHISVFGNode *phi, SVFGNode *svfgNode)
 Replace FormalParam/ActualRet node with PHI node.
 
void retargetEdgesOfAInFOut (SVFGNode *node)
 Retarget edges related to actual-in/-out and formal-in/-out.
 
void retargetEdgesOfAOutFIn (SVFGNode *node)
 Connect actual-out/formal-in's predecessors to their successors directly.
 
void handleIntraValueFlow ()
 Remove MSSAPHI SVFG nodes.
 
void initialWorkList ()
 Initial work list with MSSAPHI nodes which may be removed.
 
bool addIntoWorklist (const SVFGNode *node)
 
void bypassMSSAPHINode (const MSSAPHISVFGNode *node)
 Remove MSSAPHI node if possible.
 
bool checkSelfCycleEdges (const MSSAPHISVFGNode *node)
 Remove self cycle edges if needed. Return TRUE if some self cycle edges remained.
 
bool addNewSVFGEdge (NodeID srcId, NodeID dstId, const SVFGEdge *preEdge, const SVFGEdge *succEdge)
 Add new SVFG edge from src to dst.
 
bool bothInterEdges (const SVFGEdge *edge1, const SVFGEdge *edge2) const
 Return TRUE if both edges are indirect call/ret edges.
 
void addInterPHIOperands (PHISVFGNode *phi, const PAGNode *operand)
 
InterPHISVFGNodeaddInterPHIForFP (const FormalParmSVFGNode *fp)
 Add inter PHI SVFG node for formal parameter.
 
InterPHISVFGNodeaddInterPHIForAR (const ActualRetSVFGNode *ar)
 Add inter PHI SVFG node for actual return.
 
void resetDef (const PAGNode *pagNode, const SVFGNode *node)
 
bool isDefOfAInFOut (const SVFGNode *node)
 
bool actualInOfIndCS (const ActualINSVFGNode *ai) const
 Check if actual-in/actual-out exist at indirect call site.
 
bool actualOutOfIndCS (const ActualOUTSVFGNode *ao) const
 
bool formalInOfAddressTakenFunc (const FormalINSVFGNode *fi) const
 Check if formal-in/formal-out reside in address-taken function.
 
bool formalOutOfAddressTakenFunc (const FormalOUTSVFGNode *fo) const
 
bool isConnectingTwoCallSites (const SVFGNode *node) const
 Return TRUE if this node has both incoming call/ret and outgoing call/ret edges.
 
bool canBeRemoved (const SVFGNode *node)
 
void removeAllEdges (const SVFGNode *node)
 Remove edges of a SVFG node.
 
void removeInEdges (const SVFGNode *node)
 
void removeOutEdges (const SVFGNode *node)
 
void setActualINDef (NodeID ai, NodeID def)
 
void setFormalOUTDef (NodeID fo, NodeID def)
 

Private Attributes

NodeIDToNodeIDMap actualInToDefMap
 map actual-in to its def-site node
 
NodeIDToNodeIDMap formalOutToDefMap
 map formal-out to its def-site node
 
NodeBS defNodes
 preserved def nodes of formal-in/actual-out
 
WorkList worklist
 storing MSSAPHI nodes which may be removed.
 
bool keepActualOutFormalIn
 
bool keepAllSelfCycle
 
bool keepContextSelfCycle
 

Additional Inherited Members

- Public Types inherited from SVF::SVFG
typedef VFGNodeIDToNodeMapTy SVFGNodeIDToNodeMapTy
 
typedef Map< const PAGNode *, NodeIDPAGNodeToDefMapTy
 
typedef Map< const MRVer *, NodeIDMSSAVarToDefMapTy
 
typedef NodeBS ActualINSVFGNodeSet
 
typedef NodeBS ActualOUTSVFGNodeSet
 
typedef NodeBS FormalINSVFGNodeSet
 
typedef NodeBS FormalOUTSVFGNodeSet
 
typedef Map< const CallICFGNode *, ActualINSVFGNodeSetCallSiteToActualINsMapTy
 
typedef Map< const CallICFGNode *, ActualOUTSVFGNodeSetCallSiteToActualOUTsMapTy
 
typedef Map< const SVFFunction *, FormalINSVFGNodeSetFunctionToFormalINsMapTy
 
typedef Map< const SVFFunction *, FormalOUTSVFGNodeSetFunctionToFormalOUTsMapTy
 
typedef MemSSA::MUSet MUSet
 
typedef MemSSA::CHISet CHISet
 
typedef MemSSA::PHISet PHISet
 
typedef MemSSA::MU MU
 
typedef MemSSA::CHI CHI
 
typedef MemSSA::LOADMU LOADMU
 
typedef MemSSA::STORECHI STORECHI
 
typedef MemSSA::RETMU RETMU
 
typedef MemSSA::ENTRYCHI ENTRYCHI
 
typedef MemSSA::CALLCHI CALLCHI
 
typedef MemSSA::CALLMU CALLMU
 
- Public Types inherited from SVF::VFG
enum  VFGK { FULLSVFG , PTRONLYSVFG , FULLSVFG_OPT , PTRONLYSVFG_OPT }
 VFG kind. More...
 
typedef OrderedMap< NodeID, VFGNode * > VFGNodeIDToNodeMapTy
 
typedef Set< VFGNode * > VFGNodeSet
 
typedef Map< const PAGNode *, NodeIDPAGNodeToDefMapTy
 
typedef Map< std::pair< NodeID, const CallICFGNode * >, ActualParmVFGNode * > PAGNodeToActualParmMapTy
 
typedef Map< const PAGNode *, ActualRetVFGNode * > PAGNodeToActualRetMapTy
 
typedef Map< const PAGNode *, FormalParmVFGNode * > PAGNodeToFormalParmMapTy
 
typedef Map< const PAGNode *, FormalRetVFGNode * > PAGNodeToFormalRetMapTy
 
typedef Map< const PAGEdge *, StmtVFGNode * > PAGEdgeToStmtVFGNodeMapTy
 
typedef Map< const PAGNode *, IntraPHIVFGNode * > PAGNodeToPHIVFGNodeMapTy
 
typedef Map< const PAGNode *, BinaryOPVFGNode * > PAGNodeToBinaryOPVFGNodeMapTy
 
typedef Map< const PAGNode *, UnaryOPVFGNode * > PAGNodeToUnaryOPVFGNodeMapTy
 
typedef Map< const PAGNode *, BranchVFGNode * > PAGNodeToBranchVFGNodeMapTy
 
typedef Map< const PAGNode *, CmpVFGNode * > PAGNodeToCmpVFGNodeMapTy
 
typedef Map< const SVFFunction *, VFGNodeSetFunToVFGNodesMapTy
 
typedef FormalParmVFGNode::CallPESet CallPESet
 
typedef FormalRetVFGNode::RetPESet RetPESet
 
typedef VFGEdge::VFGEdgeSetTy VFGEdgeSetTy
 
typedef VFGEdge::SVFGEdgeSetTy SVFGEdgeSetTy
 
typedef VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter
 
typedef VFGNodeIDToNodeMapTy::iterator iterator
 
typedef VFGNodeIDToNodeMapTy::const_iterator const_iterator
 
typedef SVFIR::SVFStmtSet SVFStmtSet
 
typedef Set< const VFGNode * > GlobalVFGNodeSet
 
typedef Set< const PAGNode * > PAGNodeSet
 
- Public Types inherited from SVF::GenericGraph< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy EdgeType
 
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map.
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators.
 
typedef IDToNodeMapTy::const_iterator const_iterator
 
- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node
 
u32_t nodeNum
 total num of edge
 
- Protected Attributes inherited from SVF::SVFG
MSSAVarToDefMapTy MSSAVarToDefMap
 map a memory SSA operator to its definition SVFG node
 
CallSiteToActualINsMapTy callSiteToActualINMap
 
CallSiteToActualOUTsMapTy callSiteToActualOUTMap
 
FunctionToFormalINsMapTy funToFormalINMap
 
FunctionToFormalOUTsMapTy funToFormalOUTMap
 
SVFGStatstat
 
std::unique_ptr< MemSSAmssa
 
PointerAnalysispta
 
- Protected Attributes inherited from SVF::VFG
NodeID totalVFGNode
 
PAGNodeToDefMapTy PAGNodeToDefMap
 map a pag node to its definition SVG node
 
PAGNodeToActualParmMapTy PAGNodeToActualParmMap
 map a PAGNode to an actual parameter
 
PAGNodeToActualRetMapTy PAGNodeToActualRetMap
 map a PAGNode to an actual return
 
PAGNodeToFormalParmMapTy PAGNodeToFormalParmMap
 map a PAGNode to a formal parameter
 
PAGNodeToFormalRetMapTy PAGNodeToFormalRetMap
 map a PAGNode to a formal return
 
PAGNodeToPHIVFGNodeMapTy PAGNodeToIntraPHIVFGNodeMap
 map a PAGNode to its PHIVFGNode
 
PAGNodeToBinaryOPVFGNodeMapTy PAGNodeToBinaryOPVFGNodeMap
 map a PAGNode to its BinaryOPVFGNode
 
PAGNodeToUnaryOPVFGNodeMapTy PAGNodeToUnaryOPVFGNodeMap
 map a PAGNode to its UnaryOPVFGNode
 
PAGNodeToBranchVFGNodeMapTy PAGNodeToBranchVFGNodeMap
 map a PAGNode to its BranchVFGNode
 
PAGNodeToCmpVFGNodeMapTy PAGNodeToCmpVFGNodeMap
 map a PAGNode to its CmpVFGNode
 
PAGEdgeToStmtVFGNodeMapTy PAGEdgeToStmtVFGNodeMap
 map a PAGEdge to its StmtVFGNode
 
FunToVFGNodesMapTy funToVFGNodesMap
 map a function to its VFGNodes;
 
GlobalVFGNodeSet globalVFGNodes
 set of global store VFG nodes
 
PTACallGraphcallgraph
 
SVFIRpag
 
VFGK kind
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map
 

Detailed Description

Optimised SVFG.

  1. FormalParam/ActualRet is converted into Phi. ActualParam/FormalRet becomes the operands of Phi nodes created at callee/caller's entry/callsite.
  2. ActualIns/ActualOuts resides at direct call sites id removed. Sources of its incoming edges are connected with the destinations of its outgoing edges directly.
  3. FormalIns/FormalOuts reside at the entry/exit of non-address-taken functions is removed as ActualIn/ActualOuts.
  4. MSSAPHI nodes are removed if it have no self cycle. Otherwise depends on user option.

Definition at line 56 of file SVFGOPT.h.

Member Typedef Documentation

◆ NodeIDToNodeIDMap

Definition at line 59 of file SVFGOPT.h.

◆ SVFGNodeSet

Definition at line 58 of file SVFGOPT.h.

◆ WorkList

Definition at line 60 of file SVFGOPT.h.

Constructor & Destructor Documentation

◆ SVFGOPT()

SVF::SVFGOPT::SVFGOPT ( std::unique_ptr< MemSSA mssa,
VFGK  kind 
)
inline

Constructor.

Definition at line 64 of file SVFGOPT.h.

64 : SVFG(std::move(mssa), kind)
65 {
67 }
bool keepAllSelfCycle
Definition SVFGOPT.h:357
bool keepActualOutFormalIn
Definition SVFGOPT.h:356
bool keepContextSelfCycle
Definition SVFGOPT.h:358
SVFG(std::unique_ptr< MemSSA > mssa, VFGK k)
Constructor.
Definition SVFG.cpp:204
std::unique_ptr< MemSSA > mssa
Definition SVFG.h:106
VFGK kind
Definition VFG.h:105

◆ ~SVFGOPT()

SVF::SVFGOPT::~SVFGOPT ( )
overridedefault

Destructor.

Member Function Documentation

◆ actualInOfIndCS()

bool SVF::SVFGOPT::actualInOfIndCS ( const ActualINSVFGNode ai) const
inlineprivate

Check if actual-in/actual-out exist at indirect call site.

Definition at line 293 of file SVFGOPT.h.

294 {
295 return (SVFIR::getPAG()->isIndirectCallSites(ai->getCallSite()));
296 }
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ actualOutOfIndCS()

bool SVF::SVFGOPT::actualOutOfIndCS ( const ActualOUTSVFGNode ao) const
inlineprivate

Definition at line 297 of file SVFGOPT.h.

298 {
299 return (SVFIR::getPAG()->isIndirectCallSites(ao->getCallSite()));
300 }

◆ addCallIndirectSVFGEdge()

SVFGEdge * SVFGOPT::addCallIndirectSVFGEdge ( NodeID  srcId,
NodeID  dstId,
CallSiteID  csid,
const NodeBS cpts 
)
private

Add inter-procedural value flow edge.

Add indirect call edge from src to dst with one call site ID.

Definition at line 68 of file SVFGOPT.cpp.

69{
71 return addIntraIndirectVFEdge(srcId, dstId, cpts);
72 else
73 return addCallIndirectVFEdge(srcId, dstId, cpts, csid);
74}
static const Option< bool > ContextInsensitive
Definition Options.h:106
SVFGEdge * addIntraIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts)
Add indirect def-use edges of a memory region between two statements,.
Definition SVFG.cpp:463
SVFGEdge * addCallIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
Definition SVFG.cpp:505

◆ addInterPHIForAR()

InterPHISVFGNode * SVF::SVFGOPT::addInterPHIForAR ( const ActualRetSVFGNode ar)
inlineprivate

Add inter PHI SVFG node for actual return.

Definition at line 252 of file SVFGOPT.h.

253 {
255 addSVFGNode(sNode, const_cast<RetICFGNode*>(
256 ar->getCallSite()->getRetICFGNode()));
257 resetDef(ar->getRev(),sNode);
258 return sNode;
259 }
void resetDef(const PAGNode *pagNode, const SVFGNode *node)
Definition SVFGOPT.h:261
virtual void addSVFGNode(SVFGNode *node, ICFGNode *icfgNode)
Add SVFG node.
Definition SVFG.h:397
NodeID totalVFGNode
Definition VFG.h:88
InterPHIVFGNode InterPHISVFGNode
Definition SVFG.h:58

◆ addInterPHIForFP()

InterPHISVFGNode * SVF::SVFGOPT::addInterPHIForFP ( const FormalParmSVFGNode fp)
inlineprivate

Add inter PHI SVFG node for formal parameter.

Definition at line 244 of file SVFGOPT.h.

245 {
248 resetDef(fp->getParam(),sNode);
249 return sNode;
250 }
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
Definition ICFG.cpp:234
ICFG * getICFG() const
Definition SVFIR.h:172
SVFIR * pag
Definition VFG.h:104

◆ addInterPHIOperands()

void SVF::SVFGOPT::addInterPHIOperands ( PHISVFGNode phi,
const PAGNode operand 
)
inlineprivate

Definition at line 238 of file SVFGOPT.h.

239 {
240 phi->setOpVer(phi->getOpVerNum(), operand);
241 }

◆ addIntoWorklist()

bool SVF::SVFGOPT::addIntoWorklist ( const SVFGNode node)
inlineprivate

Only MSSAPHI node which satisfy following conditions will be removed:

  1. it's not def-site of actual-in/formal-out;
  2. it doesn't have incoming and outgoing call/ret at the same time.

Definition at line 211 of file SVFGOPT.h.

212 {
213 if (const MSSAPHISVFGNode* phi = SVFUtil::dyn_cast<MSSAPHISVFGNode>(node))
214 {
215 if (isConnectingTwoCallSites(phi) == false && isDefOfAInFOut(phi) == false)
216 return worklist.push(phi);
217 }
218 return false;
219 }
bool push(const Data &data)
Definition WorkList.h:165
bool isDefOfAInFOut(const SVFGNode *node)
Definition SVFGOPT.h:286
WorkList worklist
storing MSSAPHI nodes which may be removed.
Definition SVFGOPT.h:354
bool isConnectingTwoCallSites(const SVFGNode *node) const
Return TRUE if this node has both incoming call/ret and outgoing call/ret edges.
Definition SVFGOPT.cpp:292

◆ addNewSVFGEdge()

bool SVFGOPT::addNewSVFGEdge ( NodeID  srcId,
NodeID  dstId,
const SVFGEdge preEdge,
const SVFGEdge succEdge 
)
private

Add new SVFG edge from src to dst.

Add new SVFG edge from src to dst. The edge's kind depends on preEdge and succEdge. Self-cycle edges may be added here.

Definition at line 523 of file SVFGOPT.cpp.

524{
525 assert(SVFUtil::isa<IndirectSVFGEdge>(preEdge) && SVFUtil::isa<IndirectSVFGEdge>(succEdge)
526 && "either pre or succ edge is not indirect SVFG edge");
527
528 const IndirectSVFGEdge* preIndEdge = SVFUtil::cast<IndirectSVFGEdge>(preEdge);
529 const IndirectSVFGEdge* succIndEdge = SVFUtil::cast<IndirectSVFGEdge>(succEdge);
530
531 NodeBS intersection = preIndEdge->getPointsTo();
532 intersection &= succIndEdge->getPointsTo();
533
534 if (intersection.empty())
535 return false;
536
537 assert(bothInterEdges(preEdge, succEdge) == false && "both edges are inter edges");
538
539 if (const CallIndSVFGEdge* preCallEdge = SVFUtil::dyn_cast<CallIndSVFGEdge>(preEdge))
540 {
541 return addCallIndirectSVFGEdge(srcId, dstId, preCallEdge->getCallSiteId(), intersection);
542 }
543 else if (const CallIndSVFGEdge* succCallEdge = SVFUtil::dyn_cast<CallIndSVFGEdge>(succEdge))
544 {
545 return addCallIndirectSVFGEdge(srcId, dstId, succCallEdge->getCallSiteId(), intersection);
546 }
547 else if (const RetIndSVFGEdge* preRetEdge = SVFUtil::dyn_cast<RetIndSVFGEdge>(preEdge))
548 {
549 return addRetIndirectSVFGEdge(srcId, dstId, preRetEdge->getCallSiteId(), intersection);
550 }
551 else if (const RetIndSVFGEdge* succRetEdge = SVFUtil::dyn_cast<RetIndSVFGEdge>(succEdge))
552 {
553 return addRetIndirectSVFGEdge(srcId, dstId, succRetEdge->getCallSiteId(), intersection);
554 }
555 else
556 {
558 }
559
560 return false;
561}
SVFGEdge * addCallIndirectSVFGEdge(NodeID srcId, NodeID dstId, CallSiteID csid, const NodeBS &cpts)
Add inter-procedural value flow edge.
Definition SVFGOPT.cpp:68
bool bothInterEdges(const SVFGEdge *edge1, const SVFGEdge *edge2) const
Return TRUE if both edges are indirect call/ret edges.
Definition SVFGOPT.h:231
SVFGEdge * addRetIndirectSVFGEdge(NodeID srcId, NodeID dstId, CallSiteID csid, const NodeBS &cpts)
Add indirect ret edge from src to dst with one call site ID.
Definition SVFGOPT.cpp:79

◆ addRetIndirectSVFGEdge()

SVFGEdge * SVFGOPT::addRetIndirectSVFGEdge ( NodeID  srcId,
NodeID  dstId,
CallSiteID  csid,
const NodeBS cpts 
)
private

Add indirect ret edge from src to dst with one call site ID.

Definition at line 79 of file SVFGOPT.cpp.

80{
82 return addIntraIndirectVFEdge(srcId, dstId, cpts);
83 else
84 return addRetIndirectVFEdge(srcId, dstId, cpts, csid);
85}
SVFGEdge * addRetIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
Definition SVFG.cpp:525

◆ bothInterEdges()

bool SVF::SVFGOPT::bothInterEdges ( const SVFGEdge edge1,
const SVFGEdge edge2 
) const
inlineprivate

Return TRUE if both edges are indirect call/ret edges.

Definition at line 231 of file SVFGOPT.h.

232 {
233 bool inter1 = SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(edge1);
234 bool inter2 = SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(edge2);
235 return (inter1 && inter2);
236 }

◆ buildSVFG()

void SVFGOPT::buildSVFG ( )
overrideprotectedvirtual

Start building SVFG.

Build SVFG 1) build SVFG nodes a) statements for top level pointers (PAGEdges) b) operators of address-taken variables (MSSAPHI and MSSACHI) 2) connect SVFG edges a) between two statements (PAGEdges) b) between two memory SSA operators (MSSAPHI MSSAMU and MSSACHI)

Reimplemented from SVF::SVFG.

Definition at line 47 of file SVFGOPT.cpp.

48{
50
52 dump("SVFG_before_opt");
53
54 DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("\tSVFG Optimisation\n"));
55
57
60
63
64}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:484
#define DGENERAL
Definition SVFType.h:490
static const Option< bool > KeepAOFI
Definition Options.h:107
static const Option< bool > DumpVFG
Definition Options.h:111
void handleIntraValueFlow()
Remove MSSAPHI SVFG nodes.
Definition SVFGOPT.cpp:391
void handleInterValueFlow()
Definition SVFGOPT.cpp:90
void sfvgOptEnd()
Definition SVFGStat.h:154
void sfvgOptStart()
Definition SVFGStat.h:149
virtual void buildSVFG()
Start building SVFG.
Definition SVFG.cpp:228
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
Definition SVFG.cpp:576
SVFGStat * stat
Definition SVFG.h:105
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:100
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50

◆ bypassMSSAPHINode()

void SVFGOPT::bypassMSSAPHINode ( const MSSAPHISVFGNode node)
private

Remove MSSAPHI node if possible.

Remove MSSAPHI node if possible

add new edges from predecessor to all successors.

if no new edge is added, the number of dst node's incoming edges may be decreased. try to analyze it again.

if no new edge is added, the number of src node's outgoing edges may be decreased. try to analyze it again.

Definition at line 480 of file SVFGOPT.cpp.

481{
484 for (; inEdgeIt != inEdgeEit; ++inEdgeIt)
485 {
486 const SVFGEdge* preEdge = *inEdgeIt;
487 const SVFGNode* srcNode = preEdge->getSrcNode();
488
489 bool added = false;
493 for (; outEdgeIt != outEdgeEit; ++outEdgeIt)
494 {
495 const SVFGEdge* succEdge = *outEdgeIt;
496 const SVFGNode* dstNode = (*outEdgeIt)->getDstNode();
497 if (srcNode->getId() != dstNode->getId()
498 && addNewSVFGEdge(srcNode->getId(), dstNode->getId(), preEdge, succEdge))
499 added = true;
500 else
501 {
505 }
506 }
507
508 if (added == false)
509 {
513 }
514 }
515
516 removeAllEdges(node);
517}
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators
iterator InEdgeBegin()
iterator InEdgeEnd()
bool addNewSVFGEdge(NodeID srcId, NodeID dstId, const SVFGEdge *preEdge, const SVFGEdge *succEdge)
Add new SVFG edge from src to dst.
Definition SVFGOPT.cpp:523
bool addIntoWorklist(const SVFGNode *node)
Definition SVFGOPT.h:211
void removeAllEdges(const SVFGNode *node)
Remove edges of a SVFG node.
Definition SVFGOPT.h:331
VFGEdge::VFGEdgeSetTy::const_iterator const_iterator
Definition VFGNode.h:55

◆ canBeRemoved()

bool SVFGOPT::canBeRemoved ( const SVFGNode node)
private

Return TRUE if this SVFGNode can be removed. Nodes can be removed if it is:

  1. ActualParam/FormalParam/ActualRet/FormalRet
  2. ActualIN if it doesn't reside at indirect call site
  3. FormalIN if it doesn't reside at the entry of address-taken function and it's not definition site of ActualIN
  4. ActualOUT if it doesn't reside at indirect call site and it's not definition site of FormalOUT
  5. FormalOUT if it doesn't reside at the exit of address-taken function

Now each SVFG edge can only be associated with one call site id, so if this node has both incoming call/ret and outgoing call/ret edges, we don't remove this node.

Definition at line 334 of file SVFGOPT.cpp.

335{
338 return true;
341 {
345 if (isConnectingTwoCallSites(node))
346 return false;
347
348 if (const ActualINSVFGNode* ai = SVFUtil::dyn_cast<ActualINSVFGNode>(node))
349 {
350 return (actualInOfIndCS(ai) == false);
351 }
352 else if (const ActualOUTSVFGNode* ao = SVFUtil::dyn_cast<ActualOUTSVFGNode>(node))
353 {
354 return (actualOutOfIndCS(ao) == false && isDefOfAInFOut(node) == false);
355 }
356 else if (const FormalINSVFGNode* fi = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
357 {
358 return (formalInOfAddressTakenFunc(fi) == false && isDefOfAInFOut(node) == false);
359 }
360 else if (const FormalOUTSVFGNode* fo = SVFUtil::dyn_cast<FormalOUTSVFGNode>(node))
361 {
362 return (formalOutOfAddressTakenFunc(fo) == false);
363 }
364 }
365
366 return false;
367}
bool formalInOfAddressTakenFunc(const FormalINSVFGNode *fi) const
Check if formal-in/formal-out reside in address-taken function.
Definition SVFGOPT.h:305
bool actualOutOfIndCS(const ActualOUTSVFGNode *ao) const
Definition SVFGOPT.h:297
bool formalOutOfAddressTakenFunc(const FormalOUTSVFGNode *fo) const
Definition SVFGOPT.h:309
bool actualInOfIndCS(const ActualINSVFGNode *ai) const
Check if actual-in/actual-out exist at indirect call site.
Definition SVFGOPT.h:293
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241

◆ checkSelfCycleEdges()

bool SVFGOPT::checkSelfCycleEdges ( const MSSAPHISVFGNode node)
private

Remove self cycle edges if needed. Return TRUE if some self cycle edges remained.

Remove self cycle edges according to specified options:

  1. keepAllSelfCycle = TRUE: all self cycle edges are kept;
  2. keepContextSelfCycle = TRUE: all self cycle edges related-to context are kept;
  3. Otherwise, all self cycle edges are NOT kept. Return TRUE if some self cycle edges remain in this node.

There's no need to check other edge if we do not remove self cycle

Continue checking and remove other self cycle which are NOT context-related

Definition at line 442 of file SVFGOPT.cpp.

443{
444 bool hasSelfCycle = false;
445
449 for (; inEdgeIt != inEdgeEit; ++inEdgeIt)
450 {
452
453 if (preEdge->getSrcID() == preEdge->getDstID())
454 {
456 {
457 hasSelfCycle = true;
458 break;
459 }
460 else if (keepContextSelfCycle &&
461 SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(preEdge))
462 {
463 hasSelfCycle = true;
464 continue;
465 }
466 else
467 {
468 assert(SVFUtil::isa<IndirectSVFGEdge>(preEdge) && "can only remove indirect SVFG edge");
470 }
471 }
472 }
473
474 return hasSelfCycle;
475}
const GEdgeSetTy & getInEdges() const
void removeSVFGEdge(SVFGEdge *edge)
Remove a SVFG edge.
Definition SVFG.h:238
VFGEdgeSetTy SVFGEdgeSetTy
Definition VFGEdge.h:118

◆ connectAInAndFIn()

void SVF::SVFGOPT::connectAInAndFIn ( const ActualINSVFGNode actualIn,
const FormalINSVFGNode formalIn,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineoverrideprotectedvirtual

Connect actual-in and formal-in.

Reimplemented from SVF::SVFG.

Definition at line 120 of file SVFGOPT.h.

121 {
122 NodeBS intersection = actualIn->getPointsTo();
123 intersection &= formalIn->getPointsTo();
124 if (intersection.empty() == false)
125 {
128 if (edge != nullptr)
129 edges.insert(edge);
130 }
131 }
NodeID getActualINDef(NodeID ai) const
Get def-site of actual-in/formal-out.
Definition SVFGOPT.h:149
u32_t NodeID
Definition GeneralType.h:55
VFGEdge SVFGEdge
Definition SVFG.h:42
SparseBitVector NodeBS
Definition GeneralType.h:62

◆ connectAParamAndFParam()

void SVF::SVFGOPT::connectAParamAndFParam ( const PAGNode cs_arg,
const PAGNode fun_arg,
const CallICFGNode ,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineoverrideprotectedvirtual

Connect SVFG nodes between caller and callee for indirect call sites.

Reimplemented from SVF::VFG.

Definition at line 89 of file SVFGOPT.h.

90 {
93 if (edge != nullptr)
94 {
95 PHISVFGNode* phi = SVFUtil::cast<PHISVFGNode>(getSVFGNode(phiId));
97 edges.insert(edge);
98 }
99 }
void addInterPHIOperands(PHISVFGNode *phi, const PAGNode *operand)
Definition SVFGOPT.h:238
SVFGNode * getSVFGNode(NodeID id) const
Get a SVFG node.
Definition SVFG.h:150
NodeID getDef(const PAGNode *pagNode) const
Definition SVFG.h:356
VFGEdge * addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition VFG.cpp:701
PHIVFGNode PHISVFGNode
Definition SVFG.h:56

◆ connectFOutAndAOut()

void SVF::SVFGOPT::connectFOutAndAOut ( const FormalOUTSVFGNode formalOut,
const ActualOUTSVFGNode actualOut,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineoverrideprotectedvirtual

Connect formal-out and actual-out.

Reimplemented from SVF::SVFG.

Definition at line 133 of file SVFGOPT.h.

134 {
135 NodeBS intersection = formalOut->getPointsTo();
136 intersection &= actualOut->getPointsTo();
137 if (intersection.empty() == false)
138 {
141 if (edge != nullptr)
142 edges.insert(edge);
143 }
144 }
NodeID getFormalOUTDef(NodeID fo) const
Definition SVFGOPT.h:155

◆ connectFRetAndARet()

void SVF::SVFGOPT::connectFRetAndARet ( const PAGNode fun_ret,
const PAGNode cs_ret,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineoverrideprotectedvirtual

Connect formal-ret and actual ret.

If a function does not have any return instruction. The def of a FormalRetVFGNode is itself (see VFG.h: addFormalRetVFGNode). Therefore, we do not connect return edge from a function without any return instruction (i.e., pag->isPhiNode(fun_ret)==false) because unique fun_ret PAGNode was not collected as a PhiNode in SVFIRBuilder::visitReturnInst

Reimplemented from SVF::VFG.

Definition at line 101 of file SVFGOPT.h.

102 {
108 if (pag->isPhiNode(fun_ret)==false)
109 return;
110
112 if (edge != nullptr)
113 {
114 PHISVFGNode* phi = SVFUtil::cast<PHISVFGNode>(getSVFGNode(phiId));
116 edges.insert(edge);
117 }
118 }
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:260
VFGEdge * addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition VFG.cpp:721

◆ formalInOfAddressTakenFunc()

bool SVF::SVFGOPT::formalInOfAddressTakenFunc ( const FormalINSVFGNode fi) const
inlineprivate

Check if formal-in/formal-out reside in address-taken function.

Definition at line 305 of file SVFGOPT.h.

306 {
307 return (fi->getFun()->hasAddressTaken());
308 }

◆ formalOutOfAddressTakenFunc()

bool SVF::SVFGOPT::formalOutOfAddressTakenFunc ( const FormalOUTSVFGNode fo) const
inlineprivate

Definition at line 309 of file SVFGOPT.h.

310 {
311 return (fo->getFun()->hasAddressTaken());
312 }

◆ getActualINDef()

NodeID SVF::SVFGOPT::getActualINDef ( NodeID  ai) const
inlineprotected

Get def-site of actual-in/formal-out.

Definition at line 149 of file SVFGOPT.h.

150 {
151 NodeIDToNodeIDMap::const_iterator it = actualInToDefMap.find(ai);
152 assert(it != actualInToDefMap.end() && "can not find actual-in's def");
153 return it->second;
154 }
NodeIDToNodeIDMap actualInToDefMap
map actual-in to its def-site node
Definition SVFGOPT.h:350

◆ getFormalOUTDef()

NodeID SVF::SVFGOPT::getFormalOUTDef ( NodeID  fo) const
inlineprotected

Definition at line 155 of file SVFGOPT.h.

156 {
157 NodeIDToNodeIDMap::const_iterator it = formalOutToDefMap.find(fo);
158 assert(it != formalOutToDefMap.end() && "can not find formal-out's def");
159 return it->second;
160 }
NodeIDToNodeIDMap formalOutToDefMap
map formal-out to its def-site node
Definition SVFGOPT.h:351

◆ handleInterValueFlow()

void SVFGOPT::handleInterValueFlow ( )
private
  1. Convert FormalParmSVFGNode into PHISVFGNode and add all ActualParmSVFGNoe which may propagate pts to it as phi's operands.
  2. Do the same thing for ActualRetSVFGNode and FormalRetSVFGNode.
  3. Record def site of ActualINSVFGNode. Remove all its edges and connect its predecessors and successors.
  4. Do the same thing for FormalOUTSVFGNode as 3.
  5. Remove ActualINSVFGNode/FormalINSVFGNode/ActualOUTSVFGNode/FormalOUTSVFGNode if they will not be used when updating call graph.

reset def of address-taken variable

Definition at line 90 of file SVFGOPT.cpp.

91{
92 SVFGNodeSet candidates;
93 for (SVFGNodeIDToNodeMapTy::iterator it = SVFG::begin(), eit = SVFG::end();
94 it!=eit; ++it)
95 {
96 SVFGNode* node = it->second;
100 candidates.insert(node);
101 }
102
104 for (SVFGNodeSet::const_iterator it = candidates.begin(), eit = candidates.end();
105 it!=eit; ++it)
106 {
107 SVFGNode* node = *it;
108 if (FormalParmSVFGNode* fp = SVFUtil::dyn_cast<FormalParmSVFGNode>(node))
109 {
111 nodesToBeDeleted.insert(fp);
112 }
113 else if (ActualRetSVFGNode* ar = SVFUtil::dyn_cast<ActualRetSVFGNode>(node))
114 {
116 nodesToBeDeleted.insert(ar);
117 }
118 else if (SVFUtil::isa<ActualParmSVFGNode, FormalRetSVFGNode>(node))
119 {
120 nodesToBeDeleted.insert(node);
121 }
122 else if (SVFUtil::isa<ActualINSVFGNode, FormalOUTSVFGNode>(node))
123 {
125 nodesToBeDeleted.insert(node);
126 }
127 else if (SVFUtil::isa<ActualOUTSVFGNode, FormalINSVFGNode>(node))
128 {
129 if(keepActualOutFormalIn == false)
130 nodesToBeDeleted.insert(node);
131 }
132 }
133
134 for (SVFGNodeSet::iterator it = nodesToBeDeleted.begin(), eit = nodesToBeDeleted.end(); it != eit; ++it)
135 {
136 SVFGNode* node = *it;
137 if (canBeRemoved(node))
138 {
139 if (SVFUtil::isa<ActualOUTSVFGNode, FormalINSVFGNode>(node))
141
142 removeAllEdges(node);
143 removeSVFGNode(node);
144 }
145 }
146}
iterator begin()
Iterators.
Set< SVFGNode * > SVFGNodeSet
Definition SVFGOPT.h:58
void replaceFParamARetWithPHI(PHISVFGNode *phi, SVFGNode *svfgNode)
Replace FormalParam/ActualRet node with PHI node.
Definition SVFGOPT.cpp:151
void retargetEdgesOfAOutFIn(SVFGNode *node)
Connect actual-out/formal-in's predecessors to their successors directly.
Definition SVFGOPT.cpp:250
InterPHISVFGNode * addInterPHIForAR(const ActualRetSVFGNode *ar)
Add inter PHI SVFG node for actual return.
Definition SVFGOPT.h:252
InterPHISVFGNode * addInterPHIForFP(const FormalParmSVFGNode *fp)
Add inter PHI SVFG node for formal parameter.
Definition SVFGOPT.h:244
bool canBeRemoved(const SVFGNode *node)
Definition SVFGOPT.cpp:334
void retargetEdgesOfAInFOut(SVFGNode *node)
Retarget edges related to actual-in/-out and formal-in/-out.
Definition SVFGOPT.cpp:204
void removeSVFGNode(SVFGNode *node)
Remove a SVFGNode.
Definition SVFG.h:243

◆ handleIntraValueFlow()

void SVFGOPT::handleIntraValueFlow ( )
private

Remove MSSAPHI SVFG nodes.

Remove MSSAPHI SVFG nodes.

Skip nodes which have self cycle

remove node's edges if it only has incoming or outgoing edges.

remove all the incoming edges;

remove all the outgoing edges;

remove this node if it has no edges

Definition at line 391 of file SVFGOPT.cpp.

392{
394
396
397 while (!worklist.empty())
398 {
399 const MSSAPHISVFGNode* node = worklist.pop();
400
402 if (checkSelfCycleEdges(node))
403 continue;
404
405 if (node->hasOutgoingEdge() && node->hasIncomingEdge())
406 bypassMSSAPHINode(node);
407
409 if (node->hasIncomingEdge() && node->hasOutgoingEdge() == false)
410 {
414 for (; edgeIt != edgeEit; ++edgeIt)
415 addIntoWorklist((*edgeIt)->getSrcNode());
416
417 removeInEdges(node);
418 }
419 else if (node->hasOutgoingEdge() && node->hasIncomingEdge() == false)
420 {
424 for (; edgeIt != edgeEit; ++edgeIt)
425 addIntoWorklist((*edgeIt)->getDstNode());
426
427 removeOutEdges(node);
428 }
429
431 if (node->hasIncomingEdge() == false && node->hasOutgoingEdge() == false)
432 removeSVFGNode(const_cast<MSSAPHISVFGNode*>(node));
433 }
434}
bool empty() const
Definition WorkList.h:146
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
bool hasOutgoingEdge() const
void bypassMSSAPHINode(const MSSAPHISVFGNode *node)
Remove MSSAPHI node if possible.
Definition SVFGOPT.cpp:480
void removeInEdges(const SVFGNode *node)
Definition SVFGOPT.h:336
void parseSelfCycleHandleOption()
Definition SVFGOPT.cpp:372
void initialWorkList()
Initial work list with MSSAPHI nodes which may be removed.
Definition SVFGOPT.h:202
void removeOutEdges(const SVFGNode *node)
Definition SVFGOPT.h:342
bool checkSelfCycleEdges(const MSSAPHISVFGNode *node)
Remove self cycle edges if needed. Return TRUE if some self cycle edges remained.
Definition SVFGOPT.cpp:442

◆ initialWorkList()

void SVF::SVFGOPT::initialWorkList ( )
inlineprivate

Initial work list with MSSAPHI nodes which may be removed.

Definition at line 202 of file SVFGOPT.h.

203 {
204 for (SVFG::const_iterator it = begin(), eit = end(); it != eit; ++it)
205 addIntoWorklist(it->second);
206 }
IDToNodeMapTy::const_iterator const_iterator

◆ isConnectingTwoCallSites()

bool SVFGOPT::isConnectingTwoCallSites ( const SVFGNode node) const
private

Return TRUE if this node has both incoming call/ret and outgoing call/ret edges.

Definition at line 292 of file SVFGOPT.cpp.

293{
294 bool hasInCallRet = false;
295 bool hasOutCallRet = false;
296
299 for (; edgeIt != edgeEit; ++edgeIt)
300 {
301 if (SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(*edgeIt))
302 {
303 hasInCallRet = true;
304 break;
305 }
306 }
307
308 edgeIt = node->OutEdgeBegin();
309 edgeEit = node->OutEdgeEnd();
310 for (; edgeIt != edgeEit; ++edgeIt)
311 {
312 if (SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(*edgeIt))
313 {
314 hasOutCallRet = true;
315 break;
316 }
317 }
318
320 return true;
321 else
322 return false;
323}

◆ isDefOfAInFOut()

bool SVF::SVFGOPT::isDefOfAInFOut ( const SVFGNode node)
inlineprivate

Definition at line 286 of file SVFGOPT.h.

287 {
288 return defNodes.test(node->getId());
289 }
NodeBS defNodes
preserved def nodes of formal-in/actual-out
Definition SVFGOPT.h:352
bool test(unsigned Idx) const

◆ parseSelfCycleHandleOption()

void SVFGOPT::parseSelfCycleHandleOption ( )
private

Definition at line 372 of file SVFGOPT.cpp.

373{
374 std::string choice = (Options::SelfCycle().empty()) ? "" : Options::SelfCycle();
375 if (choice.empty() || choice == KeepAllSelfCycle)
376 keepAllSelfCycle = true;
377 else if (choice == KeepContextSelfCycle)
379 else if (choice == KeepNoneSelfCycle)
381 else
382 {
383 SVFUtil::writeWrnMsg("Unrecognised option. All self cycle edges will be kept.");
384 keepAllSelfCycle = true;
385 }
386}
static std::string KeepNoneSelfCycle
Definition SVFGOPT.cpp:44
static std::string KeepContextSelfCycle
Definition SVFGOPT.cpp:43
static std::string KeepAllSelfCycle
Definition SVFGOPT.cpp:42
Carries around command line options.
Definition Options.h:20
static const Option< std::string > SelfCycle
Definition Options.h:108
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:67

◆ removeAllEdges()

void SVF::SVFGOPT::removeAllEdges ( const SVFGNode node)
inlineprivate

Remove edges of a SVFG node.

Definition at line 331 of file SVFGOPT.h.

332 {
333 removeInEdges(node);
334 removeOutEdges(node);
335 }

◆ removeInEdges()

void SVF::SVFGOPT::removeInEdges ( const SVFGNode node)
inlineprivate

remove incoming edges

Definition at line 336 of file SVFGOPT.h.

337 {
339 while (node->hasIncomingEdge())
340 removeSVFGEdge(*(node->InEdgeBegin()));
341 }

◆ removeOutEdges()

void SVF::SVFGOPT::removeOutEdges ( const SVFGNode node)
inlineprivate

Definition at line 342 of file SVFGOPT.h.

343 {
344 while (node->hasOutgoingEdge())
345 removeSVFGEdge(*(node->OutEdgeBegin()));
346 }

◆ replaceFParamARetWithPHI()

void SVFGOPT::replaceFParamARetWithPHI ( PHISVFGNode phi,
SVFGNode svfgNode 
)
private

Replace FormalParam/ActualRet node with PHI node.

create a new PHISVFGNode.

migrate formal-param's edges to phi node.

add actual-param/formal-ret into phi's operand list

Definition at line 151 of file SVFGOPT.cpp.

152{
153 assert((SVFUtil::isa<FormalParmSVFGNode, ActualRetSVFGNode>(svfgNode))
154 && "expecting a formal param or actual ret svfg node");
155
157 NodeID phiId = phi->getId();
159 for (SVFGNode::const_iterator it = svfgNode->OutEdgeBegin(), eit = svfgNode->OutEdgeEnd();
160 it != eit; ++it)
161 {
162 const SVFGEdge* outEdge = *it;
163 SVFGNode* dstNode = outEdge->getDstNode();
165 if (const CallDirSVFGEdge* callEdge = SVFUtil::dyn_cast<CallDirSVFGEdge>(outEdge))
166 addCallEdge(phiId, dstId, callEdge->getCallSiteId());
167 else if (const RetDirSVFGEdge* retEdge = SVFUtil::dyn_cast<RetDirSVFGEdge>(outEdge))
168 addRetEdge(phiId, dstId, retEdge->getCallSiteId());
169 else
171 }
172
174 if (FormalParmSVFGNode* fp = SVFUtil::dyn_cast<FormalParmSVFGNode>(svfgNode))
175 {
176 for (SVFGNode::iterator it = svfgNode->InEdgeBegin(), eit = svfgNode->InEdgeEnd();
177 it != eit; ++it)
178 {
179 ActualParmSVFGNode* ap = SVFUtil::cast<ActualParmSVFGNode>((*it)->getSrcNode());
181 // connect actual param's def node to phi node
183 }
184 }
185 else if (ActualRetSVFGNode* ar = SVFUtil::dyn_cast<ActualRetSVFGNode>(svfgNode))
186 {
187 for (SVFGNode::iterator it = svfgNode->InEdgeBegin(), eit = svfgNode->InEdgeEnd();
188 it != eit; ++it)
189 {
190 FormalRetSVFGNode* fr = SVFUtil::cast<FormalRetSVFGNode>((*it)->getSrcNode());
191 addInterPHIOperands(phi, fr->getRet());
192 // connect formal return's def node to phi node
193 addRetEdge(getDef(fr->getRet()), phiId, getCallSiteID(ar->getCallSite(), fr->getFun()));
194 }
195 }
196
198}
const PAGNode * getParam() const
Return parameter.
Definition VFGNode.h:907
const CallICFGNode * getCallSite() const
Return callsite.
Definition VFGNode.h:901
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:76
NodeID getId() const
Get ID.
VFGEdge::VFGEdgeSetTy::iterator iterator
Definition VFGNode.h:54
VFGEdge * addIntraDirectVFEdge(NodeID srcId, NodeID dstId)
Definition VFG.cpp:675
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *func) const
Get callsite given a callsiteID.
Definition VFG.h:178

◆ resetDef()

void SVF::SVFGOPT::resetDef ( const PAGNode pagNode,
const SVFGNode node 
)
inlineprivate

Definition at line 261 of file SVFGOPT.h.

262 {
263 PAGNodeToDefMapTy::iterator it = PAGNodeToDefMap.find(pagNode);
264 assert(it != PAGNodeToDefMap.end() && "a SVFIR node doesn't have definition before");
265 it->second = node->getId();
266 }
PAGNodeToDefMapTy PAGNodeToDefMap
map a pag node to its definition SVG node
Definition VFG.h:89

◆ retargetEdgesOfAInFOut()

void SVFGOPT::retargetEdgesOfAInFOut ( SVFGNode node)
private

Retarget edges related to actual-in/-out and formal-in/-out.

Record def sites of actual-in/formal-out and connect from those def-sites to formal-in/actual-out directly if they exist.

Definition at line 204 of file SVFGOPT.cpp.

205{
206 assert(node->getInEdges().size() == 1 && "actual-in/formal-out can only have one incoming edge as its def size");
207
208 SVFGNode* def = nullptr;
210
213 for (; it != eit; ++it)
214 {
215 const IndirectSVFGEdge* inEdge = SVFUtil::cast<IndirectSVFGEdge>(*it);
216 inPointsTo = inEdge->getPointsTo();
217
218 def = inEdge->getSrcNode();
219 if (SVFUtil::isa<ActualINSVFGNode>(node))
220 setActualINDef(node->getId(), def->getId());
221 else if (SVFUtil::isa<FormalOUTSVFGNode>(node))
222 setFormalOUTDef(node->getId(), def->getId());
223 }
224
225 it = node->OutEdgeBegin(), eit = node->OutEdgeEnd();
226 for (; it != eit; ++it)
227 {
228 const IndirectSVFGEdge* outEdge = SVFUtil::cast<IndirectSVFGEdge>(*it);
230 intersection &= outEdge->getPointsTo();
231
232 if (intersection.empty())
233 continue;
234
235 SVFGNode* dstNode = outEdge->getDstNode();
236 if (const CallIndSVFGEdge* callEdge = SVFUtil::dyn_cast<CallIndSVFGEdge>(outEdge))
237 addCallIndirectSVFGEdge(def->getId(), dstNode->getId(), callEdge->getCallSiteId(), intersection);
238 else if (const RetIndSVFGEdge* retEdge = SVFUtil::dyn_cast<RetIndSVFGEdge>(outEdge))
239 addRetIndirectSVFGEdge(def->getId(), dstNode->getId(), retEdge->getCallSiteId(), intersection);
240 else
241 assert(false && "expecting an inter-procedural SVFG edge");
242 }
243
244 removeAllEdges(node);
245}
void setFormalOUTDef(NodeID fo, NodeID def)
Definition SVFGOPT.h:277
void setActualINDef(NodeID ai, NodeID def)
Definition SVFGOPT.h:270

◆ retargetEdgesOfAOutFIn()

void SVFGOPT::retargetEdgesOfAOutFIn ( SVFGNode node)
private

Connect actual-out/formal-in's predecessors to their successors directly.

Definition at line 250 of file SVFGOPT.cpp.

251{
254 for (; inIt != inEit; ++inIt)
255 {
256 const IndirectSVFGEdge* inEdge = SVFUtil::cast<IndirectSVFGEdge>(*inIt);
257 NodeID srcId = inEdge->getSrcID();
258
261 for (; outIt != outEit; ++outIt)
262 {
263 const IndirectSVFGEdge* outEdge = SVFUtil::cast<IndirectSVFGEdge>(*outIt);
264
265 NodeBS intersection = inEdge->getPointsTo();
266 intersection &= outEdge->getPointsTo();
267 if (intersection.empty())
268 continue;
269
270 NodeID dstId = outEdge->getDstID();
271 if (const RetIndSVFGEdge* retEdge = SVFUtil::dyn_cast<RetIndSVFGEdge>(inEdge))
272 {
274 }
275 else if (const CallIndSVFGEdge* callEdge = SVFUtil::dyn_cast<CallIndSVFGEdge>(inEdge))
276 {
278 }
279 else
280 {
282 }
283 }
284 }
285
286 removeAllEdges(node);
287}

◆ setActualINDef()

void SVF::SVFGOPT::setActualINDef ( NodeID  ai,
NodeID  def 
)
inlineprivate

Set def-site of actual-in/formal-out.

Definition at line 270 of file SVFGOPT.h.

271 {
272 bool inserted = actualInToDefMap.emplace(ai, def).second;
273 (void)inserted; // Suppress warning of unused variable under release build
274 assert(inserted && "can not set actual-in's def twice");
275 defNodes.set(def);
276 }
void set(unsigned Idx)

◆ setFormalOUTDef()

void SVF::SVFGOPT::setFormalOUTDef ( NodeID  fo,
NodeID  def 
)
inlineprivate

Definition at line 277 of file SVFGOPT.h.

278 {
279 bool inserted = formalOutToDefMap.emplace(fo, def).second;
280 (void) inserted;
281 assert(inserted && "can not set formal-out's def twice");
282 defNodes.set(def);
283 }

◆ setTokeepActualOutFormalIn()

void SVF::SVFGOPT::setTokeepActualOutFormalIn ( )
inline

Definition at line 71 of file SVFGOPT.h.

72 {
74 }

◆ setTokeepAllSelfCycle()

void SVF::SVFGOPT::setTokeepAllSelfCycle ( )
inline

Definition at line 75 of file SVFGOPT.h.

76 {
77 keepAllSelfCycle = true;
78 }

◆ setTokeepContextSelfCycle()

void SVF::SVFGOPT::setTokeepContextSelfCycle ( )
inline

Definition at line 79 of file SVFGOPT.h.

80 {
82 }

Member Data Documentation

◆ actualInToDefMap

NodeIDToNodeIDMap SVF::SVFGOPT::actualInToDefMap
private

map actual-in to its def-site node

Definition at line 350 of file SVFGOPT.h.

◆ defNodes

NodeBS SVF::SVFGOPT::defNodes
private

preserved def nodes of formal-in/actual-out

Definition at line 352 of file SVFGOPT.h.

◆ formalOutToDefMap

NodeIDToNodeIDMap SVF::SVFGOPT::formalOutToDefMap
private

map formal-out to its def-site node

Definition at line 351 of file SVFGOPT.h.

◆ keepActualOutFormalIn

bool SVF::SVFGOPT::keepActualOutFormalIn
private

Definition at line 356 of file SVFGOPT.h.

◆ keepAllSelfCycle

bool SVF::SVFGOPT::keepAllSelfCycle
private

Definition at line 357 of file SVFGOPT.h.

◆ keepContextSelfCycle

bool SVF::SVFGOPT::keepContextSelfCycle
private

Definition at line 358 of file SVFGOPT.h.

◆ worklist

WorkList SVF::SVFGOPT::worklist
private

storing MSSAPHI nodes which may be removed.

Definition at line 354 of file SVFGOPT.h.


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