Jlm
Loading...
Searching...
No Matches
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
14namespace jlm::llvm
15{
16
17class ControlFlowGraph;
18class ControlFlowGraphNode;
19
21{
22 typedef std::vector<std::unique_ptr<DominatorTreeNode>>::const_iterator const_iterator;
23
24public:
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
93private:
94 size_t depth_;
97 std::vector<std::unique_ptr<DominatorTreeNode>> children_;
98};
99
100std::unique_ptr<DominatorTreeNode>
102
103}
104
105#endif
const_iterator end() const
Definition domtree.hpp:48
ControlFlowGraphNode * node_
Definition domtree.hpp:95
size_t depth() const noexcept
Definition domtree.hpp:82
std::vector< std::unique_ptr< DominatorTreeNode > >::const_iterator const_iterator
Definition domtree.hpp:22
DominatorTreeNode & operator=(const DominatorTreeNode &)=delete
DominatorTreeNode & operator=(DominatorTreeNode &&)=delete
DominatorTreeNode(const DominatorTreeNode &)=delete
ControlFlowGraphNode * node() const noexcept
Definition domtree.hpp:70
const_iterator begin() const
Definition domtree.hpp:42
DominatorTreeNode(ControlFlowGraphNode *node)
Definition domtree.hpp:25
DominatorTreeNode * child(size_t index) const noexcept
Definition domtree.hpp:63
DominatorTreeNode(DominatorTreeNode &&)=delete
std::vector< std::unique_ptr< DominatorTreeNode > > children_
Definition domtree.hpp:97
DominatorTreeNode * parent_
Definition domtree.hpp:96
DominatorTreeNode * add_child(std::unique_ptr< DominatorTreeNode > child)
Definition domtree.cpp:17
size_t nchildren() const noexcept
Definition domtree.hpp:57
static std::unique_ptr< DominatorTreeNode > create(ControlFlowGraphNode *node)
Definition domtree.hpp:88
DominatorTreeNode * parent() const noexcept
Definition domtree.hpp:76
#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