1 /* src/vm/jit/codegen-common.h - architecture independent code generator stuff
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: codegen-common.h 7797 2007-04-23 20:12:39Z michi $
30 #ifndef _CODEGEN_COMMON_H
31 #define _CODEGEN_COMMON_H
33 /* forward typedefs ***********************************************************/
35 typedef struct codegen_critical_section_t codegen_critical_section_t;
36 typedef struct codegendata codegendata;
37 typedef struct branchref branchref;
38 typedef struct branch_label_ref_t branch_label_ref_t;
39 typedef struct jumpref jumpref;
40 typedef struct dataref dataref;
41 typedef struct exceptionref exceptionref;
42 typedef struct patchref patchref;
43 typedef struct linenumberref linenumberref;
49 #include "vm/builtin.h"
50 #include "vm/global.h"
52 #include "vm/jit/dseg.h"
53 #include "vm/jit/jit.h"
54 #include "vm/jit/reg.h"
55 #include "vm/jit/code.h"
56 #include "vm/jit/replace.h"
58 #include "vmcore/descriptor.h"
59 #include "vmcore/method.h"
60 #include "vmcore/references.h"
63 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
64 #define DSEGINITSIZE (1<<12) /* 4 Kbyte data area initialization size */
66 #define NCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
69 /* Register Pack/Unpack Macros ************************************************/
71 /* ATTENTION: Don't change the order where low and high bits are
72 stored! At least mips32 relies in one case on that order. */
74 #define PACK_REGS(low,high) \
75 ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
77 #define GET_LOW_REG(a) ((a) & 0x0000ffff)
78 #define GET_HIGH_REG(a) (((a) & 0xffff0000) >> 16)
81 /* branch conditions **********************************************************/
83 #define BRANCH_UNCONDITIONAL -1
85 #define BRANCH_EQ (ICMD_IFEQ - ICMD_IFEQ)
86 #define BRANCH_NE (ICMD_IFNE - ICMD_IFEQ)
87 #define BRANCH_LT (ICMD_IFLT - ICMD_IFEQ)
88 #define BRANCH_GE (ICMD_IFGE - ICMD_IFEQ)
89 #define BRANCH_GT (ICMD_IFGT - ICMD_IFEQ)
90 #define BRANCH_LE (ICMD_IFLE - ICMD_IFEQ)
92 #define BRANCH_ULT 256
93 #define BRANCH_ULE 257
94 #define BRANCH_UGE 258
95 #define BRANCH_UGT 259
97 #define BRANCH_NAN 260
100 /* common branch options ******************************************************/
102 #define BRANCH_OPT_NONE 0
106 /************************* critical sections *********************************/
108 struct codegen_critical_section_t {
109 codegen_critical_section_t *next;
116 /* codegendata ****************************************************************/
119 u4 flags; /* code generator flags */
120 u1 *mcodebase; /* base pointer of code area */
121 u1 *mcodeend; /* pointer to end of code area */
122 s4 mcodesize; /* complete size of code area (bytes) */
123 u1 *mcodeptr; /* code generation pointer */
124 u1 *lastmcodeptr; /* last patcher position of basic block */
126 #if defined(ENABLE_INTRP)
127 u1 *ncodebase; /* base pointer of native code area */
128 s4 ncodesize; /* complete size of native code area */
129 u1 *ncodeptr; /* native code generation pointer */
131 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
133 s4 lastpatcheroffset; /* -1 if current super has no patcher */
134 s4 dynsuperm; /* offsets of start of current dynamic ...*/
135 s4 dynsupern; /* ... superinstruction starts */
136 struct superstart *superstarts; /* list of supers without patchers */
139 dsegentry *dseg; /* chain of data segment entries */
140 s4 dseglen; /* used size of data area (bytes) */
141 /* data area grows from top to bottom */
143 jumpref *jumpreferences; /* list of jumptable target addresses */
145 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
146 dataref *datareferences; /* list of data segment references */
149 /* list_t *patchrefs; */
151 list_t *brancheslabel;
153 linenumberref *linenumberreferences; /* list of line numbers and the */
154 /* program counters of their first */
156 s4 linenumbertablesizepos;
157 s4 linenumbertablestartpos;
162 codegen_critical_section_t *threadcrit; /* List of critical code regions */
163 codegen_critical_section_t threadcritcurrent;
164 s4 threadcritcount; /* Number of critical regions */
166 s4 stackframesize; /* stackframe size of this method */
168 #if defined(ENABLE_REPLACEMENT)
169 rplpoint *replacementpoint; /* current replacement point */
174 #define CODEGENDATA_FLAG_ERROR 0x00000001
175 #define CODEGENDATA_FLAG_LONGBRANCHES 0x00000002
178 #define CODEGENDATA_HAS_FLAG_ERROR(cd) \
179 ((cd)->flags & CODEGENDATA_FLAG_ERROR)
181 #define CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) \
182 ((cd)->flags & CODEGENDATA_FLAG_LONGBRANCHES)
185 /* branchref *****************************************************************/
188 s4 branchmpc; /* patching position in code segment */
189 s4 condition; /* conditional branch condition */
190 s4 reg; /* register number to check */
191 u4 options; /* branch options */
192 branchref *next; /* next element in branchref list */
196 /* branch_label_ref_t *********************************************************/
198 struct branch_label_ref_t {
199 s4 mpc; /* position in code segment */
200 s4 label; /* label number */
201 s4 condition; /* conditional branch condition */
202 s4 reg; /* register number to check */
203 u4 options; /* branch options */
208 /* jumpref ********************************************************************/
211 s4 tablepos; /* patching position in data segment */
212 basicblock *target; /* target basic block */
213 jumpref *next; /* next element in jumpref list */
217 /* dataref ********************************************************************/
220 s4 datapos; /* patching position in generated code */
221 dataref *next; /* next element in dataref list */
225 /* patchref *******************************************************************/
228 s4 branchpos; /* relative offset to method entrypoint */
229 s4 disp; /* displacement of ref in the data segment */
230 functionptr patcher; /* patcher function to call */
231 voidptr ref; /* reference passed */
232 /* listnode linkage; */
237 /* linenumberref **************************************************************/
239 struct linenumberref {
240 s4 tablepos; /* patching position in data segment */
241 s4 linenumber; /* line number, used for inserting into the */
242 /* table and for validity checking */
243 /* -1......start of inlined body */
244 /* -2......end of inlined body */
245 /* <= -3...special entry with methodinfo * */
246 /* (see doc/inlining_stacktrace.txt) */
247 ptrint targetmpc; /* machine code program counter of first */
248 /* instruction for given line */
249 /* NOTE: for linenumber <= -3 this is a the */
250 /* (methodinfo *) of the inlined method */
251 linenumberref *next; /* next element in linenumberref list */
255 /* methodtree_element *********************************************************/
257 typedef struct methodtree_element methodtree_element;
259 struct methodtree_element {
265 /* function prototypes ********************************************************/
267 void codegen_init(void);
268 void codegen_setup(jitdata *jd);
270 bool codegen_generate(jitdata *jd);
271 bool codegen_emit(jitdata *jd);
273 #if defined(ENABLE_INTRP)
274 bool intrp_codegen(jitdata *jd);
277 void codegen_close(void);
279 void codegen_increase(codegendata *cd);
281 #if defined(ENABLE_INTRP)
282 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
285 void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
286 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
288 void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
291 void codegen_add_patch_ref(codegendata *cd, functionptr patcher, voidptr ref,
293 /* XXX REMOVE ME: don't-break-trunk macro */
294 #define codegen_addpatchref codegen_add_patch_ref
296 void codegen_insertmethod(u1 *startpc, u1 *endpc);
297 u1 *codegen_get_pv_from_pc(u1 *pc);
298 u1 *codegen_get_pv_from_pc_nocheck(u1 *pc);
300 #if defined(ENABLE_REPLACEMENT)
302 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
303 void codegen_set_replacement_point(codegendata *cd, s4 type);
305 void codegen_set_replacement_point_notrap(codegendata *cd);
306 void codegen_set_replacement_point(codegendata *cd);
308 #endif /* defined(ENABLE_REPLACEMENT) */
310 void codegen_finish(jitdata *jd);
312 #if defined(ENABLE_DISASSEMBLER)
313 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
318 u1 *codegen_generate_stub_compiler(methodinfo *m);
319 void codegen_generate_stub_builtin(builtintable_entry *bte);
320 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f);
322 void codegen_emit_stub_compiler(jitdata *jd);
323 void codegen_emit_stub_builtin(jitdata *jd, builtintable_entry *bte);
324 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f);
326 #if defined(ENABLE_INTRP)
327 u1 *intrp_createcompilerstub(methodinfo *m);
328 u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
331 void removecompilerstub(u1 *stub);
332 void removenativestub(u1 *stub);
334 void codegen_stub_builtin_enter(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
335 void codegen_stub_builtin_exit(u1 *datasp);
337 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
338 java_objectheader *codegen_finish_native_call(u1 *datasp);
340 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
341 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
343 #if defined(ENABLE_THREADS)
344 void codegen_threadcritrestart(codegendata *cd, int offset);
345 void codegen_threadcritstart(codegendata *cd, int offset);
346 void codegen_threadcritstop(codegendata *cd, int offset);
349 /* machine dependent functions */
350 u1 *md_codegen_get_pv_from_pc(u1 *ra);
352 #endif /* _CODEGEN_COMMON_H */
356 * These are local overrides for various environment variables in Emacs.
357 * Please do not remove this and leave it at the end of the file, where
358 * Emacs will automagically detect them.
359 * ---------------------------------------------------------------------
362 * indent-tabs-mode: t
366 * vim:noexpandtab:sw=4:ts=4: