ClearBlue
SEGPhiNode.h
1 /*
2  * SEGPhiNode.h
3  *
4  * Qingkai
5  *
6  * This node is to model a phi value.
7  */
8 
9 #ifndef IR_SEG_SEGPHINODE_H
10 #define IR_SEG_SEGPHINODE_H
11 
12 #include <llvm/IR/BasicBlock.h>
13 #include <llvm/IR/CallSite.h>
14 #include <llvm/IR/Constants.h>
15 #include <llvm/IR/Function.h>
16 #include <llvm/IR/Instructions.h>
17 #include <llvm/IR/Value.h>
18 #include <llvm/Support/FileSystem.h>
19 #include <llvm/Support/Format.h>
20 #include <llvm/Support/raw_ostream.h>
21 
22 #include "IR/SEG/SymbolicExprGraph.h"
23 
24 using namespace llvm;
25 
28 class SEGPhiNode : public SEGOperandNode {
29  friend class SEGSerializer;
30  friend class SEGHash;
31 
32 public:
33  struct IncomeNode {
34  SEGNodeBase *ValNode; // The incoming value
35  BasicBlock *BB = nullptr; // The incoming basic block.
36  SEGNodeBase *InCondNode; // The condition node on immediate predecessor
37  bool Cond;
38  };
39 
40 private:
44  std::vector<IncomeNode> InComingNodes;
45 
47  friend class SymbolicExprGraph;
48 
51  SEGPhiNode(Value *Val, Type *Ty, SymbolicExprGraph *SEG, BasicBlock *BB,
52  bool fromDisk);
53 
54 public:
55  typedef std::vector<IncomeNode>::const_iterator const_iterator;
56 
57  ~SEGPhiNode() = default;
58 
60  void addIncomeValue(SEGNodeBase *InValue, BasicBlock *BB,
61  SEGNodeBase *condValue, bool Cond) {
62  struct IncomeNode Node;
63  Node.ValNode = InValue;
64  Node.BB = BB;
65  Node.InCondNode = condValue;
66  Node.Cond = Cond;
67  InComingNodes.emplace_back(Node);
68  // Also add it to children set.
69  addChild(InValue);
70  }
71 
72  // Get the "IN" condition for a phi "IN".
73  std::pair<SEGNodeBase *, bool> getInCond(size_t I) {
74  assert(I < size() && "getInCond i should less than the size.");
75 
76  auto &InComingNode = InComingNodes[I];
77  return std::make_pair(InComingNode.InCondNode, InComingNode.Cond);
78  }
79 
80  void dot(raw_fd_ostream &O) const;
81 
82  // Override
83  bool isTerminalNode() const { return InComingNodes.empty(); }
84 
85  const_iterator begin() const { return InComingNodes.begin(); }
86 
87  const_iterator end() const { return InComingNodes.end(); }
88 
89  size_t size() const { return InComingNodes.size(); }
90 
91  bool empty() const { return InComingNodes.empty(); }
92 
93 public:
94  static bool classof(const SEGObject *O) {
95  return O->getKind() == SEGOBJK_Phi;
96  }
97 };
98 
99 #endif
SEGPhiNode::IncomeNode
Definition: SEGPhiNode.h:33
SEGOperandNode
Definition: SymbolicExprGraph.h:456
SymbolicExprGraph
Definition: SymbolicExprGraph.h:708
SEGPhiNode::addIncomeValue
void addIncomeValue(SEGNodeBase *InValue, BasicBlock *BB, SEGNodeBase *condValue, bool Cond)
Add a incoming edge during construction.
Definition: SEGPhiNode.h:60
SEGObject
Definition: SymbolicExprGraph.h:76
SEGPhiNode
Definition: SEGPhiNode.h:28
SEGNodeBase
The node base of symbolic expression graph.
Definition: SymbolicExprGraph.h:244