retdec
cfg_node.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_CFG_NODE_H
8 #define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_CFG_NODE_H
9 
10 #include <string>
11 #include <unordered_set>
12 #include <vector>
13 
16 
17 namespace llvm {
18 
19 class BasicBlock;
20 class Instruction;
21 class Value;
22 
23 } // namespace llvm
24 
25 namespace retdec {
26 namespace llvmir2hll {
27 
28 class Statement;
29 
33 class CFGNode: public SharableFromThis<CFGNode>,
35 private:
40  public:
42 
43  ShPtr<CFGNode> getTarget() const;
44  bool isBackEdge() const;
45 
46  void setBackEdge(bool isBackEdge = true);
47 
48  private:
51 
53  bool backEdge;
54  };
55 
56 public:
57  using CFGEdgeVector = std::vector<ShPtr<CFGEdge>>;
58  using CFGNodeSet = std::unordered_set<ShPtr<CFGNode>>;
59  using CFGNodeVector = std::vector<ShPtr<CFGNode>>;
60 
61 public:
62  CFGNode(llvm::BasicBlock *bb, ShPtr<Statement> body);
63 
66  llvm::BasicBlock *getFirstBB() const;
67  llvm::BasicBlock *getLastBB() const;
68  void setLastBB(llvm::BasicBlock *bb);
70 
73  llvm::Instruction *getTerm() const;
74  llvm::Value *getCond() const;
76 
79  ShPtr<Statement> getBody() const;
81  void appendToBody(ShPtr<Statement> statement);
83 
86  void addSuccessor(ShPtr<CFGNode> succ);
87  void moveSuccessorsFrom(const ShPtr<CFGNode> &node);
88  void removeSucc(std::size_t i);
89  void deleteSucc(std::size_t i);
90  void deleteSuccessors();
92 
95  std::size_t getPredsNum() const;
96  std::size_t getSuccNum() const;
98 
103  ShPtr<CFGNode> getSucc(std::size_t i) const;
104  ShPtr<CFGNode> getSuccOrNull(std::size_t i) const;
105  bool hasSuccessor(const ShPtr<CFGNode> &node) const;
107 
110  void markAsBackEdge(const ShPtr<CFGNode> &node);
111  bool isBackEdge(const ShPtr<CFGNode> &node) const;
113 
116  bool hasStatementSuccessor() const;
121 
124  std::string getName() const;
125  void debugPrint() const;
127 
128 private:
130  llvm::BasicBlock *firstBasicBlock;
131 
133  llvm::BasicBlock *lastBasicBlock;
134 
137 
140 
143 
146 };
147 
148 } // namespace llvmir2hll
149 } // namespace retdec
150 
151 #endif
A representation of a control-flow graph edge.
Definition: cfg_node.h:39
CFGEdge(ShPtr< CFGNode > target)
Constructs a new control-flow graph edge.
Definition: cfg_node.cpp:25
ShPtr< CFGNode > target
A target of this edge.
Definition: cfg_node.h:50
void setBackEdge(bool isBackEdge=true)
Sets flag whether this node is a back-edge to value isBackEdge.
Definition: cfg_node.cpp:45
bool isBackEdge() const
Returns true if this edge is a back-edge.
Definition: cfg_node.cpp:38
bool backEdge
Is this edge a back-edge?
Definition: cfg_node.h:53
ShPtr< CFGNode > getTarget() const
Returns the target of this edge.
Definition: cfg_node.cpp:31
A representation of a control-flow graph node.
Definition: cfg_node.h:34
void deleteSucc(std::size_t i)
Deletes a successor of this node on the index i.
Definition: cfg_node.cpp:203
llvm::BasicBlock * getLastBB() const
Returns the last LLVM basic block in sequence which is represented by this node.
Definition: cfg_node.cpp:71
ShPtr< CFGNode > statementSuccessor
A successor of the high-level statement represented by this node.
Definition: cfg_node.h:145
ShPtr< CFGNode > getSucc(std::size_t i) const
Returns a successor of this node on the index i.
Definition: cfg_node.cpp:265
void setBody(ShPtr< Statement > body)
Sets a new body body to this node.
Definition: cfg_node.cpp:121
ShPtr< Statement > getBody() const
Returns the body in BIR of this node.
Definition: cfg_node.cpp:111
void setLastBB(llvm::BasicBlock *bb)
Sets bb as the last LLVM basic block in sequence which is represented by this node.
Definition: cfg_node.cpp:79
void debugPrint() const
Emits this node's name and its successors and predecessors to the standard error output.
Definition: cfg_node.cpp:387
CFGNodeSet predecessors
A set of node predecessors.
Definition: cfg_node.h:139
void moveSuccessorsFrom(const ShPtr< CFGNode > &node)
Moves all successors from the given node node to this node.
Definition: cfg_node.cpp:157
llvm::BasicBlock * firstBasicBlock
A first LLVM basic block in sequence which is represented by this node.
Definition: cfg_node.h:130
std::string getName() const
Returns the label of first basic block in this node.
Definition: cfg_node.cpp:373
ShPtr< Statement > body
A body of this tree node.
Definition: cfg_node.h:136
std::unordered_set< ShPtr< CFGNode > > CFGNodeSet
Definition: cfg_node.h:58
void setStatementSuccessor(ShPtr< CFGNode > succ)
Sets succ as a new statement successor.
Definition: cfg_node.cpp:346
void markAsBackEdge(const ShPtr< CFGNode > &node)
Sets flag that this node's succ node is a back-edge.
Definition: cfg_node.cpp:305
llvm::BasicBlock * lastBasicBlock
A last LLVM basic block in sequence which is represented by this node.
Definition: cfg_node.h:133
llvm::Instruction * getTerm() const
Returns the terminator instruction of stored basic block in this node.
Definition: cfg_node.cpp:86
CFGNodeSet getPredecessors()
Returns a set of predecessors of this node.
Definition: cfg_node.cpp:242
std::size_t getPredsNum() const
Returns a number of this node successors.
Definition: cfg_node.cpp:228
CFGNode(llvm::BasicBlock *bb, ShPtr< Statement > body)
Constructs a new control-flow graph node.
Definition: cfg_node.cpp:55
std::size_t getSuccNum() const
Returns a number of this node successors.
Definition: cfg_node.cpp:235
bool hasStatementSuccessor() const
Determines whether this node has a statement successor.
Definition: cfg_node.cpp:332
void appendToBody(ShPtr< Statement > statement)
Appends the given statement statement to this node's body.
Definition: cfg_node.cpp:132
llvm::Value * getCond() const
Returns a condition of this node if this is conditional branch. Otherwise, returns nullptr.
Definition: cfg_node.cpp:94
ShPtr< CFGNode > getStatementSuccessor() const
Returns the statement successor.
Definition: cfg_node.cpp:339
std::vector< ShPtr< CFGEdge > > CFGEdgeVector
Definition: cfg_node.h:57
bool isBackEdge(const ShPtr< CFGNode > &node) const
Returns true if this node's succ node is a back-edge.
Definition: cfg_node.cpp:317
std::vector< ShPtr< CFGNode > > CFGNodeVector
Definition: cfg_node.h:59
void removeStatementSuccessor()
Removes statement successor if exists.
Definition: cfg_node.cpp:358
CFGEdgeVector successors
An ordered vector of node successors.
Definition: cfg_node.h:142
ShPtr< CFGNode > getSuccOrNull(std::size_t i) const
Returns a successor of this node on the index i. If this node does not have a successor on the index ...
Definition: cfg_node.cpp:276
void addSuccessor(ShPtr< CFGNode > succ)
Adds a new successor succ to this node.
Definition: cfg_node.cpp:144
void deleteSuccessors()
Deletes all successors of this node.
Definition: cfg_node.cpp:219
CFGNodeVector getSuccessors()
Returns a vector of successors of this node.
Definition: cfg_node.cpp:249
void removeSucc(std::size_t i)
Removes a successor of this node on the index i.
Definition: cfg_node.cpp:178
llvm::BasicBlock * getFirstBB() const
Returns the first LLVM basic block in sequence which is represented by this node.
Definition: cfg_node.cpp:63
bool hasSuccessor(const ShPtr< CFGNode > &node) const
Determines whether the given node node is this node's successor.
Definition: cfg_node.cpp:290
Enables shared_from_this() in the inheriting class.
Definition: smart_ptr.h:44
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
Definition: itanium_ast_ctypes_parser.h:12
A library providing API for working with back-end IR.
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.
Declarations, aliases, macros, etc. for the use of smart pointers.