40 #define DEBUG_NAME "compiler2/PassManager"
48 RT_REGISTER_GROUP(compiler2_rtgroup,
"compiler2-pipeline",
"compiler2 pass pipeline")
50 typedef alloc::unordered_map<PassInfo::IDTy,RTTimer>::type PassTimerMap;
51 PassTimerMap pass_timers;
58 Option<bool> print_pass_dependencies(
"PrintPassDependencies",
"compiler2: print pass dependencies",
false,::
cacao::option::xx_root());
66 assert(PI &&
"Pass not registered");
73 RTTimer &timer = pass_timers[ID];
92 LOG(
"runPasses" <<
nl);
93 if (option::print_pass_dependencies) {
102 PassTimerMap::iterator f = pass_timers.find(
id);
103 assert(f != pass_timers.end());
104 RTTimer &timer = f->second;
147 #define DEBUG_NAME "compiler2/PassManager/Scheduler"
150 #if defined(ENABLE_LOGGING) || !defined(NDEBUG)
152 PassManager* latest = NULL;
155 if (!latest)
return "PassManager not available";
156 return latest->get_Pass_name(
id);
158 #endif // defined(ENABLE_LOGGING) || !defined(NDEBUG)
160 template <
class InputIterator,
class ValueType>
161 inline bool contains(InputIterator begin, InputIterator end,
const ValueType &val) {
162 return std::find(begin,end,val) != end;
165 template <
class Container,
class ValueType>
167 bool operator()(
const Container &c,
const ValueType &val) {
168 return contains(c.begin(),c.end(),val);
172 template <
class ValueType>
173 struct ContainsFn<typename alloc::
set<ValueType>::type,ValueType> {
174 bool operator()(
const typename alloc::set<ValueType>::type &c,
const ValueType &val) {
175 return c.find(val) != c.end();
179 template <
class ValueType>
180 struct ContainsFn<unordered_set<ValueType>,ValueType> {
181 bool operator()(
const typename alloc::unordered_set<ValueType>::type &c,
const ValueType &val) {
182 return c.find(val) != c.end();
186 template <
class Container,
class ValueType>
187 inline bool contains(
const Container &c,
const ValueType &val) {
188 return ContainsFn<Container,ValueType>()(c,val);
192 typedef alloc::unordered_map<PassInfo::IDTy,PassUsage>::type ID2PUTy;
193 typedef alloc::unordered_map<PassInfo::IDTy,alloc::unordered_set<PassInfo::IDTy>::type >::type ID2MapTy;
196 public std::unary_function<PassInfo::IDTy,void> {
201 : reverse_require_map(reverse_require_map), ready(ready) {}
204 if (
ready.erase(
id)) {
205 LOG3(
" invalidated: " << get_Pass_name(
id) <<
nl);
211 class PassScheduler {
215 alloc::list<PassInfo::IDTy>::type &
stack;
224 : unhandled(unhandled), ready(ready), stack(stack), new_schedule(new_schedule),
225 pu_map(pu_map), reverse_require_map(reverse_require_map) {}
228 if (contains(
ready,
id))
return;
230 if (contains(
stack,
id)) {
231 ABORT_MSG(
"PassManager: dependency cycle detected",
232 "Pass " << get_Pass_name(
id) <<
" already stacked for scheduling!");
237 LOG3(
"prescheduled: " << get_Pass_name(
id) <<
nl);
244 LOG3(
" schedule_after: " << get_Pass_name(*
i) <<
nl);
253 LOG3(
" requires: " << get_Pass_name(*
i) <<
nl);
261 LOG3(
"scheduled: " << get_Pass_name(
id) <<
nl);
268 LOG3(
" modifies: " << get_Pass_name(*
i) <<
nl);
281 struct RunBefore :
public std::unary_function<PassInfo::IDTy,void> {
286 : pu_map(pu_map), id(id) {}
290 pu_map[before].add_requires(
id);
294 struct ScheduleBefore :
public std::unary_function<PassInfo::IDTy,void> {
299 : pu_map(pu_map), id(id) {}
302 pu_map[before].add_schedule_after(
id);
306 struct AddReverseRequire :
public std::unary_function<PassInfo::IDTy,void> {
311 : map(map), id(id) {}
314 map[required_by].insert(
id);
318 struct ReverseRequire :
319 public std::unary_function<ID2PUTy::value_type,void> {
322 ReverseRequire(ID2MapTy &
map) : map(map) {}
324 void operator()(argument_type pair) {
325 std::for_each(pair.second.requires_begin(), pair.second.requires_end(),AddReverseRequire(
map,pair.first));
332 #if defined(ENABLE_LOGGING) || !defined(NDEBUG)
356 std::for_each(pu_map.begin(),pu_map.end(),ReverseRequire(reverse_require_map));
360 PassScheduler scheduler(unhandled,ready,stack,new_schedule,pu_map,reverse_require_map);
361 while (!unhandled.empty()) {
363 unhandled.pop_front();
366 assert(stack.empty());
370 LOG2(
"old Schedule:" <<
nl);
371 for (ScheduleListTy::const_iterator
i =
schedule.begin(),
375 LOG2(
"new Schedule:" <<
nl);
376 for (ScheduleListTy::const_iterator
i = new_schedule.begin(),
377 e = new_schedule.end();
i !=
e ; ++
i) {
void finalizePasses()
run pass finalizers
ID2MapTy & reverse_require_map
Pass superclass All compiler passes should inheritate this class.
void set_PassManager(PassManager *PM)
virtual PassUsage & get_PassUsage(PassUsage &PU) const
Set the requirements for the pass.
PassMapTy initialized_passes
This stores the initialized passes.
void print_PassDependencyGraph(PassManager &PM)
const_iterator destroys_end() const
std::deque< T, Allocator< T > > type
_Base::const_iterator const_iterator
virtual void finalize()
Finalize the Pass.
#define DEBUG_COND_N(VERBOSE)
Pass * get_initialized_Pass(PassInfo::IDTy ID)
#define RT_REGISTER_GROUP(var, name, description)
Register a new (toplevel) group.
std::list< T, Allocator< T > > type
PassManager::ScheduleListTy & new_schedule
const_iterator schedule_before_end() const
const_iterator run_before_begin() const
void initializePasses()
run pass initializers
alloc::list< PassInfo::IDTy >::type & stack
Stores the interdependencies of a pass.
const_iterator schedule_before_begin() const
static PassInfoMapTy & registered_passes()
Pass * create_Pass() const
virtual bool run(JITData &JD)=0
Run the Pass.
This file contains the real-time timing utilities.
virtual bool verify() const
Verify the Result.
alloc::vector< PassInfo::IDTy >::type ScheduleListTy
This file contains the command line option parsing library.
#define LOG(STMT)
Analogous to DEBUG.
const char * get_Pass_name(PassInfo::IDTy ID)
jmethodID jint const void jint const jvmtiAddrLocationMap * map
void runPasses(JITData &JD)
run passes
const_iterator destroys_begin() const
const char * get_name() const
alloc::deque< PassInfo::IDTy >::type & unhandled
const_iterator run_before_end() const
cacao::unordered_set< PassInfo::IDTy, cacao::hash< PassInfo::IDTy >, std::equal_to< PassInfo::IDTy >, Allocator< PassInfo::IDTy > > type
PIIDSet::const_iterator const_iterator
ResultReadyMapTy result_ready
Map of ready results.
#define ABORT_MSG(EXPR_SHORT, EXPR_LONG)
virtual void initialize()
Initialize the Pass.
ScheduleListTy schedule
This variable contains a schedule of the passes.