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 7596 2007-03-28 21:05:53Z twisti $
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/global.h"
51 #include "vm/jit/dseg.h"
52 #include "vm/jit/jit.h"
53 #include "vm/jit/reg.h"
54 #include "vm/jit/code.h"
55 #include "vm/jit/replace.h"
57 #include "vmcore/descriptor.h"
58 #include "vmcore/method.h"
59 #include "vmcore/references.h"
62 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
63 #define DSEGINITSIZE (1<<12) /* 4 Kbyte data area initialization size */
65 #define NCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
68 /* Register Pack/Unpack Macros ************************************************/
70 /* ATTENTION: Don't change the order where low and high bits are
71 stored! At least mips32 relies in one case on that order. */
73 #define PACK_REGS(low,high) \
74 ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
76 #define GET_LOW_REG(a) ((a) & 0x0000ffff)
77 #define GET_HIGH_REG(a) (((a) & 0xffff0000) >> 16)
80 /* branch conditions **********************************************************/
82 #define BRANCH_UNCONDITIONAL -1
84 #define BRANCH_EQ (ICMD_IFEQ - ICMD_IFEQ)
85 #define BRANCH_NE (ICMD_IFNE - ICMD_IFEQ)
86 #define BRANCH_LT (ICMD_IFLT - ICMD_IFEQ)
87 #define BRANCH_GE (ICMD_IFGE - ICMD_IFEQ)
88 #define BRANCH_GT (ICMD_IFGT - ICMD_IFEQ)
89 #define BRANCH_LE (ICMD_IFLE - ICMD_IFEQ)
91 #define BRANCH_ULT 256
92 #define BRANCH_ULE 257
93 #define BRANCH_UGE 258
94 #define BRANCH_UGT 259
96 #define BRANCH_NAN 260
99 /* common branch options ******************************************************/
101 #define BRANCH_OPT_NONE 0
105 /************************* critical sections *********************************/
107 struct codegen_critical_section_t {
108 codegen_critical_section_t *next;
115 /* codegendata ****************************************************************/
118 u4 flags; /* code generator flags */
119 u1 *mcodebase; /* base pointer of code area */
120 u1 *mcodeend; /* pointer to end of code area */
121 s4 mcodesize; /* complete size of code area (bytes) */
122 u1 *mcodeptr; /* code generation pointer */
123 u1 *lastmcodeptr; /* last patcher position of basic block */
125 #if defined(ENABLE_INTRP)
126 u1 *ncodebase; /* base pointer of native code area */
127 s4 ncodesize; /* complete size of native code area */
128 u1 *ncodeptr; /* native code generation pointer */
130 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
132 s4 lastpatcheroffset; /* -1 if current super has no patcher */
133 s4 dynsuperm; /* offsets of start of current dynamic ...*/
134 s4 dynsupern; /* ... superinstruction starts */
135 struct superstart *superstarts; /* list of supers without patchers */
138 dsegentry *dseg; /* chain of data segment entries */
139 s4 dseglen; /* used size of data area (bytes) */
140 /* data area grows from top to bottom */
142 jumpref *jumpreferences; /* list of jumptable target addresses */
144 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
145 dataref *datareferences; /* list of data segment references */
148 /* list *patchrefs; */
152 linenumberref *linenumberreferences; /* list of line numbers and the */
153 /* program counters of their first */
155 s4 linenumbertablesizepos;
156 s4 linenumbertablestartpos;
161 codegen_critical_section_t *threadcrit; /* List of critical code regions */
162 codegen_critical_section_t threadcritcurrent;
163 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 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m);
313 #if defined(ENABLE_DISASSEMBLER)
314 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
317 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
318 java_objectheader *codegen_finish_native_call(u1 *datasp);
320 u1 *createcompilerstub(methodinfo *m);
321 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd);
323 #if defined(ENABLE_INTRP)
324 u1 *intrp_createcompilerstub(methodinfo *m);
325 u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
328 void removecompilerstub(u1 *stub);
329 void removenativestub(u1 *stub);
331 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
332 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
334 #if defined(ENABLE_THREADS)
335 void codegen_threadcritrestart(codegendata *cd, int offset);
336 void codegen_threadcritstart(codegendata *cd, int offset);
337 void codegen_threadcritstop(codegendata *cd, int offset);
340 /* machine dependent functions */
341 u1 *md_codegen_get_pv_from_pc(u1 *ra);
343 #endif /* _CODEGEN_COMMON_H */
347 * These are local overrides for various environment variables in Emacs.
348 * Please do not remove this and leave it at the end of the file, where
349 * Emacs will automagically detect them.
350 * ---------------------------------------------------------------------
353 * indent-tabs-mode: t
357 * vim:noexpandtab:sw=4:ts=4: