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 
29 #include "future/unordered_map.hpp"
31 
32 #include <list>
33 
34 namespace cacao {
35 namespace jit {
36 namespace compiler2 {
37 
38 // forward declaration
39 class Instruction;
40 
41 /**
42  * ConstantPropagationPass
43  *
44  * This optimization pass is a combined version of constant folding (a.k.a
45  * constant expression evaluation) and constant propagation, based on the
46  * algorithm in @cite ReisingerBScThesis. Analysis and program transformations
47  * in the course of this optimization are targeted at the high-level
48  * intermediate representation of the compiler2. It evalutes operations at
49  * compile-time, whose operands are all constants and propagates the results
50  * of these evaluations as far as possible through the program.
51  */
52 class ConstantPropagationPass : public Pass {
53 private:
56  typedef std::list<Instruction*> WorkListTy;
57 
58  /**
59  * This work list is used by the algorithm to store the instructions which
60  * have to be reconsidered. at the beginning it therefore contains all
61  * instructions.
62  */
64 
65  /**
66  * will be used to look up whether an instruction is currently contained in the
67  * worklist to avoid inserting an instruction which is already in the list
68  */
70 
71  /**
72  * used to track for each instruction the number of its operands which are
73  * already known to be constant
74  */
76 
78  void propagate(Instruction *inst);
79 
80 public:
81  static char ID;
83  virtual bool run(JITData &JD);
84  virtual PassUsage& get_PassUsage(PassUsage &PA) const;
85 };
86 
87 } // end namespace compiler2
88 } // end namespace jit
89 } // end namespace cacao
90 
91 #endif /* _JIT_COMPILER2_CONSTANTPROPAGATIONPASS */
92 
93 
94 /*
95  * These are local overrides for various environment variables in Emacs.
96  * Please do not remove this and leave it at the end of the file, where
97  * Emacs will automagically detect them.
98  * ---------------------------------------------------------------------
99  * Local variables:
100  * mode: c++
101  * indent-tabs-mode: t
102  * c-basic-offset: 4
103  * tab-width: 4
104  * End:
105  * vim:noexpandtab:sw=4:ts=4:
106  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:48
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:73
unordered_map< Instruction *, std::size_t > InstIntMapTy
const Method & M
unordered_map< Instruction *, bool > InstBoolMapTy
void replace_by_constant(Instruction *isnt, CONSTInst *c, Method *M)