MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
domtree.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/analyses/cfg.h"
4
5namespace mim {
6
7/// A Dominance Tree.
8/// The template parameter @p forward determines
9/// whether a regular dominance tree (@c true) or a post-dominance tree (@c false) should be constructed.
10/// This template parameter is associated with @p CFG's @c forward parameter.
11template<bool forward> class DomTreeBase {
12public:
13 DomTreeBase(const DomTreeBase&) = delete;
15
16 explicit DomTreeBase(const CFG<forward>& cfg)
17 : cfg_(cfg)
18 , children_(cfg)
19 , idoms_(cfg)
20 , depth_(cfg) {
21 create();
22 depth(root(), 0);
23 }
24
25 const CFG<forward>& cfg() const { return cfg_; }
26 size_t index(const CFNode* n) const { return cfg().index(n); }
27 const std::vector<const CFNode*>& children(const CFNode* n) const { return children_[n]; }
28 const CFNode* root() const { return *idoms_.begin(); }
29 const CFNode* idom(const CFNode* n) const { return idoms_[n]; }
30 int depth(const CFNode* n) const { return depth_[n]; }
31 const CFNode* least_common_ancestor(const CFNode* i,
32 const CFNode* j) const; ///< Returns the least common ancestor of @p i and @p j.
33
34private:
35 void create();
36 void depth(const CFNode* n, int i);
37
38 const CFG<forward>& cfg_;
39 typename CFG<forward>::template Map<std::vector<const CFNode*>> children_;
40 typename CFG<forward>::template Map<const CFNode*> idoms_;
41 typename CFG<forward>::template Map<int> depth_;
42};
43
44/// @name Control Flow
45///@{
48///@}
49
50} // namespace mim
A Control-Flow Graph.
Definition scope.h:8
static size_t index(const CFNode *n)
Definition cfg.h:150
A Control-Flow Node.
Definition cfg.h:27
A Dominance Tree.
Definition schedule.h:7
const std::vector< const CFNode * > & children(const CFNode *n) const
Definition domtree.h:27
const CFNode * root() const
Definition domtree.h:28
DomTreeBase(const CFG< forward > &cfg)
Definition domtree.h:16
DomTreeBase & operator=(DomTreeBase)=delete
const CFNode * idom(const CFNode *n) const
Definition domtree.h:29
int depth(const CFNode *n) const
Definition domtree.h:30
size_t index(const CFNode *n) const
Definition domtree.h:26
const CFG< forward > & cfg() const
Definition domtree.h:25
DomTreeBase(const DomTreeBase &)=delete
const CFNode * least_common_ancestor(const CFNode *i, const CFNode *j) const
Returns the least common ancestor of i and j.
Definition domtree.cpp:45
Definition cfg.h:11