CACAO
CodeGenPass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/CodeGenPass.hpp - CodeGenPass
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_CODEGENPASS
26 #define _JIT_COMPILER2_CODEGENPASS
27 
31 #include "toolbox/Option.hpp"
32 
33 MM_MAKE_NAME(CodeGenPass)
34 
35 namespace cacao {
36 namespace jit {
37 namespace compiler2 {
38 
39 struct MBBCompare {
41  return lhs->self_iterator() < rhs->self_iterator();
42  }
43 };
44 
45 /**
46  * CodeGenPass
47  * TODO: more info
48  */
49 class CodeGenPass : public Pass, public memory::ManagerMixin<CodeGenPass> {
50 public:
52 #ifdef ENABLE_LOGGING
53  static Option<bool> print_code;
54  static Option<bool> print_data;
55 #endif
56 private:
57 
58  typedef std::vector<MachineInstruction*> MInstListTy;
61 
62  /// Map a MachineInstruction to a offset in the current CodeMemory.
63  ///
64  /// This map stores for each MachineInstruction the offset of the native
65  /// code that was written to the CodeSegment by MachineInstruction::emit().
67 
68  /// Map a MachineInstruction to its size in the code memory (number of emitted bytes)
70 
71  /// Create the final rplpoint structures for the current method.
72  ///
73  /// Create a rplpoint structure for each MachineReplacementPointInst in
74  /// the range @p first to @p last and store them in the codeinfo of @p JD.
75  ///
76  /// @param first Forward iterator that points to the first
77  /// MachineReplacementPointInst* in the range.
78  /// @param last Forward iterator that marks the end of the range.
79  /// @param JD The JITData of the currently compiled method.
80  template<class ForwardIt>
81  void resolve_replacement_points(ForwardIt first, ForwardIt last, JITData &JD);
82 
83  /**
84  * finish code generation
85  *
86  * Finishes the code generation. A new memory, large enough for both
87  * data and code, is allocated and data and code are copied together
88  * to their final layout, unresolved jumps are resolved, ...
89  */
90  void finish(JITData &JD);
92 public:
93  CodeGenPass() : Pass() {}
94  virtual bool run(JITData &JD);
95  virtual PassUsage& get_PassUsage(PassUsage &PU) const;
96  std::size_t get_block_size(MachineBasicBlock *MBB) const;
97  BasicBlockMap::const_iterator begin() const { return bbmap.begin(); }
98  BasicBlockMap::const_iterator end() const { return bbmap.end(); }
99 };
100 
101 } // end namespace compiler2
102 } // end namespace jit
103 } // end namespace cacao
104 
105 #endif /* _JIT_COMPILER2_CODEGENPASS */
106 
107 
108 /*
109  * These are local overrides for various environment variables in Emacs.
110  * Please do not remove this and leave it at the end of the file, where
111  * Emacs will automagically detect them.
112  * ---------------------------------------------------------------------
113  * Local variables:
114  * mode: c++
115  * indent-tabs-mode: t
116  * c-basic-offset: 4
117  * tab-width: 4
118  * End:
119  * vim:noexpandtab:sw=4:ts=4:
120  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:47
alloc::map< MachineInstruction *, std::size_t >::type InstructionSizeMap
Definition: CodeGenPass.hpp:60
InstructionSizeMap instruction_sizes
Map a MachineInstruction to its size in the code memory (number of emitted bytes) ...
Definition: CodeGenPass.hpp:69
alloc::map< MachineInstruction *, std::size_t >::type InstructionPositionMap
Definition: CodeGenPass.hpp:59
alloc::map< MachineBasicBlock *, std::size_t, MBBCompare >::type BasicBlockMap
Definition: CodeGenPass.hpp:51
Custom new/delete handler mixin.
Definition: Manager.hpp:43
A basic block of (scheduled) machine instructions.
MBBIterator self_iterator() const
get self iterator
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:128
CodeGenPass TODO: more info.
Definition: CodeGenPass.hpp:49
bool operator()(MachineBasicBlock *lhs, MachineBasicBlock *rhs) const
Definition: CodeGenPass.hpp:40
std::vector< MachineInstruction * > MInstListTy
Definition: CodeGenPass.hpp:58
BasicBlockMap::const_iterator begin() const
Definition: CodeGenPass.hpp:97
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
InstructionPositionMap instruction_positions
Map a MachineInstruction to a offset in the current CodeMemory.
Definition: CodeGenPass.hpp:66
This file contains the command line option parsing library.
BasicBlockMap::const_iterator end() const
Definition: CodeGenPass.hpp:98