CACAO
DominatorPass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/DominatorPass.hpp - DominatorPass
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #ifndef _JIT_COMPILER2_DOMINATORPASS
26 #define _JIT_COMPILER2_DOMINATORPASS
27 
30 
34 
35 MM_MAKE_NAME(DominatorPass)
36 
37 namespace cacao {
38 namespace jit {
39 namespace compiler2 {
40 
42 public:
43  typedef BeginInst NodeTy;
45 protected:
47 public:
48  /**
49  * True if a dominates b.
50  */
51  bool dominates(NodeTy *a, NodeTy *b) const;
52  /**
53  * True if b is dominated by b.
54  */
55  inline bool is_dominated_by(NodeTy *b, NodeTy *a) const {
56  return dominates(a,b);
57  }
58 
59  /**
60  * Get the immediate dominator.
61  *
62  * @return the immediate dominator or NULL if it is the starting node of
63  * the dominator tree (and if a is not in the tree).
64  */
65  inline NodeTy* get_idominator(NodeTy *a) const {
66  EdgeMapTy::const_iterator i = dom.find(a);
67  if (i == dom.end())
68  return NULL;
69  return i->second;
70  }
71 
72  /**
73  * Find the nearest common dominator.
74  */
75  NodeTy* find_nearest_common_dom(NodeTy *a, NodeTy *b) const;
76 
77  /**
78  * Depth of a tree node.
79  *
80  * The depth is defined as the length of the path from the node to the
81  * root. The depth of the root is 0.
82  */
83  int depth(NodeTy *node) const {
84  int d = 0;
85  while ( (node = get_idominator(node)) != NULL) {
86  ++d;
87  }
88  return d;
89  }
90 };
91 
92 /**
93  * Calculate the Dominator Tree.
94  *
95  * This Pass implements the algorithm proposed by Lengauer and Tarjan.
96  * The variable and function are named accoring to the paper. Currently the
97  * 'simple' version is implemented. The 'sophisticated' version is left
98  * for future work.
99  *
100  * A Fast Algorithm for Finding Dominators in a Flowgraph, by Lengauer
101  * and Tarjan, 1979 @cite Lengauer1979.
102  */
103 class DominatorPass : public Pass, public memory::ManagerMixin<DominatorPass> , public DominatorTree {
104 private:
105  typedef BeginInst NodeTy;
111 
117  int n;
118 
121 
122  NodeListTy& succ(NodeTy *v, NodeListTy &list);
123  void DFS(NodeTy * v);
124 
125  void Link(NodeTy *v, NodeTy *w);
126  NodeTy* Eval(NodeTy *v);
127  void Compress(NodeTy *v);
128 public:
130  virtual bool run(JITData &JD);
131  virtual PassUsage& get_PassUsage(PassUsage &PU) const;
132 };
133 
134 } // end namespace compiler2
135 } // end namespace jit
136 } // end namespace cacao
137 
138 #endif /* _JIT_COMPILER2_DOMINATORPASS */
139 
140 
141 /*
142  * These are local overrides for various environment variables in Emacs.
143  * Please do not remove this and leave it at the end of the file, where
144  * Emacs will automagically detect them.
145  * ---------------------------------------------------------------------
146  * Local variables:
147  * mode: c++
148  * indent-tabs-mode: t
149  * c-basic-offset: 4
150  * tab-width: 4
151  * End:
152  * vim:noexpandtab:sw=4:ts=4:
153  */
std::set< Key, Compare, Allocator< Key > > type
Definition: set.hpp:38
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:47
alloc::set< NodeTy * >::type NodeListTy
This Instruction marks the start of a basic block.
Custom new/delete handler mixin.
Definition: Manager.hpp:43
alloc::map< NodeTy *, NodeTy * >::type EdgeMapTy
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:128
alloc::map< NodeTy *, NodeTy * >::type EdgeMapTy
alloc::vector< NodeTy * >::type NodeMapTy
int depth(NodeTy *node) const
Depth of a tree node.
alloc::map< NodeTy *, NodeListTy >::type NodeListMapTy
NodeTy * get_idominator(NodeTy *a) const
Get the immediate dominator.
std::vector< T, Allocator< T > > type
Definition: vector.hpp:38
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
alloc::map< NodeTy *, int >::type IndexMapTy
MIIterator i
bool is_dominated_by(NodeTy *b, NodeTy *a) const
True if b is dominated by b.
bool dominates(dominatordata *dd, int i, int j)
Definition: lifetimes.cpp:830
Calculate the Dominator Tree.