Static Value-Flow Analysis
SVFValue.h
Go to the documentation of this file.
1 //===- BasicTypes.h -- Basic types used in SVF-------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <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  * BasicTypes.h
25  *
26  * Created on: Apr 1, 2014
27  * Author: Yulei Sui
28  */
29 
30 #ifndef INCLUDE_SVFIR_SVFVALUE_H_
31 #define INCLUDE_SVFIR_SVFVALUE_H_
32 
33 #include "SVFIR/SVFType.h"
34 #include "Graphs/GraphPrinter.h"
35 #include "Util/Casting.h"
36 
37 namespace SVF
38 {
39 
42 
43 
44 class SVFInstruction;
45 class SVFBasicBlock;
46 class SVFArgument;
47 class SVFFunction;
48 class SVFType;
49 
51 {
52  friend class SVFIRWriter;
53  friend class SVFIRReader;
54 public:
56  typedef std::vector<const SVFBasicBlock*> BBList;
57  typedef BBList LoopBBs;
58 
59 private:
67 
68 public:
70  {
71  }
72 
73  virtual ~SVFLoopAndDomInfo() {}
74 
76  {
77  return dfBBsMap;
78  }
79 
81  {
82  return dfBBsMap;
83  }
84 
85  inline bool hasLoopInfo(const SVFBasicBlock* bb) const
86  {
87  return bb2LoopMap.find(bb) != bb2LoopMap.end();
88  }
89 
90  const LoopBBs& getLoopInfo(const SVFBasicBlock* bb) const;
91 
92  inline const SVFBasicBlock* getLoopHeader(const LoopBBs& lp) const
93  {
94  assert(!lp.empty() && "this is not a loop, empty basic block");
95  return lp.front();
96  }
97 
98  inline bool loopContainsBB(const LoopBBs& lp, const SVFBasicBlock* bb) const
99  {
100  return std::find(lp.begin(), lp.end(), bb) != lp.end();
101  }
102 
103  inline void addToBB2LoopMap(const SVFBasicBlock* bb, const SVFBasicBlock* loopBB)
104  {
105  bb2LoopMap[bb].push_back(loopBB);
106  }
107 
109  {
110  return pdtBBsMap;
111  }
112 
114  {
115  return pdtBBsMap;
116  }
117 
119  {
120  return bb2PdomLevel;
121  }
122 
124  {
125  return bb2PdomLevel;
126  }
127 
129  {
130  return bb2PIdom;
131  }
132 
134  {
135  return bb2PIdom;
136  }
137 
138 
140  {
141  return dtBBsMap;
142  }
143 
145  {
146  return dtBBsMap;
147  }
148 
149  inline bool isUnreachable(const SVFBasicBlock* bb) const
150  {
151  return std::find(reachableBBs.begin(), reachableBBs.end(), bb) ==
152  reachableBBs.end();
153  }
154 
155  inline const BBList& getReachableBBs() const
156  {
157  return reachableBBs;
158  }
159 
160  inline void setReachableBBs(BBList& bbs)
161  {
162  reachableBBs = bbs;
163  }
164 
165  void getExitBlocksOfLoop(const SVFBasicBlock* bb, BBList& exitbbs) const;
166 
167  bool isLoopHeader(const SVFBasicBlock* bb) const;
168 
169  bool dominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const;
170 
171  bool postDominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const;
172 
174  const SVFBasicBlock *findNearestCommonPDominator(const SVFBasicBlock *A, const SVFBasicBlock *B) const;
175 };
176 
177 class SVFValue
178 {
179  friend class SVFIRWriter;
180  friend class SVFIRReader;
181  friend class LLVMModuleSet;
182 
183 public:
184  typedef s64_t GNodeK;
185 
187  {
203  SVFOther
204  };
205 
206 private:
210 
211 protected:
212  const SVFType* type;
217  : kind(k), ptrInUncalledFun(false),
218  constDataOrAggData(SVFConstData == k), type(ty), sourceLoc("NoLoc")
219  {
220  }
221 
224  inline void setConstDataOrAggData()
225  {
226  constDataOrAggData = true;
227  }
229  {
230  ptrInUncalledFun = true;
231  }
233 public:
234  SVFValue() = delete;
235  virtual ~SVFValue() = default;
236 
238  inline GNodeK getKind() const
239  {
240  return kind;
241  }
242 
243  inline const std::string &getName() const
244  {
245  return name;
246  }
247  inline void setName(const std::string& n)
248  {
249  name = n;
250  }
251  inline void setName(std::string&& n)
252  {
253  name = std::move(n);
254  }
255 
256  inline virtual const SVFType* getType() const
257  {
258  return type;
259  }
260  inline bool isConstDataOrAggData() const
261  {
262  return constDataOrAggData;
263  }
264  inline bool ptrInUncalledFunction() const
265  {
266  return ptrInUncalledFun;
267  }
268  inline bool isblackHole() const
269  {
270  return getKind() == SVFBlackHole;;
271  }
272  inline bool isNullPtr() const
273  {
274  return getKind() == SVFNullPtr;
275  }
276  inline virtual void setSourceLoc(const std::string& sourceCodeInfo)
277  {
278  sourceLoc = sourceCodeInfo;
279  }
280  inline virtual const std::string getSourceLoc() const
281  {
282  return sourceLoc;
283  }
284 
286  std::string toString() const;
287 
289 
290  friend OutStream& operator<<(OutStream &os, const SVFValue &value)
291  {
292  return os << value.toString();
293  }
295 };
296 
297 class SVFFunction : public SVFValue
298 {
299  friend class LLVMModuleSet;
300  friend class SVFIRWriter;
301  friend class SVFIRReader;
302  friend class SVFIRBuilder;
303 
304 public:
305  typedef std::vector<const SVFBasicBlock*>::const_iterator const_iterator;
309 
310 private:
311  bool isDecl;
312  bool intrinsic;
313  bool addrTaken;
314  bool isUncalled;
315  bool isNotRet;
316  bool varArg;
320  std::vector<const SVFBasicBlock*> allBBs;
321  std::vector<const SVFArgument*> allArgs;
323 
324 protected:
326  inline void addBasicBlock(const SVFBasicBlock* bb)
327  {
328  allBBs.push_back(bb);
329  }
330 
331  inline void addArgument(SVFArgument* arg)
332  {
333  allArgs.push_back(arg);
334  }
335 
336  inline void setIsUncalledFunction(bool uncalledFunction)
337  {
338  isUncalled = uncalledFunction;
339  }
340 
341  inline void setIsNotRet(bool notRet)
342  {
343  isNotRet = notRet;
344  }
345 
346  inline void setDefFunForMultipleModule(const SVFFunction* deffun)
347  {
348  realDefFun = deffun;
349  }
351 
352 public:
353  SVFFunction(const SVFType* ty,const SVFFunctionType* ft, bool declare, bool intrinsic, bool addrTaken, bool varg, SVFLoopAndDomInfo* ld);
354  SVFFunction(void) = delete;
355  virtual ~SVFFunction();
356 
357  static inline bool classof(const SVFValue *node)
358  {
359  return node->getKind() == SVFFunc;
360  }
361 
363  {
364  return loopAndDom;
365  }
366  inline bool isDeclaration() const
367  {
368  return isDecl;
369  }
370 
371  inline bool isIntrinsic() const
372  {
373  return intrinsic;
374  }
375 
376  inline bool hasAddressTaken() const
377  {
378  return addrTaken;
379  }
380 
382  inline const SVFFunctionType* getFunctionType() const
383  {
384  return funcType;
385  }
386 
388  inline const SVFType* getReturnType() const
389  {
390  return funcType->getReturnType();
391  }
392 
394  {
395  if(realDefFun==nullptr)
396  return this;
397  return realDefFun;
398  }
399 
400  u32_t arg_size() const;
401  const SVFArgument* getArg(u32_t idx) const;
402  bool isVarArg() const;
403 
404  inline bool hasBasicBlock() const
405  {
406  return !allBBs.empty();
407  }
408 
409  inline const SVFBasicBlock* getEntryBlock() const
410  {
411  assert(hasBasicBlock() && "function does not have any Basicblock, external function?");
412  return allBBs.front();
413  }
414 
417  const SVFBasicBlock* getExitBB() const;
418 
419  void setExitBlock(SVFBasicBlock *bb);
420 
421  inline const SVFBasicBlock* front() const
422  {
423  return getEntryBlock();
424  }
425 
426  inline const SVFBasicBlock* back() const
427  {
428  assert(hasBasicBlock() && "function does not have any Basicblock, external function?");
432  return allBBs.back();
433  }
434 
435  inline const_iterator begin() const
436  {
437  return allBBs.begin();
438  }
439 
440  inline const_iterator end() const
441  {
442  return allBBs.end();
443  }
444 
445  inline const std::vector<const SVFBasicBlock*>& getBasicBlockList() const
446  {
447  return allBBs;
448  }
449 
450  inline const std::vector<const SVFBasicBlock*>& getReachableBBs() const
451  {
452  return loopAndDom->getReachableBBs();
453  }
454 
455  inline bool isUncalledFunction() const
456  {
457  return isUncalled;
458  }
459 
460  inline bool hasReturn() const
461  {
462  return !isNotRet;
463  }
464 
465  inline void getExitBlocksOfLoop(const SVFBasicBlock* bb, BBList& exitbbs) const
466  {
467  return loopAndDom->getExitBlocksOfLoop(bb,exitbbs);
468  }
469 
470  inline bool hasLoopInfo(const SVFBasicBlock* bb) const
471  {
472  return loopAndDom->hasLoopInfo(bb);
473  }
474 
475  const LoopBBs& getLoopInfo(const SVFBasicBlock* bb) const
476  {
477  return loopAndDom->getLoopInfo(bb);
478  }
479 
480  inline const SVFBasicBlock* getLoopHeader(const BBList& lp) const
481  {
482  return loopAndDom->getLoopHeader(lp);
483  }
484 
485  inline bool loopContainsBB(const BBList& lp, const SVFBasicBlock* bb) const
486  {
487  return loopAndDom->loopContainsBB(lp,bb);
488  }
489 
491  {
492  return loopAndDom->getDomTreeMap();
493  }
494 
496  {
497  return loopAndDom->getDomFrontierMap();
498  }
499 
500  inline bool isLoopHeader(const SVFBasicBlock* bb) const
501  {
502  return loopAndDom->isLoopHeader(bb);
503  }
504 
505  inline bool dominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const
506  {
507  return loopAndDom->dominate(bbKey,bbValue);
508  }
509 
510  inline bool postDominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const
511  {
512  return loopAndDom->postDominate(bbKey,bbValue);
513  }
514 };
515 
516 class ICFGNode;
517 
518 class SVFBasicBlock : public SVFValue
519 {
520  friend class LLVMModuleSet;
521  friend class SVFIRWriter;
522  friend class SVFIRReader;
523  friend class SVFIRBuilder;
524  friend class SVFFunction;
525  friend class ICFGBuilder;
526  friend class ICFG;
527 
528 public:
529  typedef std::vector<const ICFGNode*>::const_iterator const_iterator;
530 
531 private:
532  std::vector<const ICFGNode*> allICFGNodes;
533  std::vector<const SVFBasicBlock*> succBBs;
534  std::vector<const SVFBasicBlock*> predBBs;
535  const SVFFunction* fun;
536 
537 protected:
539 
540  inline void addICFGNode(const ICFGNode* icfgNode)
541  {
542  assert(std::find(getICFGNodeList().begin(), getICFGNodeList().end(),
543  icfgNode) == getICFGNodeList().end() && "duplicated icfgnode");
544  allICFGNodes.push_back(icfgNode);
545  }
546 
547  inline void addSuccBasicBlock(const SVFBasicBlock* succ)
548  {
549  succBBs.push_back(succ);
550  }
551 
552  inline void addPredBasicBlock(const SVFBasicBlock* pred)
553  {
554  predBBs.push_back(pred);
555  }
557 
558 public:
560  SVFBasicBlock(const SVFType* ty, const SVFFunction* f);
561  SVFBasicBlock() = delete;
562  ~SVFBasicBlock() override;
563 
564  static inline bool classof(const SVFValue *node)
565  {
566  return node->getKind() == SVFBB;
567  }
568 
569  inline const std::vector<const ICFGNode*>& getICFGNodeList() const
570  {
571  return allICFGNodes;
572  }
573 
574  inline const_iterator begin() const
575  {
576  return allICFGNodes.begin();
577  }
578 
579  inline const_iterator end() const
580  {
581  return allICFGNodes.end();
582  }
583 
584  inline const SVFFunction* getParent() const
585  {
586  return fun;
587  }
588 
589  inline const SVFFunction* getFunction() const
590  {
591  return fun;
592  }
593 
594  inline const ICFGNode* front() const
595  {
596  assert(!allICFGNodes.empty() && "bb empty?");
597  return allICFGNodes.front();
598  }
599 
600  inline const ICFGNode* back() const
601  {
602  assert(!allICFGNodes.empty() && "bb empty?");
603  return allICFGNodes.back();
604  }
605 
606  inline const std::vector<const SVFBasicBlock*>& getSuccessors() const
607  {
608  return succBBs;
609  }
610 
611  inline const std::vector<const SVFBasicBlock*>& getPredecessors() const
612  {
613  return predBBs;
614  }
616  {
617  return succBBs.size();
618  }
619  u32_t getBBSuccessorPos(const SVFBasicBlock* succbb);
620  u32_t getBBSuccessorPos(const SVFBasicBlock* succbb) const;
621  u32_t getBBPredecessorPos(const SVFBasicBlock* succbb);
622  u32_t getBBPredecessorPos(const SVFBasicBlock* succbb) const;
623 };
624 
625 class SVFInstruction : public SVFValue
626 {
627  friend class SVFIRWriter;
628  friend class SVFIRReader;
629 
630 private:
631  const SVFBasicBlock* bb;
632  bool terminator;
633  bool ret;
634 
635 public:
637  SVFInstruction(const SVFType* ty, const SVFBasicBlock* b, bool tm,
638  bool isRet, SVFValKind k = SVFInst);
639  SVFInstruction(void) = delete;
640 
641  static inline bool classof(const SVFValue *node)
642  {
643  return node->getKind() == SVFInst ||
644  node->getKind() == SVFCall ||
645  node->getKind() == SVFVCall;
646  }
647 
648  inline const SVFBasicBlock* getParent() const
649  {
650  return bb;
651  }
652 
653  inline const SVFFunction* getFunction() const
654  {
655  return bb->getParent();
656  }
657 
658  inline bool isRetInst() const
659  {
660  return ret;
661  }
662 };
663 
665 {
666  friend class SVFIRWriter;
667  friend class SVFIRReader;
668  friend class LLVMModuleSet;
669  friend class SVFIRBuilder;
670 
671 private:
672  std::vector<const SVFValue*> args;
673  bool varArg;
675 
676 protected:
678  inline void addArgument(const SVFValue* a)
679  {
680  args.push_back(a);
681  }
682  inline void setCalledOperand(const SVFValue* v)
683  {
684  calledVal = v;
685  }
687 
688 public:
689  SVFCallInst(const SVFType* ty, const SVFBasicBlock* b, bool va, bool tm, SVFValKind k = SVFCall) :
690  SVFInstruction(ty, b, tm, false, k), varArg(va), calledVal(nullptr)
691  {
692  }
693  SVFCallInst(void) = delete;
694 
695  static inline bool classof(const SVFValue *node)
696  {
697  return node->getKind() == SVFCall || node->getKind() == SVFVCall;
698  }
699  static inline bool classof(const SVFInstruction *node)
700  {
701  return node->getKind() == SVFCall || node->getKind() == SVFVCall;
702  }
703  inline u32_t arg_size() const
704  {
705  return args.size();
706  }
707  inline bool arg_empty() const
708  {
709  return args.empty();
710  }
711  inline const SVFValue* getArgOperand(u32_t i) const
712  {
713  assert(i < arg_size() && "out of bound access of the argument");
714  return args[i];
715  }
716  inline u32_t getNumArgOperands() const
717  {
718  return arg_size();
719  }
720  inline const SVFValue* getCalledOperand() const
721  {
722  return calledVal;
723  }
724  inline bool isVarArg() const
725  {
726  return varArg;
727  }
728  inline const SVFFunction* getCalledFunction() const
729  {
730  return SVFUtil::dyn_cast<SVFFunction>(calledVal);
731  }
732  inline const SVFFunction* getCaller() const
733  {
734  return getFunction();
735  }
736 };
737 
739 {
740  friend class SVFIRWriter;
741  friend class SVFIRReader;
742  friend class LLVMModuleSet;
743 
744 private:
748 
749 protected:
750  inline void setFunIdxInVtable(s32_t idx)
751  {
752  virtualFunIdx = idx;
753  }
755  {
757  }
758  inline void setVtablePtr(const SVFValue* vptr)
759  {
760  vCallVtblPtr = vptr;
761  }
762 
763 public:
764  SVFVirtualCallInst(const SVFType* ty, const SVFBasicBlock* b, bool vararg,
765  bool tm)
766  : SVFCallInst(ty, b, vararg, tm, SVFVCall), vCallVtblPtr(nullptr),
768  {
769  }
770  inline const SVFValue* getVtablePtr() const
771  {
772  assert(vCallVtblPtr && "virtual call does not have a vtblptr? set it first");
773  return vCallVtblPtr;
774  }
775  inline s32_t getFunIdxInVtable() const
776  {
777  assert(virtualFunIdx >=0 && "virtual function idx is less than 0? not set yet?");
778  return virtualFunIdx;
779  }
780  inline const std::string& getFunNameOfVirtualCall() const
781  {
782  return funNameOfVcall;
783  }
784  static inline bool classof(const SVFValue *node)
785  {
786  return node->getKind() == SVFVCall;
787  }
788  static inline bool classof(const SVFInstruction *node)
789  {
790  return node->getKind() == SVFVCall;
791  }
792  static inline bool classof(const SVFCallInst *node)
793  {
794  return node->getKind() == SVFVCall;
795  }
796 };
797 
798 class SVFConstant : public SVFValue
799 {
800  friend class SVFIRWriter;
801  friend class SVFIRReader;
802 public:
804  {
805  }
806  SVFConstant() = delete;
807 
808  static inline bool classof(const SVFValue *node)
809  {
810  return node->getKind() == SVFConst ||
811  node->getKind() == SVFGlob ||
812  node->getKind() == SVFConstData ||
813  node->getKind() == SVFConstInt ||
814  node->getKind() == SVFConstFP ||
815  node->getKind() == SVFNullPtr ||
816  node->getKind() == SVFBlackHole;
817  }
818 
819 };
820 
822 {
823  friend class SVFIRWriter;
824  friend class SVFIRReader;
825  friend class LLVMModuleSet;
826 
827 private:
829 
830 protected:
831  inline void setDefGlobalForMultipleModule(const SVFValue* defg)
832  {
833  realDefGlobal = defg;
834  }
835 
836 public:
838  {
839  }
841  {
843  }
844  SVFGlobalValue() = delete;
845 
847  {
848  if(realDefGlobal==nullptr)
849  return this;
850  return realDefGlobal;
851  }
852  static inline bool classof(const SVFValue *node)
853  {
854  return node->getKind() == SVFGlob;
855  }
856  static inline bool classof(const SVFConstant *node)
857  {
858  return node->getKind() == SVFGlob;
859  }
860 };
861 
862 class SVFArgument : public SVFValue
863 {
864  friend class SVFIRWriter;
865  friend class SVFIRReader;
866 private:
867  const SVFFunction* fun;
869  bool uncalled;
870 public:
872  bool uncalled)
873  : SVFValue(ty, SVFValue::SVFArg), fun(fun), argNo(argNo),
875  {
876  }
877  SVFArgument() = delete;
878 
879  inline const SVFFunction* getParent() const
880  {
881  return fun;
882  }
883 
886  inline u32_t getArgNo() const
887  {
888  return argNo;
889  }
890 
891  inline bool isArgOfUncalledFunction() const
892  {
893  return uncalled;
894  }
895 
896  static inline bool classof(const SVFValue *node)
897  {
898  return node->getKind() == SVFArg;
899  }
900 };
901 
903 {
904  friend class SVFIRWriter;
905  friend class SVFIRReader;
906 public:
908  : SVFConstant(ty, k)
909  {
910  }
911  SVFConstantData() = delete;
912 
913  static inline bool classof(const SVFValue *node)
914  {
915  return node->getKind() == SVFConstData ||
916  node->getKind() == SVFConstInt ||
917  node->getKind() == SVFConstFP ||
918  node->getKind() == SVFNullPtr ||
919  node->getKind() == SVFBlackHole;
920  }
921  static inline bool classof(const SVFConstantData *node)
922  {
923  return node->getKind() == SVFConstData ||
924  node->getKind() == SVFConstInt ||
925  node->getKind() == SVFConstFP ||
926  node->getKind() == SVFNullPtr ||
927  node->getKind() == SVFBlackHole;
928  }
929 };
930 
932 {
933  friend class SVFIRWriter;
934  friend class SVFIRReader;
935 private:
938 public:
941  {
942  }
943  SVFConstantInt() = delete;
944 
945  static inline bool classof(const SVFValue *node)
946  {
947  return node->getKind() == SVFConstInt;
948  }
949  static inline bool classof(const SVFConstantData *node)
950  {
951  return node->getKind() == SVFConstInt;
952  }
953  // Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate for the type of this constant.
954  inline u64_t getZExtValue () const
955  {
956  return zval;
957  }
958  // Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the type of this constant
959  inline s64_t getSExtValue () const
960  {
961  return sval;
962  }
963 };
964 
966 {
967  friend class SVFIRWriter;
968  friend class SVFIRReader;
969 private:
970  float dval;
971 public:
972  SVFConstantFP(const SVFType* ty, double d)
974  {
975  }
976  SVFConstantFP() = delete;
977 
978  inline double getFPValue () const
979  {
980  return dval;
981  }
982  static inline bool classof(const SVFValue *node)
983  {
984  return node->getKind() == SVFConstFP;
985  }
986  static inline bool classof(const SVFConstantData *node)
987  {
988  return node->getKind() == SVFConstFP;
989  }
990 };
991 
993 {
994  friend class SVFIRWriter;
995  friend class SVFIRReader;
996 
997 public:
1000  {
1001  }
1003 
1004  static inline bool classof(const SVFValue *node)
1005  {
1006  return node->getKind() == SVFNullPtr;
1007  }
1008  static inline bool classof(const SVFConstantData *node)
1009  {
1010  return node->getKind() == SVFNullPtr;
1011  }
1012 };
1013 
1015 {
1016  friend class SVFIRWriter;
1017  friend class SVFIRReader;
1018 
1019 public:
1022  {
1023  }
1024  SVFBlackHoleValue() = delete;
1025 
1026  static inline bool classof(const SVFValue *node)
1027  {
1028  return node->getKind() == SVFBlackHole;
1029  }
1030  static inline bool classof(const SVFConstantData *node)
1031  {
1032  return node->getKind() == SVFBlackHole;
1033  }
1034 };
1035 
1036 class SVFOtherValue : public SVFValue
1037 {
1038  friend class SVFIRWriter;
1039  friend class SVFIRReader;
1040 public:
1042  : SVFValue(ty, k)
1043  {
1044  }
1045  SVFOtherValue() = delete;
1046 
1047  static inline bool classof(const SVFValue *node)
1048  {
1049  return node->getKind() == SVFOther || node->getKind() == SVFMetaAsValue;
1050  }
1051 };
1052 
1053 /*
1054  * This class is only for LLVM's MetadataAsValue
1055 */
1057 {
1058  friend class SVFIRWriter;
1059  friend class SVFIRReader;
1060 public:
1063  {
1064  }
1066 
1067  static inline bool classof(const SVFValue *node)
1068  {
1069  return node->getKind() == SVFMetaAsValue;
1070  }
1071  static inline bool classof(const SVFOtherValue *node)
1072  {
1073  return node->getKind() == SVFMetaAsValue;
1074  }
1075 };
1076 
1077 
1083 
1084 template <typename F, typename S>
1085 OutStream& operator<< (OutStream &o, const std::pair<F, S> &var)
1086 {
1087  o << "<" << var.first << ", " << var.second << ">";
1088  return o;
1089 }
1090 
1091 } // End namespace SVF
1092 
1093 #endif /* INCLUDE_SVFIR_SVFVALUE_H_ */
#define false
Definition: cJSON.cpp:70
cJSON * a
Definition: cJSON.cpp:2560
cJSON * n
Definition: cJSON.cpp:2558
const cJSON *const b
Definition: cJSON.h:255
const char *const string
Definition: cJSON.h:172
Definition: ICFG.h:48
bool isArgOfUncalledFunction() const
Definition: SVFValue.h:891
const SVFFunction * fun
Definition: SVFValue.h:867
static bool classof(const SVFValue *node)
Definition: SVFValue.h:896
const SVFFunction * getParent() const
Definition: SVFValue.h:879
SVFArgument()=delete
u32_t getArgNo() const
Definition: SVFValue.h:886
SVFArgument(const SVFType *ty, const SVFFunction *fun, u32_t argNo, bool uncalled)
Definition: SVFValue.h:871
static bool classof(const SVFValue *node)
Definition: SVFValue.h:564
std::vector< const ICFGNode * >::const_iterator const_iterator
Definition: SVFValue.h:529
void addPredBasicBlock(const SVFBasicBlock *pred)
Definition: SVFValue.h:552
const std::vector< const ICFGNode * > & getICFGNodeList() const
Definition: SVFValue.h:569
u32_t getBBPredecessorPos(const SVFBasicBlock *succbb)
Definition: SVFValue.cpp:241
const std::vector< const SVFBasicBlock * > & getSuccessors() const
Definition: SVFValue.h:606
void addICFGNode(const ICFGNode *icfgNode)
Function where this BasicBlock is.
Definition: SVFValue.h:540
std::vector< const SVFBasicBlock * > succBBs
all successor BasicBlocks of this BasicBlock
Definition: SVFValue.h:533
std::vector< const ICFGNode * > allICFGNodes
all ICFGNodes in this BasicBlock
Definition: SVFValue.h:532
const ICFGNode * front() const
Definition: SVFValue.h:594
const_iterator end() const
Definition: SVFValue.h:579
u32_t getBBSuccessorPos(const SVFBasicBlock *succbb)
Definition: SVFValue.cpp:212
~SVFBasicBlock() override
Definition: SVFValue.cpp:204
void addSuccBasicBlock(const SVFBasicBlock *succ)
Definition: SVFValue.h:547
const std::vector< const SVFBasicBlock * > & getPredecessors() const
Definition: SVFValue.h:611
const_iterator begin() const
Definition: SVFValue.h:574
const SVFFunction * fun
Definition: SVFValue.h:535
const ICFGNode * back() const
Definition: SVFValue.h:600
SVFBasicBlock()=delete
const SVFFunction * getFunction() const
Definition: SVFValue.h:589
u32_t getNumSuccessors() const
Definition: SVFValue.h:615
std::vector< const SVFBasicBlock * > predBBs
all predecessor BasicBlocks of this BasicBlock
Definition: SVFValue.h:534
const SVFFunction * getParent() const
Definition: SVFValue.h:584
static bool classof(const SVFValue *node)
Definition: SVFValue.h:1026
static bool classof(const SVFConstantData *node)
Definition: SVFValue.h:1030
SVFBlackHoleValue(const SVFType *ty)
Definition: SVFValue.h:1020
const SVFValue * calledVal
Definition: SVFValue.h:674
bool isVarArg() const
Definition: SVFValue.h:724
const SVFValue * getArgOperand(u32_t i) const
Definition: SVFValue.h:711
static bool classof(const SVFValue *node)
Definition: SVFValue.h:695
u32_t arg_size() const
Definition: SVFValue.h:703
const SVFValue * getCalledOperand() const
Definition: SVFValue.h:720
SVFCallInst(const SVFType *ty, const SVFBasicBlock *b, bool va, bool tm, SVFValKind k=SVFCall)
Definition: SVFValue.h:689
void setCalledOperand(const SVFValue *v)
Definition: SVFValue.h:682
const SVFFunction * getCaller() const
Definition: SVFValue.h:732
static bool classof(const SVFInstruction *node)
Definition: SVFValue.h:699
SVFCallInst(void)=delete
const SVFFunction * getCalledFunction() const
Definition: SVFValue.h:728
u32_t getNumArgOperands() const
Definition: SVFValue.h:716
void addArgument(const SVFValue *a)
attributes to be set only through Module builders e.g., LLVMModule
Definition: SVFValue.h:678
bool arg_empty() const
Definition: SVFValue.h:707
std::vector< const SVFValue * > args
Definition: SVFValue.h:672
SVFConstantData(const SVFType *ty, SVFValKind k=SVFConstData)
Definition: SVFValue.h:907
static bool classof(const SVFValue *node)
Definition: SVFValue.h:913
static bool classof(const SVFConstantData *node)
Definition: SVFValue.h:921
SVFConstantFP()=delete
static bool classof(const SVFConstantData *node)
Definition: SVFValue.h:986
static bool classof(const SVFValue *node)
Definition: SVFValue.h:982
SVFConstantFP(const SVFType *ty, double d)
Definition: SVFValue.h:972
double getFPValue() const
Definition: SVFValue.h:978
SVFConstantInt(const SVFType *ty, u64_t z, s64_t s)
Definition: SVFValue.h:939
static bool classof(const SVFValue *node)
Definition: SVFValue.h:945
s64_t getSExtValue() const
Definition: SVFValue.h:959
u64_t getZExtValue() const
Definition: SVFValue.h:954
static bool classof(const SVFConstantData *node)
Definition: SVFValue.h:949
SVFConstantNullPtr(const SVFType *ty)
Definition: SVFValue.h:998
static bool classof(const SVFConstantData *node)
Definition: SVFValue.h:1008
static bool classof(const SVFValue *node)
Definition: SVFValue.h:1004
SVFConstant(const SVFType *ty, SVFValKind k=SVFConst)
Definition: SVFValue.h:803
SVFConstant()=delete
static bool classof(const SVFValue *node)
Definition: SVFValue.h:808
const SVFType * getReturnType() const
Definition: SVFType.h:336
bool intrinsic
return true if this function does not have a body
Definition: SVFValue.h:312
bool dominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition: SVFValue.h:505
static bool classof(const SVFValue *node)
Definition: SVFValue.h:357
void addBasicBlock(const SVFBasicBlock *bb)
a 'single' basic block having no successors and containing return instruction in a function
Definition: SVFValue.h:326
const SVFArgument * getArg(u32_t idx) const
Definition: SVFValue.cpp:175
bool varArg
return true if this function never returns
Definition: SVFValue.h:316
bool loopContainsBB(const BBList &lp, const SVFBasicBlock *bb) const
Definition: SVFValue.h:485
bool isUncalled
return true if this function is address-taken (for indirect call purposes)
Definition: SVFValue.h:314
const_iterator end() const
Definition: SVFValue.h:440
SVFBasicBlock * exitBlock
all formal arguments of this function
Definition: SVFValue.h:322
void setIsUncalledFunction(bool uncalledFunction)
Definition: SVFValue.h:336
const SVFBasicBlock * front() const
Definition: SVFValue.h:421
bool addrTaken
return true if this function is an intrinsic function (e.g., llvm.dbg), which does not reside in the ...
Definition: SVFValue.h:313
const_iterator begin() const
Definition: SVFValue.h:435
SVFLoopAndDomInfo * getLoopAndDomInfo()
Definition: SVFValue.h:362
virtual ~SVFFunction()
Definition: SVFValue.cpp:161
const SVFBasicBlock * back() const
Definition: SVFValue.h:426
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
Definition: SVFValue.h:465
std::vector< const SVFArgument * > allArgs
all BasicBlocks of this function
Definition: SVFValue.h:321
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap() const
Definition: SVFValue.h:495
bool hasReturn() const
Definition: SVFValue.h:460
const Map< const SVFBasicBlock *, BBSet > & getDomTreeMap() const
Definition: SVFValue.h:490
bool hasAddressTaken() const
Definition: SVFValue.h:376
const SVFFunctionType * getFunctionType() const
Returns the FunctionType.
Definition: SVFValue.h:382
const SVFBasicBlock * getLoopHeader(const BBList &lp) const
Definition: SVFValue.h:480
const SVFFunction * realDefFun
the loop and dominate information
Definition: SVFValue.h:319
const SVFBasicBlock * getEntryBlock() const
Definition: SVFValue.h:409
bool isIntrinsic() const
Definition: SVFValue.h:371
SVFFunction(void)=delete
const SVFFunction * getDefFunForMultipleModule() const
Definition: SVFValue.h:393
bool isUncalledFunction() const
Definition: SVFValue.h:455
SVFLoopAndDomInfo::LoopBBs LoopBBs
Definition: SVFValue.h:308
const std::vector< const SVFBasicBlock * > & getBasicBlockList() const
Definition: SVFValue.h:445
const std::vector< const SVFBasicBlock * > & getReachableBBs() const
Definition: SVFValue.h:450
bool hasBasicBlock() const
Definition: SVFValue.h:404
std::vector< const SVFBasicBlock * > allBBs
the definition of a function across multiple modules
Definition: SVFValue.h:320
void setIsNotRet(bool notRet)
Definition: SVFValue.h:341
std::vector< const SVFBasicBlock * >::const_iterator const_iterator
Definition: SVFValue.h:305
bool isDeclaration() const
Definition: SVFValue.h:366
u32_t arg_size() const
Definition: SVFValue.cpp:170
void setExitBlock(SVFBasicBlock *bb)
Definition: SVFValue.cpp:193
const SVFBasicBlock * getExitBB() const
Definition: SVFValue.cpp:186
bool isNotRet
return true if this function is never called
Definition: SVFValue.h:315
bool postDominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition: SVFValue.h:510
SVFLoopAndDomInfo::BBList BBList
Definition: SVFValue.h:307
const SVFFunctionType * funcType
return true if this function supports variable arguments
Definition: SVFValue.h:317
void addArgument(SVFArgument *arg)
Definition: SVFValue.h:331
SVFLoopAndDomInfo::BBSet BBSet
Definition: SVFValue.h:306
bool isVarArg() const
Definition: SVFValue.cpp:181
bool hasLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.h:470
SVFLoopAndDomInfo * loopAndDom
FunctionType, which is different from the type (PointerType) of this SVFFunction.
Definition: SVFValue.h:318
void setDefFunForMultipleModule(const SVFFunction *deffun)
Definition: SVFValue.h:346
const SVFType * getReturnType() const
Returns the FunctionType.
Definition: SVFValue.h:388
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.h:475
bool isLoopHeader(const SVFBasicBlock *bb) const
Definition: SVFValue.h:500
SVFGlobalValue(const SVFType *ty)
Definition: SVFValue.h:837
const SVFValue * realDefGlobal
Definition: SVFValue.h:828
static bool classof(const SVFConstant *node)
Definition: SVFValue.h:856
static bool classof(const SVFValue *node)
Definition: SVFValue.h:852
void setDefGlobalForMultipleModule(const SVFValue *defg)
the definition of a function across multiple modules
Definition: SVFValue.h:831
const SVFValue * getDefGlobalForMultipleModule() const
Definition: SVFValue.h:846
SVFGlobalValue(std::string &&name, const SVFType *ty)
Definition: SVFValue.h:840
static bool classof(const SVFValue *node)
Definition: SVFValue.h:641
bool isRetInst() const
Definition: SVFValue.h:658
bool ret
return true if this is a terminator instruction
Definition: SVFValue.h:633
SVFInstruction(void)=delete
bool terminator
The BasicBlock where this Instruction resides.
Definition: SVFValue.h:632
const SVFBasicBlock * bb
Definition: SVFValue.h:631
const SVFBasicBlock * getParent() const
Definition: SVFValue.h:648
const SVFFunction * getFunction() const
Definition: SVFValue.h:653
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.cpp:28
const Map< const SVFBasicBlock *, BBSet > & getDomTreeMap() const
Definition: SVFValue.h:144
Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom()
Definition: SVFValue.h:133
Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel()
Definition: SVFValue.h:123
Map< const SVFBasicBlock *, BBSet > & getDomTreeMap()
Definition: SVFValue.h:139
std::vector< const SVFBasicBlock * > BBList
Definition: SVFValue.h:56
Map< const SVFBasicBlock *, BBSet > dtBBsMap
map a BasicBlock to BasicBlocks it Dominates
Definition: SVFValue.h:61
bool dominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition: SVFValue.cpp:54
bool isLoopHeader(const SVFBasicBlock *bb) const
Definition: SVFValue.cpp:141
Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap()
Definition: SVFValue.h:80
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
Definition: SVFValue.cpp:35
const SVFBasicBlock * findNearestCommonPDominator(const SVFBasicBlock *A, const SVFBasicBlock *B) const
find nearest common post dominator of two basic blocks
Definition: SVFValue.cpp:115
Map< const SVFBasicBlock *, BBSet > pdtBBsMap
map a BasicBlock to BasicBlocks it PostDominates
Definition: SVFValue.h:62
Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap()
Definition: SVFValue.h:113
Map< const SVFBasicBlock *, u32_t > bb2PdomLevel
map a BasicBlock to its level in pdom tree, used in findNearestCommonPDominator
Definition: SVFValue.h:65
const BBList & getReachableBBs() const
Definition: SVFValue.h:155
bool isUnreachable(const SVFBasicBlock *bb) const
Definition: SVFValue.h:149
virtual ~SVFLoopAndDomInfo()
Definition: SVFValue.h:73
Map< const SVFBasicBlock *, const SVFBasicBlock * > bb2PIdom
map a BasicBlock to its immediate dominator in pdom tree, used in findNearestCommonPDominator
Definition: SVFValue.h:66
bool hasLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.h:85
const Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel() const
Definition: SVFValue.h:118
const SVFBasicBlock * getLoopHeader(const LoopBBs &lp) const
Definition: SVFValue.h:92
void setReachableBBs(BBList &bbs)
Definition: SVFValue.h:160
const Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap() const
Definition: SVFValue.h:108
Set< const SVFBasicBlock * > BBSet
Definition: SVFValue.h:55
Map< const SVFBasicBlock *, LoopBBs > bb2LoopMap
map a BasicBlock (if it is in a loop) to all the BasicBlocks in this loop
Definition: SVFValue.h:64
bool loopContainsBB(const LoopBBs &lp, const SVFBasicBlock *bb) const
Definition: SVFValue.h:98
Map< const SVFBasicBlock *, BBSet > dfBBsMap
map a BasicBlock to its Dominate Frontier BasicBlocks
Definition: SVFValue.h:63
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap() const
Definition: SVFValue.h:75
const Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom() const
Definition: SVFValue.h:128
void addToBB2LoopMap(const SVFBasicBlock *bb, const SVFBasicBlock *loopBB)
Definition: SVFValue.h:103
BBList reachableBBs
reachable BasicBlocks from the function entry.
Definition: SVFValue.h:60
bool postDominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition: SVFValue.cpp:85
static bool classof(const SVFOtherValue *node)
Definition: SVFValue.h:1071
SVFMetadataAsValue(const SVFType *ty)
Definition: SVFValue.h:1061
static bool classof(const SVFValue *node)
Definition: SVFValue.h:1067
SVFOtherValue()=delete
SVFOtherValue(const SVFType *ty, SVFValKind k=SVFValue::SVFOther)
Definition: SVFValue.h:1041
static bool classof(const SVFValue *node)
Definition: SVFValue.h:1047
virtual const SVFType * getType() const
Definition: SVFValue.h:256
void setName(std::string &&n)
Definition: SVFValue.h:251
const std::string & getName() const
Definition: SVFValue.h:243
GNodeK getKind() const
Get the type of this SVFValue.
Definition: SVFValue.h:238
bool ptrInUncalledFunction() const
Definition: SVFValue.h:264
std::string toString() const
Needs to be implemented by a SVF front end.
Definition: LLVMUtil.cpp:663
SVFValue(const SVFType *ty, SVFValKind k)
Constructor without name.
Definition: SVFValue.h:216
virtual void setSourceLoc(const std::string &sourceCodeInfo)
Definition: SVFValue.h:276
virtual const std::string getSourceLoc() const
Definition: SVFValue.h:280
void setName(const std::string &n)
Definition: SVFValue.h:247
std::string sourceLoc
Definition: SVFValue.h:214
s64_t GNodeK
Definition: SVFValue.h:184
virtual ~SVFValue()=default
bool ptrInUncalledFun
true if this pointer is in an uncalled function
Definition: SVFValue.h:208
std::string name
Short name of value for printing & debugging.
Definition: SVFValue.h:213
bool isNullPtr() const
Definition: SVFValue.h:272
void setPtrInUncalledFunction()
Definition: SVFValue.h:228
bool isblackHole() const
Definition: SVFValue.h:268
bool isConstDataOrAggData() const
Definition: SVFValue.h:260
friend OutStream & operator<<(OutStream &os, const SVFValue &value)
Overloading operator << for dumping ICFG node ID.
Definition: SVFValue.h:290
SVFValue()=delete
GNodeK kind
used for classof
Definition: SVFValue.h:207
bool constDataOrAggData
true if this value is a ConstantData (e.g., numbers, string, floats) or a constantAggregate
Definition: SVFValue.h:209
const SVFType * type
Type of this SVFValue.
Definition: SVFValue.h:212
void setConstDataOrAggData()
Definition: SVFValue.h:224
const std::string & getFunNameOfVirtualCall() const
Definition: SVFValue.h:780
const SVFValue * getVtablePtr() const
Definition: SVFValue.h:770
static bool classof(const SVFCallInst *node)
Definition: SVFValue.h:792
static bool classof(const SVFValue *node)
Definition: SVFValue.h:784
std::string funNameOfVcall
virtual function index of the virtual table(s) at a virtual call
Definition: SVFValue.h:747
SVFVirtualCallInst(const SVFType *ty, const SVFBasicBlock *b, bool vararg, bool tm)
Definition: SVFValue.h:764
const SVFValue * vCallVtblPtr
Definition: SVFValue.h:745
void setFunIdxInVtable(s32_t idx)
the function name of this virtual call
Definition: SVFValue.h:750
void setVtablePtr(const SVFValue *vptr)
Definition: SVFValue.h:758
static bool classof(const SVFInstruction *node)
Definition: SVFValue.h:788
s32_t getFunIdxInVtable() const
Definition: SVFValue.h:775
void setFunNameOfVirtualCall(const std::string &name)
Definition: SVFValue.h:754
s32_t virtualFunIdx
virtual table pointer
Definition: SVFValue.h:746
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447
for isBitcode
Definition: BasicTypes.h:68
unsigned long long u64_t
Definition: GeneralType.h:48
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
std::ostream OutStream
Definition: GeneralType.h:45
signed s32_t
Definition: GeneralType.h:47
SVF::GraphPrinter GraphPrinter
LLVM Aliases and constants.
Definition: SVFValue.h:41
unsigned u32_t
Definition: GeneralType.h:46
std::string dumpLLVMValue(const SVFValue *svfValue)
signed long long s64_t
Definition: GeneralType.h:49
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96
IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.