19 const Node*
inest()
const {
return inest_; }
20 bool is_root()
const {
return inest_ ==
nullptr; }
26 uint32_t
level()
const {
return level_; }
27 uint32_t
loop_depth()
const {
return sccs().loop_depth_; }
36 auto mut2node()
const {
return mut2node_ | std::views::transform([](
auto p) {
return std::pair{p.first,
const_cast<const Node*
>(p.second)}; }); }
37 auto muts()
const {
return mut2node_ | std::views::keys; }
38 auto nodes()
const {
return mut2node_ | std::views::transform([](
auto p) {
return const_cast<const Node*
>(p.second); }); }
40 size_t num()
const {
return mut2node_.size(); }
51 auto begin()
const {
return mut2node_.cbegin(); }
52 auto end()
const {
return mut2node_.cend(); }
56 const auto&
mut2node() {
return mut2node_; }
57 auto nodes() {
return mut2node_ | std::views::values; }
58 auto muts() {
return mut2node_ | std::views::keys; }
59 auto begin() {
return mut2node_.begin(); }
60 auto end() {
return mut2node_.end(); }
72 template<
bool Forward>
77 return nodes_ | std::views::transform([](Node* n) {
return const_cast<const Node*
>(n); });
84 bool contains(
const Node* n)
const {
return nodes_.contains(n); }
89 auto begin()
const {
return nodes_.cbegin(); }
90 auto end()
const {
return nodes_.cend(); }
94 const auto&
nodes() {
return nodes_; }
95 auto begin() {
return nodes_.begin(); }
96 auto end() {
return nodes_.end(); }
98 absl::flat_hash_set<Node*> nodes_;
107 template<
bool Forward = true>
109 nest().calc_sibl_deps();
110 if constexpr (Forward)
113 return sibl_rev_deps_;
116 template<
bool Forward = true>
123 using SCC = absl::flat_hash_set<const Node*>;
129 const auto&
SCCs() {
return sccs().SCCs_; }
130 const auto&
topo()
const {
return sccs().topo_; }
145 const Node& sccs()
const {
return nest().calc_SCCs(), *
this; }
147 void link(Node* other) { this->sibl_deps_.nodes_.emplace(other), other->sibl_rev_deps_.nodes_.emplace(
this); }
148 void dot(Tab, std::ostream&)
const;
151 using Stack = std::stack<Node*>;
153 uint32_t tarjan(uint32_t, Node*, Stack&);
159 uint32_t loop_depth_ : 31 = 0;
160 bool recursive_ : 1 =
false;
164 std::deque<std::unique_ptr<SCC>> topo_;
165 absl::node_hash_map<const Node*, const SCC*> SCCs_;
168 static constexpr uint32_t Unvisited = uint32_t(-1);
169 uint32_t idx_ = Unvisited;
170 uint32_t low_ : 31 = 0;
171 bool on_stack_ : 1 =
false;
172 Node* curr_child =
nullptr;
190 bool is_recursive()
const {
return calc_SCCs().root()->is_recursive(); }
197 auto muts()
const {
return mut2node_ | std::views::keys; }
198 auto nodes()
const {
return mut2node_ | std::views::transform([](
const auto& p) {
return (
const Node*)p.second.get(); }); }
205 auto begin()
const {
return mut2node_.cbegin(); }
206 auto end()
const {
return mut2node_.cend(); }
214 void dot(std::ostream& os)
const;
215 void dot(
const char* file =
nullptr)
const;
216 void dot(std::string s)
const {
dot(s.c_str()); }
220 auto begin() {
return mut2node_.begin(); }
221 auto end() {
return mut2node_.end(); }
224 Node* make_node(Def*,
Node* inest =
nullptr);
225 void calc_sibl_deps(
Node*)
const;
226 void calc_SCCs(
Node*)
const;
229 if (
auto i = mut2node_.find(mut); i != mut2node_.end())
return i->second.get();
233 void calc_sibl_deps()
const {
236 calc_sibl_deps(root_);
240 const Nest& calc_SCCs()
const {
249 absl::flat_hash_map<Def*, std::unique_ptr<Node>> mut2node_;
252 mutable bool siblings_ =
false;
253 mutable bool sccs_ =
false;
std::string unique_name() const
name + "_" + Def::gid
Vars free_vars() const
Compute a global solution by transitively following mutables as well.
const auto & sibl_deps() const
Def * mut() const
The mutable capsulated in this Node or nullptr, if it's a virtual root comprising several Nodes.
bool is_recursive() const
const Children & children() const
absl::flat_hash_set< const Node * > SCC
Strongly Connected Component.
const auto & topo() const
Topological sorting of all SCCs.
const Nest & nest() const
bool is_directly_recursive() const
bool is_mutually_recursive() const
uint32_t loop_depth() const
const Node * inest() const
Immediate nester/parent of this Node.
void dot(std::ostream &os) const
bool is_recursive() const
const Node * operator[](Def *mut) const
static const Node * lca(const Node *n, const Node *m)
Least common ancestor of n and m.
void dot(std::string s) const
const Node * root() const
Vars vars() const
All Vars occurring in this Nest.
bool contains(const Def *def) const
bool has_intersection(Set other) const noexcept
Is ?.
The World represents the whole program and manages creation of MimIR nodes (Defs).
auto lookup(const C &container, const K &key)
Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr ot...
Sets< const Var >::Set Vars
GIDMap< Def *, To > MutMap
size_t num() const
Number of children.
bool contains(Def *mut) const
is mut a child?
const Node * operator[](Def *mut) const
bool contains(const Node *n) const