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 
28 #include <unordered_map>
29 
33 #include "toolbox/Option.hpp"
34 
35 namespace cacao {
36 namespace jit {
37 namespace compiler2 {
38 
39 /**
40  * GlobalValueNumberingPass
41  *
42  * This pass finds and removes redundant computations based on the high-level
43  * intermediate representation of the compiler2, i.e., it removes redundant
44  * nodes. It therefore uses the global value numbering algorithm in
45  * @cite ReisingerBScThesis.
46  */
48 private:
50  typedef std::list<BlockTy*> PartitionTy;
51  typedef std::pair<BlockTy*,int> WorkListPairTy;
52  typedef std::list<WorkListPairTy*> WorkListTy;
53  typedef std::unordered_map<BlockTy*,std::vector<bool>* > InWorkListTy;
54  typedef std::unordered_map<Instruction*,BlockTy*> Inst2BlockMapTy;
55  typedef std::list<Instruction*> InstructionListTy;
56  typedef std::vector<InstructionListTy*> OperandIndex2UsersTy;
57  typedef std::unordered_map<Instruction*,OperandIndex2UsersTy*> OperandInverseMapTy;
58 
59  /// these types are needed for the creation of the inital blocks
60  typedef std::unordered_map<Instruction::InstID,BlockTy*,std::hash<int> > OpcodeBlockMapTy;
61  typedef std::unordered_map<int32_t,BlockTy*> IntBlockMapTy;
62  typedef std::unordered_map<int64_t,BlockTy*> LongBlockMapTy;
63  typedef std::unordered_map<float,BlockTy*> FloatBlockMapTy;
64  typedef std::unordered_map<double,BlockTy*> DoubleBlockMapTy;
65  typedef std::unordered_map<BeginInst*,BlockTy*> BBBlockMapTy;
66 
68  typedef std::unordered_map<BlockTy*,TouchedInstListTy*> Block2TouchedInstListMapTy;
69 
70  int max_arity;
77 
84 
85  InstructionListTy *get_users(Instruction *inst, int op_index);
86  void add_to_block(BlockTy *block, Instruction *inst);
87 
88  void add_to_worklist(BlockTy *block, int operandIndex);
89  std::vector<bool> *get_worklist_flags(BlockTy *block);
90  void set_in_worklist(BlockTy *block, int index, bool flag);
91  bool is_in_worklist(BlockTy *block, int index);
93 
96 
97  void split(BlockTy *block, TouchedInstListTy *instructions);
98 
99  void print_block(BlockTy *block);
100  void print_blocks();
101  void print_instructions(TouchedInstListTy *instructions);
102 
103  static int arity(BlockTy *block);
104  static int compute_max_arity(Method::const_iterator begin,
106 
107  void eliminate_redundancies();
109 
110  template <typename T1, typename T2>
112  BlockTy *block = map[key];
113  if (!block) {
114  block = create_block();
115  map[key] = block;
116  }
117  return block;
118  }
119 
121 public:
124  virtual bool run(JITData &JD);
125  virtual PassUsage& get_PassUsage(PassUsage &PU) const;
126 
127  virtual bool is_enabled() const {
129  }
130 };
131 
132 } // end namespace compiler2
133 } // end namespace jit
134 } // end namespace cacao
135 
136 #endif /* _JIT_COMPILER2_GLOBALVALUENUMBERINGPASS */
137 
138 
139 /*
140  * These are local overrides for various environment variables in Emacs.
141  * Please do not remove this and leave it at the end of the file, where
142  * Emacs will automagically detect them.
143  * ---------------------------------------------------------------------
144  * Local variables:
145  * mode: c++
146  * indent-tabs-mode: t
147  * c-basic-offset: 4
148  * tab-width: 4
149  * End:
150  * vim:noexpandtab:sw=4:ts=4:
151  */
std::unordered_map< int32_t, BlockTy * > IntBlockMapTy
std::size_t index
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:47
std::unordered_map< Instruction::InstID, BlockTy *, std::hash< int > > OpcodeBlockMapTy
these types are needed for the creation of the inital blocks
alloc::unordered_set< Instruction * >::type BlockTy
InstructionListTy * get_users(Instruction *inst, int op_index)
alloc::unordered_set< Instruction * >::type TouchedInstListTy
std::unordered_set< Key, Hash, KeyEqual, Allocator< Key > > type
std::unordered_map< BlockTy *, TouchedInstListTy * > Block2TouchedInstListMapTy
BeginInst *& block
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)
std::unordered_map< int64_t, BlockTy * > LongBlockMapTy
std::unordered_map< Instruction *, OperandIndex2UsersTy * > OperandInverseMapTy
Instruction super class.
Definition: Instruction.hpp:75
void split(BlockTy *block, TouchedInstListTy *instructions)
std::unordered_map< double, BlockTy * > DoubleBlockMapTy
void add_to_worklist(BlockTy *block, int operandIndex)
InstructionListTy::const_iterator const_iterator
Definition: MethodC2.hpp:69
std::vector< InstructionListTy * > OperandIndex2UsersTy
This file contains the command line option parsing library.
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.
std::unordered_map< Instruction *, BlockTy * > Inst2BlockMapTy
virtual bool is_enabled() const
Allows concrete passes to enable/disable themselves the way they like.
std::unordered_map< float, BlockTy * > FloatBlockMapTy
std::unordered_map< BeginInst *, BlockTy * > BBBlockMapTy
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)
std::unordered_map< BlockTy *, std::vector< bool > * > InWorkListTy