1 /* src/vm/jit/codegen-common.h - 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_H
27 #define _CODEGEN_COMMON_H
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;
36 typedef struct exceptionref exceptionref;
37 typedef struct linenumberref linenumberref;
43 #include "vm/builtin.h"
44 #include "vm/global.h"
46 #include "vm/jit/dseg.h"
47 #include "vm/jit/jit.h"
48 #include "vm/jit/reg.h"
49 #include "vm/jit/code.h"
50 #include "vm/jit/replace.h"
52 #include "vmcore/descriptor.h"
53 #include "vmcore/method.h"
54 #include "vmcore/references.h"
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)
75 /* branch conditions **********************************************************/
77 #define BRANCH_UNCONDITIONAL -1
79 #define BRANCH_EQ (ICMD_IFEQ - ICMD_IFEQ)
80 #define BRANCH_NE (ICMD_IFNE - ICMD_IFEQ)
81 #define BRANCH_LT (ICMD_IFLT - ICMD_IFEQ)
82 #define BRANCH_GE (ICMD_IFGE - ICMD_IFEQ)
83 #define BRANCH_GT (ICMD_IFGT - ICMD_IFEQ)
84 #define BRANCH_LE (ICMD_IFLE - ICMD_IFEQ)
86 #define BRANCH_ULT 256
87 #define BRANCH_ULE 257
88 #define BRANCH_UGE 258
89 #define BRANCH_UGT 259
91 #define BRANCH_NAN 260
94 /* common branch options ******************************************************/
96 #define BRANCH_OPT_NONE 0
99 /* codegendata ****************************************************************/
102 u4 flags; /* code generator flags */
103 u1 *mcodebase; /* base pointer of code area */
104 u1 *mcodeend; /* pointer to end of code area */
105 s4 mcodesize; /* complete size of code area (bytes) */
106 u1 *mcodeptr; /* code generation pointer */
107 u1 *lastmcodeptr; /* last patcher position of basic block */
109 #if defined(ENABLE_INTRP)
110 u1 *ncodebase; /* base pointer of native code area */
111 s4 ncodesize; /* complete size of native code area */
112 u1 *ncodeptr; /* native code generation pointer */
114 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
116 s4 lastpatcheroffset; /* -1 if current super has no patcher */
117 s4 dynsuperm; /* offsets of start of current dynamic ...*/
118 s4 dynsupern; /* ... superinstruction starts */
119 struct superstart *superstarts; /* list of supers without patchers */
122 dsegentry *dseg; /* chain of data segment entries */
123 s4 dseglen; /* used size of data area (bytes) */
124 /* data area grows from top to bottom */
126 jumpref *jumpreferences; /* list of jumptable target addresses */
128 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
129 dataref *datareferences; /* list of data segment references */
132 list_t *brancheslabel;
133 list_t *linenumbers; /* list of line numbers */
137 s4 stackframesize; /* stackframe size of this method */
139 #if defined(ENABLE_REPLACEMENT)
140 rplpoint *replacementpoint; /* current replacement point */
145 #define CODEGENDATA_FLAG_ERROR 0x00000001
146 #define CODEGENDATA_FLAG_LONGBRANCHES 0x00000002
149 #define CODEGENDATA_HAS_FLAG_ERROR(cd) \
150 ((cd)->flags & CODEGENDATA_FLAG_ERROR)
152 #define CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) \
153 ((cd)->flags & CODEGENDATA_FLAG_LONGBRANCHES)
156 /* branchref *****************************************************************/
159 s4 branchmpc; /* patching position in code segment */
160 s4 condition; /* conditional branch condition */
161 s4 reg; /* register number to check */
162 u4 options; /* branch options */
163 branchref *next; /* next element in branchref list */
167 /* branch_label_ref_t *********************************************************/
169 struct branch_label_ref_t {
170 s4 mpc; /* position in code segment */
171 s4 label; /* label number */
172 s4 condition; /* conditional branch condition */
173 s4 reg; /* register number to check */
174 u4 options; /* branch options */
179 /* jumpref ********************************************************************/
182 s4 tablepos; /* patching position in data segment */
183 basicblock *target; /* target basic block */
184 jumpref *next; /* next element in jumpref list */
188 /* dataref ********************************************************************/
191 s4 datapos; /* patching position in generated code */
192 dataref *next; /* next element in dataref list */
196 /* linenumberref **************************************************************/
198 struct linenumberref {
199 s4 tablepos; /* patching position in data segment */
200 s4 linenumber; /* line number, used for inserting into the */
201 /* table and for validity checking */
202 /* -1......start of inlined body */
203 /* -2......end of inlined body */
204 /* <= -3...special entry with methodinfo * */
205 /* (see doc/inlining_stacktrace.txt) */
206 ptrint targetmpc; /* machine code program counter of first */
207 /* instruction for given line */
208 /* NOTE: for linenumber <= -3 this is a the */
209 /* (methodinfo *) of the inlined method */
210 linenumberref *next; /* next element in linenumberref list */
214 /* function prototypes ********************************************************/
216 void codegen_init(void);
217 void codegen_setup(jitdata *jd);
219 bool codegen_generate(jitdata *jd);
220 bool codegen_emit(jitdata *jd);
222 #if defined(ENABLE_INTRP)
223 bool intrp_codegen(jitdata *jd);
226 void codegen_close(void);
228 void codegen_increase(codegendata *cd);
230 #if defined(ENABLE_INTRP)
231 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
234 void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
235 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
237 void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
239 #if defined(ENABLE_REPLACEMENT)
241 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
242 void codegen_set_replacement_point(codegendata *cd, s4 type);
244 void codegen_set_replacement_point_notrap(codegendata *cd);
245 void codegen_set_replacement_point(codegendata *cd);
247 #endif /* defined(ENABLE_REPLACEMENT) */
249 void codegen_finish(jitdata *jd);
251 #if defined(ENABLE_DISASSEMBLER)
252 void codegen_disassemble_stub(methodinfo *m, u1 *start, u1 *end);
257 u1 *codegen_generate_stub_compiler(methodinfo *m);
258 void codegen_generate_stub_builtin(methodinfo *m, builtintable_entry *bte);
259 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f);
261 #if !defined(JIT_COMPILER_VIA_SIGNAL)
262 void codegen_emit_stub_compiler(jitdata *jd);
264 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams);
266 #if defined(ENABLE_INTRP)
267 u1 *intrp_createcompilerstub(methodinfo *m);
268 u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
271 void removecompilerstub(u1 *stub);
272 void removenativestub(u1 *stub);
274 java_handle_t *codegen_start_native_call(u1 *currentsp, u1 *pv);
275 java_object_t *codegen_finish_native_call(u1 *currentsp, u1 *pv);
277 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
278 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
280 #if defined(ENABLE_SSA)
281 void codegen_emit_phi_moves(jitdata *jd, basicblock *bptr);
284 #endif /* _CODEGEN_COMMON_H */
288 * These are local overrides for various environment variables in Emacs.
289 * Please do not remove this and leave it at the end of the file, where
290 * Emacs will automagically detect them.
291 * ---------------------------------------------------------------------
294 * indent-tabs-mode: t
298 * vim:noexpandtab:sw=4:ts=4: