112 PAG(
bool buildFromFile);
149 NodeID nodeId = nIter->first;
154 candidatePointers.insert(nodeId);
164 pag =
new PAG(buildFromFile);
199 callSiteSet.insert(call);
210 return PAGEdgeKindToSetMap[kind];
215 return PTAPAGEdgeKindToSetMap[kind];
220 return inst2PAGEdgesMap.find(inst)!=inst2PAGEdgesMap.end();
224 return inst2PTAPAGEdgesMap.find(inst)!=inst2PTAPAGEdgesMap.end();
229 return inst2PAGEdgesMap[inst];
234 return inst2PTAPAGEdgesMap[inst];
240 inst2PAGEdgesMap[inst].push_back(edge);
242 inst2PTAPAGEdgesMap[inst].push_back(edge);
247 globPAGEdgesSet.insert(edge);
257 phiNodeMap[res].push_back(edge);
262 return phiNodeMap.find(node) != phiNodeMap.end();
272 binaryNodeMap[res].push_back(edge);
277 return binaryNodeMap.find(node) != binaryNodeMap.end();
287 unaryNodeMap[res].push_back(edge);
292 return unaryNodeMap.find(node) != unaryNodeMap.end();
302 cmpNodeMap[res].push_back(edge);
307 return cmpNodeMap.find(node) != cmpNodeMap.end();
323 funArgsListMap[fun].push_back(arg);
330 funRetMap[fun] = ret;
336 callSiteArgsListMap[callBlockNode].push_back(arg);
342 callSiteRetMap[retBlockNode]= arg;
347 return (funArgsListMap.find(func) != funArgsListMap.end());
357 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
358 assert(it != funArgsListMap.end() &&
"this function doesn't have arguments");
364 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
374 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
375 assert(it != callSiteArgsListMap.end() &&
"this call site doesn't have arguments");
386 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
387 assert(it != callSiteRetMap.end() &&
"this call site doesn't have return");
392 return callSiteRetMap.find(cs) != callSiteRetMap.end();
402 FunToRetMap::const_iterator it = funRetMap.find(func);
403 assert(it != funRetMap.end() &&
"this function doesn't have return");
408 return funRetMap.find(func) != funRetMap.end();
424 return symInfo->
valSyms().size();
432 return GepValNodeMap.size();
436 return GepObjNodeMap.size();
443 GepValPNMap::const_iterator iter = GepValNodeMap.find(curInst);
444 if(iter==GepValNodeMap.end()){
448 NodeLocationSetMap::const_iterator lit = iter->second.find(std::make_pair(base, ls));
449 if(lit==iter->second.end())
464 bool added = indCallSiteToFunPtrMap.insert(std::make_pair(cs,funPtr)).second;
465 funPtrToCallSitesMap[funPtr].insert(cs);
466 assert(added &&
"adding the same indirect callsite twice?");
470 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
471 assert(it!=indCallSiteToFunPtrMap.end() &&
"indirect callsite not have a function pointer?");
476 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
477 assert(it!=funPtrToCallSitesMap.end() &&
"function pointer not used at any indirect callsite?");
482 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
486 return (funPtrToCallSitesMap.find(
id) != funPtrToCallSitesMap.end());
506 PAGEdge::PAGEdgeSetTy::const_iterator it = edgeSet.find(&edge);
507 assert(it != edgeSet.end() &&
"can not find pag edge");
547 if(
const ObjPN* objPN = SVFUtil::dyn_cast<ObjPN>(node))
581 assert(SVFUtil::isa<ObjPN>(node) &&
"need an object node");
582 ObjPN* obj = SVFUtil::cast<ObjPN>(node);
624 assert(obj &&
"not an object node?");
630 if (
FIObjPN* fiNode = SVFUtil::dyn_cast<FIObjPN>(node))
632 return (fiNode->getMemObj()->hasPtrObj() ==
false);
634 else if (
GepObjPN* gepNode = SVFUtil::dyn_cast<GepObjPN>(node))
636 return (gepNode->getMemObj()->isNonPtrFieldObj(gepNode->getLocationSet()));
638 else if (SVFUtil::isa<DummyObjPN>(node))
644 assert(
false &&
"expecting a object node");
664 nodeNumAfterPAGBuild = num;
679 assert(SVFUtil::isa<ObjPN>(node) &&
"need an object node");
680 const ObjPN* obj = SVFUtil::cast<ObjPN>(node);
774 assert(
hasGNode(i) ==
false &&
"This NodeID clashes here. Please check NodeIDAllocator. Switch Strategy::DEBUG to SEQ or DENSE");
780 assert(
hasGNode(i) ==
false &&
"This NodeID clashes here. Please check NodeIDAllocator. Switch Strategy::DEBUG to SEQ or DENSE");
855 void dump(std::string name);
871 template<>
struct GraphTraits<
SVF::PAGNode*> :
public GraphTraits<SVF::GenericNode<SVF::PAGNode,SVF::PAGEdge>* >
876 template<>
struct GraphTraits<Inverse<SVF::PAGNode *> > :
public GraphTraits<Inverse<SVF::GenericNode<SVF::PAGNode,SVF::PAGEdge>* > >
880 template<>
struct GraphTraits<SVF::
PAG*> :
public GraphTraits<SVF::GenericGraph<SVF::PAGNode,SVF::PAGEdge>* >
std::vector< const CopyPE * > CopyPEList
Map< const PAGNode *, BinaryOPList > BinaryNodeMap
iterator begin()
Iterators.
bool hasPAGEdgeList(const ICFGNode *inst) const
Whether this instruction has PAG Edge.
NodeID addValNode(const Value *val, NodeID i)
Add a value (pointer) node.
static PAG * pag
Singleton pattern here to enable instance of PAG can only be created once.
const PAGNode * getFunRet(const SVFFunction *func) const
Get function return list.
bool hasCallSiteArgsMap(const CallBlockNode *cs) const
Callsite has argument list.
bool hasValSym(const Value *val)
static bool isBlkObj(NodeID id)
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
std::vector< const UnaryOPPE * > UnaryOPList
NodeID getBaseValNode(NodeID nodeId)
Base and Offset methods for Value and Object node.
MemObj * getBlkObj() const
static void handleBlackHole(bool b)
PAG build configurations.
void addToInstPAGEdgeList(ICFGNode *inst, PAGEdge *edge)
Add a PAGEdge into instruction map.
const MemObj * getBlackHoleObj() const
NodeID addConstantObjNode()
NodeID addGepObjNode(const MemObj *obj, const LocationSet &ls)
Add a field obj node, this method can only invoked by getGepObjNode.
IDToMemMapTy & idToObjMap()
ICFG * getICFG()
Return ICFG.
MemObj * getConstantObj() const
bool isBlkObjOrConstantObj(NodeID id) const
void addFunRet(const SVFFunction *fun, const PAGNode *ret)
Add function returns.
Map< const SVFFunction *, PAGEdgeSet > FunToPAGEdgeSetMap
SymID blackholeSymID() const
const MemObj * getMemObj() const
Return memory object.
const MemObj * addDummyMemObj(NodeID i, const Type *type)
SymID getVarargSym(const Function *val) const
void addGlobalPAGEdge(const PAGEdge *edge)
Get global PAGEdges (not in a procedure)
const MemObj * getObject(const ObjPN *node) const
CallPE * addCallPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Call edge.
BinaryOPPE * addBinaryOPPE(NodeID src, NodeID dst)
Add Copy edge.
SymID getRetSym(const Function *val) const
virtual ~PAG()
Destructor.
NodeID addVarargNode(const SVFFunction *, PAGNode *node, NodeID i)
Add a unique vararg node for a procedure.
Map< NodeID, NodeID > NodeToNodeMap
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
bool addEdge(PAGNode *src, PAGNode *dst, PAGEdge *edge)
Add an edge into PAG.
void addFunArgs(const SVFFunction *fun, const PAGNode *arg)
Get/set method for function/callsite arguments and returns.
u32_t getNodeNumAfterPAGBuild() const
bool funHasRet(const SVFFunction *func) const
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
bool isNonPointerObj(NodeID id) const
static bool isNullPtr(NodeID id)
GenericNode< PAGNode, PAGEdge >::GEdgeSetTy PAGEdgeSetTy
BinaryNodeMap binaryNodeMap
A set of binary edges.
Size_t getValueNodeNum() const
void destroy()
Clean up memory.
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
NodeID addDummyValNode(NodeID i)
PAGEdgeSet globPAGEdgesSet
Global PAGEdges without control flow information.
const Value * getGlobalRep(const Value *val) const
find the unique defined global across multiple modules
u32_t edgeNum
total num of node
Map< const RetBlockNode *, const PAGNode * > CSToRetMap
static bool isConstantObj(NodeID id)
bool isUnaryNode(const PAGNode *node) const
Whether this PAGNode is an unary node.
Map< const SVFFunction *, PAGNodeList > FunToArgsListMap
void addActualParms(const PAGNode *ap)
Add actual parameters.
LocationSet getLocationSetFromBaseNode(NodeID nodeId)
NodeID getReturnNode(const SVFFunction *func) const
GetReturnNode - Return the unique node representing the return value of a function.
u32_t nodeNum
total num of edge
NodeID addObjNode(const Value *val, NodeID i)
Add a memory obj node.
Map< const CallBlockNode *, PAGNodeList > CSToArgsListMap
void initialiseCandidatePointers()
Initialize candidate pointers.
NodeID addDummyValNode()
Add a dummy value/object node according to node ID (llvm value is null)
NodeID getObjectNode(const MemObj *mem)
getObject - return mem object id
Map< const SVFFunction *, const PAGNode * > FunToRetMap
SymID nullPtrSymID() const
ValueToIDMapTy & valSyms()
Get different kinds of syms maps.
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
NodeID addDummyObjNode(NodeID i, const Type *type)
const MemObj * getObject(NodeID id) const
NodeLocationSetMap & getGepObjNodeMap()
Return GepObjNodeMap.
Map< const PAGNode *, CmpPEList > CmpNodeMap
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Inst2PAGEdgesMap inst2PTAPAGEdgesMap
Map a instruction to its PointerAnalysis related PAGEdges.
PAGEdge::PAGKindToEdgeSetMapTy PTAPAGEdgeKindToSetMap
void view()
View graph from the debugger.
UnaryNodeMap unaryNodeMap
A set of unary edges.
Map< const ICFGNode *, PAGEdgeList > Inst2PAGEdgesMap
Size_t getFieldObjNodeNum() const
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
PAGEdgeSet & getGlobalPAGEdgeSet()
Get global PAGEdges (not in a procedure)
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
bool isPTAEdge() const
Whether src and dst nodes are both of pointer type.
void addCallSiteArgs(CallBlockNode *callBlockNode, const PAGNode *arg)
Add callsite arguments.
MemObj * getObj(SymID id) const
const MemObj * getConstantObj() const
NodeID getObjectNode(const Value *V)
void addBinaryNode(const PAGNode *res, const BinaryOPPE *edge)
Add phi node information.
OrderedNodeSet candidatePointers
GepPE * addGepPE(NodeID src, NodeID dst, const LocationSet &ls, bool constGep)
Add Gep edge.
void setNodeNumAfterPAGBuild(u32_t num)
NodeID addVarargNode(const SVFFunction *val, NodeID i)
Add a unique vararg node for a procedure.
NodeID getFIObjNode(const MemObj *obj) const
Get a field-insensitive obj PAG node according to a mem obj.
NodeID addDummyObjNode(const Type *type=nullptr)
NodeID addRetNode(const SVFFunction *, PAGNode *node, NodeID i)
Add a unique return node for a procedure.
NodeBS & getAllFieldsObjNode(const MemObj *obj)
Get all fields of an object.
bool isConstantObj(NodeID id) const
PAGEdge::PAGEdgeSetTy & getPTAEdgeSet(PAGEdge::PEDGEK kind)
Get PTA edges set according to its kind.
PAGEdge::PAGKindToEdgeSetMapTy PAGEdgeKindToSetMap
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis. ...
const PAGNodeList & getCallSiteArgsList(const CallBlockNode *cs) const
Get callsite argument list.
std::pair< NodeID, Size_t > NodeOffset
NodeID addBlackholeObjNode()
Map< NodePair, NodeID > NodePairSetMap
PAGEdge * addBlackHoleAddrPE(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
NodeID getVarargNode(const SVFFunction *func) const
getVarargNode - Return the unique node representing the variadic argument of a variadic function...
bool hasGNode(NodeID id) const
Has a node.
OrderedMap< const CallBlockNode *, NodeID > CallSiteToFunPtrMap
NodeID addGepValNode(const Value *curInst, const Value *val, const LocationSet &ls, NodeID i, const Type *type, u32_t fieldidx)
Add a temp field value node, this method can only invoked by getGepValNode.
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
PAGEdge * hasLabeledEdge(PAGNode *src, PAGNode *dst, PAGEdge::PEDGEK kind, const ICFGNode *cs)
bool isBlkPtr(NodeID id) const
IDToNodeMapTy::iterator iterator
Node Iterators.
Map< const Value *, NodeLocationSetMap > GepValPNMap
SymID constantSymID() const
std::vector< const PAGEdge * > PAGEdgeList
void addFormalParms(const PAGNode *fp)
Add formal parameters.
NodeID addRetNode(const SVFFunction *val, NodeID i)
Add a unique return node for a procedure.
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
SymID getObjSym(const Value *val) const
const MemObj * createDummyObj(SymID symId, const Type *type)
Can only be invoked by PAG::addDummyNode() when creaing PAG from file.
NodeBS getFieldsAfterCollapse(NodeID id)
NodeID getGepValNode(const Value *curInst, NodeID base, const LocationSet &ls) const
Due to constaint expression, curInst is used to distinguish different instructions (e...
NodeID getGepObjNode(const MemObj *obj, const LocationSet &ls)
Get a field PAG Object node according to base mem obj and offset.
AddrPE * addAddrPE(NodeID src, NodeID dst)
Add Address edge.
Size_t getPAGEdgeNum() const
NodeID getBlackHoleNode() const
Get black hole and constant id.
bool callsiteHasRet(const RetBlockNode *cs) const
CmpNodeMap & getCmpNodeMap()
Get all phi copy edges.
BinaryNodeMap & getBinaryNodeMap()
Get all phi copy edges.
PAGEdgeList & getInstPAGEdgeList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
NodeID addNode(PAGNode *node, NodeID i)
add node into PAG
void addCallSite(const CallBlockNode *call)
NodeID getNullPtr() const
CopyPE * addCopyPE(NodeID src, NodeID dst)
Add Copy edge.
NormalGepPE * addNormalGepPE(NodeID src, NodeID dst, const LocationSet &ls)
Add Offset(Gep) edge.
Set< const PAGEdge * > PAGEdgeSet
static bool isBlkPtr(NodeID id)
std::vector< const PAGNode * > PAGNodeList
FunExitBlockNode * getFunExitBlockNode(const SVFFunction *fun)
Add a function exit node.
const CallSiteSet & getIndCallSites(NodeID funPtr) const
UnaryNodeMap & getUnaryNodeMap()
Get all unary edges.
Set< const CallBlockNode * > CallSiteSet
SVFModule * getModule()
Module.
Size_t getObjectNodeNum() const
const PAGNode * getCallSiteRet(const RetBlockNode *cs) const
Get callsite return.
NodeID getFIObjNode(NodeID id) const
PAGEdgeList & getInstPTAPAGEdgeList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
void addActualRet(const PAGNode *ar)
Add actual return parameter.
bool hasPTAPAGEdgeList(const ICFGNode *inst) const
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...
SymID getValSym(const Value *val)
Get different kinds of syms.
NodeID addValNode(const Value *, PAGNode *node, NodeID i)
Add a value (pointer) node.
Map< const PAGNode *, CopyPEList > PHINodeMap
FunPtrToCallSitesMap funPtrToCallSitesMap
Map a function pointer to the callsites where it is used.
void addGNode(NodeID id, NodeType *node)
Add a Node.
void setICFGNode(ICFGNode *node)
VariantGepPE * addVariantGepPE(NodeID src, NodeID dst)
Add Variant(Gep) edge.
NodeID getBaseObjNode(NodeID id) const
CmpPE * addCmpPE(NodeID src, NodeID dst)
Add Copy edge.
RetPE * addRetPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Return edge.
Inst2PAGEdgesMap inst2PAGEdgesMap
Map a instruction to its PAGEdges.
PAGEdge::PAGEdgeSetTy & getEdgeSet(PAGEdge::PEDGEK kind)
Get/set methods to get control flow information of a PAGEdge.
std::string getGraphName() const
Return graph name.
SVFModule * getModule()
Get LLVM Module.
SymID getSymId() const
Get the memory object id.
SymID blkPtrSymID() const
PHINodeMap & getPhiNodeMap()
Get all phi copy edges.
Map< NodeOffset, NodeID > NodeOffsetMap
void dump(std::string name)
Dump PAG.
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
const MemObj * getBaseObj(NodeID id) const
Size_t getFieldValNodeNum() const
PAGEdge * getIntraPAGEdge(NodeID src, NodeID dst, PAGEdge::PEDGEK kind)
Get an edge according to src, dst and kind.
GepValPNMap GepValNodeMap
Map a pair<base,off> to a gep value node id.
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Thread fork edge for parameter passing.
const PAGNodeList & getFunArgsList(const SVFFunction *func) const
Get function arguments list.
Function * getLLVMFun() const
std::pair< NodeID, LocationSet > NodeLocationSet
bool hasFunArgsList(const SVFFunction *func) const
Function has arguments list.
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
bool isValidTopLevelPtr(const PAGNode *node)
void addIndirectCallsites(const CallBlockNode *cs, NodeID funPtr)
std::vector< const CmpPE * > CmpPEList
static NodeIDAllocator * get(void)
Return (singleton) allocator.
PAGEdge * getIntraPAGEdge(PAGNode *src, PAGNode *dst, PAGEdge::PEDGEK kind)
std::vector< const BinaryOPPE * > BinaryOPList
FunEntryBlockNode * getFunEntryBlockNode(const SVFFunction *fun)
Add a function entry node.
StorePE * addStorePE(NodeID src, NodeID dst, const IntraBlockNode *val)
Add Store edge.
llvm::SparseBitVector NodeBS
OrderedSet< NodeID > OrderedNodeSet
void addFormalRet(const PAGNode *fr)
Add actual return parameter.
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Thread join edge for parameter passing.
bool isCmpNode(const PAGNode *node) const
Whether this PAGNode is a result operand a of phi node.
FunToRetMap & getFunRets()
Get function return list.
Map< const PAGNode *, UnaryOPList > UnaryNodeMap
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
void addCallSiteRets(RetBlockNode *retBlockNode, const PAGNode *arg)
Add callsite returns.
Size_t getPAGNodeNum() const
Node and edge statistics.
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
void addCmpNode(const PAGNode *res, const CmpPE *edge)
Add phi node information.
NodeID addObjNode(const Value *, PAGNode *node, NodeID i)
Add a memory obj node.
NodeID addBlackholePtrNode()
bool isNullPtr(NodeID id) const
PAGEdgeToSetMapTy PAGKindToEdgeSetMapTy
bool findPAGNode(NodeID id) const
Get a pag node according to its ID.
bool isPhiNode(const PAGNode *node) const
Whether this PAGNode is a result operand a of phi node.
LoadPE * addLoadPE(NodeID src, NodeID dst)
Add Load edge.
NodeLocationSetMap GepObjNodeMap
Map a pair<base,off> to a gep obj node id.
NodeID addFIObjNode(const MemObj *obj)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
CmpNodeMap cmpNodeMap
A set of comparision edges.
Map< NodeID, NodeBS > MemObjToFieldsMap
NodeType * getGNode(NodeID id) const
Get a node.
PHINodeMap phiNodeMap
A set of phi copy edges.
PAG(bool buildFromFile)
all the callsites of a program
PAGEdge * hasNonlabeledEdge(PAGNode *src, PAGNode *dst, PAGEdge::PEDGEK kind)
CSToRetMap & getCallSiteRets()
Get callsite return.
void addUnaryNode(const PAGNode *res, const UnaryOPPE *edge)
Add unary node information.
const CallSiteSet & getCallSiteSet() const
NodeID getConstantNode() const
bool isBinaryNode(const PAGNode *node) const
Whether this PAGNode is a result operand a of phi node.
UnaryOPPE * addUnaryOPPE(NodeID src, NodeID dst)
Add Unary edge.
Map< NodeLocationSet, NodeID > NodeLocationSetMap
SymbolTableInfo * symInfo
bool hasValueNode(const Value *V)
NodeID nodeNumAfterPAGBuild
bool isBuiltFromFile()
Whether this PAG built from a txt file.
bool isBlkObj(NodeID id) const
bool isFunPtr(NodeID id) const
void addPhiNode(const PAGNode *res, const CopyPE *edge)
Add phi node information.
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
bool isIndirectCallSites(const CallBlockNode *cs) const
NodeID getFunPtr(const CallBlockNode *cs) const
std::map< Key, Value, Compare, Allocator > OrderedMap