Static Value-Flow Analysis
Loading...
Searching...
No Matches
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
35namespace SVF
36{
37class CommonCHGraph;
42class SVFIR : public IRGraph
43{
44 friend class SVFIRBuilder;
45 friend class ExternalPAG;
46 friend class PAGBuilderFromFile;
48 friend class BVDataPTAImpl;
49 friend class GraphDBClient;
50 friend class GraphDBSVFIRBuilder;
51
52public:
57 typedef std::vector<const SVFStmt*> SVFStmtList;
58 typedef std::vector<const ValVar*> ValVarList;
67 typedef std::pair<NodeID, APOffset> GepOffset;
68 typedef std::pair<NodeID, AccessPath> NodeAccessPath;
72 typedef std::pair<const SVFType*, std::vector<AccessPath>> SVFTypeLocSetsPair;
75
76private:
96 ICFG* icfg; // ICFG
97 CommonCHGraph* chgraph; // class hierarchy graph
100
101 static std::unique_ptr<SVFIR> pag;
102 static std::string pagReadFromTxt;
103
104 std::string moduleIdentifier;
105
107 SVFIR(bool buildFromFile);
108
110 void destroy();
111
112public:
113
115
116 static inline SVFIR* getPAG(bool buildFromFile = false)
117 {
118 if (pag == nullptr)
119 {
120 pag = std::unique_ptr<SVFIR>(new SVFIR(buildFromFile));
121 }
122 return pag.get();
123 }
124 static void releaseSVFIR()
125 {
126 pag = nullptr;
127 }
129
131 inline const SVFVar* getSVFVar(NodeID id) const
132 {
133 return getGNode(id);
134 }
135 inline const ValVar* getValVar(NodeID id) const
136 {
137 if(const SVFVar* var = getSVFVar(id))
138 return SVFUtil::dyn_cast<ValVar>(var);
139 else
140 {
141 assert(false && "the Node is not a ValVar");
142 return nullptr;
143 }
144 }
145 inline const ObjVar* getObjVar(NodeID id) const
146 {
147 if(const SVFVar* var = getSVFVar(id))
148 return SVFUtil::dyn_cast<ObjVar>(var);
149 else
150 {
151 assert(false && "the Node is not an ObjVar");
152 return nullptr;
153 }
154 }
155 inline const BaseObjVar* getBaseObjVar(NodeID id) const
156 {
157 if(const SVFVar* var = getSVFVar(id))
158 return SVFUtil::dyn_cast<BaseObjVar>(var);
159 else
160 {
161 assert(false && "the Node is not a BaseObjVar");
162 return nullptr;
163 }
164 }
165 inline const GepObjVar* getGepObjVar(NodeID id) const
166 {
167 if(const SVFVar* var = getSVFVar(id))
168 return SVFUtil::dyn_cast<GepObjVar>(var);
169 else
170 {
171 assert(false && "the Node is not a GepObjVar");
172 return nullptr;
173 }
174 }
175 inline bool isObjVar(NodeID id) const
176 {
177 return SVFUtil::isa<ObjVar>(getSVFVar(id));
178 }
179 inline bool isBaseObjVar(NodeID id) const
180 {
181 return SVFUtil::isa<BaseObjVar>(getSVFVar(id));
182 }
183 inline bool isGepObjVar(NodeID id) const
184 {
185 return SVFUtil::isa<GepObjVar>(getSVFVar(id));
186 }
188 inline const IDToNodeMapTy& getSVFVarMap() const
189 {
190 return IDToNodeMap;
191 }
193
195 {
196 return memToFieldsMap;
197 }
200 {
201 return GepObjVarMap;
202 }
205 {
206 return candidatePointers;
207 }
210
212 virtual ~SVFIR()
213 {
214 destroy();
215 }
217
218
219 static void handleBlackHole(bool b);
221
223 inline void setICFG(ICFG* i)
224 {
225 icfg = i;
226 }
227 inline ICFG* getICFG() const
228 {
229 assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
230 return icfg;
231 }
233 inline void setCHG(CommonCHGraph* c)
234 {
235 chgraph = c;
236 }
238 {
239 assert(chgraph && "empty ICFG! Build SVF IR first!");
240 return chgraph;
241 }
242
244 inline const CallGraph* getCallGraph()
245 {
246 assert(callGraph && "empty CallGraph! Build SVF IR first!");
247 return callGraph;
248 }
249
251 {
252 callGraph = cg;
253 }
254
255 const FunObjVar* getFunObjVar(const std::string& name);
256
257 inline const std::string& getModuleIdentifier() const
258 {
259 if (pagReadFromTxt.empty())
260 {
261 assert(!moduleIdentifier.empty() &&
262 "No module found! Reading from a file other than LLVM-IR?");
263 return moduleIdentifier;
264 }
265 else
266 {
267 return pagReadFromTxt;
268 }
269 }
270
271 static inline std::string pagFileName()
272 {
273 return pagReadFromTxt;
274 }
275
276 static inline bool pagReadFromTXT()
277 {
278 return !pagReadFromTxt.empty();
279 }
280
281 static inline void setPagFromTXT(const std::string& txt)
282 {
284 }
285
286 inline void setModuleIdentifier(const std::string& moduleIdentifier)
287 {
288 this->moduleIdentifier = moduleIdentifier;
289 }
290
292
293
295 {
296 return KindToSVFStmtSetMap[kind];
297 }
304 inline bool hasSVFStmtList(const ICFGNode* inst) const
305 {
306 return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
307 }
308 inline bool hasPTASVFStmtList(const ICFGNode* inst) const
309 {
310 return icfgNode2PTASVFStmtsMap.find(inst) !=
312 }
315 {
316 return icfgNode2SVFStmtsMap[inst];
317 }
320 {
321 return icfgNode2PTASVFStmtsMap[inst];
322 }
325 {
326 edge->setICFGNode(inst);
327 icfgNode2SVFStmtsMap[inst].push_back(edge);
328 if (edge->isPTAEdge())
329 icfgNode2PTASVFStmtsMap[inst].push_back(edge);
330 }
343 {
344 return globSVFStmtSet;
345 }
347 inline const CallSiteSet& getCallSiteSet() const
348 {
349 return callSiteSet;
350 }
352 inline bool isPhiNode(const SVFVar* node) const
353 {
354 return phiNodeMap.find(node) != phiNodeMap.end();
355 }
356
358 inline bool hasFunArgsList(const FunObjVar* func) const
359 {
360 return (funArgsListMap.find(func) != funArgsListMap.end());
361 }
364 {
365 return funArgsListMap;
366 }
368 inline const ValVarList& getFunArgsList(const FunObjVar* func) const
369 {
370 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
371 assert(it != funArgsListMap.end() && "this function doesn't have arguments");
372 return it->second;
373 }
375 inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
376 {
377 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
378 }
381 {
382 return callSiteArgsListMap;
383 }
385 inline const ValVarList& getCallSiteArgsList(const CallICFGNode* cs) const
386 {
387 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
388 assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
389 return it->second;
390 }
393 {
394 return callSiteRetMap;
395 }
397 inline const ValVar* getCallSiteRet(const RetICFGNode* cs) const
398 {
399 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
400 assert(it != callSiteRetMap.end() && "this call site doesn't have return");
401 return it->second;
402 }
403 inline bool callsiteHasRet(const RetICFGNode* cs) const
404 {
405 return callSiteRetMap.find(cs) != callSiteRetMap.end();
406 }
409 {
410 return funRetMap;
411 }
413 inline const ValVar* getFunRet(const FunObjVar* func) const
414 {
415 FunToRetMap::const_iterator it = funRetMap.find(func);
416 assert(it != funRetMap.end() && "this function doesn't have return");
417 return it->second;
418 }
419 inline bool funHasRet(const FunObjVar* func) const
420 {
421 return funRetMap.find(func) != funRetMap.end();
422 }
424
426
428 {
429 return GepValObjMap.size();
430 }
432 {
433 return GepObjVarMap.size();
434 }
436
439 const AccessPath& ap) const;
440
442
444 {
446 }
447 inline NodeID getFunPtr(const CallICFGNode* cs) const
448 {
449 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
450 assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
451 return it->second;
452 }
454 {
455 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
456 assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
457 return it->second;
458 }
459 inline bool isIndirectCallSites(const CallICFGNode* cs) const
460 {
461 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
462 }
463 inline bool isFunPtr(NodeID id) const
464 {
465 return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
466 }
468
471 {
472 return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
473 }
475 {
476 SVFStmt edge(src, dst, kind, false);
478 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
479 assert(it != edgeSet.end() && "can not find pag edge");
480 return (*it);
481 }
483
487
488 inline const BaseObjVar* getBaseObject(NodeID id) const
489 {
490 const SVFVar* node = getSVFVar(id);
491 if(const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
492 return SVFUtil::dyn_cast<BaseObjVar>(
493 getSVFVar(gepObjVar->getBaseNode()));
494 else
495 return SVFUtil::dyn_cast<BaseObjVar>(node);
496 }
497
498 inline const ValVar* getBaseValVar(NodeID id) const
499 {
500 const SVFVar* node = getSVFVar(id);
501 if(const GepValVar* gepVar = SVFUtil::dyn_cast<GepValVar>(node))
502 return gepVar->getBaseNode();
503 else
504 return SVFUtil::dyn_cast<ValVar>(node);
505 }
507
509 NodeID getGepObjVar(const BaseObjVar* baseObj, const APOffset& ap);
511 NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
513
514 inline NodeID getFIObjVar(const BaseObjVar* obj) const
515 {
516 return obj->getId();
517 }
518 inline NodeID getFIObjVar(NodeID id) const
519 {
520 return getBaseObjVarID(id);
521 }
523
525
526
527 inline bool isBlkObjOrConstantObj(NodeID id) const
528 {
529 return (isBlkObj(id) || isConstantObj(id));
530 }
531
532 inline bool isConstantObj(NodeID id) const
533 {
534 const BaseObjVar* obj = getBaseObject(id);
535 assert(obj && "not an object node?");
536 return isConstantSym(id) ||
537 obj->isConstDataOrConstGlobal();
538 }
540
542
543
545 {
546 return getBaseObject(id)->getId();
547 }
549
551
557 {
558 return addDummyValNode(NodeIDAllocator::get()->allocateValueId(), nullptr);
559 }
561 {
562 return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
563 }
565
566 bool isValidPointer(NodeID nodeId) const;
567
568 bool isValidTopLevelPtr(const SVFVar* node);
570
572 void print();
573
574protected:
576 {
577 memToFieldsMap[node->getId()].set(node->getId());
578 return addObjNode(node);
579 }
580
582
583 NodeID addGepObjNode(GepObjVar* gepObj, NodeID base, const APOffset& apOffset);
584
586 {
587 GepValObjMap[curInstID][std::make_pair(gepValvar->getBaseNode()->getId(), gepValvar->getAccessPath())] = gepValvar->getId();
588 }
589
590private:
591
594 {
595 bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
596 (void)added; // Suppress warning of unused variable under release build
597 assert(added && "duplicated edge, not added!!!");
599 if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
600 {
602 KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
603 }
604 }
606
607
608 inline void addFunArgs(const FunObjVar* fun, const ValVar* arg)
609 {
612 }
613
615 {
616 funEntryBlockNode->addFormalParms(arg);
617 funArgsListMap[fun].push_back(arg);
618 }
620 inline void addFunRet(const FunObjVar* fun, const ValVar* ret)
621 {
623 addFunRet(funExitBlockNode, fun, ret);
624 }
625
626 inline void addFunRet(FunExitICFGNode* funExitBlockNode, const FunObjVar* fun, const ValVar* ret)
627 {
628 funExitBlockNode->addFormalRet(ret);
629 funRetMap[fun] = ret;
630 }
632 inline void addCallSiteArgs(CallICFGNode* callBlockNode,const ValVar* arg)
633 {
634 callBlockNode->addActualParms(arg);
635 callSiteArgsListMap[callBlockNode].push_back(arg);
636 }
639 {
640 retBlockNode->addActualRet(arg);
642 }
645 {
646 bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
647 (void) added;
648 funPtrToCallSitesMap[funPtr].insert(cs);
649 assert(added && "adding the same indirect callsite twice?");
650 }
651
653
654
655 inline NodeID addValNode(NodeID i, const SVFType* type, const ICFGNode* icfgNode)
656 {
657 ValVar *node = new ValVar(i, type, icfgNode, ValVar::ValNode);
658 return addValNode(node);
659 }
660
661 NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const FunObjVar* funObjVar, const SVFType* type)
662 {
663 FunValVar* node = new FunValVar(i, icfgNode, funObjVar, type);
664 return addValNode(node);
665 }
666
667 NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const FunObjVar* callGraphNode, const SVFType* type)
668 {
669 ArgValVar* node =
670 new ArgValVar(i, argNo, icfgNode, callGraphNode, type);
671 return addValNode(node);
672 }
673
674 inline NodeID addConstantFPValNode(const NodeID i, double dval,
675 const ICFGNode* icfgNode, const SVFType* type)
676 {
677 SVFVar* node = new ConstFPValVar(i, dval, icfgNode, type);
678 return addNode(node);
679 }
680
681 inline NodeID addConstantIntValNode(NodeID i, const std::pair<s64_t, u64_t>& intValue,
682 const ICFGNode* icfgNode, const SVFType* type)
683 {
684 SVFVar* node = new ConstIntValVar(i, intValue.first, intValue.second, icfgNode, type);
685 return addNode(node);
686 }
687
688 inline NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
689 {
690 SVFVar* node = new ConstNullPtrValVar(i, icfgNode, type);
691 return addNode(node);
692 }
693
694 inline NodeID addGlobalValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
695 {
696 SVFVar* node = new GlobalValVar(i, icfgNode, svfType);
697 return addNode(node);
698 }
699
700 inline NodeID addConstantAggValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
701 {
702 SVFVar* node = new ConstAggValVar(i, icfgNode, svfType);
703 return addNode(node);
704 }
705
706 inline NodeID addConstantDataValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
707 {
708 SVFVar* node = new ConstDataValVar(i, icfgNode, type);
709 return addNode(node);
710 }
711
712
715 {
716 return addFIObjNode( i, ti, node);
717 }
718
723 {
724 HeapObjVar *heapObj = new HeapObjVar(i, ti, node);
725 return addBaseObjNode(heapObj);
726 }
727
732 {
733 StackObjVar *stackObj = new StackObjVar(i, ti, node);
734 return addBaseObjNode(stackObj);
735 }
736
738 {
739 FunObjVar* funObj = new FunObjVar(id, ti, node);
740 return addBaseObjNode(funObj);
741 }
742
743
744 inline NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo* ti, double dval, const ICFGNode* node)
745 {
746 ConstFPObjVar* conObj = new ConstFPObjVar(i, dval, ti, node);
747 return addBaseObjNode(conObj);
748 }
749
750
751 inline NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo* ti, const std::pair<s64_t, u64_t>& intValue, const ICFGNode* node)
752 {
754 new ConstIntObjVar(i, intValue.first, intValue.second, ti, node);
755 return addBaseObjNode(conObj);
756 }
757
758
760 {
762 return addBaseObjNode(conObj);
763 }
764
765 inline NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo* ti, const ICFGNode* node)
766 {
767 GlobalObjVar* gObj = new GlobalObjVar(i, ti, node);
768 return addBaseObjNode(gObj);
769 }
771 {
772 ConstAggObjVar* conObj = new ConstAggObjVar(i, ti, node);
773 return addBaseObjNode(conObj);
774 }
776 {
778 return addBaseObjNode(conObj);
779 }
780
782 inline NodeID addRetNode(NodeID i, const FunObjVar* callGraphNode, const SVFType* type, const ICFGNode* icn)
783 {
784 SVFVar *node = new RetValPN(i, callGraphNode, type, icn);
785 return addRetNode(callGraphNode, node);
786 }
788 inline NodeID addVarargNode(NodeID i, const FunObjVar* val, const SVFType* type, const ICFGNode* n)
789 {
790 SVFVar *node = new VarArgValPN(i, val, type, n);
791 return addNode(node);
792 }
793
795 NodeID addGepValNode(NodeID curInst, const ValVar* base, const AccessPath& ap, NodeID i, const SVFType* type, const ICFGNode* node);
797 NodeID addGepObjNode(const BaseObjVar* baseObj, const APOffset& apOffset, const NodeID gepId);
800 {
801 BaseObjVar* baseObj = new BaseObjVar(i, ti, node);
802 return addBaseObjNode(baseObj);
803 }
804
805
807
809
811 {
812 return addValNode(new DummyValVar(i, node));
813 }
815 {
816 if (idToObjTypeInfoMap().find(i) == idToObjTypeInfoMap().end())
817 {
820 return addDummyObjNode(new DummyObjVar(i, ti, nullptr));
821 }
822 else
823 {
824 return addDummyObjNode(new DummyObjVar(i, getObjTypeInfo(i), nullptr));
825 }
826 }
827
833 {
835 }
837 {
838 return addDummyValNode(getBlkPtr(), nullptr);
839 }
841
843 NodeID addValNode(ValVar* node);
845 NodeID addObjNode(ObjVar *node);
847 inline NodeID addRetNode(const FunObjVar*, SVFVar *node)
848 {
849 return addNode(node);
850 }
852 inline NodeID addVarargNode(const FunObjVar*, SVFVar *node)
853 {
854 return addNode(node);
855 }
856
858 inline void addGlobalPAGEdge(const SVFStmt* edge)
859 {
860 globSVFStmtSet.insert(edge);
861 }
863 inline void addCallSite(const CallICFGNode* call)
864 {
865 callSiteSet.insert(call);
866 }
868
869
875
878 void addPhiStmt(PhiStmt* edge, SVFVar* src, SVFVar* dst);
881 void addSelectStmt(SelectStmt* edge, SVFVar* src, SVFVar* dst);
884 void addCmpStmt(CmpStmt* edge, SVFVar* src, SVFVar* dst);
887 u32_t opcode);
888 void addBinaryOPStmt(BinaryOPStmt* edge, SVFVar* src, SVFVar* dst);
890 UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
891 void addUnaryOPStmt(UnaryOPStmt* edge, SVFVar* src, SVFVar* dst);
895 void addBranchStmt(BranchStmt* edge, SVFVar* src, SVFVar* dst);
900 StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
901 void addStoreStmt(StoreStmt* edge, SVFVar* src, SVFVar* dst);
903 CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
904 const FunEntryICFGNode* entry);
905 void addCallPE(CallPE* edge, SVFVar* src, SVFVar* dst);
907 RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
908 const FunExitICFGNode* exit);
909 void addRetPE(RetPE* edge, SVFVar* src, SVFVar* dst);
911 GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
912 bool constGep);
913 void addGepStmt(GepStmt* edge);
915 GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
917 GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
920 const FunEntryICFGNode* entry);
923 const FunExitICFGNode* exit);
925
928};
929
930typedef SVFIR PAG;
931
932} // End namespace SVF
933
934
935
936#endif /* INCLUDE_SVFIR_H_ */
newitem type
Definition cJSON.cpp:2739
cJSON * n
Definition cJSON.cpp:2558
const cJSON *const b
Definition cJSON.h:255
const char *const name
Definition cJSON.h:264
Class representing a function argument variable in the SVFIR.
NodeID getId() const
Get the memory object id.
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
void addActualParms(const ValVar *ap)
Add actual parameters.
Definition ICFGNode.h:476
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
NodeType * getGNode(NodeID id) const
Get a node.
OrderedMap< NodeID, NodeType * > IDToNodeMapTy
NodeID to GenericNode map.
Class representing a heap object variable in the SVFIR.
NodeID totalICFGNode
Definition ICFG.h:66
FunExitICFGNode * getFunExitICFGNode(const FunObjVar *fun)
Add a function exit node.
Definition ICFG.cpp:249
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
Definition ICFG.cpp:242
Set< const SVFStmt * > SVFStmtSet
Definition IRGraph.h:105
NodeID addNode(SVFVar *node)
Add a node into the graph.
Definition IRGraph.h:117
NodeID getBlkPtr() const
Definition IRGraph.h:255
NodeID getBlackHoleNode() const
Definition IRGraph.h:247
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
Definition IRGraph.h:108
ObjTypeInfo * createObjTypeInfo(const SVFType *type)
Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy ...
Definition IRGraph.cpp:231
static bool isBlkObj(NodeID id)
Definition IRGraph.h:165
u32_t totalPTAPAGEdge
Definition IRGraph.h:112
static bool isConstantSym(NodeID id)
Definition IRGraph.h:169
ObjTypeInfo * getObjTypeInfo(NodeID id) const
Definition IRGraph.h:234
NodeID getConstantNode() const
Definition IRGraph.h:251
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
Definition IRGraph.h:109
IDToTypeInfoMapTy & idToObjTypeInfoMap()
Get different kinds of syms maps.
Definition IRGraph.h:212
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static void releaseSVFIR()
Definition SVFIR.h:124
NodeID addFIObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition SVFIR.h:799
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:347
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition SVFIR.h:380
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition SVFIR.h:299
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null)
Definition SVFIR.h:810
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:308
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition SVFIR.cpp:450
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition SVFIR.h:294
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition SVFIR.h:59
bool funHasRet(const FunObjVar *func) const
Definition SVFIR.h:419
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
Definition SVFIR.h:91
NodeID addGlobalValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:694
void addFunArgs(const FunObjVar *fun, const ValVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:608
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition SVFIR.cpp:85
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Definition SVFIR.h:89
NodeID getGepValVar(NodeID curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
Definition SVFIR.cpp:597
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
Definition SVFIR.cpp:333
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:447
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
Definition SVFIR.h:358
std::pair< NodeID, APOffset > GepOffset
Definition SVFIR.h:67
Map< const CallICFGNode *, ValVarList > CSToArgsListMap
Definition SVFIR.h:61
const IDToNodeMapTy & getSVFVarMap() const
Return the entire SVFID to SVFVar map.
Definition SVFIR.h:188
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Definition SVFIR.cpp:404
void print()
Print SVFIR.
Definition SVFIR.cpp:632
static void handleBlackHole(bool b)
SVFIR build configurations.
Definition SVFIR.cpp:765
NodeID getBaseObjVarID(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:544
const ValVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:397
const ValVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
Definition SVFIR.h:368
NodeID addConstantAggObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:770
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition SVFIR.h:593
friend class ExternalPAG
Definition SVFIR.h:45
NodeID addBlackholePtrNode()
Definition SVFIR.h:836
Set< const CallICFGNode * > CallSiteSet
Definition SVFIR.h:53
NodeID addBlackholeObjNode()
Definition SVFIR.h:828
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:765
CommonCHGraph * chgraph
Definition SVFIR.h:97
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
Definition SVFIR.cpp:356
NodeID addDummyObjNode(NodeID i, const SVFType *type)
Definition SVFIR.h:814
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition SVFIR.cpp:263
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.
Definition SVFIR.cpp:471
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:775
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:423
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:431
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Definition SVFIR.h:84
virtual ~SVFIR()
Destructor.
Definition SVFIR.h:212
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition SVFIR.h:459
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const ICFGNode *node)
Definition SVFIR.h:744
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition SVFIR.h:474
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition SVFIR.h:86
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:579
std::vector< const ValVar * > ValVarList
Definition SVFIR.h:58
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
Definition SVFIR.h:852
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
Definition SVFIR.h:65
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a memory obj node.
Definition SVFIR.h:714
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition SVFIR.h:90
void addFunRet(const FunObjVar *fun, const ValVar *ret)
Add function returns.
Definition SVFIR.h:620
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:54
static std::string pagFileName()
Definition SVFIR.h:271
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
Definition SVFIR.cpp:310
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:688
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:722
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:314
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:748
bool isConstantObj(NodeID id) const
Definition SVFIR.h:532
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:352
static bool pagReadFromTXT()
Definition SVFIR.h:276
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:204
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:304
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
Definition SVFIR.h:82
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
Definition SVFIR.cpp:384
CallGraph * callGraph
all the callsites of a program
Definition SVFIR.h:99
Map< NodeID, NodeID > NodeToNodeMap
Definition SVFIR.h:66
static std::string pagReadFromTxt
Definition SVFIR.h:102
friend class GraphDBSVFIRBuilder
Definition SVFIR.h:50
CSToRetMap & getCallSiteRets()
Get callsite return.
Definition SVFIR.h:392
void destroy()
Clean up memory.
Definition SVFIR.cpp:619
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:324
std::vector< const SVFStmt * > SVFStmtList
Definition SVFIR.h:57
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:488
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:244
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:759
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
Definition SVFIR.h:85
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:706
std::pair< NodeID, AccessPath > NodeAccessPath
Definition SVFIR.h:68
void setICFG(ICFG *i)
Set/Get ICFG.
Definition SVFIR.h:223
Map< NodeAccessPath, NodeID > NodeAccessPathMap
Definition SVFIR.h:70
std::string moduleIdentifier
Definition SVFIR.h:104
const FunObjVar * getFunObjVar(const std::string &name)
Definition SVFIR.cpp:47
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
Definition SVFIR.cpp:167
FunToRetMap & getFunRets()
Get function return list.
Definition SVFIR.h:408
const BaseObjVar * getBaseObjVar(NodeID id) const
Definition SVFIR.h:155
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition SVFIR.h:342
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:632
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:63
Map< const FunObjVar *, ValVarList > FunToArgsListMap
Definition SVFIR.h:60
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
Definition SVFIR.h:87
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
Definition SVFIR.h:79
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:731
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:681
ICFG * getICFG() const
Definition SVFIR.h:227
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:427
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:661
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:674
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition SVFIR.cpp:217
NodeID addConstantAggValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:700
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
Definition SVFIR.h:72
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
Definition SVFIR.cpp:367
bool isFunPtr(NodeID id) const
Definition SVFIR.h:463
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition SVFIR.h:470
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition SVFIR.cpp:193
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition SVFIR.h:375
const ObjVar * getObjVar(NodeID id) const
Definition SVFIR.h:145
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:558
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition SVFIR.h:863
static std::unique_ptr< SVFIR > pag
Callgraph with direct calls only; no change allowed after init and use callgraph in PointerAnalysis f...
Definition SVFIR.h:101
NodeID addValNode(NodeID i, const SVFType *type, const ICFGNode *icfgNode)
add node into SVFIR
Definition SVFIR.h:655
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition SVFIR.cpp:287
NodeID addGepObjNode(GepObjVar *gepObj, NodeID base, const APOffset &apOffset)
Definition SVFIR.cpp:532
void addFunArgs(FunEntryICFGNode *funEntryBlockNode, const FunObjVar *fun, const ValVar *arg)
Definition SVFIR.h:614
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:788
void setCallGraph(CallGraph *cg)
Definition SVFIR.h:250
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition SVFIR.h:332
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
Definition SVFIR.h:88
void setCHG(CommonCHGraph *c)
Set/Get CHG.
Definition SVFIR.h:233
OffsetToGepVarMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
Definition SVFIR.h:83
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:443
bool isGepObjVar(NodeID id) const
Definition SVFIR.h:183
CommonCHGraph * getCHG()
Definition SVFIR.h:237
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:131
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:403
NodeID addDummyValNode()
Definition SVFIR.h:556
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:319
void addGepValObjFromDB(NodeID curInstID, const GepValVar *gepValvar)
Definition SVFIR.h:585
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Definition SVFIR.h:80
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:737
OffsetToGepVarMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition SVFIR.h:199
friend class GraphDBClient
Definition SVFIR.h:49
bool isObjVar(NodeID id) const
Definition SVFIR.h:175
Map< NodeID, NodeBS > MemObjToFieldsMap
Definition SVFIR.h:56
Map< NodePair, NodeID > NodePairSetMap
Definition SVFIR.h:74
Map< GepOffset, NodeID > OffsetToGepVarMap
Definition SVFIR.h:69
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
Definition SVFIR.cpp:108
const ValVar * getFunRet(const FunObjVar *func) const
Get function return list.
Definition SVFIR.h:413
NodeID addBaseObjNode(BaseObjVar *node)
Definition SVFIR.h:575
OrderedNodeSet candidatePointers
Definition SVFIR.h:95
ICFG * icfg
Definition SVFIR.h:96
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition SVFIR.h:286
Map< const FunObjVar *, const ValVar * > FunToRetMap
Definition SVFIR.h:63
CallSiteSet callSiteSet
Definition SVFIR.h:98
friend class TypeBasedHeapCloning
Definition SVFIR.h:47
NodeID getFIObjVar(NodeID id) const
Definition SVFIR.h:518
Map< const RetICFGNode *, const ValVar * > CSToRetMap
Definition SVFIR.h:62
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
Definition SVFIR.cpp:141
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *node)
Definition SVFIR.h:751
Map< const FunObjVar *, SVFStmtSet > FunToPAGEdgeSetMap
Definition SVFIR.h:64
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
Definition SVFIR.h:73
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
Definition SVFIR.h:81
const ValVar * getBaseValVar(NodeID id) const
Definition SVFIR.h:498
const ValVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:385
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:527
const GepObjVar * getGepObjVar(NodeID id) const
Definition SVFIR.h:165
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition SVFIR.h:453
Map< NodeID, NodeAccessPathMap > GepValueVarMap
Definition SVFIR.h:71
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition SVFIR.cpp:733
void addFunRet(FunExitICFGNode *funExitBlockNode, const FunObjVar *fun, const ValVar *ret)
Definition SVFIR.h:626
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition SVFIR.h:55
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:858
const std::string & getModuleIdentifier() const
Definition SVFIR.h:257
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition SVFIR.cpp:240
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
Definition SVFIR.h:847
const ValVar * getValVar(NodeID id) const
Definition SVFIR.h:135
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:644
bool isBaseObjVar(NodeID id) const
Definition SVFIR.h:179
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition SVFIR.h:363
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition SVFIR.cpp:717
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
Definition SVFIR.h:782
static void setPagFromTXT(const std::string &txt)
Definition SVFIR.h:281
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:514
FunPtrToCallSitesMap funPtrToCallSitesMap
Definition SVFIR.h:92
NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode *icfgNode, const FunObjVar *callGraphNode, const SVFType *type)
Definition SVFIR.h:667
void addCallSiteRets(RetICFGNode *retBlockNode, const ValVar *arg)
Add callsite returns.
Definition SVFIR.h:638
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition SVFIR.h:337
NodeID addDummyObjNode(const SVFType *type)
Definition SVFIR.h:560
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition SVFIR.h:194
NodeID addConstantObjNode()
Definition SVFIR.h:832
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
Represents a stack-allocated object variable in the SVFIR (SVF Intermediate Representation) @inherits...
for isBitcode
Definition BasicTypes.h:68
OrderedSet< NodeID > OrderedNodeSet
u32_t NodeID
Definition GeneralType.h:56
s64_t APOffset
Definition GeneralType.h:60
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
SVFIR PAG
Definition SVFIR.h:930
unsigned u32_t
Definition GeneralType.h:47