CACAO
Pass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Pass.hpp - Pass
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_PASS
26 #define _JIT_COMPILER2_PASS
27 
30 #include <cstddef>
31 
32 MM_MAKE_NAME(Pass)
33 
34 namespace cacao {
35 namespace jit {
36 namespace compiler2 {
37 
38 // forward declaration
39 class PassManager;
40 class PassUsage;
41 class JITData;
42 
43 /**
44  * Pass superclass
45  * All compiler passes should inheritate this class.
46  * TODO: more info
47  */
48 class Pass {
49 private:
51  bool allowed_to_use_result(char &id) const;
52 public:
53  Pass() : pm(NULL) {}
54 
56  pm = PM;
57  }
58 
59  /**
60  * Get the result of a previous compiler pass
61  *
62  * Can only be used if ResultType is added to required in get_PassUsage().
63  */
64  template<class _PassClass>
65  _PassClass *get_Pass() const {
66  if (!allowed_to_use_result(_PassClass::ID)) {
67  assert(0 && "Not allowed to get result (not declared in get_PassUsage())");
68  return NULL;
69  }
70  return pm->get_Pass_result<_PassClass>();
71  }
72 
73  /**
74  * Get the result of a previous compiler pass
75  *
76  * Can only be used if ResultType is added to required in get_PassUsage().
77  */
78  template<class _PassClass>
79  _PassClass *get_Pass_if_available() const {
80  if (!pm->result_ready[&_PassClass::ID])
81  return NULL;
82  return pm->get_Pass_result<_PassClass>();
83  }
84  /**
85  * Set the requirements for the pass
86  */
87  virtual PassUsage& get_PassUsage(PassUsage &PU) const {
88  // default: require nothing, destroy nothing
89  return PU;
90  }
91 
92  /**
93  * Initialize the Pass.
94  * This method is called by the PassManager before the pass is started. It should be used to
95  * initialize e.g. data structures. A Pass object might be reused so the construtor can not be
96  * used in some cases.
97  */
98  virtual void initialize() {}
99 
100  /**
101  * Finalize the Pass.
102  * This method is called by the PassManager after the pass is no longer used. It should be used to
103  * clean up stuff done in initialize().
104  */
105  virtual void finalize() {}
106 
107  /**
108  * Run the Pass.
109  * This method implements the compiler pass.
110  *
111  * @return false if a problem occurred, true otherwise
112  */
113  virtual bool run(JITData &JD) = 0;
114 
115  /**
116  * Verify the Result.
117  * This method is used to verify the result of the pass. It has the same motivation
118  * than the assert() statement. It should be only used for debugging purposes
119  * and might not be called in release builds.
120  */
121  virtual bool verify() const { return true; }
122 
123  /**
124  * Destructor
125  */
126  virtual ~Pass() {}
127 };
128 
129 
130 } // end namespace compiler2
131 } // end namespace jit
132 } // end namespace cacao
133 
134 #endif /* _JIT_COMPILER2_PASS */
135 
136 
137 /*
138  * These are local overrides for various environment variables in Emacs.
139  * Please do not remove this and leave it at the end of the file, where
140  * Emacs will automagically detect them.
141  * ---------------------------------------------------------------------
142  * Local variables:
143  * mode: c++
144  * indent-tabs-mode: t
145  * c-basic-offset: 4
146  * tab-width: 4
147  * End:
148  * vim:noexpandtab:sw=4:ts=4:
149  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:48
void set_PassManager(PassManager *PM)
Definition: Pass.hpp:55
virtual PassUsage & get_PassUsage(PassUsage &PU) const
Set the requirements for the pass.
Definition: Pass.hpp:87
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:127
virtual void finalize()
Finalize the Pass.
Definition: Pass.hpp:105
_PassClass * get_Pass() const
Get the result of a previous compiler pass.
Definition: Pass.hpp:65
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
PassManager * pm
Definition: Pass.hpp:50
Manage the execution of compiler passes.
Definition: PassManager.hpp:75
virtual bool verify() const
Verify the Result.
Definition: Pass.hpp:121
virtual ~Pass()
Destructor.
Definition: Pass.hpp:126
_PassClass * get_Pass_if_available() const
Get the result of a previous compiler pass.
Definition: Pass.hpp:79
virtual void initialize()
Initialize the Pass.
Definition: Pass.hpp:98