CACAO
PassUsage.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/PassUsage.hpp - PassUsage
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_PASSUSAGE
26 #define _JIT_COMPILER2_PASSUSAGE
27 
30 
31 namespace cacao {
32 namespace jit {
33 namespace compiler2 {
34 
35 // forward declaration
36 class Pass;
37 
38 /**
39  * Stores the interdependencies of a pass.
40  *
41  * add_modifies and add_destroys can be use to invalidate other passes.
42  *
43  * The others are used to control the placement of a pass.
44  *
45  * add_requires<PassName>() and add_schedule_after<>(PassName) assert that the pass
46  * PassName must be scheduled before the current pass. The first version also ensures
47  * that PassName is up to date. It also allows the retrieval of the info by using
48  * get_Pass<PassName>().
49  *
50  * add_run_before<PassName> and add_schedule_before<PassName>() ensure that the
51  * current pass is scheduled before PassName. The first version also enforces
52  * that the current pass is up to date. add_run_before(add_schedule_before) is the
53  * inverse operation of add_requires(add_schedule_after).
54  */
55 class PassUsage {
56 public:
59 private:
66 
67  bool is_required(char &ID) const {
68  return requires.find(&ID) != requires.end();
69  }
70 
71 public:
72  PassUsage() {}
73 
74  /**
75  * PassName is required.
76  */
77  template<class PassName>
78  void add_requires() {
79  requires.insert(&PassName::ID);
80  }
82  requires.insert(id);
83  }
84 
85  /**
86  * PassName will be invalidated.
87  */
88  template<class PassName>
89  void add_destroys() {
90  destroys.insert(&PassName::ID);
91  }
93  destroys.insert(id);
94  }
95 
96  /**
97  * PassName will be modified. All passed depending on PassName are invalidated.
98  */
99  template<class PassName>
100  void add_modifies() {
101  modifies.insert(&PassName::ID);
102  }
104  modifies.insert(id);
105  }
106 
107  /**
108  * Run before PassName.
109  *
110  * This enforces that the current pass is up to date before running PassName.
111  */
112  template<class PassName>
113  void add_run_before() {
114  run_before.insert(&PassName::ID);
115  }
117  run_before.insert(id);
118  }
119 
120  /**
121  * Schedule before PassName.
122  *
123  * This ensures that the current pass has been executed at least once. It is
124  * _not_ needed to be up to date.
125  */
126  template<class PassName>
128  schedule_before.insert(&PassName::ID);
129  }
131  schedule_before.insert(id);
132  }
133 
134  /**
135  * Schedule after PassName.
136  *
137  * Like add_requires but does not rerun PassName if not up to date. Also,
138  * it is not allowed the use get_Pass<PassName>(). This does _not_ force
139  * a pass to be scheduled at all! It is only used to express schedule
140  * dependencies.
141  */
142  template<class PassName>
144  schedule_after.insert(&PassName::ID);
145  }
147  schedule_after.insert(id);
148  }
149 
150  const_iterator destroys_begin() const { return destroys.begin(); }
151  const_iterator destroys_end() const { return destroys.end(); }
152 
153  const_iterator modifies_begin() const { return modifies.begin(); }
154  const_iterator modifies_end() const { return modifies.end(); }
155 
156  const_iterator requires_begin() const { return requires.begin(); }
157  const_iterator requires_end() const { return requires.end(); }
158 
159  const_iterator run_before_begin() const { return run_before.begin(); }
160  const_iterator run_before_end() const { return run_before.end(); }
161 
164 
167 
168  friend class Pass;
169 };
170 
171 
172 } // end namespace compiler2
173 } // end namespace jit
174 } // end namespace cacao
175 
176 #endif /* _JIT_COMPILER2_PASSUSAGE */
177 
178 
179 /*
180  * These are local overrides for various environment variables in Emacs.
181  * Please do not remove this and leave it at the end of the file, where
182  * Emacs will automagically detect them.
183  * ---------------------------------------------------------------------
184  * Local variables:
185  * mode: c++
186  * indent-tabs-mode: t
187  * c-basic-offset: 4
188  * tab-width: 4
189  * End:
190  * vim:noexpandtab:sw=4:ts=4:
191  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:48
_Base::const_iterator const_iterator
void add_run_before()
Run before PassName.
Definition: PassUsage.hpp:113
const_iterator destroys_end() const
Definition: PassUsage.hpp:151
const_iterator requires_end() const
Definition: PassUsage.hpp:157
const_iterator schedule_after_end() const
Definition: PassUsage.hpp:163
const_iterator modifies_end() const
Definition: PassUsage.hpp:154
bool is_required(char &ID) const
Definition: PassUsage.hpp:67
void add_schedule_before(PassInfo::IDTy id)
Definition: PassUsage.hpp:130
alloc::unordered_set< PassInfo::IDTy >::type PIIDSet
Definition: PassUsage.hpp:57
void add_schedule_after()
Schedule after PassName.
Definition: PassUsage.hpp:143
void add_schedule_before()
Schedule before PassName.
Definition: PassUsage.hpp:127
const_iterator schedule_after_begin() const
Definition: PassUsage.hpp:162
const_iterator schedule_before_end() const
Definition: PassUsage.hpp:166
const_iterator run_before_begin() const
Definition: PassUsage.hpp:159
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
const_iterator schedule_before_begin() const
Definition: PassUsage.hpp:165
void add_modifies(PassInfo::IDTy id)
Definition: PassUsage.hpp:103
void add_requires(PassInfo::IDTy id)
Definition: PassUsage.hpp:81
void add_destroys()
PassName will be invalidated.
Definition: PassUsage.hpp:89
const_iterator destroys_begin() const
Definition: PassUsage.hpp:150
void add_run_before(PassInfo::IDTy id)
Definition: PassUsage.hpp:116
const_iterator run_before_end() const
Definition: PassUsage.hpp:160
PIIDSet::const_iterator const_iterator
Definition: PassUsage.hpp:58
void add_modifies()
PassName will be modified.
Definition: PassUsage.hpp:100
void add_destroys(PassInfo::IDTy id)
Definition: PassUsage.hpp:92
const_iterator requires_begin() const
Definition: PassUsage.hpp:156
void add_requires()
PassName is required.
Definition: PassUsage.hpp:78
void add_schedule_after(PassInfo::IDTy id)
Definition: PassUsage.hpp:146
const_iterator modifies_begin() const
Definition: PassUsage.hpp:153