Jlm
domtree.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_LLVM_IR_DOMTREE_HPP
7 #define JLM_LLVM_IR_DOMTREE_HPP
8 
9 #include <jlm/util/common.hpp>
10 
11 #include <memory>
12 #include <vector>
13 
14 namespace jlm::llvm
15 {
16 
17 class ControlFlowGraph;
18 class ControlFlowGraphNode;
19 
20 class DominatorTreeNode final
21 {
22  typedef std::vector<std::unique_ptr<DominatorTreeNode>>::const_iterator const_iterator;
23 
24 public:
26  : depth_(0),
27  node_(node),
28  parent_(nullptr)
29  {}
30 
32 
34 
36  operator=(const DominatorTreeNode &) = delete;
37 
40 
42  begin() const
43  {
44  return children_.begin();
45  }
46 
48  end() const
49  {
50  return children_.end();
51  }
52 
54  add_child(std::unique_ptr<DominatorTreeNode> child);
55 
56  size_t
57  nchildren() const noexcept
58  {
59  return children_.size();
60  }
61 
62  [[nodiscard]] DominatorTreeNode *
63  child(size_t index) const noexcept
64  {
65  JLM_ASSERT(index < nchildren());
66  return children_[index].get();
67  }
68 
70  node() const noexcept
71  {
72  return node_;
73  }
74 
75  [[nodiscard]] DominatorTreeNode *
76  parent() const noexcept
77  {
78  return parent_;
79  }
80 
81  size_t
82  depth() const noexcept
83  {
84  return depth_;
85  }
86 
87  static std::unique_ptr<DominatorTreeNode>
89  {
90  return std::unique_ptr<DominatorTreeNode>(new DominatorTreeNode(node));
91  }
92 
93 private:
94  size_t depth_;
97  std::vector<std::unique_ptr<DominatorTreeNode>> children_;
98 };
99 
100 std::unique_ptr<DominatorTreeNode>
102 
103 }
104 
105 #endif
std::vector< std::unique_ptr< DominatorTreeNode > >::const_iterator const_iterator
Definition: domtree.hpp:22
const_iterator end() const
Definition: domtree.hpp:48
ControlFlowGraphNode * node() const noexcept
Definition: domtree.hpp:70
ControlFlowGraphNode * node_
Definition: domtree.hpp:95
static std::unique_ptr< DominatorTreeNode > create(ControlFlowGraphNode *node)
Definition: domtree.hpp:88
DominatorTreeNode * parent() const noexcept
Definition: domtree.hpp:76
size_t depth() const noexcept
Definition: domtree.hpp:82
DominatorTreeNode(const DominatorTreeNode &)=delete
const_iterator begin() const
Definition: domtree.hpp:42
DominatorTreeNode(ControlFlowGraphNode *node)
Definition: domtree.hpp:25
DominatorTreeNode(DominatorTreeNode &&)=delete
std::vector< std::unique_ptr< DominatorTreeNode > > children_
Definition: domtree.hpp:97
DominatorTreeNode * parent_
Definition: domtree.hpp:96
DominatorTreeNode & operator=(DominatorTreeNode &&)=delete
DominatorTreeNode * add_child(std::unique_ptr< DominatorTreeNode > child)
Definition: domtree.cpp:17
size_t nchildren() const noexcept
Definition: domtree.hpp:57
DominatorTreeNode & operator=(const DominatorTreeNode &)=delete
DominatorTreeNode * child(size_t index) const noexcept
Definition: domtree.hpp:63
#define JLM_ASSERT(x)
Definition: common.hpp:16
Global memory state passed between functions.
std::unique_ptr< DominatorTreeNode > domtree(ControlFlowGraph &cfg)
Definition: domtree.cpp:91