CACAO
MethodC2.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/MethodC2.hpp - Method
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_METHOD
26 #define _JIT_COMPILER2_METHOD
27 
28 #include <cstddef>
29 
32 
33 #include "vm/method.hpp"
34 
35 // forware declaration
36 struct methodinfo;
37 class Utf8String;
38 
39 namespace cacao {
40 class OStream;
41 }
42 
43 namespace cacao {
44 namespace jit {
45 namespace compiler2 {
46 
47 // forware declaration
48 class Instruction;
49 class BeginInst;
50 class MethodDescriptor;
51 
52 template <typename _NodeType>
53 struct edge {
54  _NodeType predecessor;
55  _NodeType successsor;
56  edge(_NodeType p, _NodeType s) : predecessor(p), successsor(s) {}
57 };
58 
59 template <typename _NodeType>
60 edge<_NodeType> make_edge (_NodeType x, _NodeType y) {
61  return ( edge<_NodeType>(x,y) );
62 }
63 
64 class Method {
65 public:
68  typedef InstructionListTy::iterator iterator;
69  typedef InstructionListTy::const_iterator const_iterator;
70  typedef BBListTy::iterator bb_iterator;
71  typedef BBListTy::const_iterator const_bb_iterator;
72 private:
73  /**
74  * This is were the instructions live.
75  */
84 public:
85  Method(methodinfo *m);
86  ~Method();
87 
88  const Utf8String& get_name_utf8() const { return method_name_utf8; }
89  const Utf8String& get_class_name_utf8() const { return class_name_utf8; }
90  const Utf8String& get_desc_utf8() const { return method_desc_utf8; }
91 
92  bool is_static() const { return method->flags & ACC_STATIC; }
93 
94  /**
95  * Add instructions to a Method.
96  *
97  * Instructions added via this method will be deleted by ~Method.
98  * use remove_Instruction() to delete them manually.
99  */
101 
102  /**
103  * Remove an Instruction for a Method.
104  *
105  * The constructor will be called
106  */
108 
109  /**
110  * Replaces the instructions of the method, with the instructions in the
111  * given range [first, last).
112  *
113  * Instructions added via this method will be deleted by ~Method.
114  * use remove_Instruction() to delete them manually.
115  */
116  template <class InputIterator>
117  void replace_instruction_list(InputIterator first, InputIterator last) {
118  inst_list.assign(first, last);
119  }
120 
121  /**
122  * Add a BeginInst.
123  *
124  * The Instruction will be added using add_Instruction().
125  */
126  void add_bb(BeginInst *bi);
127 
128  /**
129  * Remove BeginInst.
130  *
131  * The Instruction will be removed using remove_Instruction().
132  */
133  void remove_bb(BeginInst *bi);
134 
135  void set_init_bb(BeginInst *bi) {
136  init_bb = bi;
137  }
138 
140  return init_bb;
141  }
142 
144  return inst_list.begin();
145  }
146 
147  const_iterator end() const {
148  return inst_list.end();
149  }
150 
151  size_t size() const {
152  return inst_list.size();
153  }
154 
156  return bb_list.begin();
157  }
158 
160  return bb_list.end();
161  }
162 
163  size_t bb_size() const {
164  return bb_list.size();
165  }
166 
167  /**
168  * Get the MethodDescriptor
169  */
171  return *method_desc;
172  }
173 
174  void clear_schedule() const;
175 
176  /**
177  * Get a BeginInst representing an edge
178  */
180 
181 };
182 
183 OStream& operator<<(OStream &OS, const Method &M);
184 
185 } // end namespace cacao
186 } // end namespace jit
187 } // end namespace compiler2
188 
189 #endif /* _JIT_COMPILER2_METHOD */
190 
191 
192 /*
193  * These are local overrides for various environment variables in Emacs.
194  * Please do not remove this and leave it at the end of the file, where
195  * Emacs will automagically detect them.
196  * ---------------------------------------------------------------------
197  * Local variables:
198  * mode: c++
199  * indent-tabs-mode: t
200  * c-basic-offset: 4
201  * tab-width: 4
202  * End:
203  * vim:noexpandtab:sw=4:ts=4:
204  */
const Utf8String & get_name_utf8() const
Definition: MethodC2.hpp:88
edge< _NodeType > make_edge(_NodeType x, _NodeType y)
Definition: MethodC2.hpp:60
alloc::list< Instruction * >::type InstructionListTy
Definition: MethodC2.hpp:66
BeginInst * get_edge_block(BeginInst *pred, BeginInst *succ)
Get a BeginInst representing an edge.
Definition: MethodC2.cpp:117
const MethodDescriptor & get_MethodDescriptor() const
Get the MethodDescriptor.
Definition: MethodC2.hpp:170
BBListTy::const_iterator const_bb_iterator
Definition: MethodC2.hpp:71
const_bb_iterator bb_end() const
Definition: MethodC2.hpp:159
This Instruction marks the start of a basic block.
void remove_Instruction(Instruction *I)
Remove an Instruction for a Method.
Definition: MethodC2.cpp:89
BBListTy::iterator bb_iterator
Definition: MethodC2.hpp:70
alloc::list< BeginInst * >::type BBListTy
Definition: MethodC2.hpp:67
void replace_instruction_list(InputIterator first, InputIterator last)
Replaces the instructions of the method, with the instructions in the given range [first...
Definition: MethodC2.hpp:117
InstructionListTy::iterator iterator
Definition: MethodC2.hpp:68
const Utf8String & get_desc_utf8() const
Definition: MethodC2.hpp:90
std::list< T, Allocator< T > > type
Definition: list.hpp:38
JNIEnv jthread jmethodID method
Definition: jvmti.h:207
MethodDescriptor * method_desc
Definition: MethodC2.hpp:80
void remove_bb(BeginInst *bi)
Remove BeginInst.
Definition: MethodC2.cpp:102
Simple stream class for formatted output.
Definition: OStream.hpp:141
Instruction super class.
Definition: Instruction.hpp:75
OStream & operator<<(OStream &OS, const Conditional::CondID &cond)
Definition: Conditional.cpp:34
void add_Instruction(Instruction *I)
Add instructions to a Method.
Definition: MethodC2.cpp:82
void set_init_bb(BeginInst *bi)
Definition: MethodC2.hpp:135
InstructionListTy::const_iterator const_iterator
Definition: MethodC2.hpp:69
const_iterator end() const
Definition: MethodC2.hpp:147
OStream & OS
const Utf8String & get_class_name_utf8() const
Definition: MethodC2.hpp:89
#define I(value)
Definition: codegen.c:279
InstructionListTy inst_list
This is were the instructions live.
Definition: MethodC2.hpp:76
void add_bb(BeginInst *bi)
Add a BeginInst.
Definition: MethodC2.cpp:97
const Method & M
const_iterator begin() const
Definition: MethodC2.hpp:143
edge(_NodeType p, _NodeType s)
Definition: MethodC2.hpp:56
BeginInst * get_init_bb() const
Definition: MethodC2.hpp:139
const_bb_iterator bb_begin() const
Definition: MethodC2.hpp:155
MethodDescriptor TODO: more info.