Static Value-Flow Analysis
SVFIR.h
Go to the documentation of this file.
1 //===- SVFIR.h -- IR of SVF ---------------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * SVFIR.h
25  *
26  * Created on: 31, 12, 2021
27  * Author: Yulei Sui
28  */
29 
30 #ifndef INCLUDE_SVFIR_H_
31 #define INCLUDE_SVFIR_H_
32 
33 #include "Graphs/IRGraph.h"
34 
35 namespace SVF
36 {
37 class CommonCHGraph;
43 class SVFIR : public IRGraph
44 {
45  friend class SVFIRBuilder;
46  friend class ExternalPAG;
47  friend class PAGBuilderFromFile;
48  friend class TypeBasedHeapCloning;
49  friend class SVFIRWriter;
50  friend class SVFIRReader;
51  friend class BVDataPTAImpl;
52 
53 public:
58  typedef std::vector<const SVFStmt*> SVFStmtList;
59  typedef std::vector<const SVFVar*> SVFVarList;
68  typedef std::pair<NodeID, APOffset> NodeOffset;
69  typedef std::pair<NodeID, AccessPath> NodeAccessPath;
73  typedef std::pair<const SVFType*, std::vector<AccessPath>> SVFTypeLocSetsPair;
76 
77 private:
98  ICFG* icfg; // ICFG
99  CommonCHGraph* chgraph; // class hierarchy graph
102 
103  static std::unique_ptr<SVFIR> pag;
104 
106  SVFIR(bool buildFromFile);
107 
109  void destroy();
110 
111 public:
112 
114 
115  static inline SVFIR* getPAG(bool buildFromFile = false)
116  {
117  if (pag == nullptr)
118  {
119  pag = std::unique_ptr<SVFIR>(new SVFIR(buildFromFile));
120  }
121  return pag.get();
122  }
123  static void releaseSVFIR()
124  {
125  pag = nullptr;
126  }
130  {
131  return memToFieldsMap;
132  }
135  {
136  return GepObjVarMap;
137  }
140  {
141  return candidatePointers;
142  }
145 
147  virtual ~SVFIR()
148  {
149  destroy();
150  }
152 
153  static void handleBlackHole(bool b);
156  inline void setModule(SVFModule* mod)
158  {
159  svfModule = mod;
160  }
162  {
163  assert(svfModule && "empty SVFModule! Build SVF IR first!");
164  return svfModule;
165  }
167  inline void setICFG(ICFG* i)
168  {
169  icfg = i;
170  }
171  inline ICFG* getICFG() const
172  {
173  assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
174  return icfg;
175  }
177  inline void setCHG(CommonCHGraph* c)
178  {
179  chgraph = c;
180  }
182  {
183  assert(chgraph && "empty ICFG! Build SVF IR first!");
184  return chgraph;
185  }
186 
188  inline void setCallGraph(PTACallGraph* c)
189  {
190  callGraph = c;
191  }
193  {
194  assert(callGraph && "empty PTACallGraph! Build SVF IR first!");
195  return callGraph;
196  }
197 
199 
202  {
203  return KindToSVFStmtSetMap[kind];
204  }
207  {
208  return KindToPTASVFStmtSetMap[kind];
209  }
211  inline bool hasSVFStmtList(const ICFGNode* inst) const
212  {
213  return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
214  }
215  inline bool hasPTASVFStmtList(const ICFGNode* inst) const
216  {
217  return icfgNode2PTASVFStmtsMap.find(inst) !=
219  }
221  inline SVFStmtList& getSVFStmtList(const ICFGNode* inst)
222  {
223  return icfgNode2SVFStmtsMap[inst];
224  }
227  {
228  return icfgNode2PTASVFStmtsMap[inst];
229  }
231  inline void addToSVFStmtList(ICFGNode* inst, SVFStmt* edge)
232  {
233  edge->setICFGNode(inst);
234  icfgNode2SVFStmtsMap[inst].push_back(edge);
235  if (edge->isPTAEdge())
236  icfgNode2PTASVFStmtsMap[inst].push_back(edge);
237  }
239  inline void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair& locSets)
240  {
241  typeLocSetsMap[argId]=locSets;
242  }
245  {
246  return typeLocSetsMap[argId];
247  }
250  {
251  return globSVFStmtSet;
252  }
254  inline const CallSiteSet& getCallSiteSet() const
255  {
256  return callSiteSet;
257  }
259  inline bool isPhiNode(const SVFVar* node) const
260  {
261  return phiNodeMap.find(node) != phiNodeMap.end();
262  }
263 
265  inline bool hasFunArgsList(const SVFFunction* func) const
266  {
267  return (funArgsListMap.find(func) != funArgsListMap.end());
268  }
271  {
272  return funArgsListMap;
273  }
275  inline const SVFVarList& getFunArgsList(const SVFFunction* func) const
276  {
277  FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
278  assert(it != funArgsListMap.end() && "this function doesn't have arguments");
279  return it->second;
280  }
282  inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
283  {
284  return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
285  }
288  {
289  return callSiteArgsListMap;
290  }
292  inline const SVFVarList& getCallSiteArgsList(const CallICFGNode* cs) const
293  {
294  CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
295  assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
296  return it->second;
297  }
300  {
301  return callSiteRetMap;
302  }
304  inline const SVFVar* getCallSiteRet(const RetICFGNode* cs) const
305  {
306  CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
307  assert(it != callSiteRetMap.end() && "this call site doesn't have return");
308  return it->second;
309  }
310  inline bool callsiteHasRet(const RetICFGNode* cs) const
311  {
312  return callSiteRetMap.find(cs) != callSiteRetMap.end();
313  }
316  {
317  return funRetMap;
318  }
320  inline const SVFVar* getFunRet(const SVFFunction* func) const
321  {
322  FunToRetMap::const_iterator it = funRetMap.find(func);
323  assert(it != funRetMap.end() && "this function doesn't have return");
324  return it->second;
325  }
326  inline bool funHasRet(const SVFFunction* func) const
327  {
328  return funRetMap.find(func) != funRetMap.end();
329  }
331 
333 
334  inline u32_t getFieldValNodeNum() const
335  {
336  return GepValObjMap.size();
337  }
338  inline u32_t getFieldObjNodeNum() const
339  {
340  return GepObjVarMap.size();
341  }
343 
345  NodeID getGepValVar(const SVFValue* curInst, NodeID base,
346  const AccessPath& ap) const;
347 
349 
351  {
352  return indCallSiteToFunPtrMap;
353  }
354  inline NodeID getFunPtr(const CallICFGNode* cs) const
355  {
356  CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
357  assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
358  return it->second;
359  }
360  inline const CallSiteSet& getIndCallSites(NodeID funPtr) const
361  {
362  FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
363  assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
364  return it->second;
365  }
366  inline bool isIndirectCallSites(const CallICFGNode* cs) const
367  {
368  return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
369  }
370  inline bool isFunPtr(NodeID id) const
371  {
372  return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
373  }
375 
378  {
379  return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
380  }
382  {
383  SVFStmt edge(src, dst, kind, false);
384  const SVFStmt::SVFStmtSetTy& edgeSet = getSVFStmtSet(kind);
385  SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
386  assert(it != edgeSet.end() && "can not find pag edge");
387  return (*it);
388  }
390 
394 
395  inline const MemObj* getObject(NodeID id) const
396  {
397  const SVFVar* node = getGNode(id);
398  if (const ObjVar* objPN = SVFUtil::dyn_cast<ObjVar>(node))
399  return getObject(objPN);
400  else
401  return nullptr;
402  }
403  inline const MemObj*getObject(const ObjVar* node) const
404  {
405  return node->getMemObj();
406  }
408 
410  NodeID getGepObjVar(const MemObj* obj, const APOffset& ap);
412  NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
414 
415  inline NodeID getFIObjVar(const MemObj* obj) const
416  {
417  return obj->getId();
418  }
419  inline NodeID getFIObjVar(NodeID id) const
420  {
421  return getBaseObjVar(id);
422  }
424 
426 
427  inline bool isBlkPtr(NodeID id) const
428  {
429  return (SymbolTableInfo::isBlkPtr(id));
430  }
431  inline bool isNullPtr(NodeID id) const
432  {
433  return (SymbolTableInfo::isNullPtr(id));
434  }
435  inline bool isBlkObjOrConstantObj(NodeID id) const
436  {
437  return (isBlkObj(id) || isConstantObj(id));
438  }
439  inline bool isBlkObj(NodeID id) const
440  {
441  return SymbolTableInfo::isBlkObj(id);
442  }
443  inline bool isConstantObj(NodeID id) const
444  {
445  const MemObj* obj = getObject(id);
446  assert(obj && "not an object node?");
447  return SymbolTableInfo::isConstantObj(id) ||
449  }
451 
453 
454  inline NodeID getBaseObjVar(NodeID id) const
456  {
457  return getBaseObj(id)->getId();
458  }
459  inline const MemObj* getBaseObj(NodeID id) const
460  {
461  const SVFVar* node = pag->getGNode(id);
462  assert(SVFUtil::isa<ObjVar>(node) && "need an object node");
463  const ObjVar* obj = SVFUtil::cast<ObjVar>(node);
464  return obj->getMemObj();
465  }
467 
469 
470  NodeBS& getAllFieldsObjVars(const MemObj* obj);
475  {
476  return addDummyValNode(NodeIDAllocator::get()->allocateValueId());
477  }
479  {
480  return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
481  }
483 
484  bool isValidPointer(NodeID nodeId) const;
485 
486  bool isValidTopLevelPtr(const SVFVar* node);
488 
490  void print();
491 
492 private:
493 
495  inline void addToStmt2TypeMap(SVFStmt* edge)
496  {
497  bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
498  (void)added; // Suppress warning of unused variable under release build
499  assert(added && "duplicated edge, not added!!!");
501  if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
502  {
503  totalPTAPAGEdge++;
504  KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
505  }
506  }
508 
509  inline void addFunArgs(const SVFFunction* fun, const SVFVar* arg)
511  {
512  FunEntryICFGNode* funEntryBlockNode = icfg->getFunEntryICFGNode(fun);
513  funEntryBlockNode->addFormalParms(arg);
514  funArgsListMap[fun].push_back(arg);
515  }
517  inline void addFunRet(const SVFFunction* fun, const SVFVar* ret)
518  {
519  FunExitICFGNode* funExitBlockNode = icfg->getFunExitICFGNode(fun);
520  funExitBlockNode->addFormalRet(ret);
521  funRetMap[fun] = ret;
522  }
524  inline void addCallSiteArgs(CallICFGNode* callBlockNode,const SVFVar* arg)
525  {
526  callBlockNode->addActualParms(arg);
527  callSiteArgsListMap[callBlockNode].push_back(arg);
528  }
530  inline void addCallSiteRets(RetICFGNode* retBlockNode,const SVFVar* arg)
531  {
532  retBlockNode->addActualRet(arg);
533  callSiteRetMap[retBlockNode]= arg;
534  }
536  inline void addIndirectCallsites(const CallICFGNode* cs,NodeID funPtr)
537  {
538  bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
539  (void) added;
540  funPtrToCallSitesMap[funPtr].insert(cs);
541  assert(added && "adding the same indirect callsite twice?");
542  }
543 
545 
546  inline NodeID addValNode(const SVFValue* val, NodeID i, const SVFBaseNode* gNode)
548  {
549  SVFVar *node = new ValVar(val,i, ValVar::ValNode, gNode);
550  return addValNode(val, node, i);
551  }
553  inline NodeID addObjNode(const SVFValue* val, NodeID i)
554  {
555  const MemObj* mem = getMemObj(val);
556  assert(mem->getId() == i && "not same object id?");
557  return addFIObjNode(mem);
558  }
560  inline NodeID addRetNode(const SVFFunction* val, NodeID i)
561  {
562  SVFVar *node = new RetPN(val,i);
563  return addRetNode(val, node, i);
564  }
566  inline NodeID addVarargNode(const SVFFunction* val, NodeID i)
567  {
568  SVFVar *node = new VarArgPN(val,i);
569  return addNode(node,i);
570  }
571 
573  NodeID addGepValNode(const SVFValue* curInst,const SVFValue* val, const AccessPath& ap, NodeID i, const SVFType* type);
575  NodeID addGepObjNode(const MemObj* obj, const APOffset& apOffset, const NodeID gepId);
577  NodeID addFIObjNode(const MemObj* obj);
579 
581 
583  {
584  return addValNode(nullptr, new DummyValVar(i), i);
585  }
587  {
588  const MemObj* mem = addDummyMemObj(i, type);
589  return addObjNode(nullptr, new DummyObjVar(i,mem), i);
590  }
591  inline const MemObj* addDummyMemObj(NodeID i, const SVFType* type)
592  {
593  return getSymbolInfo()->createDummyObj(i,type);
594  }
596  {
597  return addObjNode(
598  nullptr, new DummyObjVar(getBlackHoleNode(), getBlackHoleObj()),
599  getBlackHoleNode());
600  }
602  {
603  return addObjNode(nullptr,
605  getConstantNode());
606  }
608  {
609  return addDummyValNode(getBlkPtr());
610  }
612 
614  inline NodeID addValNode(const SVFValue*, SVFVar *node, NodeID i)
615  {
616  assert(hasGNode(i) == false &&
617  "This NodeID clashes here. Please check NodeIDAllocator. Switch "
618  "Strategy::DBUG to SEQ or DENSE");
619  return addNode(node, i);
620  }
622  inline NodeID addObjNode(const SVFValue*, SVFVar *node, NodeID i)
623  {
624  assert(hasGNode(i) == false &&
625  "This NodeID clashes here. Please check NodeIDAllocator. Switch "
626  "Strategy::DBUG to SEQ or DENSE");
627  return addNode(node, i);
628  }
630  inline NodeID addRetNode(const SVFFunction*, SVFVar *node, NodeID i)
631  {
632  return addNode(node,i);
633  }
635  inline NodeID addVarargNode(const SVFFunction*, SVFVar *node, NodeID i)
636  {
637  return addNode(node,i);
638  }
639 
641  inline void addGlobalPAGEdge(const SVFStmt* edge)
642  {
643  globSVFStmtSet.insert(edge);
644  }
646  inline void addCallSite(const CallICFGNode* call)
647  {
648  callSiteSet.insert(call);
649  }
651 
652  AddrStmt* addAddrStmt(NodeID src, NodeID dst);
656 
658  PhiStmt* addPhiStmt(NodeID res, NodeID opnd, const ICFGNode* pred);
660  SelectStmt* addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond);
662  CmpStmt* addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict);
665  u32_t opcode);
667  UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
670  const BranchStmt::SuccAndCondPairVec& succs);
672  LoadStmt* addLoadStmt(NodeID src, NodeID dst);
674  StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
676  CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
677  const FunEntryICFGNode* entry);
679  RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
680  const FunExitICFGNode* exit);
682  GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
683  bool constGep);
685  GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
687  GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
689  TDForkPE* addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode* cs,
690  const FunEntryICFGNode* entry);
692  TDJoinPE* addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode* cs,
693  const FunExitICFGNode* exit);
695 
698 };
699 
700 typedef SVFIR PAG;
701 
702 } // End namespace SVF
703 
704 
705 
706 #endif /* INCLUDE_SVFIR_H_ */
newitem type
Definition: cJSON.cpp:2739
const cJSON *const b
Definition: cJSON.h:255
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
void addActualParms(const SVFVar *ap)
Add actual parameters.
Definition: ICFGNode.h:494
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition: CHG.h:51
void addFormalParms(const SVFVar *fp)
Add formal parameters.
Definition: ICFGNode.h:307
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
Definition: ICFGNode.h:378
GEdgeKind getEdgeKind() const
Definition: GenericGraph.h:89
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
bool hasGNode(NodeID id) const
Has a node.
Definition: GenericGraph.h:661
Definition: ICFG.h:48
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
Definition: ICFG.cpp:234
NodeID totalICFGNode
Definition: ICFG.h:66
FunExitICFGNode * getFunExitICFGNode(const SVFFunction *fun)
Add a function exit node.
Definition: ICFG.cpp:241
Set< const SVFStmt * > SVFStmtSet
Definition: IRGraph.h:55
NodeID getBlkPtr() const
Definition: IRGraph.h:169
NodeID getBlackHoleNode() const
Definition: IRGraph.h:161
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
Definition: IRGraph.h:59
NodeID addNode(SVFVar *node, NodeID i)
Add a node into the graph.
Definition: IRGraph.h:68
u32_t totalPTAPAGEdge
Definition: IRGraph.h:63
SymbolTableInfo * getSymbolInfo() const
Definition: IRGraph.h:114
const MemObj * getBlackHoleObj() const
Definition: IRGraph.h:177
NodeID getConstantNode() const
Definition: IRGraph.h:165
const MemObj * getConstantObj() const
Definition: IRGraph.h:181
const MemObj * getMemObj(const SVFValue *val) const
get MemObj according to LLVM value
Definition: IRGraph.h:98
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
Definition: IRGraph.h:60
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.
Definition: SVFVariables.h:358
void addActualRet(const SVFVar *ar)
Add actual return parameter.
Definition: ICFGNode.h:633
static void releaseSVFIR()
Definition: SVFIR.h:123
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition: SVFIR.h:215
NodeID addFIObjNode(const MemObj *obj)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition: SVFIR.cpp:465
NodeID addVarargNode(const SVFFunction *, SVFVar *node, NodeID i)
Add a unique vararg node for a procedure.
Definition: SVFIR.h:635
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition: SVFIR.cpp:365
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition: SVFIR.h:60
NodeOffsetMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
Definition: SVFIR.h:84
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
Definition: SVFIR.h:92
PTACallGraph * getCallGraph()
Definition: SVFIR.h:192
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition: SVFIR.cpp:64
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Definition: SVFIR.h:90
bool isBlkObj(NodeID id) const
Definition: SVFIR.h:439
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
Definition: SVFIR.cpp:259
NodeID getFunPtr(const CallICFGNode *cs) const
Definition: SVFIR.h:354
bool isNullPtr(NodeID id) const
Definition: SVFIR.h:431
NodeID addRetNode(const SVFFunction *, SVFVar *node, NodeID i)
Add a unique return node for a procedure.
Definition: SVFIR.h:630
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Definition: SVFIR.cpp:327
NodeID addObjNode(const SVFValue *val, NodeID i)
Add a memory obj node.
Definition: SVFIR.h:553
void print()
Print SVFIR.
Definition: SVFIR.cpp:554
static void handleBlackHole(bool b)
SVFIR build configurations.
Definition: SVFIR.cpp:688
const MemObj * getObject(const ObjVar *node) const
Definition: SVFIR.h:403
NodeID getFIObjVar(const MemObj *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition: SVFIR.h:415
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition: SVFIR.h:495
friend class ExternalPAG
Definition: SVFIR.h:46
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition: SVFIR.h:292
NodeID addBlackholePtrNode()
Definition: SVFIR.h:607
Set< const CallICFGNode * > CallSiteSet
Definition: SVFIR.h:54
NodeID addBlackholeObjNode()
Definition: SVFIR.h:595
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition: SVFIR.h:350
const MemObj * getObject(NodeID id) const
Definition: SVFIR.h:395
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition: SVFIR.h:304
CommonCHGraph * chgraph
Definition: SVFIR.h:99
Map< const CallICFGNode *, SVFVarList > CSToArgsListMap
Definition: SVFIR.h:62
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
Definition: SVFIR.cpp:277
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition: SVFIR.h:287
const SVFVar * getFunRet(const SVFFunction *func) const
Get function return list.
Definition: SVFIR.h:320
NodeID addDummyObjNode(NodeID i, const SVFType *type)
Definition: SVFIR.h:586
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition: SVFIR.cpp:204
NodeID addRetNode(const SVFFunction *val, NodeID i)
Add a unique return node for a procedure.
Definition: SVFIR.h:560
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition: SVFIR.cpp:346
u32_t getFieldObjNodeNum() const
Definition: SVFIR.h:338
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Definition: SVFIR.h:85
Map< const RetICFGNode *, const SVFVar * > CSToRetMap
Definition: SVFIR.h:63
virtual ~SVFIR()
Destructor.
Definition: SVFIR.h:147
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition: SVFIR.h:366
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition: SVFIR.h:87
NodeBS getFieldsAfterCollapse(NodeID id)
Definition: SVFIR.cpp:499
std::pair< NodeID, APOffset > NodeOffset
Definition: SVFIR.h:68
Map< const SVFFunction *, SVFVarList > FunToArgsListMap
Definition: SVFIR.h:61
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
Definition: SVFIR.h:66
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition: SVFIR.h:91
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition: SVFIR.h:55
void setModule(SVFModule *mod)
Set/Get LLVM Module.
Definition: SVFIR.h:157
void addFunRet(const SVFFunction *fun, const SVFVar *ret)
Add function returns.
Definition: SVFIR.h:517
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.
Definition: SVFIR.cpp:386
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition: SVFIR.h:221
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
Definition: SVFIR.cpp:241
bool isValidTopLevelPtr(const SVFVar *node)
Definition: SVFIR.cpp:673
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition: SVFIR.h:249
bool isConstantObj(NodeID id) const
Definition: SVFIR.h:443
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition: SVFIR.h:259
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition: SVFIR.h:270
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition: SVFIR.h:211
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
Definition: SVFIR.h:83
std::vector< const SVFVar * > SVFVarList
Definition: SVFIR.h:59
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
Definition: SVFIR.cpp:306
CSToRetMap & getCallSiteRets()
Get callsite return.
Definition: SVFIR.h:299
Map< NodeID, NodeID > NodeToNodeMap
Definition: SVFIR.h:67
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition: SVFIR.h:206
void destroy()
Clean up memory.
Definition: SVFIR.cpp:539
NodeID addGepObjNode(const MemObj *obj, const APOffset &apOffset, const NodeID gepId)
Add a field obj node, this method can only invoked by getGepObjVar.
Definition: SVFIR.cpp:449
void addCallSiteArgs(CallICFGNode *callBlockNode, const SVFVar *arg)
Add callsite arguments.
Definition: SVFIR.h:524
bool isBlkPtr(NodeID id) const
Get black hole and constant id.
Definition: SVFIR.h:427
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition: SVFIR.h:231
NodeID addVarargNode(const SVFFunction *val, NodeID i)
Add a unique vararg node for a procedure.
Definition: SVFIR.h:566
NodeID addDummyValNode(NodeID i)
Add a dummy value/object node according to node ID (llvm value is null)
Definition: SVFIR.h:582
std::vector< const SVFStmt * > SVFStmtList
Definition: SVFIR.h:58
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition: SVFIR.h:377
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition: SVFIR.h:129
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
Definition: SVFIR.h:86
NodeBS & getAllFieldsObjVars(const MemObj *obj)
Get all fields of an object.
Definition: SVFIR.cpp:477
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
Definition: SVFIR.h:530
std::pair< NodeID, AccessPath > NodeAccessPath
Definition: SVFIR.h:69
void setICFG(ICFG *i)
Set/Get ICFG.
Definition: SVFIR.h:167
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition: SVFIR.h:455
Map< NodeAccessPath, NodeID > NodeAccessPathMap
Definition: SVFIR.h:71
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition: SVFIR.h:139
CommonCHGraph * getCHG()
Definition: SVFIR.h:181
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
Definition: SVFIR.cpp:127
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition: SVFIR.cpp:46
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
Definition: SVFIR.h:88
const MemObj * addDummyMemObj(NodeID i, const SVFType *type)
Definition: SVFIR.h:591
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
Definition: SVFIR.h:80
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition: SVFIR.h:334
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition: SVFIR.cpp:168
SVFModule * svfModule
Definition: SVFIR.h:97
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
Definition: SVFIR.h:73
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
Definition: SVFIR.cpp:288
bool isFunPtr(NodeID id) const
Definition: SVFIR.h:370
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition: SVFIR.cpp:148
NodeID addValNode(const SVFValue *val, NodeID i, const SVFBaseNode *gNode)
add node into SVFIR
Definition: SVFIR.h:547
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition: SVFIR.h:282
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition: SVFIR.h:646
static std::unique_ptr< SVFIR > pag
call graph
Definition: SVFIR.h:103
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition: SVFIR.cpp:223
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition: SVFIR.h:239
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
Definition: SVFIR.h:89
const SVFVarList & getFunArgsList(const SVFFunction *func) const
Get function arguments list.
Definition: SVFIR.h:275
void setCHG(CommonCHGraph *c)
Set/Get CHG.
Definition: SVFIR.h:177
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition: SVFIR.h:254
bool callsiteHasRet(const RetICFGNode *cs) const
Definition: SVFIR.h:310
NodeID addDummyValNode()
Definition: SVFIR.h:474
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Definition: SVFIR.h:81
Map< NodeID, NodeBS > MemObjToFieldsMap
Definition: SVFIR.h:57
Map< NodePair, NodeID > NodePairSetMap
Definition: SVFIR.h:75
void setCallGraph(PTACallGraph *c)
Set/Get CG.
Definition: SVFIR.h:188
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
Definition: SVFIR.cpp:82
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition: SVFIR.h:226
FunToRetMap & getFunRets()
Get function return list.
Definition: SVFIR.h:315
OrderedNodeSet candidatePointers
Definition: SVFIR.h:96
ICFG * getICFG() const
Definition: SVFIR.h:171
ICFG * icfg
SVF Module.
Definition: SVFIR.h:98
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition: SVFIR.h:360
SVFIR(bool buildFromFile)
Constructor.
Definition: SVFIR.cpp:39
NodeOffsetMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition: SVFIR.h:134
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition: SVFIR.h:381
void addFunArgs(const SVFFunction *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
Definition: SVFIR.h:510
bool hasFunArgsList(const SVFFunction *func) const
Function has arguments list.
Definition: SVFIR.h:265
CallSiteSet callSiteSet
Definition: SVFIR.h:100
friend class TypeBasedHeapCloning
Definition: SVFIR.h:48
Map< const SVFFunction *, SVFStmtSet > FunToPAGEdgeSetMap
Definition: SVFIR.h:65
NodeID getFIObjVar(NodeID id) const
Definition: SVFIR.h:419
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
Definition: SVFIR.cpp:106
PTACallGraph * callGraph
all the callsites of a program
Definition: SVFIR.h:101
NodeID getGepValVar(const SVFValue *curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
Definition: SVFIR.cpp:517
SVFModule * getModule()
Definition: SVFIR.h:161
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
Definition: SVFIR.h:74
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
Definition: SVFIR.h:82
bool isBlkObjOrConstantObj(NodeID id) const
Definition: SVFIR.h:435
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition: SVFIR.h:244
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition: SVFIR.cpp:655
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition: SVFIR.h:56
NodeID getGepObjVar(const MemObj *obj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
Definition: SVFIR.cpp:422
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition: SVFIR.h:201
Map< const SVFFunction *, const SVFVar * > FunToRetMap
Definition: SVFIR.h:64
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition: SVFIR.h:641
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition: SVFIR.cpp:186
Map< NodeOffset, NodeID > NodeOffsetMap
Definition: SVFIR.h:70
NodeID addValNode(const SVFValue *, SVFVar *node, NodeID i)
Add a value (pointer) node.
Definition: SVFIR.h:614
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition: SVFIR.h:536
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition: SVFIR.cpp:639
const MemObj * getBaseObj(NodeID id) const
Definition: SVFIR.h:459
Map< const SVFValue *, NodeAccessPathMap > GepValueVarMap
Definition: SVFIR.h:72
NodeID addObjNode(const SVFValue *, SVFVar *node, NodeID i)
Add a memory obj node.
Definition: SVFIR.h:622
FunPtrToCallSitesMap funPtrToCallSitesMap
Definition: SVFIR.h:93
NodeID addDummyObjNode(const SVFType *type)
Definition: SVFIR.h:478
bool funHasRet(const SVFFunction *func) const
Definition: SVFIR.h:326
NodeID addConstantObjNode()
Definition: SVFIR.h:601
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.
for isBitcode
Definition: BasicTypes.h:68
OrderedSet< NodeID > OrderedNodeSet
Definition: GeneralType.h:112
u32_t NodeID
Definition: GeneralType.h:55
s64_t APOffset
Definition: GeneralType.h:60
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
SVFIR PAG
Definition: SVFIR.h:700
unsigned u32_t
Definition: GeneralType.h:46
std::map< Key, Value, Compare, Allocator > OrderedMap
Definition: GeneralType.h:109
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96