CACAO
SSAConstructionPass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/SSAConstructionPass.hpp - SSAConstructionPass
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_SSACONSTRUCTIONPASS
26 #define _JIT_COMPILER2_SSACONSTRUCTIONPASS
27 
30 #include "vm/jit/jit.hpp"
32 
34 
35 MM_MAKE_NAME(SSAConstructionPass)
36 
37 namespace cacao {
38 namespace jit {
39 namespace compiler2 {
40 
41 class InVarPhis;
42 
43 /**
44  * SSAConstructionPass
45  *
46  * This Pass constructs the compiler2 specific SSA based IR from
47  * the ICMD_* style IR used in the baseline compiler.
48  *
49  * The approach is based on "Simple and Efficient Construction of
50  * Static Singe Assignment Form" by Braun et al. 2013 @cite SSAsimple2013.
51  */
52 class SSAConstructionPass : public Pass, public memory::ManagerMixin<SSAConstructionPass> {
53 private:
59  // TODO may be changed to std::vector<unordered_map<int,PHIInst*> > incomplete_phi;
61  // TODO this should be merged with incomplete_phi
63 
66 
67  /// Used to remember which basicblocks have already been visited.
68  ///
69  /// This vector is indexed by basicblock indices (i.e. by basicblock::nr).
71 
72  /// Indicates whether IR construction should be skipped for a basicblock.
73  ///
74  /// This vector is indexed by basicblock indices (i.e. by basicblock::nr).
75  ///
76  /// @see SSAConstructionPass::deoptimize()
78 
80  void write_variable(size_t varindex, size_t bb, Value *V);
81  Value* read_variable_recursive(size_t varindex, size_t bb);
82  Value* add_phi_operands(size_t varindex, PHIInst *phi);
83  Value* try_remove_trivial_phi(PHIInst *phi);
84  void seal_block(size_t bb);
85  bool try_seal_block(basicblock *bb);
86  void print_current_def() const;
87 
88  /// Check whether all predecessor blocks of @p bb have been skipped.
89  ///
90  /// @param bb The block to check.
91  ///
92  /// @return True if all predecessors have been skipped, false otherwise.
93  bool skipped_all_predecessors(basicblock *bb);
94 
95  /// Remove unreachable BeginInsts and their corresponding EndInsts.
96  void remove_unreachable_blocks();
97 
98  /// Helper function to terminate a block with a DeoptimizeInst.
99  ///
100  /// Assigns a new DeoptimizeInst to the BeginInst that corresponds to the
101  /// given @p bbindex. Additionally the corresponding skipped_blocks flag
102  /// is set to true in order to signal that IR construction should be skipped
103  /// for the rest of this block.
104  ///
105  /// @param bbindex The corresponding basicblock index.
106  void deoptimize(int bbindex);
107 
108  void install_javalocal_dependencies(SourceStateInst *source_state,
109  s4 *javalocals, basicblock *bb);
110 
111  void install_stackvar_dependencies(SourceStateInst *source_state,
112  s4 *stack, s4 stackdepth, s4 paramcount, basicblock *bb);
113 
114  SourceStateInst *record_source_state(Instruction *I, instruction *iptr,
115  basicblock *bb, s4 *javalocals, s4 *stack, s4 stackdepth);
116 
117  /// Creates a CONSTInst of type @p type from the s2 operand of @p iptr.
118  ///
119  /// @param iptr The corresponding baseline IR instruction.
120  /// @param type The corresponding type.
121  ///
122  /// @return The new CONSTInst.
123  CONSTInst *parse_s2_constant(instruction *iptr, Type::TypeID type);
124 
125 public:
126  Value* read_variable(size_t varindex, size_t bb);
128  virtual bool run(JITData &JD);
129  virtual bool verify() const;
130  virtual PassUsage& get_PassUsage(PassUsage &PU) const;
131 };
132 
133 } // end namespace cacao
134 } // end namespace jit
135 } // end namespace compiler2
136 
137 #endif /* _JIT_COMPILER2_SSACONSTRUCTIONPASS */
138 
139 
140 /*
141  * These are local overrides for various environment variables in Emacs.
142  * Please do not remove this and leave it at the end of the file, where
143  * Emacs will automagically detect them.
144  * ---------------------------------------------------------------------
145  * Local variables:
146  * mode: c++
147  * indent-tabs-mode: t
148  * c-basic-offset: 4
149  * tab-width: 4
150  * End:
151  * vim:noexpandtab:sw=4:ts=4:
152  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:47
alloc::vector< alloc::vector< Value * >::type >::type current_def
alloc::vector< BeginInst * >::type BB
Definition: jit.hpp:126
Custom new/delete handler mixin.
Definition: Manager.hpp:43
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:128
alloc::vector< alloc::vector< PHIInst * >::type >::type incomplete_phi
Provides a mapping from HIR values to baseline IR variables.
alloc::vector< Type::TypeID >::type var_type_tbl
std::vector< T, Allocator< T > > type
Definition: vector.hpp:38
alloc::list< PassInfo::IDTy >::type & stack
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
Instruction super class.
Definition: Instruction.hpp:75
int32_t s4
Definition: types.hpp:45
#define I(value)
Definition: codegen.c:279
alloc::unordered_map< BeginInst *, size_t >::type beginToIndex
alloc::vector< bool >::type visited_blocks
Used to remember which basicblocks have already been visited.
alloc::vector< bool >::type skipped_blocks
Indicates whether IR construction should be skipped for a basicblock.
alloc::vector< alloc::list< InVarPhis * >::type >::type incomplete_in_phi
std::unordered_map< Key, T, Hash, KeyEqual, Allocator< std::pair< const Key, T > > > type