30 #ifndef INCLUDE_SVFIR_H_
31 #define INCLUDE_SVFIR_H_
103 static std::unique_ptr<SVFIR>
pag;
106 SVFIR(
bool buildFromFile);
119 pag = std::unique_ptr<SVFIR>(
new SVFIR(buildFromFile));
163 assert(
svfModule &&
"empty SVFModule! Build SVF IR first!");
183 assert(
chgraph &&
"empty ICFG! Build SVF IR first!");
194 assert(
callGraph &&
"empty PTACallGraph! Build SVF IR first!");
278 assert(it !=
funArgsListMap.end() &&
"this function doesn't have arguments");
307 assert(it !=
callSiteRetMap.end() &&
"this call site doesn't have return");
322 FunToRetMap::const_iterator it =
funRetMap.find(func);
323 assert(it !=
funRetMap.end() &&
"this function doesn't have return");
363 assert(it!=
funPtrToCallSitesMap.end() &&
"function pointer not used at any indirect callsite?");
383 SVFStmt edge(src, dst, kind,
false);
385 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
386 assert(it != edgeSet.end() &&
"can not find pag edge");
398 if (
const ObjVar* objPN = SVFUtil::dyn_cast<ObjVar>(node))
446 assert(obj &&
"not an object node?");
462 assert(SVFUtil::isa<ObjVar>(node) &&
"need an object node");
463 const ObjVar* obj = SVFUtil::cast<ObjVar>(node);
499 assert(added &&
"duplicated edge, not added!!!");
501 if (edge->
isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
541 assert(added &&
"adding the same indirect callsite twice?");
556 assert(mem->
getId() == i &&
"not same object id?");
617 "This NodeID clashes here. Please check NodeIDAllocator. Switch "
618 "Strategy::DBUG to SEQ or DENSE");
625 "This NodeID clashes here. Please check NodeIDAllocator. Switch "
626 "Strategy::DBUG to SEQ or DENSE");
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
void addActualParms(const SVFVar *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
NodeType * getGNode(NodeID id) const
Get a node.
bool hasGNode(NodeID id) const
Has a node.
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
FunExitICFGNode * getFunExitICFGNode(const SVFFunction *fun)
Add a function exit node.
Set< const SVFStmt * > SVFStmtSet
NodeID getBlackHoleNode() const
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
NodeID addNode(SVFVar *node, NodeID i)
Add a node into the graph.
SymbolTableInfo * getSymbolInfo() const
const MemObj * getBlackHoleObj() const
NodeID getConstantNode() const
const MemObj * getConstantObj() const
const MemObj * getMemObj(const SVFValue *val) const
get MemObj according to LLVM value
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
bool isConstDataOrConstGlobal() const
SymID getId() const
Get the memory object id.
static NodeIDAllocator * get(void)
Return (singleton) allocator.
const MemObj * getMemObj() const
Return memory object.
void addActualRet(const SVFVar *ar)
Add actual return parameter.
static void releaseSVFIR()
bool hasPTASVFStmtList(const ICFGNode *inst) const
NodeID addFIObjNode(const MemObj *obj)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
NodeID addVarargNode(const SVFFunction *, SVFVar *node, NodeID i)
Add a unique vararg node for a procedure.
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Map< const SVFVar *, PhiStmt * > PHINodeMap
NodeOffsetMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
PTACallGraph * getCallGraph()
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
bool isBlkObj(NodeID id) const
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
NodeID getFunPtr(const CallICFGNode *cs) const
bool isNullPtr(NodeID id) const
NodeID addRetNode(const SVFFunction *, SVFVar *node, NodeID i)
Add a unique return node for a procedure.
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
NodeID addObjNode(const SVFValue *val, NodeID i)
Add a memory obj node.
static void handleBlackHole(bool b)
SVFIR build configurations.
const MemObj * getObject(const ObjVar *node) const
NodeID getFIObjVar(const MemObj *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
NodeID addBlackholePtrNode()
Set< const CallICFGNode * > CallSiteSet
NodeID addBlackholeObjNode()
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
const MemObj * getObject(NodeID id) const
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Map< const CallICFGNode *, SVFVarList > CSToArgsListMap
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
const SVFVar * getFunRet(const SVFFunction *func) const
Get function return list.
NodeID addDummyObjNode(NodeID i, const SVFType *type)
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
NodeID addRetNode(const SVFFunction *val, NodeID i)
Add a unique return node for a procedure.
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
u32_t getFieldObjNodeNum() const
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Map< const RetICFGNode *, const SVFVar * > CSToRetMap
virtual ~SVFIR()
Destructor.
bool isIndirectCallSites(const CallICFGNode *cs) const
PHINodeMap phiNodeMap
A set of phi copy edges.
NodeBS getFieldsAfterCollapse(NodeID id)
std::pair< NodeID, APOffset > NodeOffset
Map< const SVFFunction *, SVFVarList > FunToArgsListMap
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
void setModule(SVFModule *mod)
Set/Get LLVM Module.
void addFunRet(const SVFFunction *fun, const SVFVar *ret)
Add function returns.
NodeID addGepValNode(const SVFValue *curInst, const SVFValue *val, const AccessPath &ap, NodeID i, const SVFType *type)
Add a temp field value node, this method can only invoked by getGepValVar.
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
bool isValidTopLevelPtr(const SVFVar *node)
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
bool isConstantObj(NodeID id) const
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
std::vector< const SVFVar * > SVFVarList
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
CSToRetMap & getCallSiteRets()
Get callsite return.
Map< NodeID, NodeID > NodeToNodeMap
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
void destroy()
Clean up memory.
NodeID addGepObjNode(const MemObj *obj, const APOffset &apOffset, const NodeID gepId)
Add a field obj node, this method can only invoked by getGepObjVar.
void addCallSiteArgs(CallICFGNode *callBlockNode, const SVFVar *arg)
Add callsite arguments.
bool isBlkPtr(NodeID id) const
Get black hole and constant id.
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
NodeID addVarargNode(const SVFFunction *val, NodeID i)
Add a unique vararg node for a procedure.
NodeID addDummyValNode(NodeID i)
Add a dummy value/object node according to node ID (llvm value is null)
std::vector< const SVFStmt * > SVFStmtList
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
NodeBS & getAllFieldsObjVars(const MemObj *obj)
Get all fields of an object.
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
std::pair< NodeID, AccessPath > NodeAccessPath
void setICFG(ICFG *i)
Set/Get ICFG.
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Map< NodeAccessPath, NodeID > NodeAccessPathMap
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
const MemObj * addDummyMemObj(NodeID i, const SVFType *type)
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
u32_t getFieldValNodeNum() const
Node and edge statistics.
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
bool isFunPtr(NodeID id) const
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
NodeID addValNode(const SVFValue *val, NodeID i, const SVFBaseNode *gNode)
add node into SVFIR
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
void addCallSite(const CallICFGNode *call)
Add callsites.
static std::unique_ptr< SVFIR > pag
call graph
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
const SVFVarList & getFunArgsList(const SVFFunction *func) const
Get function arguments list.
void setCHG(CommonCHGraph *c)
Set/Get CHG.
const CallSiteSet & getCallSiteSet() const
Get all callsites.
bool callsiteHasRet(const RetICFGNode *cs) const
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Map< NodeID, NodeBS > MemObjToFieldsMap
Map< NodePair, NodeID > NodePairSetMap
void setCallGraph(PTACallGraph *c)
Set/Get CG.
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
FunToRetMap & getFunRets()
Get function return list.
OrderedNodeSet candidatePointers
const CallSiteSet & getIndCallSites(NodeID funPtr) const
SVFIR(bool buildFromFile)
Constructor.
NodeOffsetMap & getGepObjNodeMap()
Return GepObjVarMap.
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
void addFunArgs(const SVFFunction *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
bool hasFunArgsList(const SVFFunction *func) const
Function has arguments list.
friend class TypeBasedHeapCloning
Map< const SVFFunction *, SVFStmtSet > FunToPAGEdgeSetMap
NodeID getFIObjVar(NodeID id) const
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
PTACallGraph * callGraph
all the callsites of a program
NodeID getGepValVar(const SVFValue *curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
bool isBlkObjOrConstantObj(NodeID id) const
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
NodeID getGepObjVar(const MemObj *obj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Map< const SVFFunction *, const SVFVar * > FunToRetMap
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Map< NodeOffset, NodeID > NodeOffsetMap
NodeID addValNode(const SVFValue *, SVFVar *node, NodeID i)
Add a value (pointer) node.
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
void initialiseCandidatePointers()
Initialize candidate pointers.
const MemObj * getBaseObj(NodeID id) const
Map< const SVFValue *, NodeAccessPathMap > GepValueVarMap
NodeID addObjNode(const SVFValue *, SVFVar *node, NodeID i)
Add a memory obj node.
FunPtrToCallSitesMap funPtrToCallSitesMap
NodeID addDummyObjNode(const SVFType *type)
bool funHasRet(const SVFFunction *func) const
NodeID addConstantObjNode()
bool isPTAEdge() const
Whether src and dst nodes are both of pointer type.
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
void setICFGNode(ICFGNode *node)
static bool isConstantObj(NodeID id)
static bool isBlkPtr(NodeID id)
special value
static bool isNullPtr(NodeID id)
static bool isBlkObj(NodeID id)
const MemObj * createDummyObj(SymID symId, const SVFType *type)
Can only be invoked by SVFIR::addDummyNode() when creating SVFIR from file.
OrderedSet< NodeID > OrderedNodeSet
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
std::map< Key, Value, Compare, Allocator > OrderedMap
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set