CACAO
GlobalValueNumberingPass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/GlobalValueNumberingPass.hpp - GlobalValueNumberingPass
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_GLOBALVALUENUMBERINGPASS
26 #define _JIT_COMPILER2_GLOBALVALUENUMBERINGPASS
27 
31 #include "future/unordered_set.hpp"
32 #include "future/unordered_map.hpp"
33 
34 namespace cacao {
35 namespace jit {
36 namespace compiler2 {
37 
38 /**
39  * GlobalValueNumberingPass
40  *
41  * This pass finds and removes redundant computations based on the high-level
42  * intermediate representation of the compiler2, i.e., it removes redundant
43  * nodes. It therefore uses the global value numbering algorithm in
44  * @cite ReisingerBScThesis.
45  */
47 private:
49  typedef std::list<BlockTy*> PartitionTy;
50  typedef std::pair<BlockTy*,int> WorkListPairTy;
51  typedef std::list<WorkListPairTy*> WorkListTy;
54  typedef std::list<Instruction*> InstructionListTy;
55  typedef std::vector<InstructionListTy*> OperandIndex2UsersTy;
57 
58  /// these types are needed for the creation of the inital blocks
65 
68 
69  int max_arity;
76 
83 
84  InstructionListTy *get_users(Instruction *inst, int op_index);
85  void add_to_block(BlockTy *block, Instruction *inst);
86 
87  void add_to_worklist(BlockTy *block, int operandIndex);
88  std::vector<bool> *get_worklist_flags(BlockTy *block);
89  void set_in_worklist(BlockTy *block, int index, bool flag);
90  bool is_in_worklist(BlockTy *block, int index);
92 
95 
96  void split(BlockTy *block, TouchedInstListTy *instructions);
97 
98  void print_block(BlockTy *block);
99  void print_blocks();
100  void print_instructions(TouchedInstListTy *instructions);
101 
102  static int arity(BlockTy *block);
103  static int compute_max_arity(Method::const_iterator begin,
105 
106  void eliminate_redundancies();
108 
109  template <typename T1, typename T2>
111  BlockTy *block = map[key];
112  if (!block) {
113  block = create_block();
114  map[key] = block;
115  }
116  return block;
117  }
118 
120 public:
121  static char ID;
123  virtual bool run(JITData &JD);
124  virtual PassUsage& get_PassUsage(PassUsage &PU) const;
125 
126  // virtual void initialize(); (optional)
127  // virtual void finalize(); (optional)
128  // virtual bool verify() const; (optional)
129 };
130 
131 } // end namespace compiler2
132 } // end namespace jit
133 } // end namespace cacao
134 
135 #endif /* _JIT_COMPILER2_GLOBALVALUENUMBERINGPASS */
136 
137 
138 /*
139  * These are local overrides for various environment variables in Emacs.
140  * Please do not remove this and leave it at the end of the file, where
141  * Emacs will automagically detect them.
142  * ---------------------------------------------------------------------
143  * Local variables:
144  * mode: c++
145  * indent-tabs-mode: t
146  * c-basic-offset: 4
147  * tab-width: 4
148  * End:
149  * vim:noexpandtab:sw=4:ts=4:
150  */
std::size_t index
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:48
unordered_map< BlockTy *, TouchedInstListTy * > Block2TouchedInstListMapTy
unordered_map< Instruction *, OperandIndex2UsersTy * > OperandInverseMapTy
unordered_map< BlockTy *, std::vector< bool > * > InWorkListTy
InstructionListTy * get_users(Instruction *inst, int op_index)
BeginInst *& block
unordered_map< Instruction::InstID, BlockTy *, hash< int > > OpcodeBlockMapTy
these types are needed for the creation of the inital blocks
void set_in_worklist(BlockTy *block, int index, bool flag)
std::vector< bool > * get_worklist_flags(BlockTy *block)
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
void init_operand_inverse(Method::const_iterator begin, Method::const_iterator end)
Instruction super class.
Definition: Instruction.hpp:73
void split(BlockTy *block, TouchedInstListTy *instructions)
void add_to_worklist(BlockTy *block, int operandIndex)
unordered_map< BeginInst *, BlockTy * > BBBlockMapTy
unordered_map< Instruction *, BlockTy * > Inst2BlockMapTy
InstructionListTy::const_iterator const_iterator
Definition: MethodC2.hpp:67
std::vector< InstructionListTy * > OperandIndex2UsersTy
static int compute_max_arity(Method::const_iterator begin, Method::const_iterator end)
jmethodID jint const void jint const jvmtiAddrLocationMap * map
Definition: jvmti.h:338
TouchedInstListTy * get_touched_instructions(BlockTy *block)
void init_partition(Method::const_iterator begin, Method::const_iterator end)
void add_to_block(BlockTy *block, Instruction *inst)
virtual PassUsage & get_PassUsage(PassUsage &PU) const
Set the requirements for the pass.
BlockTy * create_block()
creates and returns a new block and does some setup work needed for the further execution of the part...
void print_instructions(TouchedInstListTy *instructions)