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 SVFIRWriter;
49 friend class SVFIRReader;
50 friend class BVDataPTAImpl;
51
52public:
57 typedef std::vector<const SVFStmt*> SVFStmtList;
58 typedef std::vector<const SVFVar*> SVFVarList;
67 typedef std::pair<NodeID, APOffset> NodeOffset;
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 {
132 return memToFieldsMap;
133 }
136 {
137 return GepObjVarMap;
138 }
141 {
142 return candidatePointers;
143 }
146
148 virtual ~SVFIR()
149 {
150 destroy();
151 }
153
154
155 static void handleBlackHole(bool b);
157
159 inline void setICFG(ICFG* i)
160 {
161 icfg = i;
162 }
163 inline ICFG* getICFG() const
164 {
165 assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
166 return icfg;
167 }
169 inline void setCHG(CommonCHGraph* c)
170 {
171 chgraph = c;
172 }
174 {
175 assert(chgraph && "empty ICFG! Build SVF IR first!");
176 return chgraph;
177 }
178
180 inline const CallGraph* getCallGraph()
181 {
182 assert(callGraph && "empty CallGraph! Build SVF IR first!");
183 return callGraph;
184 }
185
186 const FunObjVar* getFunObjVar(const std::string& name);
187
188 inline const std::string& getModuleIdentifier() const
189 {
190 if (pagReadFromTxt.empty())
191 {
192 assert(!moduleIdentifier.empty() &&
193 "No module found! Reading from a file other than LLVM-IR?");
194 return moduleIdentifier;
195 }
196 else
197 {
198 return pagReadFromTxt;
199 }
200 }
201
202 static inline std::string pagFileName()
203 {
204 return pagReadFromTxt;
205 }
206
207 static inline bool pagReadFromTXT()
208 {
209 return !pagReadFromTxt.empty();
210 }
211
212 static inline void setPagFromTXT(const std::string& txt)
213 {
215 }
216
217 inline void setModuleIdentifier(const std::string& moduleIdentifier)
218 {
219 this->moduleIdentifier = moduleIdentifier;
220 }
221
223
224
226 {
227 return KindToSVFStmtSetMap[kind];
228 }
235 inline bool hasSVFStmtList(const ICFGNode* inst) const
236 {
237 return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
238 }
239 inline bool hasPTASVFStmtList(const ICFGNode* inst) const
240 {
241 return icfgNode2PTASVFStmtsMap.find(inst) !=
243 }
246 {
247 return icfgNode2SVFStmtsMap[inst];
248 }
251 {
252 return icfgNode2PTASVFStmtsMap[inst];
253 }
256 {
257 edge->setICFGNode(inst);
258 icfgNode2SVFStmtsMap[inst].push_back(edge);
259 if (edge->isPTAEdge())
260 icfgNode2PTASVFStmtsMap[inst].push_back(edge);
261 }
274 {
275 return globSVFStmtSet;
276 }
278 inline const CallSiteSet& getCallSiteSet() const
279 {
280 return callSiteSet;
281 }
283 inline bool isPhiNode(const SVFVar* node) const
284 {
285 return phiNodeMap.find(node) != phiNodeMap.end();
286 }
287
289 inline bool hasFunArgsList(const FunObjVar* func) const
290 {
291 return (funArgsListMap.find(func) != funArgsListMap.end());
292 }
295 {
296 return funArgsListMap;
297 }
299 inline const SVFVarList& getFunArgsList(const FunObjVar* func) const
300 {
301 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
302 assert(it != funArgsListMap.end() && "this function doesn't have arguments");
303 return it->second;
304 }
306 inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
307 {
308 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
309 }
312 {
313 return callSiteArgsListMap;
314 }
316 inline const SVFVarList& getCallSiteArgsList(const CallICFGNode* cs) const
317 {
318 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
319 assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
320 return it->second;
321 }
324 {
325 return callSiteRetMap;
326 }
328 inline const SVFVar* getCallSiteRet(const RetICFGNode* cs) const
329 {
330 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
331 assert(it != callSiteRetMap.end() && "this call site doesn't have return");
332 return it->second;
333 }
334 inline bool callsiteHasRet(const RetICFGNode* cs) const
335 {
336 return callSiteRetMap.find(cs) != callSiteRetMap.end();
337 }
340 {
341 return funRetMap;
342 }
344 inline const SVFVar* getFunRet(const FunObjVar* func) const
345 {
346 FunToRetMap::const_iterator it = funRetMap.find(func);
347 assert(it != funRetMap.end() && "this function doesn't have return");
348 return it->second;
349 }
350 inline bool funHasRet(const FunObjVar* func) const
351 {
352 return funRetMap.find(func) != funRetMap.end();
353 }
355
357
359 {
360 return GepValObjMap.size();
361 }
363 {
364 return GepObjVarMap.size();
365 }
367
370 const AccessPath& ap) const;
371
373
375 {
377 }
378 inline NodeID getFunPtr(const CallICFGNode* cs) const
379 {
380 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
381 assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
382 return it->second;
383 }
385 {
386 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
387 assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
388 return it->second;
389 }
390 inline bool isIndirectCallSites(const CallICFGNode* cs) const
391 {
392 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
393 }
394 inline bool isFunPtr(NodeID id) const
395 {
396 return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
397 }
399
402 {
403 return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
404 }
406 {
407 SVFStmt edge(src, dst, kind, false);
409 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
410 assert(it != edgeSet.end() && "can not find pag edge");
411 return (*it);
412 }
414
418
419 inline const BaseObjVar* getBaseObject(NodeID id) const
420 {
421 const SVFVar* node = getGNode(id);
422 if(const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
423 return SVFUtil::dyn_cast<BaseObjVar>(
424 getGNode(gepObjVar->getBaseNode()));
425 else
426 return SVFUtil::dyn_cast<BaseObjVar>(node);
427 }
428
429 inline const ValVar* getBaseValVar(NodeID id) const
430 {
431 const SVFVar* node = getGNode(id);
432 if(const GepValVar* gepVar = SVFUtil::dyn_cast<GepValVar>(node))
433 return gepVar->getBaseNode();
434 else
435 return SVFUtil::dyn_cast<ValVar>(node);
436 }
438
440 NodeID getGepObjVar(const BaseObjVar* baseObj, const APOffset& ap);
442 NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
444
445 inline NodeID getFIObjVar(const BaseObjVar* obj) const
446 {
447 return obj->getId();
448 }
449 inline NodeID getFIObjVar(NodeID id) const
450 {
451 return getBaseObjVar(id);
452 }
454
456
457
458 inline bool isBlkObjOrConstantObj(NodeID id) const
459 {
460 return (isBlkObj(id) || isConstantObj(id));
461 }
462
463 inline bool isConstantObj(NodeID id) const
464 {
465 const BaseObjVar* obj = getBaseObject(id);
466 assert(obj && "not an object node?");
467 return isConstantSym(id) ||
468 obj->isConstDataOrConstGlobal();
469 }
471
473
474
475 inline NodeID getBaseObjVar(NodeID id) const
476 {
477 return getBaseObject(id)->getId();
478 }
480
482
488 {
489 return addDummyValNode(NodeIDAllocator::get()->allocateValueId(), nullptr);
490 }
492 {
493 return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
494 }
496
497 bool isValidPointer(NodeID nodeId) const;
498
499 bool isValidTopLevelPtr(const SVFVar* node);
501
503 void print();
504
505private:
506
509 {
510 bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
511 (void)added; // Suppress warning of unused variable under release build
512 assert(added && "duplicated edge, not added!!!");
514 if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
515 {
517 KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
518 }
519 }
521
522
523 inline void addFunArgs(const FunObjVar* fun, const SVFVar* arg)
524 {
527 funArgsListMap[fun].push_back(arg);
528 }
530 inline void addFunRet(const FunObjVar* fun, const SVFVar* ret)
531 {
534 funRetMap[fun] = ret;
535 }
537 inline void addCallSiteArgs(CallICFGNode* callBlockNode,const ValVar* arg)
538 {
539 callBlockNode->addActualParms(arg);
540 callSiteArgsListMap[callBlockNode].push_back(arg);
541 }
544 {
545 retBlockNode->addActualRet(arg);
547 }
550 {
551 bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
552 (void) added;
553 funPtrToCallSitesMap[funPtr].insert(cs);
554 assert(added && "adding the same indirect callsite twice?");
555 }
556
558
559
560 inline NodeID addValNode(NodeID i, const SVFType* type, const ICFGNode* icfgNode)
561 {
562 SVFVar *node = new ValVar(i, type, icfgNode, ValVar::ValNode);
563 return addValNode(node);
564 }
565
566 NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const FunObjVar* funObjVar, const SVFType* type)
567 {
568 FunValVar* node = new FunValVar(i, icfgNode, funObjVar, type);
569 return addValNode(node);
570 }
571
572 NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const FunObjVar* callGraphNode, const SVFType* type)
573 {
574 ArgValVar* node =
575 new ArgValVar(i, argNo, icfgNode, callGraphNode, type);
576 return addValNode(node);
577 }
578
579 inline NodeID addConstantFPValNode(const NodeID i, double dval,
580 const ICFGNode* icfgNode, const SVFType* type)
581 {
582 SVFVar* node = new ConstFPValVar(i, dval, icfgNode, type);
583 return addNode(node);
584 }
585
586 inline NodeID addConstantIntValNode(NodeID i, const std::pair<s64_t, u64_t>& intValue,
587 const ICFGNode* icfgNode, const SVFType* type)
588 {
589 SVFVar* node = new ConstIntValVar(i, intValue.first, intValue.second, icfgNode, type);
590 return addNode(node);
591 }
592
593 inline NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
594 {
595 SVFVar* node = new ConstNullPtrValVar(i, icfgNode, type);
596 return addNode(node);
597 }
598
599 inline NodeID addGlobalValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
600 {
601 SVFVar* node = new GlobalValVar(i, icfgNode, svfType);
602 return addNode(node);
603 }
604
605 inline NodeID addConstantAggValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
606 {
607 SVFVar* node = new ConstAggValVar(i, icfgNode, svfType);
608 return addNode(node);
609 }
610
611 inline NodeID addConstantDataValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
612 {
613 SVFVar* node = new ConstDataValVar(i, icfgNode, type);
614 return addNode(node);
615 }
616
617
619 inline NodeID addObjNode(NodeID i, ObjTypeInfo* ti, const SVFType* type, const ICFGNode* node)
620 {
621 return addFIObjNode( i, ti, type, node);
622 }
623
628 {
629 memToFieldsMap[i].set(i);
630 HeapObjVar *heapObj = new HeapObjVar(i, ti, type, node);
631 return addObjNode(heapObj);
632 }
633
638 {
639 memToFieldsMap[i].set(i);
640 StackObjVar *stackObj = new StackObjVar(i, ti, type, node);
641 return addObjNode(stackObj);
642 }
643
645 {
646 memToFieldsMap[id].set(id);
647 FunObjVar* funObj = new FunObjVar(id, ti, type, node);
648 return addObjNode(funObj);
649 }
650
651
652 inline NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo* ti, double dval, const SVFType* type, const ICFGNode* node)
653 {
654 memToFieldsMap[i].set(i);
655 ConstFPObjVar* conObj = new ConstFPObjVar(i, dval, ti, type, node);
656 return addObjNode(conObj);
657 }
658
659
660 inline NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo* ti, const std::pair<s64_t, u64_t>& intValue, const SVFType* type, const ICFGNode* node)
661 {
662 memToFieldsMap[i].set(i);
664 new ConstIntObjVar(i, intValue.first, intValue.second, ti, type, node);
665 return addObjNode(conObj);
666 }
667
668
670 {
671 memToFieldsMap[i].set(i);
673 return addObjNode(conObj);
674 }
675
676 inline NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo* ti, const SVFType* type, const ICFGNode* node)
677 {
678 memToFieldsMap[i].set(i);
679 GlobalObjVar* gObj = new GlobalObjVar(i, ti, type, node);
680 return addObjNode(gObj);
681 }
683 {
684 memToFieldsMap[i].set(i);
686 return addObjNode(conObj);
687 }
689 {
690 memToFieldsMap[i].set(i);
692 return addObjNode(conObj);
693 }
694
696 inline NodeID addRetNode(NodeID i, const FunObjVar* callGraphNode, const SVFType* type, const ICFGNode* icn)
697 {
698 SVFVar *node = new RetValPN(i, callGraphNode, type, icn);
699 return addRetNode(callGraphNode, node);
700 }
702 inline NodeID addVarargNode(NodeID i, const FunObjVar* val, const SVFType* type, const ICFGNode* n)
703 {
704 SVFVar *node = new VarArgValPN(i, val, type, n);
705 return addNode(node);
706 }
707
709 NodeID addGepValNode(NodeID curInst, const ValVar* base, const AccessPath& ap, NodeID i, const SVFType* type, const ICFGNode* node);
711 NodeID addGepObjNode(const BaseObjVar* baseObj, const APOffset& apOffset, const NodeID gepId);
714 {
715 memToFieldsMap[i].set(i);
716 BaseObjVar* baseObj = new BaseObjVar(i, ti, type, node);
717 return addObjNode(baseObj);
718 }
719
720
722
724
726 {
727 return addValNode(new DummyValVar(i, node));
728 }
730 {
731 if (idToObjTypeInfoMap().find(i) == idToObjTypeInfoMap().end())
732 {
735 return addObjNode(new DummyObjVar(i, ti, nullptr, type));
736 }
737 else
738 {
739 return addObjNode(new DummyObjVar(i, getObjTypeInfo(i), nullptr, type));
740 }
741 }
742
748 {
750 }
752 {
753 return addDummyValNode(getBlkPtr(), nullptr);
754 }
756
759 {
760 assert(node && "node cannot be nullptr.");
761 assert(hasGNode(node->getId()) == false &&
762 "This NodeID clashes here. Please check NodeIDAllocator. Switch "
763 "Strategy::DBUG to SEQ or DENSE");
764 return addNode(node);
765 }
768 {
769 assert(node && "node cannot be nullptr.");
770 assert(hasGNode(node->getId()) == false &&
771 "This NodeID clashes here. Please check NodeIDAllocator. Switch "
772 "Strategy::DBUG to SEQ or DENSE");
773 return addNode(node);
774 }
776 inline NodeID addRetNode(const FunObjVar*, SVFVar *node)
777 {
778 return addNode(node);
779 }
781 inline NodeID addVarargNode(const FunObjVar*, SVFVar *node)
782 {
783 return addNode(node);
784 }
785
787 inline void addGlobalPAGEdge(const SVFStmt* edge)
788 {
789 globSVFStmtSet.insert(edge);
790 }
792 inline void addCallSite(const CallICFGNode* call)
793 {
794 callSiteSet.insert(call);
795 }
797
798
802
811 u32_t opcode);
813 UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
820 StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
822 CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
823 const FunEntryICFGNode* entry);
825 RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
826 const FunExitICFGNode* exit);
828 GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
829 bool constGep);
831 GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
833 GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
836 const FunEntryICFGNode* entry);
839 const FunExitICFGNode* exit);
841
844};
845
846typedef SVFIR PAG;
847
848} // End namespace SVF
849
850
851
852#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:488
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
void addFormalParms(const SVFVar *fp)
Add formal parameters.
Definition ICFGNode.h:307
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
Definition ICFGNode.h:375
bool hasGNode(NodeID id) const
Has a node.
NodeType * getGNode(NodeID id) const
Get a node.
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:106
NodeID addNode(SVFVar *node)
Add a node into the graph.
Definition IRGraph.h:118
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:109
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:113
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:110
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 addGepObjNode(const BaseObjVar *baseObj, const APOffset &apOffset, const NodeID gepId)
Add a field obj node, this method can only invoked by getGepObjVar.
Definition SVFIR.cpp:466
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:278
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition SVFIR.h:311
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Add a memory obj node.
Definition SVFIR.h:619
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition SVFIR.h:230
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null)
Definition SVFIR.h:725
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:239
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition SVFIR.cpp:382
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition SVFIR.h:225
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition SVFIR.h:59
bool funHasRet(const FunObjVar *func) const
Definition SVFIR.h:350
NodeOffsetMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
Definition SVFIR.h:83
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:599
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition SVFIR.cpp:81
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Definition SVFIR.h:89
NodeID addObjNode(SVFVar *node)
Add a memory obj node.
Definition SVFIR.h:767
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:522
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
Definition SVFIR.cpp:276
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:378
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
Definition SVFIR.h:289
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:676
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Definition SVFIR.cpp:344
void print()
Print SVFIR.
Definition SVFIR.cpp:557
static void handleBlackHole(bool b)
SVFIR build configurations.
Definition SVFIR.cpp:690
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:652
NodeID addValNode(SVFVar *node)
Add a value (pointer) node.
Definition SVFIR.h:758
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition SVFIR.h:508
friend class ExternalPAG
Definition SVFIR.h:45
NodeID addBlackholePtrNode()
Definition SVFIR.h:751
Set< const CallICFGNode * > CallSiteSet
Definition SVFIR.h:53
NodeID addBlackholeObjNode()
Definition SVFIR.h:743
void addFunArgs(const FunObjVar *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:523
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:294
NodeID addDummyObjNode(NodeID i, const SVFType *type)
Definition SVFIR.h:729
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:627
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition SVFIR.cpp:221
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:403
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:363
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:362
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:148
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition SVFIR.h:390
void addFunRet(const FunObjVar *fun, const SVFVar *ret)
Add function returns.
Definition SVFIR.h:530
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition SVFIR.h:405
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition SVFIR.h:86
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:504
std::pair< NodeID, APOffset > NodeOffset
Definition SVFIR.h:67
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
Definition SVFIR.h:781
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
Definition SVFIR.h:65
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:644
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition SVFIR.h:90
NodeID getGepObjVar(const BaseObjVar *baseObj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
Definition SVFIR.cpp:439
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:637
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:54
static std::string pagFileName()
Definition SVFIR.h:202
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
Definition SVFIR.cpp:258
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:593
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:245
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:673
bool isConstantObj(NodeID id) const
Definition SVFIR.h:463
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:283
static bool pagReadFromTXT()
Definition SVFIR.h:207
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:140
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:235
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:323
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
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:688
CSToRetMap & getCallSiteRets()
Get callsite return.
Definition SVFIR.h:323
void destroy()
Clean up memory.
Definition SVFIR.cpp:544
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:255
std::vector< const SVFStmt * > SVFStmtList
Definition SVFIR.h:57
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:419
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:180
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:543
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:611
std::pair< NodeID, AccessPath > NodeAccessPath
Definition SVFIR.h:68
void setICFG(ICFG *i)
Set/Get ICFG.
Definition SVFIR.h:159
NodeID addFIObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition SVFIR.h:713
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:475
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:144
FunToRetMap & getFunRets()
Get function return list.
Definition SVFIR.h:339
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition SVFIR.h:273
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:537
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:63
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 addConstantAggObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:682
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:586
ICFG * getICFG() const
Definition SVFIR.h:163
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:358
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:566
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:579
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition SVFIR.cpp:185
NodeID addConstantAggValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:605
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:669
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:305
bool isFunPtr(NodeID id) const
Definition SVFIR.h:394
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition SVFIR.h:401
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition SVFIR.cpp:165
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition SVFIR.h:306
friend class SVFIRReader
Definition SVFIR.h:49
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:483
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition SVFIR.h:792
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:560
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition SVFIR.cpp:240
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:702
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition SVFIR.h:263
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:169
NodeOffsetMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition SVFIR.h:135
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:374
CommonCHGraph * getCHG()
Definition SVFIR.h:173
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:334
NodeID addDummyValNode()
Definition SVFIR.h:487
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:250
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Definition SVFIR.h:80
Map< NodeID, NodeBS > MemObjToFieldsMap
Definition SVFIR.h:56
Map< NodePair, NodeID > NodePairSetMap
Definition SVFIR.h:74
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
Definition SVFIR.cpp:99
OrderedNodeSet candidatePointers
Definition SVFIR.h:95
ICFG * icfg
Definition SVFIR.h:96
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition SVFIR.h:217
CallSiteSet callSiteSet
Definition SVFIR.h:98
friend class SVFIRWriter
Definition SVFIR.h:48
friend class TypeBasedHeapCloning
Definition SVFIR.h:47
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:316
NodeID getFIObjVar(NodeID id) const
Definition SVFIR.h:449
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:123
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
Map< const FunObjVar *, SVFStmtSet > FunToPAGEdgeSetMap
Definition SVFIR.h:64
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:660
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:429
Map< const FunObjVar *, SVFVarList > FunToArgsListMap
Definition SVFIR.h:60
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:458
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition SVFIR.h:384
Map< NodeID, NodeAccessPathMap > GepValueVarMap
Definition SVFIR.h:71
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition SVFIR.cpp:658
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition SVFIR.h:55
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:328
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:787
const std::string & getModuleIdentifier() const
Definition SVFIR.h:188
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition SVFIR.cpp:203
Map< NodeOffset, NodeID > NodeOffsetMap
Definition SVFIR.h:69
const SVFVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
Definition SVFIR.h:299
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
Definition SVFIR.h:776
const SVFVar * getFunRet(const FunObjVar *func) const
Get function return list.
Definition SVFIR.h:344
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:549
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition SVFIR.h:294
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition SVFIR.cpp:642
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
Definition SVFIR.h:696
static void setPagFromTXT(const std::string &txt)
Definition SVFIR.h:212
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:445
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:572
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition SVFIR.h:268
NodeID addDummyObjNode(const SVFType *type)
Definition SVFIR.h:491
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition SVFIR.h:130
NodeID addConstantObjNode()
Definition SVFIR.h:747
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
NodeID getId() const
Get ID.
Definition SVFValue.h:158
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:846
unsigned u32_t
Definition GeneralType.h:47