30 #ifndef INCLUDE_UTIL_VFG_H_
31 #define INCLUDE_UTIL_VFG_H_
42 class PointerAnalysis;
80 typedef VFGNodeIDToNodeMapTy::iterator
iterator;
270 if (
const AddrVFGNode* addr = SVFUtil::dyn_cast<AddrVFGNode>(defNode))
272 if (
SVFIR::getPAG()->isBlkObjOrConstantObj(addr->getPAGEdge()->getSrcID()))
275 else if(
const CopyVFGNode*
copy = SVFUtil::dyn_cast<CopyVFGNode>(defNode))
301 assert(it !=
funToVFGNodesMap.end() &&
"this function does not have any VFGNode");
302 return it->second.begin();
307 assert(it !=
funToVFGNodesMap.end() &&
"this function does not have any VFGNode");
308 return it->second.end();
341 bool added1 = edge->
getDstNode()->addIncomingEdge(edge);
342 bool added2 = edge->
getSrcNode()->addOutgoingEdge(edge);
343 bool both_added = added1 & added2;
344 assert(both_added &&
"VFGEdge not added??");
355 if(srcfun !=
nullptr && dstfun !=
nullptr)
357 assert((srcfun == dstfun) &&
"src and dst nodes of an intra VFG edge are not in the same function?");
417 assert((it->second == node->
getId()) &&
"a SVFVar can only have unique definition ");
423 assert(it!=
PAGNodeToDefMap.end() &&
"SVFVar does not have a definition??");
542 for(CallPESet::const_iterator it = callPEs.begin(), eit=callPEs.end();
556 for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it)
567 setDef(uniqueFunRet, sNode);
SVFVar * getLHSVar() const
void setOpVer(u32_t pos, const PAGNode *node)
const SVFVar * getBranchInst() const
const RetICFGNode * getRetICFGNode() const
Return callsite.
void setOpVer(u32_t pos, const PAGNode *node)
NodeType * getSrcNode() const
NodeType * getDstNode() const
void addGNode(NodeID id, NodeType *node)
Add a Node.
void removeGNode(NodeType *node)
Delete a node.
NodeType * getGNode(NodeID id) const
Get a node.
bool hasGNode(NodeID id) const
Has a node.
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
void addVFGNode(const VFGNode *vfgNode)
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
GlobalICFGNode * getGlobalICFGNode() const
FunExitICFGNode * getFunExitICFGNode(const SVFFunction *fun)
Add a function exit node.
Set< const SVFStmt * > SVFStmtSet
void setOpVerAndBB(u32_t pos, const PAGNode *node, const ICFGNode *bb)
const SVFVar * getRes() const
Result SVFVar.
const OPVars & getOpndVars() const
const CallICFGNode * getCallSite(CallSiteID id) const
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *callee) const
NodeID getId() const
Get ID.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
ICFGNode * getICFGNode() const
const std::string & getName() const
virtual bool isPointer() const
Whether it is a pointer.
const SVFVar * getRes() const
const SVFVar * getOpVar() const
void setOpVer(u32_t pos, const PAGNode *node)
GenericNode< VFGNode, VFGEdge >::GEdgeSetTy VFGEdgeSetTy
VFGEdgeSetTy SVFGEdgeSetTy
Set< const RetPE * > RetPESet
Set< const CallPE * > CallPESet
virtual void setICFGNode(const ICFGNode *node)
Set corresponding ICFG node.
virtual const SVFFunction * getFun() const
Get the function of this SVFGNode.
Set< VFGNode * > VFGNodeSet
ActualRetVFGNode * getActualRetVFGNode(const PAGNode *aret) const
VFGEdge::VFGEdgeSetTy VFGEdgeSetTy
void updateCallGraph(PointerAnalysis *pta)
Update VFG based on pointer analysis results.
PAGNodeToBinaryOPVFGNodeMapTy PAGNodeToBinaryOPVFGNodeMap
map a PAGNode to its BinaryOPVFGNode
Set< const VFGNode * > GlobalVFGNodeSet
void removeVFGNode(VFGNode *node)
Remove a VFGNode.
void addStoreVFGNode(const StoreStmt *store)
PTACallGraph * getCallGraph() const
Return PTACallGraph.
VFGEdge * addInterEdgeFromAPToFP(NodeID src, NodeID dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
void addBranchVFGNode(const BranchStmt *edge)
Add a BranchVFGNode.
VFGNodeSet & getVFGNodes(const SVFFunction *fun)
PAGNodeToFormalRetMapTy PAGNodeToFormalRetMap
map a PAGNode to a formal return
UnaryOPVFGNode * getUnaryOPVFGNode(const PAGNode *pagNode) const
void setDef(const PAGNode *pagNode, const VFGNode *node)
Given a PAGNode, set/get its def VFG node (definition of top level pointers)
const PAGNode * getLHSTopLevPtr(const VFGNode *node) const
VFGNodeIDToNodeMapTy::const_iterator const_iterator
VFGNodeIDToNodeMapTy::iterator iterator
const CallICFGNode * getCallSite(CallSiteID id) const
bool isPtrOnlySVFG() const
Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.
VFGEdge * addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
BinaryOPVFGNode * getBinaryOPVFGNode(const PAGNode *pagNode) const
PAGNodeToActualRetMapTy PAGNodeToActualRetMap
map a PAGNode to an actual return
VFGNodeSet::const_iterator getVFGNodeEnd(const SVFFunction *fun) const
virtual void connectAParamAndFParam(const PAGNode *csArg, const PAGNode *funArg, const CallICFGNode *cbn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
virtual SVFStmt::SVFStmtSetTy & getPAGEdgeSet(SVFStmt::PEDGEK kind)
Get PAGEdge set.
VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter
bool hasVFGNode(NodeID id) const
Whether has the VFGNode.
StmtVFGNode * getStmtVFGNode(const PAGEdge *pagEdge) const
Get an VFGNode.
void addVFGNodes()
Create VFG nodes.
void addLoadVFGNode(const LoadStmt *load)
Add a Load VFG node.
VFGEdge * addIntraDirectVFEdge(NodeID srcId, NodeID dstId)
void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
sanitize Intra edges, verify that both nodes belong to the same function.
bool VFGNodes(const SVFFunction *fun) const
PAGEdgeToStmtVFGNodeMapTy PAGEdgeToStmtVFGNodeMap
map a PAGEdge to its StmtVFGNode
BranchVFGNode * getBranchVFGNode(const PAGNode *pagNode) const
void addCopyVFGNode(const CopyStmt *copy)
Add a Copy VFG node.
VFGEdge * addInterEdgeFromFRToAR(NodeID src, NodeID dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
void addGepVFGNode(const GepStmt *gep)
Add a Gep VFG node.
VFGNodeSet::const_iterator getVFGNodeBegin(const SVFFunction *fun) const
Map< const PAGNode *, FormalRetVFGNode * > PAGNodeToFormalRetMapTy
PAGNodeToPHIVFGNodeMapTy PAGNodeToIntraPHIVFGNodeMap
map a PAGNode to its PHIVFGNode
void addNullPtrVFGNode(const PAGNode *pagNode)
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *func) const
Get callsite given a callsiteID.
void addActualRetVFGNode(const PAGNode *ret, const CallICFGNode *cs)
Add a callsite Receive VFG node.
void addUnaryOPVFGNode(const UnaryOPStmt *edge)
Add a UnaryOperator VFG node.
virtual ~VFG()
Destructor.
IntraPHIVFGNode * getIntraPHIVFGNode(const PAGNode *pagNode) const
void addActualParmVFGNode(const PAGNode *aparm, const CallICFGNode *cs)
ActualParmVFGNode * getActualParmVFGNode(const PAGNode *aparm, const CallICFGNode *cs) const
void addCmpVFGNode(const CmpStmt *edge)
Add a Compare VFG node.
GlobalVFGNodeSet globalVFGNodes
set of global store VFG nodes
Map< std::pair< NodeID, const CallICFGNode * >, ActualParmVFGNode * > PAGNodeToActualParmMapTy
void addStmtVFGNode(StmtVFGNode *node, const PAGEdge *pagEdge)
Add a VFG node for program statement.
Map< const PAGNode *, FormalParmVFGNode * > PAGNodeToFormalParmMapTy
Map< const PAGNode *, BranchVFGNode * > PAGNodeToBranchVFGNodeMapTy
VFGEdge * addInterEdgeFromAPToFP(ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
NodeID getDef(const PAGNode *pagNode) const
FormalParmVFGNode * getFormalParmVFGNode(const PAGNode *fparm) const
SVFIR * getPAG() const
Return SVFIR.
bool hasVFGNodes(const SVFFunction *fun) const
Map< const PAGNode *, BinaryOPVFGNode * > PAGNodeToBinaryOPVFGNodeMapTy
bool addVFGEdge(VFGEdge *edge)
Add VFG edge.
virtual bool isInterestedPAGNode(const SVFVar *node) const
bool hasBlackHoleConstObjAddrAsDef(const PAGNode *pagNode) const
Whether a PAGNode has a blackhole or const object as its definition.
const SVFFunction * isFunEntryVFGNode(const VFGNode *node) const
Whether a node is function entry VFGNode.
PAGNodeToActualParmMapTy PAGNodeToActualParmMap
map a PAGNode to an actual parameter
VFG(PTACallGraph *callgraph, VFGK k=FULLSVFG)
Constructor.
bool isPhiCopyEdge(const PAGEdge *copy) const
SVFIR::SVFStmtSet SVFStmtSet
VFGNode * getVFGNode(NodeID id) const
Get a VFG node.
CmpVFGNode * getCmpVFGNode(const PAGNode *pagNode) const
Map< const PAGNode *, ActualRetVFGNode * > PAGNodeToActualRetMapTy
PAGNodeToCmpVFGNodeMapTy PAGNodeToCmpVFGNodeMap
map a PAGNode to its CmpVFGNode
FunToVFGNodesMapTy funToVFGNodesMap
map a function to its VFGNodes;
Map< const PAGNode *, CmpVFGNode * > PAGNodeToCmpVFGNodeMapTy
VFGEdge * addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
virtual void connectCallerAndCallee(const CallICFGNode *cs, const SVFFunction *callee, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
void addFormalRetVFGNode(const PAGNode *uniqueFunRet, const SVFFunction *fun, RetPESet &retPEs)
Set< const PAGNode * > PAGNodeSet
Map< const PAGEdge *, StmtVFGNode * > PAGEdgeToStmtVFGNodeMapTy
virtual void connectFRetAndARet(const PAGNode *funReturn, const PAGNode *csReturn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect formal-ret and actual ret.
bool hasDef(const PAGNode *pagNode) const
FormalRetVFGNode * getFormalRetVFGNode(const PAGNode *fret) const
Map< const PAGNode *, NodeID > PAGNodeToDefMapTy
VFGEdge * addInterEdgeFromFRToAR(FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
FormalRetVFGNode::RetPESet RetPESet
VFGEdge * hasIntraVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Whether we has a SVFG edge.
PAGNodeToUnaryOPVFGNodeMapTy PAGNodeToUnaryOPVFGNodeMap
map a PAGNode to its UnaryOPVFGNode
void addBinaryOPVFGNode(const BinaryOPStmt *edge)
Add a BinaryOperator VFG node.
PAGNodeToDefMapTy PAGNodeToDefMap
map a pag node to its definition SVG node
VFGEdge::SVFGEdgeSetTy SVFGEdgeSetTy
void addAddrVFGNode(const AddrStmt *addr)
Add an Address VFG node.
OrderedMap< NodeID, VFGNode * > VFGNodeIDToNodeMapTy
Map< const PAGNode *, UnaryOPVFGNode * > PAGNodeToUnaryOPVFGNodeMapTy
PAGNodeToFormalParmMapTy PAGNodeToFormalParmMap
map a PAGNode to a formal parameter
const VFGNode * getDefVFGNode(const PAGNode *pagNode) const
Given a pagNode, return its definition site.
Map< const SVFFunction *, VFGNodeSet > FunToVFGNodesMapTy
VFGK getKind() const
Get VFG kind.
VFGEdge * hasInterVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
virtual void addVFGNode(VFGNode *vfgNode, ICFGNode *icfgNode)
Add a VFG node.
FormalParmVFGNode::CallPESet CallPESet
void connectDirectVFGEdges()
Create edges between VFG nodes within a function.
VFGEdge * getIntraVFGEdge(const VFGNode *src, const VFGNode *dst, VFGEdge::VFGEdgeK kind)
Get a SVFG edge according to src and dst.
void view()
Dump graph into dot file.
VFGEdge * hasThreadVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
void removeVFGEdge(VFGEdge *edge)
Remove a SVFG edge.
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
Map< const PAGNode *, IntraPHIVFGNode * > PAGNodeToPHIVFGNodeMapTy
void destroy()
Clean up memory.
PAGNodeToBranchVFGNodeMapTy PAGNodeToBranchVFGNodeMap
map a PAGNode to its BranchVFGNode
void addIntraPHIVFGNode(const MultiOpndStmt *edge)
Add an llvm PHI VFG node.
void addFormalParmVFGNode(const PAGNode *fparm, const SVFFunction *fun, CallPESet &callPEs)
Add a formal parameter VFG node.
void addVFGInterEdges(const CallICFGNode *cs, const SVFFunction *callee)
Create edges between VFG nodes across functions.
GlobalVFGNodeSet & getGlobalVFGNodes()
Return global stores.
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
GenericGraph< VFGNode, VFGEdge > GenericVFGTy
std::map< Key, Value, Compare, Allocator > OrderedMap
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set