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_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;
36 typedef struct exceptionref exceptionref;
37 typedef struct linenumberref linenumberref;
43 #include "vm/jit/builtin.hpp"
44 #include "vm/descriptor.h"
45 #include "vm/global.h"
46 #include "vm/method.h"
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.h"
53 #include "vm/jit/replace.hpp"
56 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
57 #define DSEGINITSIZE (1<<12) /* 4 Kbyte data area initialization size */
59 #define NCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
62 /* Register Pack/Unpack Macros ************************************************/
64 /* ATTENTION: Don't change the order where low and high bits are
65 stored! At least mips32 relies in one case on that order. */
67 #define PACK_REGS(low,high) \
68 ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
70 #define GET_LOW_REG(a) ((a) & 0x0000ffff)
71 #define GET_HIGH_REG(a) (((a) & 0xffff0000) >> 16)
74 /* branch conditions **********************************************************/
76 #define BRANCH_UNCONDITIONAL -1
78 #define BRANCH_EQ (ICMD_IFEQ - ICMD_IFEQ)
79 #define BRANCH_NE (ICMD_IFNE - ICMD_IFEQ)
80 #define BRANCH_LT (ICMD_IFLT - ICMD_IFEQ)
81 #define BRANCH_GE (ICMD_IFGE - ICMD_IFEQ)
82 #define BRANCH_GT (ICMD_IFGT - ICMD_IFEQ)
83 #define BRANCH_LE (ICMD_IFLE - ICMD_IFEQ)
85 #define BRANCH_ULT 256
86 #define BRANCH_ULE 257
87 #define BRANCH_UGE 258
88 #define BRANCH_UGT 259
90 #define BRANCH_NAN 260
93 /* common branch options ******************************************************/
95 #define BRANCH_OPT_NONE 0
98 /* codegendata ****************************************************************/
101 u4 flags; /* code generator flags */
102 u1 *mcodebase; /* base pointer of code area */
103 u1 *mcodeend; /* pointer to end of code area */
104 s4 mcodesize; /* complete size of code area (bytes) */
105 u1 *mcodeptr; /* code generation pointer */
106 u1 *lastmcodeptr; /* last patcher position of basic block */
108 #if defined(ENABLE_INTRP)
109 u1 *ncodebase; /* base pointer of native code area */
110 s4 ncodesize; /* complete size of native code area */
111 u1 *ncodeptr; /* native code generation pointer */
113 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
115 s4 lastpatcheroffset; /* -1 if current super has no patcher */
116 s4 dynsuperm; /* offsets of start of current dynamic ...*/
117 s4 dynsupern; /* ... superinstruction starts */
118 struct superstart *superstarts; /* list of supers without patchers */
121 dsegentry *dseg; /* chain of data segment entries */
122 s4 dseglen; /* used size of data area (bytes) */
123 /* data area grows from top to bottom */
125 jumpref *jumpreferences; /* list of jumptable target addresses */
127 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
128 dataref *datareferences; /* list of data segment references */
131 list_t *brancheslabel;
132 list_t *linenumbers; /* list of line numbers */
136 s4 stackframesize; /* stackframe size of this method */
138 #if defined(ENABLE_REPLACEMENT)
139 rplpoint *replacementpoint; /* current replacement point */
144 #define CODEGENDATA_FLAG_ERROR 0x00000001
145 #define CODEGENDATA_FLAG_LONGBRANCHES 0x00000002
148 #define CODEGENDATA_HAS_FLAG_ERROR(cd) \
149 ((cd)->flags & CODEGENDATA_FLAG_ERROR)
151 #define CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) \
152 ((cd)->flags & CODEGENDATA_FLAG_LONGBRANCHES)
155 /* branchref *****************************************************************/
158 s4 branchmpc; /* patching position in code segment */
159 s4 condition; /* conditional branch condition */
160 s4 reg; /* register number to check */
161 u4 options; /* branch options */
162 branchref *next; /* next element in branchref list */
166 /* branch_label_ref_t *********************************************************/
168 struct branch_label_ref_t {
169 s4 mpc; /* position in code segment */
170 s4 label; /* label number */
171 s4 condition; /* conditional branch condition */
172 s4 reg; /* register number to check */
173 u4 options; /* branch options */
178 /* jumpref ********************************************************************/
181 s4 tablepos; /* patching position in data segment */
182 basicblock *target; /* target basic block */
183 jumpref *next; /* next element in jumpref list */
187 /* dataref ********************************************************************/
190 s4 datapos; /* patching position in generated code */
191 dataref *next; /* next element in dataref list */
195 /* linenumberref **************************************************************/
197 struct linenumberref {
198 s4 tablepos; /* patching position in data segment */
199 s4 linenumber; /* line number, used for inserting into the */
200 /* table and for validity checking */
201 /* -1......start of inlined body */
202 /* -2......end of inlined body */
203 /* <= -3...special entry with methodinfo * */
204 /* (see doc/inlining_stacktrace.txt) */
205 ptrint targetmpc; /* machine code program counter of first */
206 /* instruction for given line */
207 /* NOTE: for linenumber <= -3 this is a the */
208 /* (methodinfo *) of the inlined method */
209 linenumberref *next; /* next element in linenumberref list */
213 /* function prototypes ********************************************************/
219 void codegen_init(void);
220 void codegen_setup(jitdata *jd);
222 bool codegen_generate(jitdata *jd);
223 bool codegen_emit(jitdata *jd);
225 #if defined(ENABLE_INTRP)
226 bool intrp_codegen(jitdata *jd);
229 void codegen_close(void);
231 void codegen_increase(codegendata *cd);
233 #if defined(ENABLE_INTRP)
234 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
237 void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
238 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
240 void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
242 #if defined(ENABLE_REPLACEMENT)
244 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
245 void codegen_set_replacement_point(codegendata *cd, s4 type);
247 void codegen_set_replacement_point_notrap(codegendata *cd);
248 void codegen_set_replacement_point(codegendata *cd);
250 #endif /* defined(ENABLE_REPLACEMENT) */
252 void codegen_finish(jitdata *jd);
254 java_handle_t *codegen_start_native_call(u1 *currentsp, u1 *pv);
255 java_object_t *codegen_finish_native_call(u1 *currentsp, u1 *pv);
257 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
258 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
260 #if defined(ENABLE_SSA)
261 void codegen_emit_phi_moves(jitdata *jd, basicblock *bptr);
265 void codegen_emit_stub_compiler(jitdata *jd);
266 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams);
272 #endif // _CODEGEN_COMMON_HPP
276 * These are local overrides for various environment variables in Emacs.
277 * Please do not remove this and leave it at the end of the file, where
278 * Emacs will automagically detect them.
279 * ---------------------------------------------------------------------
282 * indent-tabs-mode: t
286 * vim:noexpandtab:sw=4:ts=4: