ClearBlue
SEGReturnNode.h
1 /*
2  * SEGReturnNode.h
3  *
4  * Qingkai
5  *
6  * This node is to model a super return that merge all returned value.
7  */
8 
9 #ifndef IR_SEG_SEGRETURNNODE_H
10 #define IR_SEG_SEGRETURNNODE_H
11 
12 #include <llvm/IR/BasicBlock.h>
13 
14 #include <unordered_map>
15 #include <unordered_set>
16 
17 #include "CBAccessPath.h"
18 #include "IR/SEG/SymbolicExprGraph.h"
19 
20 using namespace llvm;
21 
22 class SEGReturnSite;
23 
25 class SEGReturnNode : public SEGOperandNode {
26  friend class SEGSerializer;
27  friend class SEGHash;
28 
29 protected:
30  std::unordered_set<SEGReturnSite *> RetInsts;
31  std::unordered_map<const SEGNodeBase *, SEGReturnSite *> RetNodeSiteMap;
32 
33  SEGReturnNode(SEGObjectKind, Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB,
34  bool fromDisk);
35  SEGReturnNode(SEGObjectKind, Value *Val, Type *Ty, SymbolicExprGraph *SEG,
36  BasicBlock *BB, bool fromDisk);
37 
38  friend class SymbolicExprGraph;
39 
40 public:
41  virtual ~SEGReturnNode();
42 
43  void addReturnNodeSitePair(const SEGNodeBase *Node, SEGReturnSite *Site);
44 
45  SEGReturnSite *getReturnSite(const SEGNodeBase *Node) const;
46 
47  decltype(RetNodeSiteMap)::const_iterator returnNodeSiteBegin() const {
48  return RetNodeSiteMap.begin();
49  }
50 
51  decltype(RetNodeSiteMap)::const_iterator returnNodeSiteEnd() const {
52  return RetNodeSiteMap.end();
53  }
54 
55  virtual int64_t getIndex() const = 0;
56 
57 public:
58  static bool classof(const SEGObject *O) {
59  return O->getKind() >= SEGOBJK_ReturnBegin &&
60  O->getKind() <= SEGOBJK_ReturnEnd;
61  }
62 };
63 
65 
66 private:
67  SEGCommonReturnNode(Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB,
68  bool fromDisk);
69 
70  friend class SymbolicExprGraph;
71 
72 public:
73  virtual int64_t getIndex() const {
74  assert(false);
75  return 0;
76  }
77 
78 public:
79  static bool classof(const SEGObject *O) {
80  return O->getKind() == SEGOBJK_CommonReturn;
81  }
82 };
83 
85 private:
86  // set by SEG
87  int64_t Index = -1;
88 
89  CBAccessPath AP;
90 
91  SEGPseudoReturnNode(Value *Val, Type *Ty, SymbolicExprGraph *SEG,
92  BasicBlock *BB, bool fromDisk);
93 
94  friend class SymbolicExprGraph;
95  friend class SEGSerializer;
96 
97 public:
98  virtual int64_t getIndex() const { return Index; }
99 
100  const CBAccessPath &getAccessPath() const { return AP; }
101 
102  CBAccessPath &getAccessPath() { return AP; }
103 
104 public:
105  static bool classof(const SEGObject *O) {
106  return O->getKind() == SEGOBJK_PseudoReturn;
107  }
108 };
109 
110 #endif
SEGOperandNode
Definition: SymbolicExprGraph.h:456
SymbolicExprGraph
Definition: SymbolicExprGraph.h:710
SEGCommonReturnNode
Definition: SEGReturnNode.h:64
SEGReturnSite
Definition: SEGReturnSite.h:18
SEGObject
Definition: SymbolicExprGraph.h:76
CBAccessPath
Definition: CBAccessPath.h:22
SEGPseudoReturnNode
Definition: SEGReturnNode.h:84
SEGReturnNode
The return node.
Definition: SEGReturnNode.h:25
SEGNodeBase
The node base of symbolic expression graph.
Definition: SymbolicExprGraph.h:244