CACAO
ConstantPropagationPass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/ConstantPropagationPass.hpp - ConstantPropagationPass
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_CONSTANTPROPAGATIONPASS
26 #define _JIT_COMPILER2_CONSTANTPROPAGATIONPASS
27 
31 #include "toolbox/Option.hpp"
32 
33 #include <list>
34 
35 namespace cacao {
36 namespace jit {
37 namespace compiler2 {
38 
39 // forward declaration
40 class Instruction;
41 
42 /**
43  * ConstantPropagationPass
44  *
45  * This optimization pass is a combined version of constant folding (a.k.a
46  * constant expression evaluation) and constant propagation, based on the
47  * algorithm in @cite ReisingerBScThesis. Analysis and program transformations
48  * in the course of this optimization are targeted at the high-level
49  * intermediate representation of the compiler2. It evalutes operations at
50  * compile-time, whose operands are all constants and propagates the results
51  * of these evaluations as far as possible through the program.
52  */
53 class ConstantPropagationPass : public Pass {
54 private:
57  typedef std::list<Instruction*> WorkListTy;
58 
59  /**
60  * This work list is used by the algorithm to store the instructions which
61  * have to be reconsidered. at the beginning it therefore contains all
62  * instructions.
63  */
65 
66  /**
67  * will be used to look up whether an instruction is currently contained in the
68  * worklist to avoid inserting an instruction which is already in the list
69  */
71 
72  /**
73  * used to track for each instruction the number of its operands which are
74  * already known to be constant
75  */
77 
79  void propagate(Instruction *inst);
80 
81 public:
84  virtual bool run(JITData &JD);
85  virtual PassUsage& get_PassUsage(PassUsage &PA) const;
86 
87  virtual bool is_enabled() const {
89  }
90 };
91 
92 } // end namespace compiler2
93 } // end namespace jit
94 } // end namespace cacao
95 
96 #endif /* _JIT_COMPILER2_CONSTANTPROPAGATIONPASS */
97 
98 
99 /*
100  * These are local overrides for various environment variables in Emacs.
101  * Please do not remove this and leave it at the end of the file, where
102  * Emacs will automagically detect them.
103  * ---------------------------------------------------------------------
104  * Local variables:
105  * mode: c++
106  * indent-tabs-mode: t
107  * c-basic-offset: 4
108  * tab-width: 4
109  * End:
110  * vim:noexpandtab:sw=4:ts=4:
111  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:47
virtual bool is_enabled() const
Allows concrete passes to enable/disable themselves the way they like.
alloc::unordered_map< Instruction *, std::size_t >::type InstIntMapTy
virtual bool run(JITData &JD)
Run the Pass.
WorkListTy workList
This work list is used by the algorithm to store the instructions which have to be reconsidered...
InstBoolMapTy inWorkList
will be used to look up whether an instruction is currently contained in the worklist to avoid insert...
InstIntMapTy constantOperands
used to track for each instruction the number of its operands which are already known to be constant ...
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
virtual PassUsage & get_PassUsage(PassUsage &PA) const
Set the requirements for the pass.
Instruction super class.
Definition: Instruction.hpp:75
alloc::unordered_map< Instruction *, bool >::type InstBoolMapTy
This file contains the command line option parsing library.
const Method & M
void replace_by_constant(Instruction *isnt, CONSTInst *c, Method *M)
std::unordered_map< Key, T, Hash, KeyEqual, Allocator< std::pair< const Key, T > > > type