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 SVFVar*> SVFVarList;
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 ObjVar* getObjVar(NodeID id) const
136 {
137 if(const SVFVar* var = getSVFVar(id))
138 return SVFUtil::dyn_cast<ObjVar>(var);
139 else
140 {
141 assert(false && "the Node is not an ObjVar");
142 return nullptr;
143 }
144 }
145 inline const BaseObjVar* getBaseObjVar(NodeID id) const
146 {
147 if(const SVFVar* var = getSVFVar(id))
148 return SVFUtil::dyn_cast<BaseObjVar>(var);
149 else
150 {
151 assert(false && "the Node is not a BaseObjVar");
152 return nullptr;
153 }
154 }
155 inline const GepObjVar* getGepObjVar(NodeID id) const
156 {
157 if(const SVFVar* var = getSVFVar(id))
158 return SVFUtil::dyn_cast<GepObjVar>(var);
159 else
160 {
161 assert(false && "the Node is not a GepObjVar");
162 return nullptr;
163 }
164 }
165 inline bool isObjVar(NodeID id) const
166 {
167 return SVFUtil::isa<ObjVar>(getSVFVar(id));
168 }
169 inline bool isBaseObjVar(NodeID id) const
170 {
171 return SVFUtil::isa<BaseObjVar>(getSVFVar(id));
172 }
173 inline bool isGepObjVar(NodeID id) const
174 {
175 return SVFUtil::isa<GepObjVar>(getSVFVar(id));
176 }
178 inline const IDToNodeMapTy& getSVFVarMap() const
179 {
180 return IDToNodeMap;
181 }
183
185 {
186 return memToFieldsMap;
187 }
190 {
191 return GepObjVarMap;
192 }
195 {
196 return candidatePointers;
197 }
200
202 virtual ~SVFIR()
203 {
204 destroy();
205 }
207
208
209 static void handleBlackHole(bool b);
211
213 inline void setICFG(ICFG* i)
214 {
215 icfg = i;
216 }
217 inline ICFG* getICFG() const
218 {
219 assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
220 return icfg;
221 }
223 inline void setCHG(CommonCHGraph* c)
224 {
225 chgraph = c;
226 }
228 {
229 assert(chgraph && "empty ICFG! Build SVF IR first!");
230 return chgraph;
231 }
232
234 inline const CallGraph* getCallGraph()
235 {
236 assert(callGraph && "empty CallGraph! Build SVF IR first!");
237 return callGraph;
238 }
239
241 {
242 callGraph = cg;
243 }
244
245 const FunObjVar* getFunObjVar(const std::string& name);
246
247 inline const std::string& getModuleIdentifier() const
248 {
249 if (pagReadFromTxt.empty())
250 {
251 assert(!moduleIdentifier.empty() &&
252 "No module found! Reading from a file other than LLVM-IR?");
253 return moduleIdentifier;
254 }
255 else
256 {
257 return pagReadFromTxt;
258 }
259 }
260
261 static inline std::string pagFileName()
262 {
263 return pagReadFromTxt;
264 }
265
266 static inline bool pagReadFromTXT()
267 {
268 return !pagReadFromTxt.empty();
269 }
270
271 static inline void setPagFromTXT(const std::string& txt)
272 {
274 }
275
276 inline void setModuleIdentifier(const std::string& moduleIdentifier)
277 {
278 this->moduleIdentifier = moduleIdentifier;
279 }
280
282
283
285 {
286 return KindToSVFStmtSetMap[kind];
287 }
294 inline bool hasSVFStmtList(const ICFGNode* inst) const
295 {
296 return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
297 }
298 inline bool hasPTASVFStmtList(const ICFGNode* inst) const
299 {
300 return icfgNode2PTASVFStmtsMap.find(inst) !=
302 }
305 {
306 return icfgNode2SVFStmtsMap[inst];
307 }
310 {
311 return icfgNode2PTASVFStmtsMap[inst];
312 }
315 {
316 edge->setICFGNode(inst);
317 icfgNode2SVFStmtsMap[inst].push_back(edge);
318 if (edge->isPTAEdge())
319 icfgNode2PTASVFStmtsMap[inst].push_back(edge);
320 }
333 {
334 return globSVFStmtSet;
335 }
337 inline const CallSiteSet& getCallSiteSet() const
338 {
339 return callSiteSet;
340 }
342 inline bool isPhiNode(const SVFVar* node) const
343 {
344 return phiNodeMap.find(node) != phiNodeMap.end();
345 }
346
348 inline bool hasFunArgsList(const FunObjVar* func) const
349 {
350 return (funArgsListMap.find(func) != funArgsListMap.end());
351 }
354 {
355 return funArgsListMap;
356 }
358 inline const SVFVarList& getFunArgsList(const FunObjVar* func) const
359 {
360 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
361 assert(it != funArgsListMap.end() && "this function doesn't have arguments");
362 return it->second;
363 }
365 inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
366 {
367 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
368 }
371 {
372 return callSiteArgsListMap;
373 }
375 inline const SVFVarList& getCallSiteArgsList(const CallICFGNode* cs) const
376 {
377 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
378 assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
379 return it->second;
380 }
383 {
384 return callSiteRetMap;
385 }
387 inline const SVFVar* getCallSiteRet(const RetICFGNode* cs) const
388 {
389 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
390 assert(it != callSiteRetMap.end() && "this call site doesn't have return");
391 return it->second;
392 }
393 inline bool callsiteHasRet(const RetICFGNode* cs) const
394 {
395 return callSiteRetMap.find(cs) != callSiteRetMap.end();
396 }
399 {
400 return funRetMap;
401 }
403 inline const SVFVar* getFunRet(const FunObjVar* func) const
404 {
405 FunToRetMap::const_iterator it = funRetMap.find(func);
406 assert(it != funRetMap.end() && "this function doesn't have return");
407 return it->second;
408 }
409 inline bool funHasRet(const FunObjVar* func) const
410 {
411 return funRetMap.find(func) != funRetMap.end();
412 }
414
416
418 {
419 return GepValObjMap.size();
420 }
422 {
423 return GepObjVarMap.size();
424 }
426
429 const AccessPath& ap) const;
430
432
434 {
436 }
437 inline NodeID getFunPtr(const CallICFGNode* cs) const
438 {
439 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
440 assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
441 return it->second;
442 }
444 {
445 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
446 assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
447 return it->second;
448 }
449 inline bool isIndirectCallSites(const CallICFGNode* cs) const
450 {
451 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
452 }
453 inline bool isFunPtr(NodeID id) const
454 {
455 return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
456 }
458
461 {
462 return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
463 }
465 {
466 SVFStmt edge(src, dst, kind, false);
468 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
469 assert(it != edgeSet.end() && "can not find pag edge");
470 return (*it);
471 }
473
477
478 inline const BaseObjVar* getBaseObject(NodeID id) const
479 {
480 const SVFVar* node = getSVFVar(id);
481 if(const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
482 return SVFUtil::dyn_cast<BaseObjVar>(
483 getSVFVar(gepObjVar->getBaseNode()));
484 else
485 return SVFUtil::dyn_cast<BaseObjVar>(node);
486 }
487
488 inline const ValVar* getBaseValVar(NodeID id) const
489 {
490 const SVFVar* node = getSVFVar(id);
491 if(const GepValVar* gepVar = SVFUtil::dyn_cast<GepValVar>(node))
492 return gepVar->getBaseNode();
493 else
494 return SVFUtil::dyn_cast<ValVar>(node);
495 }
497
499 NodeID getGepObjVar(const BaseObjVar* baseObj, const APOffset& ap);
501 NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
503
504 inline NodeID getFIObjVar(const BaseObjVar* obj) const
505 {
506 return obj->getId();
507 }
508 inline NodeID getFIObjVar(NodeID id) const
509 {
510 return getBaseObjVarID(id);
511 }
513
515
516
517 inline bool isBlkObjOrConstantObj(NodeID id) const
518 {
519 return (isBlkObj(id) || isConstantObj(id));
520 }
521
522 inline bool isConstantObj(NodeID id) const
523 {
524 const BaseObjVar* obj = getBaseObject(id);
525 assert(obj && "not an object node?");
526 return isConstantSym(id) ||
527 obj->isConstDataOrConstGlobal();
528 }
530
532
533
535 {
536 return getBaseObject(id)->getId();
537 }
539
541
547 {
548 return addDummyValNode(NodeIDAllocator::get()->allocateValueId(), nullptr);
549 }
551 {
552 return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
553 }
555
556 bool isValidPointer(NodeID nodeId) const;
557
558 bool isValidTopLevelPtr(const SVFVar* node);
560
562 void print();
563
564protected:
566 {
567 memToFieldsMap[node->getId()].set(node->getId());
568 return addObjNode(node);
569 }
570
572
573 NodeID addGepObjNode(GepObjVar* gepObj, NodeID base, const APOffset& apOffset);
574
576 {
577 GepValObjMap[curInstID][std::make_pair(gepValvar->getBaseNode()->getId(), gepValvar->getAccessPath())] = gepValvar->getId();
578 }
579
580private:
581
584 {
585 bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
586 (void)added; // Suppress warning of unused variable under release build
587 assert(added && "duplicated edge, not added!!!");
589 if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
590 {
592 KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
593 }
594 }
596
597
598 inline void addFunArgs(const FunObjVar* fun, const SVFVar* arg)
599 {
602 }
603
605 {
606 funEntryBlockNode->addFormalParms(arg);
607 funArgsListMap[fun].push_back(arg);
608 }
610 inline void addFunRet(const FunObjVar* fun, const SVFVar* ret)
611 {
613 addFunRet(funExitBlockNode, fun, ret);
614 }
615
616 inline void addFunRet(FunExitICFGNode* funExitBlockNode, const FunObjVar* fun, const SVFVar* ret)
617 {
618 funExitBlockNode->addFormalRet(ret);
619 funRetMap[fun] = ret;
620 }
622 inline void addCallSiteArgs(CallICFGNode* callBlockNode,const ValVar* arg)
623 {
624 callBlockNode->addActualParms(arg);
625 callSiteArgsListMap[callBlockNode].push_back(arg);
626 }
629 {
630 retBlockNode->addActualRet(arg);
632 }
635 {
636 bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
637 (void) added;
638 funPtrToCallSitesMap[funPtr].insert(cs);
639 assert(added && "adding the same indirect callsite twice?");
640 }
641
643
644
645 inline NodeID addValNode(NodeID i, const SVFType* type, const ICFGNode* icfgNode)
646 {
647 ValVar *node = new ValVar(i, type, icfgNode, ValVar::ValNode);
648 return addValNode(node);
649 }
650
651 NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const FunObjVar* funObjVar, const SVFType* type)
652 {
653 FunValVar* node = new FunValVar(i, icfgNode, funObjVar, type);
654 return addValNode(node);
655 }
656
657 NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const FunObjVar* callGraphNode, const SVFType* type)
658 {
659 ArgValVar* node =
660 new ArgValVar(i, argNo, icfgNode, callGraphNode, type);
661 return addValNode(node);
662 }
663
664 inline NodeID addConstantFPValNode(const NodeID i, double dval,
665 const ICFGNode* icfgNode, const SVFType* type)
666 {
667 SVFVar* node = new ConstFPValVar(i, dval, icfgNode, type);
668 return addNode(node);
669 }
670
671 inline NodeID addConstantIntValNode(NodeID i, const std::pair<s64_t, u64_t>& intValue,
672 const ICFGNode* icfgNode, const SVFType* type)
673 {
674 SVFVar* node = new ConstIntValVar(i, intValue.first, intValue.second, icfgNode, type);
675 return addNode(node);
676 }
677
678 inline NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
679 {
680 SVFVar* node = new ConstNullPtrValVar(i, icfgNode, type);
681 return addNode(node);
682 }
683
684 inline NodeID addGlobalValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
685 {
686 SVFVar* node = new GlobalValVar(i, icfgNode, svfType);
687 return addNode(node);
688 }
689
690 inline NodeID addConstantAggValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
691 {
692 SVFVar* node = new ConstAggValVar(i, icfgNode, svfType);
693 return addNode(node);
694 }
695
696 inline NodeID addConstantDataValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
697 {
698 SVFVar* node = new ConstDataValVar(i, icfgNode, type);
699 return addNode(node);
700 }
701
702
705 {
706 return addFIObjNode( i, ti, node);
707 }
708
713 {
714 HeapObjVar *heapObj = new HeapObjVar(i, ti, node);
715 return addBaseObjNode(heapObj);
716 }
717
722 {
723 StackObjVar *stackObj = new StackObjVar(i, ti, node);
724 return addBaseObjNode(stackObj);
725 }
726
728 {
729 FunObjVar* funObj = new FunObjVar(id, ti, node);
730 return addBaseObjNode(funObj);
731 }
732
733
734 inline NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo* ti, double dval, const ICFGNode* node)
735 {
736 ConstFPObjVar* conObj = new ConstFPObjVar(i, dval, ti, node);
737 return addBaseObjNode(conObj);
738 }
739
740
741 inline NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo* ti, const std::pair<s64_t, u64_t>& intValue, const ICFGNode* node)
742 {
744 new ConstIntObjVar(i, intValue.first, intValue.second, ti, node);
745 return addBaseObjNode(conObj);
746 }
747
748
750 {
752 return addBaseObjNode(conObj);
753 }
754
755 inline NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo* ti, const ICFGNode* node)
756 {
757 GlobalObjVar* gObj = new GlobalObjVar(i, ti, node);
758 return addBaseObjNode(gObj);
759 }
761 {
762 ConstAggObjVar* conObj = new ConstAggObjVar(i, ti, node);
763 return addBaseObjNode(conObj);
764 }
766 {
768 return addBaseObjNode(conObj);
769 }
770
772 inline NodeID addRetNode(NodeID i, const FunObjVar* callGraphNode, const SVFType* type, const ICFGNode* icn)
773 {
774 SVFVar *node = new RetValPN(i, callGraphNode, type, icn);
775 return addRetNode(callGraphNode, node);
776 }
778 inline NodeID addVarargNode(NodeID i, const FunObjVar* val, const SVFType* type, const ICFGNode* n)
779 {
780 SVFVar *node = new VarArgValPN(i, val, type, n);
781 return addNode(node);
782 }
783
785 NodeID addGepValNode(NodeID curInst, const ValVar* base, const AccessPath& ap, NodeID i, const SVFType* type, const ICFGNode* node);
787 NodeID addGepObjNode(const BaseObjVar* baseObj, const APOffset& apOffset, const NodeID gepId);
790 {
791 BaseObjVar* baseObj = new BaseObjVar(i, ti, node);
792 return addBaseObjNode(baseObj);
793 }
794
795
797
799
801 {
802 return addValNode(new DummyValVar(i, node));
803 }
805 {
806 if (idToObjTypeInfoMap().find(i) == idToObjTypeInfoMap().end())
807 {
810 return addDummyObjNode(new DummyObjVar(i, ti, nullptr));
811 }
812 else
813 {
814 return addDummyObjNode(new DummyObjVar(i, getObjTypeInfo(i), nullptr));
815 }
816 }
817
823 {
825 }
827 {
828 return addDummyValNode(getBlkPtr(), nullptr);
829 }
831
833 NodeID addValNode(ValVar* node);
835 NodeID addObjNode(ObjVar *node);
837 inline NodeID addRetNode(const FunObjVar*, SVFVar *node)
838 {
839 return addNode(node);
840 }
842 inline NodeID addVarargNode(const FunObjVar*, SVFVar *node)
843 {
844 return addNode(node);
845 }
846
848 inline void addGlobalPAGEdge(const SVFStmt* edge)
849 {
850 globSVFStmtSet.insert(edge);
851 }
853 inline void addCallSite(const CallICFGNode* call)
854 {
855 callSiteSet.insert(call);
856 }
858
859
865
868 void addPhiStmt(PhiStmt* edge, SVFVar* src, SVFVar* dst);
871 void addSelectStmt(SelectStmt* edge, SVFVar* src, SVFVar* dst);
874 void addCmpStmt(CmpStmt* edge, SVFVar* src, SVFVar* dst);
877 u32_t opcode);
878 void addBinaryOPStmt(BinaryOPStmt* edge, SVFVar* src, SVFVar* dst);
880 UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
881 void addUnaryOPStmt(UnaryOPStmt* edge, SVFVar* src, SVFVar* dst);
885 void addBranchStmt(BranchStmt* edge, SVFVar* src, SVFVar* dst);
890 StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
891 void addStoreStmt(StoreStmt* edge, SVFVar* src, SVFVar* dst);
893 CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
894 const FunEntryICFGNode* entry);
895 void addCallPE(CallPE* edge, SVFVar* src, SVFVar* dst);
897 RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
898 const FunExitICFGNode* exit);
899 void addRetPE(RetPE* edge, SVFVar* src, SVFVar* dst);
901 GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
902 bool constGep);
903 void addGepStmt(GepStmt* edge);
905 GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
907 GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
910 const FunEntryICFGNode* entry);
913 const FunExitICFGNode* exit);
915
918};
919
920typedef SVFIR PAG;
921
922} // End namespace SVF
923
924
925
926#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:789
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:337
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition SVFIR.h:370
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition SVFIR.h:289
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null)
Definition SVFIR.h:800
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:298
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:284
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition SVFIR.h:59
bool funHasRet(const FunObjVar *func) const
Definition SVFIR.h:409
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:684
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:437
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
Definition SVFIR.h:348
std::pair< NodeID, APOffset > GepOffset
Definition SVFIR.h:67
const IDToNodeMapTy & getSVFVarMap() const
Return the entire SVFID to SVFVar map.
Definition SVFIR.h:178
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:534
NodeID addConstantAggObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:760
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition SVFIR.h:583
friend class ExternalPAG
Definition SVFIR.h:45
NodeID addBlackholePtrNode()
Definition SVFIR.h:826
Set< const CallICFGNode * > CallSiteSet
Definition SVFIR.h:53
NodeID addBlackholeObjNode()
Definition SVFIR.h:818
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:755
void addFunArgs(const FunObjVar *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:598
CommonCHGraph * chgraph
Definition SVFIR.h:97
Map< const CallICFGNode *, SVFVarList > CSToArgsListMap
Definition SVFIR.h:61
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:804
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:765
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:423
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:421
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Definition SVFIR.h:84
Map< const RetICFGNode *, const SVFVar * > CSToRetMap
Definition SVFIR.h:62
virtual ~SVFIR()
Destructor.
Definition SVFIR.h:202
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition SVFIR.h:449
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const ICFGNode *node)
Definition SVFIR.h:734
void addFunRet(const FunObjVar *fun, const SVFVar *ret)
Add function returns.
Definition SVFIR.h:610
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition SVFIR.h:464
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition SVFIR.h:86
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:579
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
Definition SVFIR.h:842
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:704
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition SVFIR.h:90
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:54
static std::string pagFileName()
Definition SVFIR.h:261
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:678
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:712
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:304
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:748
bool isConstantObj(NodeID id) const
Definition SVFIR.h:522
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:342
static bool pagReadFromTXT()
Definition SVFIR.h:266
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:194
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:294
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
Definition SVFIR.h:82
std::vector< const SVFVar * > SVFVarList
Definition SVFIR.h:58
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:382
void destroy()
Clean up memory.
Definition SVFIR.cpp:619
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:314
std::vector< const SVFStmt * > SVFStmtList
Definition SVFIR.h:57
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:478
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:234
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:749
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
Definition SVFIR.h:85
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
Definition SVFIR.h:628
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:696
std::pair< NodeID, AccessPath > NodeAccessPath
Definition SVFIR.h:68
void setICFG(ICFG *i)
Set/Get ICFG.
Definition SVFIR.h:213
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:398
const BaseObjVar * getBaseObjVar(NodeID id) const
Definition SVFIR.h:145
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition SVFIR.h:332
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:622
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:63
void addFunArgs(FunEntryICFGNode *funEntryBlockNode, const FunObjVar *fun, const SVFVar *arg)
Definition SVFIR.h:604
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:721
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:671
ICFG * getICFG() const
Definition SVFIR.h:217
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:417
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:651
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:664
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:690
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:453
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition SVFIR.h:460
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:365
const ObjVar * getObjVar(NodeID id) const
Definition SVFIR.h:135
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:853
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:645
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
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:778
void setCallGraph(CallGraph *cg)
Definition SVFIR.h:240
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition SVFIR.h:322
void addFunRet(FunExitICFGNode *funExitBlockNode, const FunObjVar *fun, const SVFVar *ret)
Definition SVFIR.h:616
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:223
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:433
bool isGepObjVar(NodeID id) const
Definition SVFIR.h:173
CommonCHGraph * getCHG()
Definition SVFIR.h:227
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:131
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:393
NodeID addDummyValNode()
Definition SVFIR.h:546
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:309
void addGepValObjFromDB(NodeID curInstID, const GepValVar *gepValvar)
Definition SVFIR.h:575
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:727
OffsetToGepVarMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition SVFIR.h:189
friend class GraphDBClient
Definition SVFIR.h:49
bool isObjVar(NodeID id) const
Definition SVFIR.h:165
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
NodeID addBaseObjNode(BaseObjVar *node)
Definition SVFIR.h:565
OrderedNodeSet candidatePointers
Definition SVFIR.h:95
ICFG * icfg
Definition SVFIR.h:96
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition SVFIR.h:276
CallSiteSet callSiteSet
Definition SVFIR.h:98
friend class TypeBasedHeapCloning
Definition SVFIR.h:47
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:375
NodeID getFIObjVar(NodeID id) const
Definition SVFIR.h:508
Map< const FunObjVar *, const SVFVar * > FunToRetMap
Definition SVFIR.h:63
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:741
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:488
Map< const FunObjVar *, SVFVarList > FunToArgsListMap
Definition SVFIR.h:60
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:517
const GepObjVar * getGepObjVar(NodeID id) const
Definition SVFIR.h:155
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition SVFIR.h:443
Map< NodeID, NodeAccessPathMap > GepValueVarMap
Definition SVFIR.h:71
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition SVFIR.cpp:733
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition SVFIR.h:55
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:387
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:848
const std::string & getModuleIdentifier() const
Definition SVFIR.h:247
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition SVFIR.cpp:240
const SVFVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
Definition SVFIR.h:358
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
Definition SVFIR.h:837
const SVFVar * getFunRet(const FunObjVar *func) const
Get function return list.
Definition SVFIR.h:403
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:634
bool isBaseObjVar(NodeID id) const
Definition SVFIR.h:169
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition SVFIR.h:353
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:772
static void setPagFromTXT(const std::string &txt)
Definition SVFIR.h:271
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:504
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:657
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition SVFIR.h:327
NodeID addDummyObjNode(const SVFType *type)
Definition SVFIR.h:550
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition SVFIR.h:184
NodeID addConstantObjNode()
Definition SVFIR.h:822
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:920
unsigned u32_t
Definition GeneralType.h:47