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 PersistedSEGReturnNode;
23 
24 class PersistedSEGCommonReturnNode;
25 
26 class PersistedSEGPseudoReturnNode;
27 
28 class SEGReturnSite;
29 
31 class SEGReturnNode : public SEGOperandNode {
32 public:
35  SEGReturnNode(PersistedSEGReturnNode *Node, SymbolicExprGraph *SEG);
36 
37  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap);
38 
39 protected:
40  std::unordered_set<SEGReturnSite *> RetInsts;
41  std::unordered_map<const SEGNodeBase *, SEGReturnSite *> RetNodeSiteMap;
42 
43  SEGReturnNode(SEGObjectKind, Type *Ty, SymbolicExprGraph *SEG,
44  BasicBlock *BB);
45  SEGReturnNode(SEGObjectKind, Value *Val, Type *Ty, SymbolicExprGraph *SEG,
46  BasicBlock *BB);
47 
48  friend class SymbolicExprGraph;
49 
50 public:
51  virtual ~SEGReturnNode();
52 
53  void addReturnNodeSitePair(const SEGNodeBase *Node, SEGReturnSite *Site);
54 
55  SEGReturnSite *getReturnSite(const SEGNodeBase *Node) const;
56 
57  virtual size_t getIndex() const = 0;
58 
59 public:
60  static bool classof(const SEGObject *O) {
61  return O->getKind() >= SEGOBJK_ReturnBegin &&
62  O->getKind() <= SEGOBJK_ReturnEnd;
63  }
64 };
65 
67 public:
70  SEGCommonReturnNode(PersistedSEGCommonReturnNode *Node,
71  SymbolicExprGraph *SEG);
72 
73  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
74  SEGReturnNode::assembleSEGObject(FuncSEGObjMap);
75  }
76 
77 private:
78  SEGCommonReturnNode(Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB);
79 
80  friend class SymbolicExprGraph;
81 
82 public:
83  virtual PersistedSEGObject *createPersistedObject() const;
84 
85  virtual size_t getIndex() const {
86  assert(false);
87  return 0;
88  }
89 
90 public:
91  static bool classof(const SEGObject *O) {
92  return O->getKind() == SEGOBJK_CommonReturn;
93  }
94 };
95 
97 public:
100  SEGPseudoReturnNode(PersistedSEGPseudoReturnNode *Node,
101  SymbolicExprGraph *SEG);
102 
103  virtual void assembleSEGObject(std::map<int, SEGObject *> &FuncSEGObjMap) {
104  SEGReturnNode::assembleSEGObject(FuncSEGObjMap);
105  }
106 
107 private:
108  // set by SEG
109  size_t Index = -1;
110 
111  CBAccessPath AP;
112 
113  SEGPseudoReturnNode(Value *Val, Type *Ty, SymbolicExprGraph *SEG,
114  BasicBlock *BB);
115 
116  friend class SymbolicExprGraph;
117 
118 public:
119  virtual PersistedSEGObject *createPersistedObject() const;
120 
121  virtual size_t getIndex() const { return Index; }
122 
123  const CBAccessPath &getAccessPath() const { return AP; }
124 
125  CBAccessPath &getAccessPath() { return AP; }
126 
127 public:
128  static bool classof(const SEGObject *O) {
129  return O->getKind() == SEGOBJK_PseudoReturn;
130  }
131 };
132 
133 #endif
SEGOperandNode
Definition: SymbolicExprGraph.h:539
SymbolicExprGraph
Definition: SymbolicExprGraph.h:855
SEGCommonReturnNode
Definition: SEGReturnNode.h:66
SEGCommonReturnNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGReturnNode.h:73
SEGReturnSite
Definition: SEGReturnSite.h:19
SEGObject
Definition: SymbolicExprGraph.h:87
SEGReturnNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGReturnNode.cpp:32
SEGPseudoReturnNode::assembleSEGObject
virtual void assembleSEGObject(std::map< int, SEGObject * > &FuncSEGObjMap)
Assemble the SEG object's related objects.
Definition: SEGReturnNode.h:103
CBAccessPath
Definition: CBAccessPath.h:22
SEGPseudoReturnNode
Definition: SEGReturnNode.h:96
SEGReturnNode
The return node.
Definition: SEGReturnNode.h:31
SEGNodeBase
The node base of symbolic expression graph.
Definition: SymbolicExprGraph.h:288