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/ICFG.h"
34#include "Graphs/IRGraph.h"
35#include "Util/GeneralType.h"
36#include "Util/SVFUtil.h"
37
38namespace SVF
39{
40class CommonCHGraph;
45class SVFIR : public IRGraph
46{
47 friend class SVFIRBuilder;
48 friend class ExternalPAG;
49 friend class PAGBuilderFromFile;
50 friend class BVDataPTAImpl;
51 friend class GraphDBClient;
52 friend class GraphDBSVFIRBuilder;
53
54public:
59 typedef std::vector<const SVFStmt*> SVFStmtList;
60 typedef std::vector<const ValVar*> ValVarList;
70 typedef std::pair<NodeID, APOffset> GepOffset;
71 typedef std::pair<NodeID, AccessPath> NodeAccessPath;
75 typedef std::pair<const SVFType*, std::vector<AccessPath>> SVFTypeLocSetsPair;
78
79private:
101 ICFG* icfg; // ICFG
102 CommonCHGraph* chgraph; // class hierarchy graph
105
106 static std::unique_ptr<SVFIR> pag;
107 static std::string pagReadFromTxt;
108
109 std::string moduleIdentifier;
110
112 SVFIR(bool buildFromFile);
113
115 void destroy();
116
117public:
118
120
121 static inline SVFIR* getPAG(bool buildFromFile = false)
122 {
123 if (pag == nullptr)
124 {
125 pag = std::unique_ptr<SVFIR>(new SVFIR(buildFromFile));
126 }
127 return pag.get();
128 }
129 static void releaseSVFIR()
130 {
131 pag = nullptr;
132 }
134
136 inline const SVFVar* getSVFVar(NodeID id) const
137 {
138 return getGNode(id);
139 }
140 inline const ValVar* getValVar(NodeID id) const
141 {
142 if(const SVFVar* var = getSVFVar(id))
143 return SVFUtil::dyn_cast<ValVar>(var);
144 else
145 {
146 assert(false && "the Node is not a ValVar");
147 return nullptr;
148 }
149 }
150 inline const ObjVar* getObjVar(NodeID id) const
151 {
152 if(const SVFVar* var = getSVFVar(id))
153 return SVFUtil::dyn_cast<ObjVar>(var);
154 else
155 {
156 assert(false && "the Node is not an ObjVar");
157 return nullptr;
158 }
159 }
160 inline const BaseObjVar* getBaseObjVar(NodeID id) const
161 {
162 if(const SVFVar* var = getSVFVar(id))
163 return SVFUtil::dyn_cast<BaseObjVar>(var);
164 else
165 {
166 assert(false && "the Node is not a BaseObjVar");
167 return nullptr;
168 }
169 }
170 inline const GepObjVar* getGepObjVar(NodeID id) const
171 {
172 if(const SVFVar* var = getSVFVar(id))
173 return SVFUtil::dyn_cast<GepObjVar>(var);
174 else
175 {
176 assert(false && "the Node is not a GepObjVar");
177 return nullptr;
178 }
179 }
180 inline bool isObjVar(NodeID id) const
181 {
182 return SVFUtil::isa<ObjVar>(getSVFVar(id));
183 }
184 inline bool isBaseObjVar(NodeID id) const
185 {
186 return SVFUtil::isa<BaseObjVar>(getSVFVar(id));
187 }
188 inline bool isGepObjVar(NodeID id) const
189 {
190 return SVFUtil::isa<GepObjVar>(getSVFVar(id));
191 }
193 inline const IDToNodeMapTy& getSVFVarMap() const
194 {
195 return IDToNodeMap;
196 }
198
200 {
201 return memToFieldsMap;
202 }
205 {
206 return GepObjVarMap;
207 }
210 {
211 return candidatePointers;
212 }
215
217 virtual ~SVFIR()
218 {
219 destroy();
220 }
222
223
224 static void handleBlackHole(bool b);
226
228 inline void setICFG(ICFG* i)
229 {
230 icfg = i;
231 }
232 inline ICFG* getICFG() const
233 {
234 assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
235 return icfg;
236 }
238 inline void setCHG(CommonCHGraph* c)
239 {
240 chgraph = c;
241 }
243 {
244 assert(chgraph && "empty ICFG! Build SVF IR first!");
245 return chgraph;
246 }
247
249 inline const CallGraph* getCallGraph()
250 {
251 assert(callGraph && "empty CallGraph! Build SVF IR first!");
252 return callGraph;
253 }
254
256 {
257 callGraph = cg;
258 }
259
260 const FunObjVar* getFunObjVar(const std::string& name);
261
262 inline const std::string& getModuleIdentifier() const
263 {
264 if (pagReadFromTxt.empty())
265 {
266 assert(!moduleIdentifier.empty() &&
267 "No module found! Reading from a file other than LLVM-IR?");
268 return moduleIdentifier;
269 }
270 else
271 {
272 return pagReadFromTxt;
273 }
274 }
275
276 static inline std::string pagFileName()
277 {
278 return pagReadFromTxt;
279 }
280
281 static inline bool pagReadFromTXT()
282 {
283 return !pagReadFromTxt.empty();
284 }
285
286 static inline void setPagFromTXT(const std::string& txt)
287 {
289 }
290
291 inline void setModuleIdentifier(const std::string& moduleIdentifier)
292 {
293 this->moduleIdentifier = moduleIdentifier;
294 }
295
297
298
300 {
301 return KindToSVFStmtSetMap[kind];
302 }
309 inline bool hasSVFStmtList(const ICFGNode* inst) const
310 {
311 return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
312 }
313 inline bool hasPTASVFStmtList(const ICFGNode* inst) const
314 {
315 return icfgNode2PTASVFStmtsMap.find(inst) !=
317 }
320 {
321 return icfgNode2SVFStmtsMap[inst];
322 }
325 {
326 return icfgNode2PTASVFStmtsMap[inst];
327 }
330 {
331 edge->setICFGNode(inst);
332 icfgNode2SVFStmtsMap[inst].push_back(edge);
333 if (edge->isPTAEdge())
334 icfgNode2PTASVFStmtsMap[inst].push_back(edge);
335 }
348 {
349 return globSVFStmtSet;
350 }
352 inline const CallSiteSet& getCallSiteSet() const
353 {
354 return callSiteSet;
355 }
357 inline bool isPhiNode(const SVFVar* node) const
358 {
359 return phiNodeMap.find(node) != phiNodeMap.end();
360 }
362 inline CallPE* getCallPEForFormalParm(const SVFVar* param) const
363 {
364 auto it = fParmToCallPEMap.find(param);
365 return it != fParmToCallPEMap.end() ? it->second : nullptr;
366 }
367
369 inline bool hasFunArgsList(const FunObjVar* func) const
370 {
371 return (funArgsListMap.find(func) != funArgsListMap.end());
372 }
375 {
376 return funArgsListMap;
377 }
379 inline const ValVarList& getFunArgsList(const FunObjVar* func) const
380 {
381 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
382 assert(it != funArgsListMap.end() && "this function doesn't have arguments");
383 return it->second;
384 }
386 inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
387 {
388 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
389 }
392 {
393 return callSiteArgsListMap;
394 }
396 inline const ValVarList& getCallSiteArgsList(const CallICFGNode* cs) const
397 {
398 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
399 assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
400 return it->second;
401 }
404 {
405 return callSiteRetMap;
406 }
408 inline const ValVar* getCallSiteRet(const RetICFGNode* cs) const
409 {
410 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
411 assert(it != callSiteRetMap.end() && "this call site doesn't have return");
412 return it->second;
413 }
414 inline bool callsiteHasRet(const RetICFGNode* cs) const
415 {
416 return callSiteRetMap.find(cs) != callSiteRetMap.end();
417 }
420 {
421 return funRetMap;
422 }
424 inline const ValVar* getFunRet(const FunObjVar* func) const
425 {
426 FunToRetMap::const_iterator it = funRetMap.find(func);
427 assert(it != funRetMap.end() && "this function doesn't have return");
428 return it->second;
429 }
430 inline bool funHasRet(const FunObjVar* func) const
431 {
432 return funRetMap.find(func) != funRetMap.end();
433 }
435
437
439 {
440 return GepValObjMap.size();
441 }
443 {
444 return GepObjVarMap.size();
445 }
447
450 const AccessPath& ap) const;
451
453
455 {
457 }
458 inline NodeID getFunPtr(const CallICFGNode* cs) const
459 {
460 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
461 assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
462 return it->second;
463 }
465 {
466 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
467 assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
468 return it->second;
469 }
470 inline bool isIndirectCallSites(const CallICFGNode* cs) const
471 {
472 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
473 }
474 inline bool isFunPtr(NodeID id) const
475 {
476 return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
477 }
479
482 {
483 return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
484 }
486 {
487 SVFStmt edge(src, dst, kind, false);
489 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
490 assert(it != edgeSet.end() && "can not find pag edge");
491 return (*it);
492 }
494
498
499 inline const BaseObjVar* getBaseObject(NodeID id) const
500 {
501 const SVFVar* node = getSVFVar(id);
502 if(const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
503 return SVFUtil::dyn_cast<BaseObjVar>(
504 getSVFVar(gepObjVar->getBaseNode()));
505 else
506 return SVFUtil::dyn_cast<BaseObjVar>(node);
507 }
508
509 inline const ValVar* getBaseValVar(NodeID id) const
510 {
511 const SVFVar* node = getSVFVar(id);
512 if(const GepValVar* gepVar = SVFUtil::dyn_cast<GepValVar>(node))
513 return gepVar->getBaseNode();
514 else
515 return SVFUtil::dyn_cast<ValVar>(node);
516 }
518
520 NodeID getGepObjVar(const BaseObjVar* baseObj, const APOffset& ap);
522 NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
524
525 inline NodeID getFIObjVar(const BaseObjVar* obj) const
526 {
527 return obj->getId();
528 }
529 inline NodeID getFIObjVar(NodeID id) const
530 {
531 return getBaseObjVarID(id);
532 }
534
536
537
538 inline bool isBlkObjOrConstantObj(NodeID id) const
539 {
540 return (isBlkObj(id) || isConstantObj(id));
541 }
542
545 inline bool isConstantObj(NodeID id) const
546 {
547 return constantObjs.find(id) != constantObjs.end();
548 }
550
552
553
555 {
556 return getBaseObject(id)->getId();
557 }
559
561
567 {
568 return addDummyValNode(NodeIDAllocator::get()->allocateValueId(), nullptr);
569 }
571 {
572 return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
573 }
575
576 bool isValidPointer(NodeID nodeId) const;
577
578 bool isValidTopLevelPtr(const SVFVar* node);
580
582 void print();
583
584protected:
586 {
587 memToFieldsMap[node->getId()].set(node->getId());
588 return addObjNode(node);
589 }
590
592
593 NodeID addGepObjNode(GepObjVar* gepObj, NodeID base, const APOffset& apOffset);
594
596 {
597 GepValObjMap[curInstID][std::make_pair(gepValvar->getBaseNode()->getId(), gepValvar->getAccessPath())] = gepValvar->getId();
598 }
599
600private:
601
604 {
605 bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
606 (void)added; // Suppress warning of unused variable under release build
607 assert(added && "duplicated edge, not added!!!");
609 if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
610 {
612 KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
613 }
614 }
616
617
618 inline void addFunArgs(const FunObjVar* fun, const ValVar* arg)
619 {
622 }
623
625 {
626 funEntryBlockNode->addFormalParms(arg);
627 funArgsListMap[fun].push_back(arg);
628 }
630 inline void addFunRet(const FunObjVar* fun, const ValVar* ret)
631 {
633 addFunRet(funExitBlockNode, fun, ret);
634 }
635
636 inline void addFunRet(FunExitICFGNode* funExitBlockNode, const FunObjVar* fun, const ValVar* ret)
637 {
638 funExitBlockNode->addFormalRet(ret);
639 funRetMap[fun] = ret;
640 }
642 inline void addCallSiteArgs(CallICFGNode* callBlockNode,const ValVar* arg)
643 {
644 callBlockNode->addActualParms(arg);
645 callSiteArgsListMap[callBlockNode].push_back(arg);
646 }
649 {
650 retBlockNode->addActualRet(arg);
652 }
655 {
656 bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
657 (void) added;
658 funPtrToCallSitesMap[funPtr].insert(cs);
659 assert(added && "adding the same indirect callsite twice?");
660 }
661
663
664
665 inline NodeID addValNode(NodeID i, const SVFType* type, const ICFGNode* icfgNode)
666 {
667 ValVar *node = new ValVar(i, type, icfgNode, ValVar::ValNode);
668 return addValNode(node);
669 }
670
671 NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const FunObjVar* funObjVar, const SVFType* type)
672 {
673 FunValVar* node = new FunValVar(i, icfgNode, funObjVar, type);
674 return addValNode(node);
675 }
676
677 NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const FunObjVar* callGraphNode, const SVFType* type)
678 {
679 ArgValVar* node =
680 new ArgValVar(i, argNo, icfgNode, callGraphNode, type);
681 return addValNode(node);
682 }
683
684 inline NodeID addConstantFPValNode(const NodeID i, double dval,
685 const ICFGNode* icfgNode, const SVFType* type)
686 {
687 SVFVar* node = new ConstFPValVar(i, dval, icfgNode, type);
688 return addNode(node);
689 }
690
691 inline NodeID addConstantIntValNode(NodeID i, const std::pair<s64_t, u64_t>& intValue,
692 const ICFGNode* icfgNode, const SVFType* type)
693 {
694 SVFVar* node = new ConstIntValVar(i, intValue.first, intValue.second, icfgNode, type);
695 return addNode(node);
696 }
697
698 inline NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
699 {
700 SVFVar* node = new ConstNullPtrValVar(i, icfgNode, type);
701 return addNode(node);
702 }
703
704 inline NodeID addGlobalValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
705 {
706 SVFVar* node = new GlobalValVar(i, icfgNode, svfType);
707 return addNode(node);
708 }
709
710 inline NodeID addConstantDataValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
711 {
712 SVFVar* node = new ConstDataValVar(i, icfgNode, type);
713 return addNode(node);
714 }
715
716
719 {
720 return addFIObjNode( i, ti, node);
721 }
722
727 {
728 HeapObjVar *heapObj = new HeapObjVar(i, ti, node);
729 return addBaseObjNode(heapObj);
730 }
731
736 {
737 StackObjVar *stackObj = new StackObjVar(i, ti, node);
738 return addBaseObjNode(stackObj);
739 }
740
742 {
743 FunObjVar* funObj = new FunObjVar(id, ti, node);
744 return addBaseObjNode(funObj);
745 }
746
747
748 inline NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo* ti, double dval, const ICFGNode* node)
749 {
750 ConstFPObjVar* conObj = new ConstFPObjVar(i, dval, ti, node);
751 return addBaseObjNode(conObj);
752 }
753
754
755 inline NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo* ti, const std::pair<s64_t, u64_t>& intValue, const ICFGNode* node)
756 {
758 new ConstIntObjVar(i, intValue.first, intValue.second, ti, node);
759 return addBaseObjNode(conObj);
760 }
761
762
764 {
766 return addBaseObjNode(conObj);
767 }
768
769 inline NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo* ti, const ICFGNode* node)
770 {
771 GlobalObjVar* gObj = new GlobalObjVar(i, ti, node);
772 return addBaseObjNode(gObj);
773 }
775 {
777 return addBaseObjNode(conObj);
778 }
779
781 inline NodeID addRetNode(NodeID i, const FunObjVar* callGraphNode, const SVFType* type, const ICFGNode* icn)
782 {
783 SVFVar *node = new RetValPN(i, callGraphNode, type, icn);
784 return addRetNode(callGraphNode, node);
785 }
787 inline NodeID addVarargNode(NodeID i, const FunObjVar* val, const SVFType* type, const ICFGNode* n)
788 {
789 SVFVar *node = new VarArgValPN(i, val, type, n);
790 return addNode(node);
791 }
792
794 NodeID addGepValNode(NodeID curInst, const ValVar* base, const AccessPath& ap, NodeID i, const SVFType* type, const ICFGNode* node);
796 NodeID addGepObjNode(const BaseObjVar* baseObj, const APOffset& apOffset, const NodeID gepId);
799 {
800 BaseObjVar* baseObj = new BaseObjVar(i, ti, node);
801 return addBaseObjNode(baseObj);
802 }
803
804
806
808
810 {
811 return addValNode(new DummyValVar(i, node));
812 }
814 {
815 if (idToObjTypeInfoMap().find(i) == idToObjTypeInfoMap().end())
816 {
819 return addDummyObjNode(new DummyObjVar(i, ti, nullptr));
820 }
821 else
822 {
823 return addDummyObjNode(new DummyObjVar(i, getObjTypeInfo(i), nullptr));
824 }
825 }
826
832 {
834 }
836 {
837 return addDummyValNode(getBlkPtr(), nullptr);
838 }
840 {
841 return addValNode(new IntrinsicValVar(i, type));
842 }
844 {
845 return addValNode(new AsmPCValVar(i, type));
846 }
848
850 NodeID addValNode(ValVar* node);
852 NodeID addObjNode(ObjVar *node);
854 inline NodeID addRetNode(const FunObjVar*, SVFVar *node)
855 {
856 return addNode(node);
857 }
859 inline NodeID addVarargNode(const FunObjVar*, SVFVar *node)
860 {
861 return addNode(node);
862 }
863
865 inline void addGlobalPAGEdge(const SVFStmt* edge)
866 {
867 globSVFStmtSet.insert(edge);
868 }
870 inline void addCallSite(const CallICFGNode* call)
871 {
872 callSiteSet.insert(call);
873 }
875
876
882
885 void addPhiStmt(PhiStmt* edge, SVFVar* src, SVFVar* dst);
888 void addSelectStmt(SelectStmt* edge, SVFVar* src, SVFVar* dst);
891 void addCmpStmt(CmpStmt* edge, SVFVar* src, SVFVar* dst);
894 u32_t opcode);
895 void addBinaryOPStmt(BinaryOPStmt* edge, SVFVar* src, SVFVar* dst);
897 UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
898 void addUnaryOPStmt(UnaryOPStmt* edge, SVFVar* src, SVFVar* dst);
902 void addBranchStmt(BranchStmt* edge, SVFVar* src, SVFVar* dst);
907 StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
908 void addStoreStmt(StoreStmt* edge, SVFVar* src, SVFVar* dst);
910 CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
911 const FunEntryICFGNode* entry);
912 void addCallPE(CallPE* edge, SVFVar* src, SVFVar* dst);
914 RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
915 const FunExitICFGNode* exit);
916 void addRetPE(RetPE* edge, SVFVar* src, SVFVar* dst);
918 GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
919 bool constGep);
920 void addGepStmt(GepStmt* edge);
922 GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
924 GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
927 const FunEntryICFGNode* entry);
930 const FunExitICFGNode* exit);
932
935};
936
937typedef SVFIR PAG;
938
939} // End namespace SVF
940
941
942
943#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:477
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:250
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
Definition ICFG.cpp:243
Set< const SVFStmt * > SVFStmtSet
Definition IRGraph.h:104
NodeID addNode(SVFVar *node)
Add a node into the graph.
Definition IRGraph.h:116
NodeID getBlkPtr() const
Definition IRGraph.h:254
NodeID getBlackHoleNode() const
Definition IRGraph.h:246
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
Definition IRGraph.h:107
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:248
static bool isBlkObj(NodeID id)
Definition IRGraph.h:164
u32_t totalPTAPAGEdge
Definition IRGraph.h:111
ObjTypeInfo * getObjTypeInfo(NodeID id) const
Definition IRGraph.h:233
NodeID getConstantNode() const
Definition IRGraph.h:250
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
Definition IRGraph.h:108
IDToTypeInfoMapTy & idToObjTypeInfoMap()
Get different kinds of syms maps.
Definition IRGraph.h:211
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static void releaseSVFIR()
Definition SVFIR.h:129
NodeID addFIObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition SVFIR.h:798
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:352
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition SVFIR.h:391
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition SVFIR.h:304
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null)
Definition SVFIR.h:809
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:313
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition SVFIR.cpp:465
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition SVFIR.h:299
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition SVFIR.h:61
bool funHasRet(const FunObjVar *func) const
Definition SVFIR.h:430
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
Definition SVFIR.h:96
NodeID addGlobalValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:704
void addFunArgs(const FunObjVar *fun, const ValVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:618
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition SVFIR.cpp:86
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Definition SVFIR.h:94
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:614
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
Definition SVFIR.cpp:341
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:458
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
Definition SVFIR.h:369
std::pair< NodeID, APOffset > GepOffset
Definition SVFIR.h:70
Map< const CallICFGNode *, ValVarList > CSToArgsListMap
Definition SVFIR.h:64
const IDToNodeMapTy & getSVFVarMap() const
Return the entire SVFID to SVFVar map.
Definition SVFIR.h:193
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Definition SVFIR.cpp:419
void print()
Print SVFIR.
Definition SVFIR.cpp:649
static void handleBlackHole(bool b)
SVFIR build configurations.
Definition SVFIR.cpp:782
FParmToCallPEMap fParmToCallPEMap
Map a formal param to its CallPE.
Definition SVFIR.h:91
NodeID getBaseObjVarID(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:554
const ValVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:408
const ValVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
Definition SVFIR.h:379
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition SVFIR.h:603
friend class ExternalPAG
Definition SVFIR.h:48
NodeID addBlackholePtrNode()
Definition SVFIR.h:835
Set< const CallICFGNode * > CallSiteSet
Definition SVFIR.h:55
NodeID addBlackholeObjNode()
Definition SVFIR.h:827
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:769
CommonCHGraph * chgraph
Definition SVFIR.h:102
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
Definition SVFIR.cpp:364
NodeID addDummyObjNode(NodeID i, const SVFType *type)
Definition SVFIR.h:813
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition SVFIR.cpp:264
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:486
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:774
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:438
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:442
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Definition SVFIR.h:87
virtual ~SVFIR()
Destructor.
Definition SVFIR.h:217
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition SVFIR.h:470
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const ICFGNode *node)
Definition SVFIR.h:748
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition SVFIR.h:485
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition SVFIR.h:90
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:595
std::vector< const ValVar * > ValVarList
Definition SVFIR.h:60
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
Definition SVFIR.h:859
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
Definition SVFIR.h:68
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a memory obj node.
Definition SVFIR.h:718
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition SVFIR.h:95
void addFunRet(const FunObjVar *fun, const ValVar *ret)
Add function returns.
Definition SVFIR.h:630
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:56
static std::string pagFileName()
Definition SVFIR.h:276
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge (phi-like: merges actual params from all call sites into formal param)
Definition SVFIR.cpp:311
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:698
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:726
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:319
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:765
bool isConstantObj(NodeID id) const
Definition SVFIR.h:545
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:357
static bool pagReadFromTXT()
Definition SVFIR.h:281
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:209
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:309
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
Definition SVFIR.h:85
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
Definition SVFIR.cpp:399
CallGraph * callGraph
all the callsites of a program
Definition SVFIR.h:104
Map< NodeID, NodeID > NodeToNodeMap
Definition SVFIR.h:69
NodeSet constantObjs
Constant objects and their fields, recorded when each object node is added.
Definition SVFIR.h:88
static std::string pagReadFromTxt
Definition SVFIR.h:107
friend class GraphDBSVFIRBuilder
Definition SVFIR.h:52
CSToRetMap & getCallSiteRets()
Get callsite return.
Definition SVFIR.h:403
void destroy()
Clean up memory.
Definition SVFIR.cpp:636
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:329
std::vector< const SVFStmt * > SVFStmtList
Definition SVFIR.h:59
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:499
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:249
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:763
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
Definition SVFIR.h:89
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:710
std::pair< NodeID, AccessPath > NodeAccessPath
Definition SVFIR.h:71
void setICFG(ICFG *i)
Set/Get ICFG.
Definition SVFIR.h:228
Map< NodeAccessPath, NodeID > NodeAccessPathMap
Definition SVFIR.h:73
std::string moduleIdentifier
Definition SVFIR.h:109
const FunObjVar * getFunObjVar(const std::string &name)
Definition SVFIR.cpp:48
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
Definition SVFIR.cpp:168
FunToRetMap & getFunRets()
Get function return list.
Definition SVFIR.h:419
const BaseObjVar * getBaseObjVar(NodeID id) const
Definition SVFIR.h:160
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition SVFIR.h:347
NodeID addIntrinsicValNode(NodeID i, const SVFType *type)
Definition SVFIR.h:839
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:642
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:64
Map< const FunObjVar *, ValVarList > FunToArgsListMap
Definition SVFIR.h:63
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
Definition SVFIR.h:92
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
Definition SVFIR.h:82
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:735
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:691
ICFG * getICFG() const
Definition SVFIR.h:232
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:438
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:671
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:684
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition SVFIR.cpp:218
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
Definition SVFIR.h:75
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
Definition SVFIR.cpp:375
bool isFunPtr(NodeID id) const
Definition SVFIR.h:474
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition SVFIR.h:481
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition SVFIR.cpp:194
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition SVFIR.h:386
const ObjVar * getObjVar(NodeID id) const
Definition SVFIR.h:150
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:573
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition SVFIR.h:870
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:106
NodeID addValNode(NodeID i, const SVFType *type, const ICFGNode *icfgNode)
add node into SVFIR
Definition SVFIR.h:665
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition SVFIR.cpp:288
NodeID addGepObjNode(GepObjVar *gepObj, NodeID base, const APOffset &apOffset)
Definition SVFIR.cpp:547
void addFunArgs(FunEntryICFGNode *funEntryBlockNode, const FunObjVar *fun, const ValVar *arg)
Definition SVFIR.h:624
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:787
void setCallGraph(CallGraph *cg)
Definition SVFIR.h:255
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition SVFIR.h:337
NodeID addAsmPCValNode(NodeID i, const SVFType *type)
Definition SVFIR.h:843
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
Definition SVFIR.h:93
void setCHG(CommonCHGraph *c)
Set/Get CHG.
Definition SVFIR.h:238
OffsetToGepVarMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
Definition SVFIR.h:86
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:454
bool isGepObjVar(NodeID id) const
Definition SVFIR.h:188
CommonCHGraph * getCHG()
Definition SVFIR.h:242
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:136
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:414
NodeID addDummyValNode()
Definition SVFIR.h:566
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:324
void addGepValObjFromDB(NodeID curInstID, const GepValVar *gepValvar)
Definition SVFIR.h:595
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Definition SVFIR.h:83
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:741
Map< const SVFVar *, CallPE * > FParmToCallPEMap
Definition SVFIR.h:62
OffsetToGepVarMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition SVFIR.h:204
friend class GraphDBClient
Definition SVFIR.h:51
bool isObjVar(NodeID id) const
Definition SVFIR.h:180
Map< NodeID, NodeBS > MemObjToFieldsMap
Definition SVFIR.h:58
Map< NodePair, NodeID > NodePairSetMap
Definition SVFIR.h:77
Map< GepOffset, NodeID > OffsetToGepVarMap
Definition SVFIR.h:72
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
Definition SVFIR.cpp:109
const ValVar * getFunRet(const FunObjVar *func) const
Get function return list.
Definition SVFIR.h:424
NodeID addBaseObjNode(BaseObjVar *node)
Definition SVFIR.h:585
OrderedNodeSet candidatePointers
Definition SVFIR.h:100
ICFG * icfg
Definition SVFIR.h:101
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition SVFIR.h:291
Map< const FunObjVar *, const ValVar * > FunToRetMap
Definition SVFIR.h:66
CallSiteSet callSiteSet
Definition SVFIR.h:103
NodeID getFIObjVar(NodeID id) const
Definition SVFIR.h:529
Map< const RetICFGNode *, const ValVar * > CSToRetMap
Definition SVFIR.h:65
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
Definition SVFIR.cpp:142
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:121
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *node)
Definition SVFIR.h:755
Map< const FunObjVar *, SVFStmtSet > FunToPAGEdgeSetMap
Definition SVFIR.h:67
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
Definition SVFIR.h:76
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
Definition SVFIR.h:84
const ValVar * getBaseValVar(NodeID id) const
Definition SVFIR.h:509
const ValVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:396
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:538
const GepObjVar * getGepObjVar(NodeID id) const
Definition SVFIR.h:170
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition SVFIR.h:464
Map< NodeID, NodeAccessPathMap > GepValueVarMap
Definition SVFIR.h:74
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition SVFIR.cpp:750
void addFunRet(FunExitICFGNode *funExitBlockNode, const FunObjVar *fun, const ValVar *ret)
Definition SVFIR.h:636
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition SVFIR.h:57
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:865
const std::string & getModuleIdentifier() const
Definition SVFIR.h:262
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition SVFIR.cpp:241
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
Definition SVFIR.h:854
const ValVar * getValVar(NodeID id) const
Definition SVFIR.h:140
CallPE * getCallPEForFormalParm(const SVFVar *param) const
Get the CallPE for a formal parameter (phi-like, nullptr if not found)
Definition SVFIR.h:362
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:654
bool isBaseObjVar(NodeID id) const
Definition SVFIR.h:184
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition SVFIR.h:374
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition SVFIR.cpp:734
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
Definition SVFIR.h:781
static void setPagFromTXT(const std::string &txt)
Definition SVFIR.h:286
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:525
FunPtrToCallSitesMap funPtrToCallSitesMap
Definition SVFIR.h:97
NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode *icfgNode, const FunObjVar *callGraphNode, const SVFType *type)
Definition SVFIR.h:677
void addCallSiteRets(RetICFGNode *retBlockNode, const ValVar *arg)
Add callsite returns.
Definition SVFIR.h:648
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition SVFIR.h:342
NodeID addDummyObjNode(const SVFType *type)
Definition SVFIR.h:570
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition SVFIR.h:199
NodeID addConstantObjNode()
Definition SVFIR.h:831
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
Represents a stack-allocated object variable in the SVFIR (SVF Intermediate Representation) @inherits...
for isBitcode
Definition BasicTypes.h:70
Set< NodeID > NodeSet
Definition GeneralType.h:87
OrderedSet< NodeID > OrderedNodeSet
Definition GeneralType.h:86
u32_t NodeID
Definition GeneralType.h:76
s64_t APOffset
Definition GeneralType.h:80
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
SVFIR PAG
Definition SVFIR.h:937
unsigned u32_t
Definition GeneralType.h:67