CACAO
MachineInstructions.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/MachineInstructions.hpp - Machine Instruction Types
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_MACHINEINSTRUCTIONS
26 #define _JIT_COMPILER2_MACHINEINSTRUCTIONS
27 
30 
31 namespace cacao {
32 namespace jit {
33 namespace compiler2 {
34 
35 class MachineReplacementEntryInst;
36 class MachineReplacementPointCallSiteInst;
37 class MachineReplacementPointStaticSpecialInst;
38 class MachineDeoptInst;
39 
41 public:
43  virtual void emit(CodeMemory* CM) const;
44  virtual bool is_label() const {
45  return true;
46  }
47 };
48 
50 private:
52 public:
53  MachinePhiInst(unsigned num_operands, Type::TypeID type, PHIInst* phi)
54  : MachineInstruction("MPhi", new VirtualRegister(type),
55  num_operands), phi(phi) {
56  for(unsigned i = 0; i < num_operands; ++i) {
57  operands[i].op = new UnassignedReg(type);
58  }
59  }
60 
61  virtual bool is_phi() const {
62  return true;
63  }
65  return this;
66  }
67  // phis are never emitted
68  virtual void emit(CodeMemory* CM) const {};
69 
70  PHIInst* get_PHIInst() const {
71  return phi;
72  }
73 };
74 #if 0
75 class MachineConstInst : public MachineInstruction {
76 public:
77  /**
78  * TODO: get const parameter
79  */
80  MachineConstInst(s8 value) : MachineInstruction("MConst",
81  new Immediate(value), 0) {}
82  // mconsts are never emitted
83  virtual void emit(CodeMemory* CM) const {};
84 };
85 
86 /**
87  * Load from memory to register
88  */
89 class MachineLoadInst : public MachineInstruction {
90 public:
91  MachineLoadInst(
92  MachineOperand *dst,
93  MachineOperand *src)
94  : MachineInstruction("MLoad", dst, 1) {
95  operands[0].op = src;
96  }
97 
98 };
99 
100 /**
101  * Store register to memory
102  */
103 class MachineStoreInst : public MachineInstruction {
104 public:
105  MachineStoreInst(
106  MachineOperand *dst,
107  MachineOperand *src)
108  : MachineInstruction("MStore", dst, 1) {
109  operands[0].op = src;
110  }
111 
112 };
113 
114 class MachineOperandInst : public MachineInstruction {
115 private:
116  MachineOperand *MO;
117 public:
118  MachineOperandInst(MachineOperand *MO)
119  : MachineInstruction("MachineOperandInst", MO, 0), MO(MO) {
120  }
121 
122 };
123 #endif
125 public:
126  MachineJumpInst(const char *name)
127  : MachineInstruction(name, &NoOperand, 0) {}
128  virtual void emit(CodeMemory* CM) const = 0;
129  virtual void link(CodeFragment &CF) const = 0;
130 };
131 #if 0
132 /**
133  * Move operand to operand
134  */
135 class MachineMoveInst : public MachineInstruction {
136 public:
137  MachineMoveInst( const char* name,
138  MachineOperand *src,
139  MachineOperand *dst)
140  : MachineInstruction(name, dst, 1) {
141  operands[0].op = src;
142  }
143  virtual bool accepts_immediate(unsigned i, Immediate *imm) const {
144  return true;
145  }
146  virtual MachineMoveInst* to_MachineMoveInst() {
147  return this;
148  }
149  virtual void emit(CodeMemory* CM) const = 0;
150 
151 };
152 #endif
153 
154 /**
155  * Represents a point in the program, where it is possible to recover the source
156  * state to perform on-stack replacement.
157  */
159 private:
161 
164 
165 public:
166  /**
167  * @param source_id the id of the baseline IR instruction this replacement
168  * point represents in the source state
169  * @param num_operands the number of operands, i.e., the number of values
170  * that are live at this OSR point
171  */
172  MachineReplacementPointInst(const char *name, s4 source_id, std::size_t num_operands)
173  : MachineInstruction(name, &NoOperand, num_operands),
174  source_id(source_id), javalocal_indices(num_operands) {}
175  virtual void emit(CodeMemory* CM) const {};
176  virtual void link(CodeFragment &CF) const {};
177 
179  return this;
180  }
181 
183  return NULL;
184  }
185 
187  return NULL;
188  }
189 
191  return NULL;
192  }
193 
195  return NULL;
196  }
197 
198  s4 get_source_id() const { return source_id; }
199 
200  /**
201  * Set the javalocal index of the i-th operand of this instruction. Pass a
202  * value >= 0 to indicate a valid javalocal index. Pass RPLALLOC_STACK to
203  * indicate that the i-th operand is a stack variable. Pass RPLALLOC_PARAM
204  * to indicate that it is a parameter at a call site.
205  */
206  void set_javalocal_index(std::size_t i, s4 javalocal_index) {
207  assert(i < op_size());
208  javalocal_indices[i] = javalocal_index;
209  }
210 
211  /**
212  * @return the javalocal index of the i-th operand of this instruction. For
213  * possible return values refer to set_javalocal_index().
214  */
215  s4 get_javalocal_index(std::size_t i) {
216  assert(i < op_size());
217  return javalocal_indices[i];
218  }
219 
220  virtual bool is_trappable() const = 0;
221 };
222 
224 public:
225  MachineReplacementEntryInst(s4 source_id, std::size_t num_operands)
226  : MachineReplacementPointInst("MReplacementEntry", source_id, num_operands) {}
227  virtual void emit(CodeMemory* CM) const {};
228  virtual void link(CodeFragment &CF) const {};
229 
231  return this;
232  }
233 
234  virtual bool is_trappable() const {
235  return true;
236  }
237 };
238 
239 /**
240  * Represents a replacement point at a call site (INVOKE* ICMDs)
241  * The reference to the corresponding call MachineInstruction is needed since
242  * the replacement point needs to know the size of the callsite (in bytes)
243  */
245 private:
247 
248 public:
250  : MachineReplacementPointInst("MReplacementPointCallSite", source_id, num_operands), call_inst(call_inst) {}
251  virtual void emit(CodeMemory* CM) const {};
252  virtual void link(CodeFragment &CF) const {};
253 
255  return this;
256  }
257 
258  virtual bool is_trappable() const {
259  return false;
260  }
261 
263  return call_inst;
264  }
265 };
266 
267 /**
268  * Specialication for INVOKESpecial and INVOKEStatic.
269  * Since the target address is known during compilation, this class holds a reference
270  * to the DataSegment index where the address is stored so it can be patched
271  * during OSR
272  */
274 private:
275  /**
276  * DataSegment index that contains the address of the call target
277  */
278  DataSegment::IdxTy idx;
279 
280 public:
281  MachineReplacementPointStaticSpecialInst(MachineInstruction* call_inst, s4 source_id, std::size_t num_operands, DataSegment::IdxTy idx)
282  : MachineReplacementPointCallSiteInst(call_inst, source_id, num_operands), idx(idx) {}
283 
285  return this;
286  }
287 
288  DataSegment::IdxTy get_idx() const {
289  return idx;
290  }
291 };
292 
294 public:
295  MachineDeoptInst(s4 source_id, std::size_t num_operands)
296  : MachineReplacementPointInst("MDeopt", source_id, num_operands) {}
297  virtual void emit(CodeMemory* CM) const {};
298  virtual void link(CodeFragment &CF) const {};
299 
301  return this;
302  }
303 
304  virtual bool is_trappable() const {
305  return false;
306  }
307 };
308 
309 } // end namespace compiler2
310 } // end namespace jit
311 } // end namespace cacao
312 
313 #endif /* _JIT_COMPILER2_MACHINEINSTRUCTIONS */
314 
315 
316 /*
317  * These are local overrides for various environment variables in Emacs.
318  * Please do not remove this and leave it at the end of the file, where
319  * Emacs will automagically detect them.
320  * ---------------------------------------------------------------------
321  * Local variables:
322  * mode: c++
323  * indent-tabs-mode: t
324  * c-basic-offset: 4
325  * tab-width: 4
326  * End:
327  * vim:noexpandtab:sw=4:ts=4:
328  */
MachineReplacementPointStaticSpecialInst(MachineInstruction *call_inst, s4 source_id, std::size_t num_operands, DataSegment::IdxTy idx)
virtual void emit(CodeMemory *CM) const
emit machine code
virtual MachineReplacementPointCallSiteInst * to_MachineReplacementPointCallSiteInst()
void set_javalocal_index(std::size_t i, s4 javalocal_index)
Set the javalocal index of the i-th operand of this instruction.
virtual void link(CodeFragment &CF) const
link machine code
virtual void emit(CodeMemory *CM) const
emit machine code
Represents a point in the program, where it is possible to recover the source state to perform on-sta...
MachinePhiInst(unsigned num_operands, Type::TypeID type, PHIInst *phi)
virtual MachineReplacementPointStaticSpecialInst * to_MachineReplacementPointStaticSpecialInst()
virtual void link(CodeFragment &CF) const
link machine code
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
int64_t s8
Definition: types.hpp:48
virtual MachineReplacementPointCallSiteInst * to_MachineReplacementPointCallSiteInst()
MachineDeoptInst(s4 source_id, std::size_t num_operands)
virtual MachineReplacementEntryInst * to_MachineReplacementEntryInst()
virtual void emit(CodeMemory *CM) const =0
emit machine code
virtual void emit(CodeMemory *CM) const
emit machine code
std::vector< T, Allocator< T > > type
Definition: vector.hpp:38
virtual MachineReplacementPointInst * to_MachineReplacementPointInst()
Specialication for INVOKESpecial and INVOKEStatic.
MIIterator i
int32_t s4
Definition: types.hpp:45
virtual MachineReplacementPointStaticSpecialInst * to_MachineReplacementPointStaticSpecialInst()
DataSegment::IdxTy idx
DataSegment index that contains the address of the call target.
virtual void link(CodeFragment &CF) const
link machine code
MachineReplacementPointInst(const char *name, s4 source_id, std::size_t num_operands)
Proxy to encode explicit and implicit successors.
virtual void emit(CodeMemory *CM) const
emit machine code
MachineReplacementPointCallSiteInst(MachineInstruction *call_inst, s4 source_id, std::size_t num_operands)
Represents a replacement point at a call site (INVOKE* ICMDs) The reference to the corresponding call...
MachineReplacementEntryInst(s4 source_id, std::size_t num_operands)
virtual MachinePhiInst * to_MachinePhiInst()
virtual void link(CodeFragment &CF) const
link machine code
Segment reference.
Definition: Segment.hpp:44
virtual MachineReplacementEntryInst * to_MachineReplacementEntryInst()
virtual void link(CodeFragment &CF) const =0
link machine code
virtual MachineDeoptInst * to_MachineDeoptInst()
virtual void emit(CodeMemory *CM) const
emit machine code
virtual void emit(CodeMemory *CM) const
emit machine code