Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
deptree.h
Go to the documentation of this file.
1#pragma once
2
3#include <deque>
4
5#include "thorin/def.h"
6
7namespace thorin {
8
9class DepNode {
10public:
11 DepNode(Def* mut, size_t depth)
12 : mut_(mut)
13 , depth_(depth) {}
14
15 Def* mut() const { return mut_; }
16 size_t depth() const { return depth_; }
17 DepNode* parent() const { return parent_; }
18 const auto& children() const { return children_; }
19
20private:
21 DepNode* set_parent(DepNode* parent) {
22 parent_ = parent;
23 depth_ = parent->depth() + 1;
24 parent->children_.emplace_back(this);
25 return this;
26 }
27
28 Def* mut_;
29 size_t depth_;
30 DepNode* parent_ = nullptr;
31 std::vector<DepNode*> children_;
32
33 friend class DepTree;
34};
35
36class DepTree {
37public:
39 : world_(world)
40 , root_(std::make_unique<DepNode>(nullptr, 0)) {
41 run();
42 }
43
44 World& world() const { return world_; }
45 const DepNode* root() const { return root_.get(); }
46 const DepNode* mut2node(Def* mut) const { return mut2node_.find(mut)->second.get(); }
47 bool depends(Def* a, Def* b) const; ///< Does @p a depend on @p b?
48
49private:
50 void run();
51 VarSet run(Def*);
52 VarSet run(Def*, const Def*);
53 static void adjust_depth(DepNode* node, size_t depth);
54
55 World& world_;
56 std::unique_ptr<DepNode> root_;
58 DefMap<VarSet> def2vars_;
59 std::deque<DepNode*> stack_;
60};
61
62} // namespace thorin
Base class for all Defs.
Definition def.h:220
size_t depth() const
Definition deptree.h:16
DepNode(Def *mut, size_t depth)
Definition deptree.h:11
DepNode * parent() const
Definition deptree.h:17
const auto & children() const
Definition deptree.h:18
Def * mut() const
Definition deptree.h:15
const DepNode * mut2node(Def *mut) const
Definition deptree.h:46
World & world() const
Definition deptree.h:44
DepTree(World &world)
Definition deptree.h:38
bool depends(Def *a, Def *b) const
Does a depend on b?
Definition deptree.cpp:74
const DepNode * root() const
Definition deptree.h:45
The World represents the whole program and manages creation of Thorin nodes (Defs).
Definition world.h:33
Definition span.h:103
Definition cfg.h:11
GIDMap< Def *, To > MutMap
Definition def.h:67
GIDSet< const Var * > VarSet
Definition def.h:77
GIDMap< const Def *, To > DefMap
Definition def.h:57