* src/vm/jit/codegen-common.hpp (exceptionref): Removed.
[cacao.git] / src / vm / jit / codegen-common.hpp
1 /* src/vm/jit/codegen-common.h - architecture independent code generator stuff
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _CODEGEN_COMMON_HPP
27 #define _CODEGEN_COMMON_HPP
28
29 /* forward typedefs ***********************************************************/
30
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
37
38 #include "config.h"
39 #include "vm/types.h"
40
41 #include "vm/jit/builtin.hpp"
42 #include "vm/descriptor.h"
43 #include "vm/global.h"
44 #include "vm/method.h"
45 #include "vm/references.h"
46
47 #include "vm/jit/dseg.h"
48 #include "vm/jit/jit.hpp"
49 #include "vm/jit/reg.h"
50 #include "vm/jit/code.hpp"
51 #include "vm/jit/replace.hpp"
52
53
54 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
55 #define DSEGINITSIZE  (1<<12)       /*  4 Kbyte data area initialization size */
56
57 #define NCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
58
59
60 /* Register Pack/Unpack Macros ************************************************/
61
62 /* ATTENTION: Don't change the order where low and high bits are
63    stored! At least mips32 relies in one case on that order. */
64
65 #define PACK_REGS(low,high) \
66     ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
67
68 #define GET_LOW_REG(a)      ((a) & 0x0000ffff)
69 #define GET_HIGH_REG(a)    (((a) & 0xffff0000) >> 16)
70
71
72 /* branch conditions **********************************************************/
73
74 #define BRANCH_UNCONDITIONAL    -1
75
76 #define BRANCH_EQ               (ICMD_IFEQ - ICMD_IFEQ)
77 #define BRANCH_NE               (ICMD_IFNE - ICMD_IFEQ)
78 #define BRANCH_LT               (ICMD_IFLT - ICMD_IFEQ)
79 #define BRANCH_GE               (ICMD_IFGE - ICMD_IFEQ)
80 #define BRANCH_GT               (ICMD_IFGT - ICMD_IFEQ)
81 #define BRANCH_LE               (ICMD_IFLE - ICMD_IFEQ)
82
83 #define BRANCH_ULT              256
84 #define BRANCH_ULE              257
85 #define BRANCH_UGE              258
86 #define BRANCH_UGT              259
87
88 #define BRANCH_NAN              260
89
90
91 /* common branch options ******************************************************/
92
93 #define BRANCH_OPT_NONE         0
94
95
96 /* codegendata ****************************************************************/
97
98 struct codegendata {
99         u4              flags;          /* code generator flags                   */
100         u1             *mcodebase;      /* base pointer of code area              */
101         u1             *mcodeend;       /* pointer to end of code area            */
102         s4              mcodesize;      /* complete size of code area (bytes)     */
103         u1             *mcodeptr;       /* code generation pointer                */
104         u1             *lastmcodeptr;   /* last patcher position of basic block   */
105
106 #if defined(ENABLE_INTRP)
107         u1             *ncodebase;      /* base pointer of native code area       */
108         s4              ncodesize;      /* complete size of native code area      */
109         u1             *ncodeptr;       /* native code generation pointer         */
110
111         u4              lastinstwithoutdispatch; /* ~0 if there was a dispatch    */
112
113         s4              lastpatcheroffset; /* -1 if current super has no patcher  */
114         s4              dynsuperm;      /* offsets of start of current dynamic ...*/
115         s4              dynsupern;      /* ... superinstruction starts            */
116         struct superstart *superstarts; /* list of supers without patchers        */
117 #endif
118
119         dsegentry      *dseg;           /* chain of data segment entries          */
120         s4              dseglen;        /* used size of data area (bytes)         */
121                                     /* data area grows from top to bottom     */
122
123         jumpref        *jumpreferences; /* list of jumptable target addresses     */
124
125 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
126         dataref        *datareferences; /* list of data segment references        */
127 #endif
128
129         list_t         *brancheslabel;
130         list_t         *linenumbers;    /* list of line numbers                   */
131
132         methodinfo     *method;
133
134         s4              stackframesize;    /* stackframe size of this method      */
135
136 #if defined(ENABLE_REPLACEMENT)
137         rplpoint       *replacementpoint;  /* current replacement point           */
138 #endif
139 };
140
141
142 #define CODEGENDATA_FLAG_ERROR           0x00000001
143 #define CODEGENDATA_FLAG_LONGBRANCHES    0x00000002
144
145
146 #define CODEGENDATA_HAS_FLAG_ERROR(cd) \
147     ((cd)->flags & CODEGENDATA_FLAG_ERROR)
148
149 #define CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) \
150     ((cd)->flags & CODEGENDATA_FLAG_LONGBRANCHES)
151
152
153 /* branchref *****************************************************************/
154
155 struct branchref {
156         s4         branchmpc;       /* patching position in code segment          */
157         s4         condition;       /* conditional branch condition               */
158         s4         reg;             /* register number to check                   */
159         u4         options;         /* branch options                             */
160         branchref *next;            /* next element in branchref list             */
161 };
162
163
164 /* branch_label_ref_t *********************************************************/
165
166 struct branch_label_ref_t {
167         s4         mpc;             /* position in code segment                   */
168         s4         label;           /* label number                               */
169         s4         condition;       /* conditional branch condition               */
170         s4         reg;             /* register number to check                   */
171         u4         options;         /* branch options                             */
172         listnode_t linkage;
173 };
174
175
176 /* jumpref ********************************************************************/
177
178 struct jumpref {
179         s4          tablepos;       /* patching position in data segment          */
180         basicblock *target;         /* target basic block                         */
181         jumpref    *next;           /* next element in jumpref list               */
182 };
183
184
185 /* dataref ********************************************************************/
186
187 struct dataref {
188         s4       datapos;           /* patching position in generated code        */
189         dataref *next;              /* next element in dataref list               */
190 };
191
192
193 /* function prototypes ********************************************************/
194
195 #ifdef __cplusplus
196 extern "C" {
197 #endif
198
199 void codegen_init(void);
200 void codegen_setup(jitdata *jd);
201
202 bool codegen_generate(jitdata *jd);
203 bool codegen_emit(jitdata *jd);
204
205 #if defined(ENABLE_INTRP)
206 bool intrp_codegen(jitdata *jd);
207 #endif
208
209 void codegen_close(void);
210
211 void codegen_increase(codegendata *cd);
212
213 #if defined(ENABLE_INTRP)
214 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
215 #endif
216
217 void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
218 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
219
220 void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
221
222 #if defined(ENABLE_REPLACEMENT)
223 #if !defined(NDEBUG)
224 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
225 void codegen_set_replacement_point(codegendata *cd, s4 type);
226 #else
227 void codegen_set_replacement_point_notrap(codegendata *cd);
228 void codegen_set_replacement_point(codegendata *cd);
229 #endif
230 #endif /* defined(ENABLE_REPLACEMENT) */
231
232 void codegen_finish(jitdata *jd);
233
234 java_handle_t *codegen_start_native_call(u1 *currentsp, u1 *pv);
235 java_object_t *codegen_finish_native_call(u1 *currentsp, u1 *pv);
236
237 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
238 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
239
240 #if defined(ENABLE_SSA)
241 void codegen_emit_phi_moves(jitdata *jd, basicblock *bptr);
242 #endif
243
244 // REMOVEME
245 void codegen_emit_stub_compiler(jitdata *jd);
246 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams);
247
248 #ifdef __cplusplus
249 }
250 #endif
251
252 #endif // _CODEGEN_COMMON_HPP
253
254
255 /*
256  * These are local overrides for various environment variables in Emacs.
257  * Please do not remove this and leave it at the end of the file, where
258  * Emacs will automagically detect them.
259  * ---------------------------------------------------------------------
260  * Local variables:
261  * mode: c++
262  * indent-tabs-mode: t
263  * c-basic-offset: 4
264  * tab-width: 4
265  * End:
266  * vim:noexpandtab:sw=4:ts=4:
267  */