1 /* src/vm/jit/codegen-common.hpp - architecture independent code generator stuff
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
26 #ifndef _CODEGEN_COMMON_HPP
27 #define _CODEGEN_COMMON_HPP
29 /* forward typedefs ***********************************************************/
31 typedef struct codegendata codegendata;
32 typedef struct branchref branchref;
33 typedef struct branch_label_ref_t branch_label_ref_t;
34 typedef struct jumpref jumpref;
35 typedef struct dataref dataref;
41 #include "toolbox/list.hpp"
43 #include "vm/jit/builtin.hpp"
44 #include "vm/descriptor.hpp"
45 #include "vm/global.h"
46 #include "vm/method.hpp"
47 #include "vm/references.h"
49 #include "vm/jit/dseg.h"
50 #include "vm/jit/jit.hpp"
51 #include "vm/jit/reg.h"
52 #include "vm/jit/code.hpp"
53 #include "vm/jit/linenumbertable.hpp"
54 #include "vm/jit/replace.hpp"
57 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
58 #define DSEGINITSIZE (1<<12) /* 4 Kbyte data area initialization size */
60 #define NCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
63 /* Register Pack/Unpack Macros ************************************************/
65 /* ATTENTION: Don't change the order where low and high bits are
66 stored! At least mips32 relies in one case on that order. */
68 #define PACK_REGS(low,high) \
69 ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
71 #define GET_LOW_REG(a) ((a) & 0x0000ffff)
72 #define GET_HIGH_REG(a) (((a) & 0xffff0000) >> 16)
74 /* All 32-bit machines we support use packed registers to store
75 return values and temporary values. */
77 #if SIZEOF_VOID_P == 8
78 # define REG_LRESULT REG_RESULT
79 # define REG_LTMP12 REG_ITMP1
80 # define REG_LTMP23 REG_ITMP2
82 # define REG_LRESULT REG_RESULT_PACKED
83 # define REG_LTMP12 REG_ITMP12_PACKED
84 # define REG_LTMP23 REG_ITMP23_PACKED
88 /* branch conditions **********************************************************/
90 #define BRANCH_UNCONDITIONAL -1
92 #define BRANCH_EQ (ICMD_IFEQ - ICMD_IFEQ)
93 #define BRANCH_NE (ICMD_IFNE - ICMD_IFEQ)
94 #define BRANCH_LT (ICMD_IFLT - ICMD_IFEQ)
95 #define BRANCH_GE (ICMD_IFGE - ICMD_IFEQ)
96 #define BRANCH_GT (ICMD_IFGT - ICMD_IFEQ)
97 #define BRANCH_LE (ICMD_IFLE - ICMD_IFEQ)
99 #define BRANCH_ULT 256
100 #define BRANCH_ULE 257
101 #define BRANCH_UGE 258
102 #define BRANCH_UGT 259
104 #define BRANCH_NAN 260
107 /* common branch options ******************************************************/
109 #define BRANCH_OPT_NONE 0
112 /* codegendata ****************************************************************/
115 u4 flags; /* code generator flags */
116 u1 *mcodebase; /* base pointer of code area */
117 u1 *mcodeend; /* pointer to end of code area */
118 s4 mcodesize; /* complete size of code area (bytes) */
119 u1 *mcodeptr; /* code generation pointer */
120 u1 *lastmcodeptr; /* last patcher position of basic block */
122 #if defined(ENABLE_INTRP)
123 u1 *ncodebase; /* base pointer of native code area */
124 s4 ncodesize; /* complete size of native code area */
125 u1 *ncodeptr; /* native code generation pointer */
127 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
129 s4 lastpatcheroffset; /* -1 if current super has no patcher */
130 s4 dynsuperm; /* offsets of start of current dynamic ...*/
131 s4 dynsupern; /* ... superinstruction starts */
132 struct superstart *superstarts; /* list of supers without patchers */
135 dsegentry *dseg; /* chain of data segment entries */
136 s4 dseglen; /* used size of data area (bytes) */
137 /* data area grows from top to bottom */
139 jumpref *jumpreferences; /* list of jumptable target addresses */
141 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
142 dataref *datareferences; /* list of data segment references */
146 DumpList<branch_label_ref_t*>* brancheslabel;
147 DumpList<Linenumber>* linenumbers; ///< List of line numbers.
150 DumpList* brancheslabel;
151 DumpList* linenumbers;
156 s4 stackframesize; /* stackframe size of this method */
158 #if defined(ENABLE_REPLACEMENT)
159 rplpoint *replacementpoint; /* current replacement point */
164 #define CODEGENDATA_FLAG_ERROR 0x00000001
165 #define CODEGENDATA_FLAG_LONGBRANCHES 0x00000002
168 #define CODEGENDATA_HAS_FLAG_ERROR(cd) \
169 ((cd)->flags & CODEGENDATA_FLAG_ERROR)
171 #define CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) \
172 ((cd)->flags & CODEGENDATA_FLAG_LONGBRANCHES)
175 /* branchref *****************************************************************/
178 s4 branchmpc; /* patching position in code segment */
179 s4 condition; /* conditional branch condition */
180 s4 reg; /* register number to check */
181 u4 options; /* branch options */
182 branchref *next; /* next element in branchref list */
186 /* branch_label_ref_t *********************************************************/
188 struct branch_label_ref_t {
189 s4 mpc; /* position in code segment */
190 s4 label; /* label number */
191 s4 condition; /* conditional branch condition */
192 s4 reg; /* register number to check */
193 u4 options; /* branch options */
194 /* listnode_t linkage; */
198 /* jumpref ********************************************************************/
201 s4 tablepos; /* patching position in data segment */
202 basicblock *target; /* target basic block */
203 jumpref *next; /* next element in jumpref list */
207 /* dataref ********************************************************************/
210 s4 datapos; /* patching position in generated code */
211 dataref *next; /* next element in dataref list */
215 /* function prototypes ********************************************************/
221 void codegen_init(void);
222 void codegen_setup(jitdata *jd);
224 bool codegen_generate(jitdata *jd);
225 bool codegen_emit(jitdata *jd);
227 void codegen_emit_prolog(jitdata* jd);
228 void codegen_emit_epilog(jitdata* jd);
229 void codegen_emit_instruction(jitdata* jd, instruction* iptr);
231 #if defined(ENABLE_INTRP)
232 bool intrp_codegen(jitdata *jd);
235 void codegen_close(void);
237 void codegen_increase(codegendata *cd);
239 #if defined(ENABLE_INTRP)
240 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
243 void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
244 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
246 void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
248 #if defined(ENABLE_REPLACEMENT)
250 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
251 void codegen_set_replacement_point(codegendata *cd, s4 type);
253 void codegen_set_replacement_point_notrap(codegendata *cd);
254 void codegen_set_replacement_point(codegendata *cd);
256 #endif /* defined(ENABLE_REPLACEMENT) */
258 void codegen_finish(jitdata *jd);
260 java_handle_t *codegen_start_native_call(u1 *currentsp, u1 *pv);
261 java_object_t *codegen_finish_native_call(u1 *currentsp, u1 *pv);
263 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
264 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
266 #if defined(ENABLE_SSA)
267 void codegen_emit_phi_moves(jitdata *jd, basicblock *bptr);
271 void codegen_emit_stub_compiler(jitdata *jd);
272 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams);
278 #endif // _CODEGEN_COMMON_HPP
282 * These are local overrides for various environment variables in Emacs.
283 * Please do not remove this and leave it at the end of the file, where
284 * Emacs will automagically detect them.
285 * ---------------------------------------------------------------------
288 * indent-tabs-mode: t
292 * vim:noexpandtab:sw=4:ts=4: