106 static std::unique_ptr<PAG>
pag;
112 PAG(
bool buildFromFile);
125 pag = std::unique_ptr<PAG>(
new PAG(buildFromFile));
146 assert(
false &&
"the Node is not a ValVar");
156 assert(
false &&
"the Node is not an ObjVar");
166 assert(
false &&
"the Node is not a BaseObjVar");
176 assert(
false &&
"the Node is not a GepObjVar");
234 assert(
icfg->totalICFGNode>0 &&
"empty ICFG! Build PAG first!");
244 assert(
chgraph &&
"empty ICFG! Build PAG first!");
251 assert(
callGraph &&
"empty CallGraph! Build PAG first!");
267 "No module found! Reading from a file other than LLVM-IR?");
382 assert(it !=
funArgsListMap.end() &&
"this function doesn't have arguments");
411 assert(it !=
callSiteRetMap.end() &&
"this call site doesn't have return");
426 FunToRetMap::const_iterator it =
funRetMap.find(func);
427 assert(it !=
funRetMap.end() &&
"this function doesn't have return");
467 assert(it!=
funPtrToCallSitesMap.end() &&
"function pointer not used at any indirect callsite?");
487 SVFStmt edge(src, dst, kind,
false);
489 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
490 assert(it != edgeSet.end() &&
"can not find pag edge");
513 return gepVar->getBaseNode();
607 assert(added &&
"duplicated edge, not added!!!");
659 assert(added &&
"adding the same indirect callsite twice?");
Class representing a function argument variable in the PAG.
NodeID getId() const
Get the memory object id.
std::vector< std::pair< const ICFGNode *, s64_t > > SuccAndCondPairVec
void addActualParms(const ValVar *ap)
Add actual parameters.
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
void addFormalParms(const SVFVar *fp)
Add formal parameters.
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
GEdgeKind getEdgeKind() const
IDToNodeMapTy IDToNodeMap
NodeType * getGNode(NodeID id) const
OrderedMap< NodeID, NodeType * > IDToNodeMapTy
const ValVar * getBaseNode(void) const
Return the base object from which this GEP node came from.
const AccessPath & getAccessPath() const
Class representing a heap object variable in the PAG.
static NodeIDAllocator * get(void)
Return (singleton) allocator.
NodeID getConstantNode() const
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
PAG edge map containing all PAGEdges.
NodeID getBlackHoleNode() const
NodeID addNode(SVFVar *node)
Add a node into the graph.
ObjTypeInfo * createObjTypeInfo(const SVFType *type)
Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy ...
PAGBase(bool buildFromFile)
ObjTypeInfo * getObjTypeInfo(NodeID id) const
Set< const SVFStmt * > SVFStmtSet
static bool isBlkObj(NodeID id)
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
PAG edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
IDToTypeInfoMapTy & idToObjTypeInfoMap()
Get different kinds of syms maps.
void setModuleIdentifier(const std::string &moduleIdentifier)
NodeID addBaseObjNode(BaseObjVar *node)
NodeID addDummyObjNode(NodeID i, const SVFType *type)
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into PAG.
void addCallSiteRets(RetICFGNode *retBlockNode, const ValVar *arg)
Add callsite returns.
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const ICFGNode *node)
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
PAG(bool buildFromFile)
Constructor.
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
std::pair< NodeID, APOffset > GepOffset
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
NodeID addIntrinsicValNode(NodeID i, const SVFType *type)
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const ICFGNode *node)
void setCHG(CommonCHGraph *c)
Set/Get CHG.
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
NodeBS getFieldsAfterCollapse(NodeID id)
bool isFunPtr(NodeID id) const
NodeID getFunPtr(const CallICFGNode *cs) const
void addFunArgs(FunEntryICFGNode *funEntryBlockNode, const FunObjVar *fun, const ValVar *arg)
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
std::vector< const ValVar * > ValVarList
static std::string pagReadFromTxt
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
Map< const RetICFGNode *, const ValVar * > CSToRetMap
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
bool isValidTopLevelPtr(const SVFVar *node)
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
const FunObjVar * getFunObjVar(const std::string &name)
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
void addFunArgs(const FunObjVar *fun, const ValVar *arg)
Get/set method for function/callsite arguments and returns.
static void setPagFromTXT(const std::string &txt)
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
NodeID addAsmPCValNode(NodeID i, const SVFType *type)
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
const BaseObjVar * getBaseObject(NodeID id) const
Map< const FunObjVar *, ValVarList > FunToArgsListMap
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has PAG Edge.
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Map< NodeID, NodeBS > MemObjToFieldsMap
const CallGraph * getCallGraph()
Get CG.
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
u32_t getFieldObjNodeNum() const
void addCallSite(const CallICFGNode *call)
Add callsites.
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Map< NodeAccessPath, NodeID > NodeAccessPathMap
bool isConstantObj(NodeID id) const
bool callsiteHasRet(const RetICFGNode *cs) const
void addGepValObjFromDB(NodeID curInstID, const GepValVar *gepValvar)
NodeID getGepValVar(NodeID curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
void destroy()
Clean up memory.
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
NodeID addDummyObjNode(const SVFType *type)
const ValVar * getBaseValVar(NodeID id) const
NodeID addValNode(NodeID i, const SVFType *type, const ICFGNode *icfgNode)
add node into PAG
Map< const CallICFGNode *, ValVarList > CSToArgsListMap
const IDToNodeMapTy & getSVFVarMap() const
Return the entire SVFID to SVFVar map.
friend class PAGBuilderFromFile
bool hasPTASVFStmtList(const ICFGNode *inst) const
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Map< const SVFVar *, CallPE * > FParmToCallPEMap
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
friend class GraphDBSVFIRBuilder
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
FunToRetMap & getFunRets()
Get function return list.
OffsetToGepVarMap & getGepObjNodeMap()
Return GepObjVarMap.
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge (phi-like: merges actual params from all call sites into formal param).
NodeID addBlackholeObjNode()
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
FunPtrToCallSitesMap funPtrToCallSitesMap
NodeID getFIObjVar(NodeID id) const
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Map< GepOffset, NodeID > OffsetToGepVarMap
const std::string & getModuleIdentifier() const
u32_t getFieldValNodeNum() const
Node and edge statistics.
CSToRetMap & getCallSiteRets()
Get callsite return.
virtual ~PAG()
Destructor.
bool isObjVar(NodeID id) const
Map< const FunObjVar *, SVFStmtSet > FunToPAGEdgeSetMap
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
CallGraph * callGraph
all the callsites of a program
const ValVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *node)
Map< NodeID, NodeID > NodeToNodeMap
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null).
Map< const FunObjVar *, const ValVar * > FunToRetMap
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr).
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
void initialiseCandidatePointers()
Initialize candidate pointers.
NodeID addGepObjNode(GepObjVar *gepObj, NodeID base, const APOffset &apOffset)
static bool pagReadFromTXT()
void setICFG(ICFG *i)
Set/Get ICFG.
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
bool funHasRet(const FunObjVar *func) const
NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode *icfgNode, const FunObjVar *callGraphNode, const SVFType *type)
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
const ValVar * getFunRet(const FunObjVar *func) const
Get function return list.
CallPE * getCallPEForFormalParm(const SVFVar *param) const
Get the CallPE for a formal parameter (phi-like, nullptr if not found).
const ObjVar * getObjVar(NodeID id) const
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
bool isBaseObjVar(NodeID id) const
OrderedNodeSet candidatePointers
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj PAG node according to a mem obj.
friend class GraphDBClient
const ValVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
const BaseObjVar * getBaseObjVar(NodeID id) const
bool isIndirectCallSites(const CallICFGNode *cs) const
void setCallGraph(CallGraph *cg)
static void handleBlackHole(bool b)
PAG build configurations.
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
NodeID addGepValNode(NodeID curInst, const ValVar *base, const AccessPath &ap, NodeID i, const SVFType *type, const ICFGNode *node)
Add a temp field value node, this method can only invoked by getGepValVar.
friend class BVDataPTAImpl
NodeID addFIObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
NodeID addGlobalValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
const CallSiteSet & getIndCallSites(NodeID funPtr) const
const GepObjVar * getGepObjVar(NodeID id) const
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Map< const SVFVar *, PhiStmt * > PHINodeMap
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
NodeSet constantObjs
Constant objects and their fields, recorded when each object node is added.
void addFunRet(FunExitICFGNode *funExitBlockNode, const FunObjVar *fun, const ValVar *ret)
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
OffsetToGepVarMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
std::pair< NodeID, AccessPath > NodeAccessPath
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
NodeID addConstantObjNode()
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
void addFunRet(const FunObjVar *fun, const ValVar *ret)
Add function returns.
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
std::string moduleIdentifier
std::vector< const SVFStmt * > SVFStmtList
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
NodeID getBaseObjVarID(NodeID id) const
Base and Offset methods for Value and Object node.
bool isGepObjVar(NodeID id) const
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
FParmToCallPEMap fParmToCallPEMap
Map a formal param to its CallPE.
const ValVar * getValVar(NodeID id) const
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure).
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
static std::string pagFileName()
PHINodeMap phiNodeMap
A set of phi copy edges.
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Map< NodePair, NodeID > NodePairSetMap
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Map< NodeID, NodeAccessPathMap > GepValueVarMap
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a memory obj node.
Set< const CallICFGNode * > CallSiteSet
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
NodeID addBlackholePtrNode()
const ValVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
static std::unique_ptr< PAG > pag
Callgraph with direct calls only; no change allowed after init and use callgraph in PointerAnalysis f...
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure).
void addActualRet(const SVFVar *ar)
Add actual return parameter.
virtual bool isPTAEdge() const
Whether src and dst nodes are both of pointer type.
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
void setICFGNode(ICFGNode *node)
NodeID getId() const
Get ID.
Represents a stack-allocated object variable in the PAG (SVF Intermediate Representation) @inherits B...
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
LLVM_NODISCARD bool isa(const Y &Val)
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
std::map< Key, Value, Compare, Allocator > OrderedMap
OrderedSet< NodeID > OrderedNodeSet
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map