Remove obsolete Microsoft.Vsa and Microsoft.JScript
[mono-project/dkf.git] / mono / mini / ir-emit.h
blob6505c2a3c88bc51977abf7028e005afcc88cb0d6
1 /*
2 * ir-emit.h: IR Creation/Emission Macros
4 * Author:
5 * Zoltan Varga (vargaz@gmail.com)
7 * (C) 2002 Ximian, Inc.
8 */
10 #ifndef __MONO_IR_EMIT_H__
11 #define __MONO_IR_EMIT_H__
13 #include "mini.h"
15 G_BEGIN_DECLS
17 static inline guint32
18 alloc_ireg (MonoCompile *cfg)
20 return cfg->next_vreg ++;
23 static inline guint32
24 alloc_preg (MonoCompile *cfg)
26 return alloc_ireg (cfg);
29 static inline guint32
30 alloc_lreg (MonoCompile *cfg)
32 #if SIZEOF_REGISTER == 8
33 return cfg->next_vreg ++;
34 #else
35 /* Use a pair of consecutive vregs */
36 guint32 res = cfg->next_vreg;
38 cfg->next_vreg += 3;
40 return res;
41 #endif
44 static inline guint32
45 alloc_freg (MonoCompile *cfg)
47 #ifdef MONO_ARCH_SOFT_FLOAT
48 /* Allocate an lvreg so float ops can be decomposed into long ops */
49 return alloc_lreg (cfg);
50 #else
51 /* Allocate these from the same pool as the int regs */
52 return cfg->next_vreg ++;
53 #endif
56 static inline guint32
57 alloc_dreg (MonoCompile *cfg, MonoStackType stack_type)
59 switch (stack_type) {
60 case STACK_I4:
61 case STACK_PTR:
62 case STACK_MP:
63 case STACK_OBJ:
64 return alloc_ireg (cfg);
65 case STACK_R8:
66 return alloc_freg (cfg);
67 case STACK_I8:
68 return alloc_lreg (cfg);
69 case STACK_VTYPE:
70 return alloc_ireg (cfg);
71 default:
72 g_warning ("Unknown stack type %x\n", stack_type);
73 g_assert_not_reached ();
74 return -1;
78 #undef MONO_INST_NEW
79 /*
80 * FIXME: zeroing out some fields is not needed with the new IR, but the old
81 * JIT code still uses the left and right fields, so it has to stay.
83 #define MONO_INST_NEW(cfg,dest,op) do { \
84 (dest) = mono_mempool_alloc ((cfg)->mempool, sizeof (MonoInst)); \
85 (dest)->inst_c0 = (dest)->inst_c1 = 0; \
86 (dest)->next = (dest)->prev = NULL; \
87 (dest)->opcode = (op); \
88 (dest)->flags = 0; \
89 (dest)->type = 0; \
90 (dest)->dreg = -1; \
91 MONO_INST_NULLIFY_SREGS ((dest)); \
92 (dest)->cil_code = (cfg)->ip; \
93 } while (0)
96 * Variants which take a dest argument and don't do an emit
98 #define NEW_ICONST(cfg,dest,val) do { \
99 MONO_INST_NEW ((cfg), (dest), OP_ICONST); \
100 (dest)->inst_c0 = (val); \
101 (dest)->type = STACK_I4; \
102 (dest)->dreg = alloc_dreg ((cfg), STACK_I4); \
103 } while (0)
106 * Avoid using this with a non-NULL val if possible as it is not AOT
107 * compatible. Use one of the NEW_xxxCONST variants instead.
109 #define NEW_PCONST(cfg,dest,val) do { \
110 MONO_INST_NEW ((cfg), (dest), OP_PCONST); \
111 (dest)->inst_p0 = (val); \
112 (dest)->type = STACK_PTR; \
113 (dest)->dreg = alloc_dreg ((cfg), STACK_PTR); \
114 } while (0)
116 #define NEW_I8CONST(cfg,dest,val) do { \
117 MONO_INST_NEW ((cfg), (dest), OP_I8CONST); \
118 (dest)->dreg = alloc_lreg ((cfg)); \
119 (dest)->type = STACK_I8; \
120 (dest)->inst_l = (val); \
121 } while (0)
123 #define NEW_STORE_MEMBASE(cfg,dest,op,base,offset,sr) do { \
124 MONO_INST_NEW ((cfg), (dest), (op)); \
125 (dest)->sreg1 = sr; \
126 (dest)->inst_destbasereg = base; \
127 (dest)->inst_offset = offset; \
128 } while (0)
130 #define NEW_LOAD_MEMBASE(cfg,dest,op,dr,base,offset) do { \
131 MONO_INST_NEW ((cfg), (dest), (op)); \
132 (dest)->dreg = (dr); \
133 (dest)->inst_basereg = (base); \
134 (dest)->inst_offset = (offset); \
135 (dest)->type = STACK_I4; \
136 } while (0)
138 #define NEW_LOAD_MEM(cfg,dest,op,dr,mem) do { \
139 MONO_INST_NEW ((cfg), (dest), (op)); \
140 (dest)->dreg = (dr); \
141 (dest)->inst_p0 = (gpointer)(gssize)(mem); \
142 (dest)->type = STACK_I4; \
143 } while (0)
145 #define NEW_UNALU(cfg,dest,op,dr,sr1) do { \
146 MONO_INST_NEW ((cfg), (dest), (op)); \
147 (dest)->dreg = dr; \
148 (dest)->sreg1 = sr1; \
149 } while (0)
151 #define NEW_BIALU(cfg,dest,op,dr,sr1,sr2) do { \
152 MONO_INST_NEW ((cfg), (dest), (op)); \
153 (dest)->dreg = (dr); \
154 (dest)->sreg1 = (sr1); \
155 (dest)->sreg2 = (sr2); \
156 } while (0)
158 #define NEW_BIALU_IMM(cfg,dest,op,dr,sr,imm) do { \
159 MONO_INST_NEW ((cfg), (dest), (op)); \
160 (dest)->dreg = dr; \
161 (dest)->sreg1 = sr; \
162 (dest)->inst_imm = (imm); \
163 } while (0)
165 #ifdef MONO_ARCH_NEED_GOT_VAR
167 #define NEW_PATCH_INFO(cfg,dest,el1,el2) do { \
168 MONO_INST_NEW ((cfg), (dest), OP_PATCH_INFO); \
169 (dest)->inst_left = (gpointer)(el1); \
170 (dest)->inst_right = (gpointer)(el2); \
171 } while (0)
173 /* FIXME: Add the PUSH_GOT_ENTRY optimizations */
174 #define NEW_AOTCONST(cfg,dest,patch_type,cons) do { \
175 MONO_INST_NEW ((cfg), (dest), cfg->compile_aot ? OP_GOT_ENTRY : OP_PCONST); \
176 if (cfg->compile_aot) { \
177 MonoInst *group, *got_loc; \
178 got_loc = mono_get_got_var (cfg); \
179 NEW_PATCH_INFO ((cfg), group, cons, patch_type); \
180 (dest)->inst_basereg = got_loc->dreg; \
181 (dest)->inst_p1 = group; \
182 } else { \
183 (dest)->inst_p0 = (cons); \
184 (dest)->inst_i1 = (gpointer)(patch_type); \
186 (dest)->type = STACK_PTR; \
187 (dest)->dreg = alloc_dreg ((cfg), STACK_PTR); \
188 } while (0)
190 #define NEW_AOTCONST_TOKEN(cfg,dest,patch_type,image,token,generic_context,stack_type,stack_class) do { \
191 MonoInst *group, *got_loc; \
192 MONO_INST_NEW ((cfg), (dest), OP_GOT_ENTRY); \
193 got_loc = mono_get_got_var (cfg); \
194 NEW_PATCH_INFO ((cfg), group, NULL, patch_type); \
195 group->inst_p0 = mono_jump_info_token_new2 ((cfg)->mempool, (image), (token), (generic_context)); \
196 (dest)->inst_basereg = got_loc->dreg; \
197 (dest)->inst_p1 = group; \
198 (dest)->type = (stack_type); \
199 (dest)->klass = (stack_class); \
200 (dest)->dreg = alloc_dreg ((cfg), (stack_type)); \
201 } while (0)
203 #else
205 #define NEW_AOTCONST(cfg,dest,patch_type,cons) do { \
206 MONO_INST_NEW ((cfg), (dest), cfg->compile_aot ? OP_AOTCONST : OP_PCONST); \
207 (dest)->inst_p0 = (cons); \
208 (dest)->inst_i1 = (gpointer)(patch_type); \
209 (dest)->type = STACK_PTR; \
210 (dest)->dreg = alloc_dreg ((cfg), STACK_PTR); \
211 } while (0)
213 #define NEW_AOTCONST_TOKEN(cfg,dest,patch_type,image,token,generic_context,stack_type,stack_class) do { \
214 MONO_INST_NEW ((cfg), (dest), OP_AOTCONST); \
215 (dest)->inst_p0 = mono_jump_info_token_new2 ((cfg)->mempool, (image), (token), (generic_context)); \
216 (dest)->inst_p1 = (gpointer)(patch_type); \
217 (dest)->type = (stack_type); \
218 (dest)->klass = (stack_class); \
219 (dest)->dreg = alloc_dreg ((cfg), (stack_type)); \
220 } while (0)
222 #endif
224 #define NEW_CLASSCONST(cfg,dest,val) NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_CLASS, (val))
226 #define NEW_IMAGECONST(cfg,dest,val) NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_IMAGE, (val))
228 #define NEW_FIELDCONST(cfg,dest,val) NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_FIELD, (val))
230 #define NEW_METHODCONST(cfg,dest,val) NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_METHODCONST, (val))
232 #define NEW_VTABLECONST(cfg,dest,vtable) NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_VTABLE, cfg->compile_aot ? (gpointer)((vtable)->klass) : (vtable))
234 #define NEW_SFLDACONST(cfg,dest,val) NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_SFLDA, (val))
236 #define NEW_LDSTRCONST(cfg,dest,image,token) NEW_AOTCONST_TOKEN ((cfg), (dest), MONO_PATCH_INFO_LDSTR, (image), (token), NULL, STACK_OBJ, mono_defaults.string_class)
238 #define NEW_TYPE_FROM_HANDLE_CONST(cfg,dest,image,token,generic_context) NEW_AOTCONST_TOKEN ((cfg), (dest), MONO_PATCH_INFO_TYPE_FROM_HANDLE, (image), (token), (generic_context), STACK_OBJ, mono_defaults.monotype_class)
240 #define NEW_LDTOKENCONST(cfg,dest,image,token) NEW_AOTCONST_TOKEN ((cfg), (dest), MONO_PATCH_INFO_LDTOKEN, (image), (token), NULL, STACK_PTR, NULL)
242 #define NEW_DECLSECCONST(cfg,dest,image,entry) do { \
243 if (cfg->compile_aot) { \
244 NEW_AOTCONST_TOKEN (cfg, dest, MONO_PATCH_INFO_DECLSEC, image, (entry).index, NULL, STACK_OBJ, NULL); \
245 } else { \
246 NEW_PCONST (cfg, args [0], (entry).blob); \
248 } while (0)
250 #define NEW_METHOD_RGCTX_CONST(cfg,dest,method) do { \
251 if (cfg->compile_aot) { \
252 NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_METHOD_RGCTX, (method)); \
253 } else { \
254 MonoMethodRuntimeGenericContext *mrgctx; \
255 mrgctx = mono_method_lookup_rgctx (mono_class_vtable ((cfg)->domain, (method)->klass), mini_method_get_context ((method))->method_inst); \
256 NEW_PCONST ((cfg), (dest), (mrgctx)); \
258 } while (0)
260 #define NEW_DOMAINCONST(cfg,dest) do { \
261 if ((cfg->opt & MONO_OPT_SHARED) || cfg->compile_aot) { \
262 /* avoid depending on undefined C behavior in sequence points */ \
263 MonoInst* __domain_var = mono_get_domainvar (cfg); \
264 NEW_TEMPLOAD (cfg, dest, __domain_var->inst_c0); \
265 } else { \
266 NEW_PCONST (cfg, dest, (cfg)->domain); \
268 } while (0)
270 #define GET_VARINFO_INST(cfg,num) ((cfg)->varinfo [(num)]->inst)
272 #define NEW_VARLOAD(cfg,dest,var,vartype) do { \
273 MONO_INST_NEW ((cfg), (dest), OP_MOVE); \
274 (dest)->opcode = mono_type_to_regmove ((cfg), (vartype)); \
275 type_to_eval_stack_type ((cfg), (vartype), (dest)); \
276 (dest)->klass = var->klass; \
277 (dest)->sreg1 = var->dreg; \
278 (dest)->dreg = alloc_dreg ((cfg), (dest)->type); \
279 if ((dest)->opcode == OP_VMOVE) (dest)->klass = mono_class_from_mono_type ((vartype)); \
280 } while (0)
282 #ifdef MONO_ARCH_SOFT_FLOAT
283 #define DECOMPOSE_INTO_REGPAIR(stack_type) ((stack_type) == STACK_I8 || (stack_type) == STACK_R8)
284 #else
285 #define DECOMPOSE_INTO_REGPAIR(stack_type) ((stack_type) == STACK_I8)
286 #endif
288 #define NEW_VARLOADA(cfg,dest,var,vartype) do { \
289 MONO_INST_NEW ((cfg), (dest), OP_LDADDR); \
290 (dest)->inst_p0 = (var); \
291 (var)->flags |= MONO_INST_INDIRECT; \
292 (dest)->type = STACK_MP; \
293 (dest)->klass = (var)->klass; \
294 (dest)->dreg = alloc_dreg ((cfg), STACK_MP); \
295 if (SIZEOF_REGISTER == 4 && DECOMPOSE_INTO_REGPAIR ((var)->type)) { MonoInst *var1 = get_vreg_to_inst (cfg, (var)->dreg + 1); MonoInst *var2 = get_vreg_to_inst (cfg, (var)->dreg + 2); g_assert (var1); g_assert (var2); var1->flags |= MONO_INST_INDIRECT; var2->flags |= MONO_INST_INDIRECT; } \
296 } while (0)
298 #define NEW_VARSTORE(cfg,dest,var,vartype,inst) do { \
299 MONO_INST_NEW ((cfg), (dest), OP_MOVE); \
300 (dest)->opcode = mono_type_to_regmove ((cfg), (vartype)); \
301 (dest)->klass = (var)->klass; \
302 (dest)->sreg1 = (inst)->dreg; \
303 (dest)->dreg = (var)->dreg; \
304 if ((dest)->opcode == OP_VMOVE) (dest)->klass = mono_class_from_mono_type ((vartype)); \
305 } while (0)
307 #define NEW_TEMPLOAD(cfg,dest,num) NEW_VARLOAD ((cfg), (dest), (cfg)->varinfo [(num)], (cfg)->varinfo [(num)]->inst_vtype)
309 #define NEW_TEMPLOADA(cfg,dest,num) NEW_VARLOADA ((cfg), (dest), cfg->varinfo [(num)], cfg->varinfo [(num)]->inst_vtype)
311 #define NEW_TEMPSTORE(cfg,dest,num,inst) NEW_VARSTORE ((cfg), (dest), (cfg)->varinfo [(num)], (cfg)->varinfo [(num)]->inst_vtype, (inst))
313 #define NEW_ARGLOAD(cfg,dest,num) NEW_VARLOAD ((cfg), (dest), cfg->args [(num)], cfg->arg_types [(num)])
315 #define NEW_LOCLOAD(cfg,dest,num) NEW_VARLOAD ((cfg), (dest), cfg->locals [(num)], header->locals [(num)])
317 #define NEW_LOCSTORE(cfg,dest,num,inst) NEW_VARSTORE ((cfg), (dest), (cfg)->locals [(num)], (cfg)->locals [(num)]->inst_vtype, (inst))
319 #define NEW_ARGSTORE(cfg,dest,num,inst) NEW_VARSTORE ((cfg), (dest), cfg->args [(num)], cfg->arg_types [(num)], (inst))
321 #define NEW_LOCLOADA(cfg,dest,num) NEW_VARLOADA ((cfg), (dest), (cfg)->locals [(num)], (cfg)->locals [(num)]->inst_vtype)
323 #define NEW_RETLOADA(cfg,dest) do { \
324 MONO_INST_NEW ((cfg), (dest), OP_MOVE); \
325 (dest)->type = STACK_MP; \
326 (dest)->klass = cfg->ret->klass; \
327 (dest)->sreg1 = cfg->vret_addr->dreg; \
328 (dest)->dreg = alloc_dreg ((cfg), (dest)->type); \
329 } while (0)
331 #define NEW_ARGLOADA(cfg,dest,num) NEW_VARLOADA ((cfg), (dest), arg_array [(num)], param_types [(num)])
333 /* Promote the vreg to a variable so its address can be taken */
334 #define NEW_VARLOADA_VREG(cfg,dest,vreg,ltype) do { \
335 MonoInst *var = get_vreg_to_inst ((cfg), (vreg)); \
336 if (!var) \
337 var = mono_compile_create_var_for_vreg ((cfg), (ltype), OP_LOCAL, (vreg)); \
338 NEW_VARLOADA ((cfg), (dest), (var), (ltype)); \
339 } while (0)
341 #define NEW_DUMMY_USE(cfg,dest,var) do { \
342 MONO_INST_NEW ((cfg), (dest), OP_DUMMY_USE); \
343 (dest)->sreg1 = var->dreg; \
344 } while (0)
346 /* Variants which take a type argument and handle vtypes as well */
347 #define NEW_LOAD_MEMBASE_TYPE(cfg,dest,ltype,base,offset) do { \
348 NEW_LOAD_MEMBASE ((cfg), (dest), mono_type_to_load_membase ((cfg), (ltype)), 0, (base), (offset)); \
349 type_to_eval_stack_type ((cfg), (ltype), (dest)); \
350 (dest)->dreg = alloc_dreg ((cfg), (dest)->type); \
351 } while (0)
353 #define NEW_STORE_MEMBASE_TYPE(cfg,dest,ltype,base,offset,sr) do { \
354 MONO_INST_NEW ((cfg), (dest), mono_type_to_store_membase ((cfg), (ltype))); \
355 (dest)->sreg1 = sr; \
356 (dest)->inst_destbasereg = base; \
357 (dest)->inst_offset = offset; \
358 type_to_eval_stack_type ((cfg), (ltype), (dest)); \
359 (dest)->klass = mono_class_from_mono_type (ltype); \
360 } while (0)
362 #define NEW_SEQ_POINT(cfg,dest,il_offset,ss_loc) do { \
363 MONO_INST_NEW ((cfg), (dest), OP_SEQ_POINT); \
364 (dest)->inst_imm = (il_offset); \
365 (dest)->flags = ss_loc ? MONO_INST_SINGLE_STEP_LOC : 0; \
366 } while (0)
369 * Variants which do an emit as well.
371 #define EMIT_NEW_ICONST(cfg,dest,val) do { NEW_ICONST ((cfg), (dest), (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
373 #define EMIT_NEW_PCONST(cfg,dest,val) do { NEW_PCONST ((cfg), (dest), (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
375 #define EMIT_NEW_I8CONST(cfg,dest,val) do { NEW_I8CONST ((cfg), (dest), (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
377 #define EMIT_NEW_AOTCONST(cfg,dest,patch_type,cons) do { NEW_AOTCONST ((cfg), (dest), (patch_type), (cons)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
379 #define EMIT_NEW_AOTCONST_TOKEN(cfg,dest,patch_type,image,token,stack_type,stack_class) do { NEW_AOTCONST_TOKEN ((cfg), (dest), (patch_type), (image), (token), NULL, (stack_type), (stack_class)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
381 #define EMIT_NEW_CLASSCONST(cfg,dest,val) do { NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_CLASS, (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
383 #define EMIT_NEW_IMAGECONST(cfg,dest,val) do { NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_IMAGE, (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
385 #define EMIT_NEW_FIELDCONST(cfg,dest,val) do { NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_FIELD, (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
387 #define EMIT_NEW_METHODCONST(cfg,dest,val) do { NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_METHODCONST, (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
389 #define EMIT_NEW_VTABLECONST(cfg,dest,vtable) do { NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_VTABLE, cfg->compile_aot ? (gpointer)((vtable)->klass) : (vtable)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
391 #define EMIT_NEW_SFLDACONST(cfg,dest,val) do { NEW_AOTCONST ((cfg), (dest), MONO_PATCH_INFO_SFLDA, (val)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
393 #define EMIT_NEW_LDSTRCONST(cfg,dest,image,token) do { NEW_AOTCONST_TOKEN ((cfg), (dest), MONO_PATCH_INFO_LDSTR, (image), (token), NULL, STACK_OBJ, mono_defaults.string_class); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
395 #define EMIT_NEW_TYPE_FROM_HANDLE_CONST(cfg,dest,image,token,generic_context) do { NEW_AOTCONST_TOKEN ((cfg), (dest), MONO_PATCH_INFO_TYPE_FROM_HANDLE, (image), (token), (generic_context), STACK_OBJ, mono_defaults.monotype_class); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
397 #define EMIT_NEW_LDTOKENCONST(cfg,dest,image,token) do { NEW_AOTCONST_TOKEN ((cfg), (dest), MONO_PATCH_INFO_LDTOKEN, (image), (token), NULL, STACK_PTR, NULL); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
399 #define EMIT_NEW_DOMAINCONST(cfg,dest) do { NEW_DOMAINCONST ((cfg), (dest)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
401 #define EMIT_NEW_DECLSECCONST(cfg,dest,image,entry) do { NEW_DECLSECCONST ((cfg), (dest), (image), (entry)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
403 #define EMIT_NEW_METHOD_RGCTX_CONST(cfg,dest,method) do { NEW_METHOD_RGCTX_CONST ((cfg), (dest), (method)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
405 #define EMIT_NEW_VARLOAD(cfg,dest,var,vartype) do { NEW_VARLOAD ((cfg), (dest), (var), (vartype)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
407 #define EMIT_NEW_VARSTORE(cfg,dest,var,vartype,inst) do { NEW_VARSTORE ((cfg), (dest), (var), (vartype), (inst)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
409 #define EMIT_NEW_VARLOADA(cfg,dest,var,vartype) do { NEW_VARLOADA ((cfg), (dest), (var), (vartype)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
412 #ifdef MONO_ARCH_SOFT_FLOAT
415 * Since the IL stack (and our vregs) contain double values, we have to do a conversion
416 * when loading/storing args/locals of type R4.
419 #define EMIT_NEW_VARLOAD_SFLOAT(cfg,dest,var,vartype) do { \
420 if (COMPILE_SOFT_FLOAT ((cfg)) && !(vartype)->byref && (vartype)->type == MONO_TYPE_R4) { \
421 MonoInst *iargs [1]; \
422 EMIT_NEW_VARLOADA (cfg, iargs [0], (var), (vartype)); \
423 (dest) = mono_emit_jit_icall (cfg, mono_fload_r4, iargs); \
424 } else { \
425 EMIT_NEW_VARLOAD ((cfg), (dest), (var), (vartype)); \
427 } while (0)
429 #define EMIT_NEW_VARSTORE_SFLOAT(cfg,dest,var,vartype,inst) do { \
430 if (COMPILE_SOFT_FLOAT ((cfg)) && !(vartype)->byref && (vartype)->type == MONO_TYPE_R4) { \
431 MonoInst *iargs [2]; \
432 iargs [0] = (inst); \
433 EMIT_NEW_VARLOADA (cfg, iargs [1], (var), (vartype)); \
434 mono_emit_jit_icall (cfg, mono_fstore_r4, iargs); \
435 } else { \
436 EMIT_NEW_VARSTORE ((cfg), (dest), (var), (vartype), (inst)); \
438 } while (0)
440 #define EMIT_NEW_ARGLOAD(cfg,dest,num) EMIT_NEW_VARLOAD_SFLOAT ((cfg), (dest), cfg->args [(num)], cfg->arg_types [(num)])
442 #define EMIT_NEW_LOCLOAD(cfg,dest,num) EMIT_NEW_VARLOAD_SFLOAT ((cfg), (dest), cfg->locals [(num)], header->locals [(num)])
444 #define EMIT_NEW_LOCSTORE(cfg,dest,num,inst) EMIT_NEW_VARSTORE_SFLOAT ((cfg), (dest), (cfg)->locals [(num)], (cfg)->locals [(num)]->inst_vtype, (inst))
446 #define EMIT_NEW_ARGSTORE(cfg,dest,num,inst) EMIT_NEW_VARSTORE_SFLOAT ((cfg), (dest), cfg->args [(num)], cfg->arg_types [(num)], (inst))
448 #else
450 #define EMIT_NEW_ARGLOAD(cfg,dest,num) do { NEW_ARGLOAD ((cfg), (dest), (num)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
452 #define EMIT_NEW_LOCLOAD(cfg,dest,num) do { NEW_LOCLOAD ((cfg), (dest), (num)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
454 #define EMIT_NEW_LOCSTORE(cfg,dest,num,inst) do { NEW_LOCSTORE ((cfg), (dest), (num), (inst)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
456 #define EMIT_NEW_ARGSTORE(cfg,dest,num,inst) do { NEW_ARGSTORE ((cfg), (dest), (num), (inst)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
458 #endif
460 #define EMIT_NEW_TEMPLOAD(cfg,dest,num) do { NEW_TEMPLOAD ((cfg), (dest), (num)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
462 #define EMIT_NEW_TEMPLOADA(cfg,dest,num) do { NEW_TEMPLOADA ((cfg), (dest), (num)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
464 #define EMIT_NEW_LOCLOADA(cfg,dest,num) do { NEW_LOCLOADA ((cfg), (dest), (num)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
466 #define EMIT_NEW_ARGLOADA(cfg,dest,num) do { NEW_ARGLOADA ((cfg), (dest), (num)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
468 #define EMIT_NEW_RETLOADA(cfg,dest) do { NEW_RETLOADA ((cfg), (dest)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
470 #define EMIT_NEW_TEMPSTORE(cfg,dest,num,inst) do { NEW_TEMPSTORE ((cfg), (dest), (num), (inst)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
472 #define EMIT_NEW_VARLOADA_VREG(cfg,dest,vreg,ltype) do { NEW_VARLOADA_VREG ((cfg), (dest), (vreg), (ltype)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
474 #define EMIT_NEW_DUMMY_USE(cfg,dest,var) do { NEW_DUMMY_USE ((cfg), (dest), (var)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
476 #define EMIT_NEW_UNALU(cfg,dest,op,dr,sr1) do { NEW_UNALU ((cfg), (dest), (op), (dr), (sr1)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
478 #define EMIT_NEW_BIALU(cfg,dest,op,dr,sr1,sr2) do { NEW_BIALU ((cfg), (dest), (op), (dr), (sr1), (sr2)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
480 #define EMIT_NEW_BIALU_IMM(cfg,dest,op,dr,sr,imm) do { NEW_BIALU_IMM ((cfg), (dest), (op), (dr), (sr), (imm)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
482 #define EMIT_NEW_LOAD_MEMBASE(cfg,dest,op,dr,base,offset) do { NEW_LOAD_MEMBASE ((cfg), (dest), (op), (dr), (base), (offset)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
484 #define EMIT_NEW_STORE_MEMBASE(cfg,dest,op,base,offset,sr) do { NEW_STORE_MEMBASE ((cfg), (dest), (op), (base), (offset), (sr)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
486 #define EMIT_NEW_LOAD_MEMBASE_TYPE(cfg,dest,ltype,base,offset) do { NEW_LOAD_MEMBASE_TYPE ((cfg), (dest), (ltype), (base), (offset)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
488 #define EMIT_NEW_STORE_MEMBASE_TYPE(cfg,dest,ltype,base,offset,sr) do { NEW_STORE_MEMBASE_TYPE ((cfg), (dest), (ltype), (base), (offset), (sr)); MONO_ADD_INS ((cfg)->cbb, (dest)); } while (0)
491 * Variants which do not take an dest argument, but take a dreg argument.
493 #define MONO_EMIT_NEW_ICONST(cfg,dr,imm) do { \
494 MonoInst *inst; \
495 MONO_INST_NEW ((cfg), (inst), OP_ICONST); \
496 inst->dreg = dr; \
497 inst->inst_c0 = imm; \
498 MONO_ADD_INS ((cfg)->cbb, inst); \
499 } while (0)
501 #define MONO_EMIT_NEW_PCONST(cfg,dr,val) do { \
502 MonoInst *inst; \
503 MONO_INST_NEW ((cfg), (inst), OP_PCONST); \
504 inst->dreg = dr; \
505 (inst)->inst_p0 = (val); \
506 (inst)->type = STACK_PTR; \
507 MONO_ADD_INS ((cfg)->cbb, inst); \
508 } while (0)
510 #define MONO_EMIT_NEW_I8CONST(cfg,dr,imm) do { \
511 MonoInst *inst; \
512 MONO_INST_NEW ((cfg), (inst), OP_I8CONST); \
513 inst->dreg = dr; \
514 inst->inst_l = imm; \
515 MONO_ADD_INS ((cfg)->cbb, inst); \
516 } while (0)
518 #ifdef MONO_ARCH_NEED_GOT_VAR
520 #define MONO_EMIT_NEW_AOTCONST(cfg,dr,cons,patch_type) do { \
521 MonoInst *inst; \
522 NEW_AOTCONST ((cfg), (inst), (patch_type), (cons)); \
523 inst->dreg = (dr); \
524 MONO_ADD_INS ((cfg)->cbb, inst); \
525 } while (0)
527 #else
529 #define MONO_EMIT_NEW_AOTCONST(cfg,dr,imm,type) do { \
530 MonoInst *inst; \
531 MONO_INST_NEW ((cfg), (inst), OP_AOTCONST); \
532 inst->dreg = dr; \
533 inst->inst_p0 = imm; \
534 inst->inst_c1 = type; \
535 MONO_ADD_INS ((cfg)->cbb, inst); \
536 } while (0)
538 #endif
540 #define MONO_EMIT_NEW_CLASSCONST(cfg,dr,imm) MONO_EMIT_NEW_AOTCONST(cfg,dr,imm,MONO_PATCH_INFO_CLASS)
541 #define MONO_EMIT_NEW_VTABLECONST(cfg,dest,vtable) MONO_EMIT_NEW_AOTCONST ((cfg), (dest), (cfg)->compile_aot ? (gpointer)((vtable)->klass) : (vtable), MONO_PATCH_INFO_VTABLE)
543 #define MONO_EMIT_NEW_VZERO(cfg,dr,kl) do { \
544 MonoInst *inst; \
545 MONO_INST_NEW ((cfg), (inst), MONO_CLASS_IS_SIMD (cfg, kl) ? OP_XZERO : OP_VZERO); \
546 inst->dreg = dr; \
547 (inst)->type = STACK_VTYPE; \
548 (inst)->klass = (kl); \
549 MONO_ADD_INS ((cfg)->cbb, inst); \
550 } while (0)
552 #define MONO_EMIT_NEW_UNALU(cfg,op,dr,sr1) do { \
553 MonoInst *inst; \
554 EMIT_NEW_UNALU ((cfg), (inst), (op), (dr), (sr1)); \
555 } while (0)
557 #define MONO_EMIT_NEW_BIALU(cfg,op,dr,sr1,sr2) do { \
558 MonoInst *inst; \
559 MONO_INST_NEW ((cfg), (inst), (op)); \
560 inst->dreg = dr; \
561 inst->sreg1 = sr1; \
562 inst->sreg2 = sr2; \
563 MONO_ADD_INS (cfg->cbb, inst); \
564 } while (0)
566 #define MONO_EMIT_NEW_BIALU_IMM(cfg,op,dr,sr,imm) do { \
567 MonoInst *inst; \
568 MONO_INST_NEW ((cfg), (inst), (op)); \
569 inst->dreg = dr; \
570 inst->sreg1 = sr; \
571 inst->inst_imm = (mgreg_t)(imm); \
572 MONO_ADD_INS (cfg->cbb, inst); \
573 } while (0)
575 #define MONO_EMIT_NEW_COMPARE_IMM(cfg,sr1,imm) do { \
576 MonoInst *inst; \
577 MONO_INST_NEW ((cfg), (inst), (OP_COMPARE_IMM)); \
578 inst->sreg1 = sr1; \
579 inst->inst_imm = (imm); \
580 MONO_ADD_INS ((cfg)->cbb, inst); \
581 } while (0)
583 #define MONO_EMIT_NEW_ICOMPARE_IMM(cfg,sr1,imm) do { \
584 MonoInst *inst; \
585 MONO_INST_NEW ((cfg), (inst), sizeof (mgreg_t) == 8 ? OP_ICOMPARE_IMM : OP_COMPARE_IMM); \
586 inst->sreg1 = sr1; \
587 inst->inst_imm = (imm); \
588 MONO_ADD_INS ((cfg)->cbb, inst); \
589 } while (0)
591 #define MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg,op,dr,base,offset) do { \
592 MonoInst *inst; \
593 MONO_INST_NEW ((cfg), (inst), (op)); \
594 inst->dreg = dr; \
595 inst->inst_basereg = base; \
596 inst->inst_offset = offset; \
597 MONO_ADD_INS (cfg->cbb, inst); \
598 } while (0)
600 #define MONO_EMIT_NEW_LOAD_MEMBASE(cfg,dr,base,offset) MONO_EMIT_NEW_LOAD_MEMBASE_OP ((cfg), (OP_LOAD_MEMBASE), (dr), (base), (offset))
602 #define MONO_EMIT_NEW_STORE_MEMBASE(cfg,op,base,offset,sr) do { \
603 MonoInst *inst; \
604 MONO_INST_NEW ((cfg), (inst), (op)); \
605 (inst)->sreg1 = sr; \
606 (inst)->inst_destbasereg = base; \
607 (inst)->inst_offset = offset; \
608 MONO_ADD_INS (cfg->cbb, inst); \
609 } while (0)
611 #define MONO_EMIT_NEW_STORE_MEMBASE_IMM(cfg,op,base,offset,imm) do { \
612 MonoInst *inst; \
613 MONO_INST_NEW ((cfg), (inst), (op)); \
614 inst->inst_destbasereg = base; \
615 inst->inst_offset = offset; \
616 inst->inst_imm = (mgreg_t)(imm); \
617 MONO_ADD_INS ((cfg)->cbb, inst); \
618 } while (0)
620 #define MONO_EMIT_NEW_COND_EXC(cfg,cond,name) do { \
621 MonoInst *inst; \
622 MONO_INST_NEW ((cfg), (inst), (OP_COND_EXC_##cond)); \
623 inst->inst_p1 = (char*)name; \
624 MONO_ADD_INS ((cfg)->cbb, inst); \
625 } while (0)
627 /* Branch support */
630 * Basic blocks have two numeric identifiers:
631 * dfn: Depth First Number
632 * block_num: unique ID assigned at bblock creation
634 #define NEW_BBLOCK(cfg,bblock) do { \
635 (bblock) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoBasicBlock)); \
636 (bblock)->block_num = cfg->num_bblocks++; \
637 } while (0)
639 #define ADD_BBLOCK(cfg,b) do { \
640 if ((b)->cil_code) {\
641 cfg->cil_offset_to_bb [(b)->cil_code - cfg->cil_start] = (b); \
643 (b)->real_offset = cfg->real_offset; \
644 } while (0)
646 /* Emit a one-way conditional branch */
648 * The inst_false_bb field of the cond branch will not be set, the JIT code should be
649 * prepared to deal with this.
651 #ifdef DEBUG_EXTENDED_BBLOCKS
652 static int ccount = 0;
653 #define MONO_EMIT_NEW_BRANCH_BLOCK(cfg,op,truebb) do { \
654 MonoInst *ins; \
655 MonoBasicBlock *falsebb; \
656 MONO_INST_NEW ((cfg), (ins), (op)); \
657 if ((op) == OP_BR) { \
658 NEW_BBLOCK ((cfg), falsebb); \
659 ins->inst_target_bb = (truebb); \
660 mono_link_bblock ((cfg), (cfg)->cbb, (truebb)); \
661 MONO_ADD_INS ((cfg)->cbb, ins); \
662 MONO_START_BB ((cfg), falsebb); \
663 } else { \
664 ccount ++; \
665 ins->inst_many_bb = mono_mempool_alloc (cfg->mempool, sizeof(gpointer)*2); \
666 ins->inst_true_bb = (truebb); \
667 ins->inst_false_bb = NULL; \
668 mono_link_bblock ((cfg), (cfg)->cbb, (truebb)); \
669 MONO_ADD_INS ((cfg)->cbb, ins); \
670 if (getenv ("COUNT2") && ccount == atoi (getenv ("COUNT2")) - 1) { printf ("HIT: %d\n", cfg->cbb->block_num); } \
671 if (getenv ("COUNT2") && ccount < atoi (getenv ("COUNT2"))) { \
672 cfg->cbb->extended = TRUE; \
673 } else { NEW_BBLOCK ((cfg), falsebb); ins->inst_false_bb = (falsebb); mono_link_bblock ((cfg), (cfg)->cbb, (falsebb)); MONO_START_BB ((cfg), falsebb); } \
675 } while (0)
676 #else
677 #define MONO_EMIT_NEW_BRANCH_BLOCK(cfg,op,truebb) do { \
678 MonoInst *ins; \
679 MonoBasicBlock *falsebb; \
680 MONO_INST_NEW ((cfg), (ins), (op)); \
681 if ((op) == OP_BR) { \
682 NEW_BBLOCK ((cfg), falsebb); \
683 ins->inst_target_bb = (truebb); \
684 mono_link_bblock ((cfg), (cfg)->cbb, (truebb)); \
685 MONO_ADD_INS ((cfg)->cbb, ins); \
686 MONO_START_BB ((cfg), falsebb); \
687 } else { \
688 ins->inst_many_bb = mono_mempool_alloc (cfg->mempool, sizeof(gpointer)*2); \
689 ins->inst_true_bb = (truebb); \
690 ins->inst_false_bb = NULL; \
691 mono_link_bblock ((cfg), (cfg)->cbb, (truebb)); \
692 MONO_ADD_INS ((cfg)->cbb, ins); \
693 if (!cfg->enable_extended_bblocks) { \
694 NEW_BBLOCK ((cfg), falsebb); \
695 ins->inst_false_bb = falsebb; \
696 mono_link_bblock ((cfg), (cfg)->cbb, (falsebb)); \
697 MONO_START_BB ((cfg), falsebb); \
698 } else { \
699 cfg->cbb->extended = TRUE; \
702 } while (0)
703 #endif
705 /* Emit a two-way conditional branch */
706 #define MONO_EMIT_NEW_BRANCH_BLOCK2(cfg,op,truebb,falsebb) do { \
707 MonoInst *ins; \
708 MONO_INST_NEW ((cfg), (ins), (op)); \
709 ins->inst_many_bb = mono_mempool_alloc (cfg->mempool, sizeof(gpointer)*2); \
710 ins->inst_true_bb = (truebb); \
711 ins->inst_false_bb = (falsebb); \
712 mono_link_bblock ((cfg), (cfg)->cbb, (truebb)); \
713 mono_link_bblock ((cfg), (cfg)->cbb, (falsebb)); \
714 MONO_ADD_INS ((cfg)->cbb, ins); \
715 } while (0)
717 #define MONO_START_BB(cfg, bblock) do { \
718 ADD_BBLOCK ((cfg), (bblock)); \
719 if (cfg->cbb->last_ins && MONO_IS_COND_BRANCH_OP (cfg->cbb->last_ins) && !cfg->cbb->last_ins->inst_false_bb) { \
720 cfg->cbb->last_ins->inst_false_bb = (bblock); \
721 mono_link_bblock ((cfg), (cfg)->cbb, (bblock)); \
722 } else if (! (cfg->cbb->last_ins && ((cfg->cbb->last_ins->opcode == OP_BR) || (cfg->cbb->last_ins->opcode == OP_BR_REG) || MONO_IS_COND_BRANCH_OP (cfg->cbb->last_ins)))) \
723 mono_link_bblock ((cfg), (cfg)->cbb, (bblock)); \
724 (cfg)->cbb->next_bb = (bblock); \
725 (cfg)->cbb = (bblock); \
726 } while (0)
728 /* This marks a place in code where an implicit exception could be thrown */
729 #define MONO_EMIT_NEW_IMPLICIT_EXCEPTION(cfg) do { \
730 if (COMPILE_LLVM ((cfg))) { \
731 MONO_EMIT_NEW_UNALU (cfg, OP_IMPLICIT_EXCEPTION, -1, -1); \
733 } while (0)
735 /* Loads/Stores which can fault are handled correctly by the LLVM mono branch */
736 #define MONO_EMIT_NEW_IMPLICIT_EXCEPTION_LOAD_STORE(cfg) do { \
737 if (COMPILE_LLVM (cfg) && !IS_LLVM_MONO_BRANCH) \
738 MONO_EMIT_NEW_IMPLICIT_EXCEPTION ((cfg)); \
739 } while (0)
741 /* Emit an explicit null check which doesn't depend on SIGSEGV signal handling */
742 #define MONO_EMIT_NULL_CHECK(cfg, reg) do { \
743 if (cfg->explicit_null_checks) { \
744 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_COMPARE_IMM, -1, (reg), 0); \
745 MONO_EMIT_NEW_COND_EXC (cfg, EQ, "NullReferenceException"); \
746 } else { \
747 MONO_EMIT_NEW_IMPLICIT_EXCEPTION_LOAD_STORE (cfg); \
749 } while (0)
751 #define MONO_EMIT_NEW_CHECK_THIS(cfg, sreg) do { \
752 cfg->flags |= MONO_CFG_HAS_CHECK_THIS; \
753 if (cfg->explicit_null_checks) { \
754 MONO_EMIT_NULL_CHECK (cfg, sreg); \
755 } else { \
756 MONO_EMIT_NEW_UNALU (cfg, OP_CHECK_THIS, -1, sreg); \
757 MONO_EMIT_NEW_IMPLICIT_EXCEPTION_LOAD_STORE (cfg); \
759 MONO_EMIT_NEW_UNALU (cfg, OP_NOT_NULL, -1, sreg); \
760 } while (0)
762 #define NEW_LOAD_MEMBASE_FLAGS(cfg,dest,op,dr,base,offset,ins_flags) do { \
763 int __ins_flags = ins_flags; \
764 if (__ins_flags & MONO_INST_FAULT) { \
765 MONO_EMIT_NULL_CHECK ((cfg), (base)); \
766 if (cfg->explicit_null_checks) \
767 __ins_flags &= ~MONO_INST_FAULT; \
769 NEW_LOAD_MEMBASE ((cfg), (dest), (op), (dr), (base), (offset)); \
770 (dest)->flags = (__ins_flags); \
771 } while (0)
773 #define MONO_EMIT_NEW_LOAD_MEMBASE_OP_FLAGS(cfg,op,dr,base,offset,ins_flags) do { \
774 MonoInst *inst; \
775 int __ins_flags = ins_flags; \
776 if (__ins_flags & MONO_INST_FAULT) { \
777 MONO_EMIT_NULL_CHECK ((cfg), (base)); \
778 if (cfg->explicit_null_checks) \
779 __ins_flags &= ~MONO_INST_FAULT; \
781 NEW_LOAD_MEMBASE ((cfg), (inst), (op), (dr), (base), (offset)); \
782 inst->flags = (__ins_flags); \
783 MONO_ADD_INS (cfg->cbb, inst); \
784 } while (0)
786 #define MONO_EMIT_NEW_LOAD_MEMBASE_FLAGS(cfg,dr,base,offset,ins_flags) MONO_EMIT_NEW_LOAD_MEMBASE_OP_FLAGS ((cfg), (OP_LOAD_MEMBASE), (dr), (base), (offset),(ins_flags))
788 /* A load which can cause a nullref */
789 #define NEW_LOAD_MEMBASE_FAULT(cfg,dest,op,dr,base,offset) NEW_LOAD_MEMBASE_FLAGS ((cfg), (dest), (op), (dr), (base), (offset), MONO_INST_FAULT)
791 #define EMIT_NEW_LOAD_MEMBASE_FAULT(cfg,dest,op,dr,base,offset) do { \
792 NEW_LOAD_MEMBASE_FAULT ((cfg), (dest), (op), (dr), (base), (offset)); \
793 MONO_ADD_INS ((cfg)->cbb, (dest)); \
794 } while (0)
796 #define MONO_EMIT_NEW_LOAD_MEMBASE_OP_FAULT(cfg,op,dr,base,offset) MONO_EMIT_NEW_LOAD_MEMBASE_OP_FLAGS ((cfg), (op), (dr), (base), (offset), MONO_INST_FAULT)
798 #define MONO_EMIT_NEW_LOAD_MEMBASE_FAULT(cfg,dr,base,offset) MONO_EMIT_NEW_LOAD_MEMBASE_OP_FAULT ((cfg), (OP_LOAD_MEMBASE), (dr), (base), (offset))
800 /*Object Model related macros*/
802 /* Default bounds check implementation for most architectures + llvm */
803 #define MONO_EMIT_DEFAULT_BOUNDS_CHECK(cfg, array_reg, offset, index_reg, fault) do { \
804 int _length_reg = alloc_ireg (cfg); \
805 if (fault) \
806 MONO_EMIT_NEW_LOAD_MEMBASE_OP_FAULT (cfg, OP_LOADI4_MEMBASE, _length_reg, array_reg, offset); \
807 else \
808 MONO_EMIT_NEW_LOAD_MEMBASE_OP_FLAGS (cfg, OP_LOADI4_MEMBASE, _length_reg, array_reg, offset, MONO_INST_CONSTANT_LOAD); \
809 MONO_EMIT_NEW_BIALU (cfg, OP_COMPARE, -1, _length_reg, index_reg); \
810 MONO_EMIT_NEW_COND_EXC (cfg, LE_UN, "IndexOutOfRangeException"); \
811 } while (0)
813 #ifndef MONO_ARCH_EMIT_BOUNDS_CHECK
814 #define MONO_ARCH_EMIT_BOUNDS_CHECK(cfg, array_reg, offset, index_reg) MONO_EMIT_DEFAULT_BOUNDS_CHECK ((cfg), (array_reg), (offset), (index_reg), TRUE)
815 #endif
817 /* cfg is the MonoCompile been used
818 * array_reg is the vreg holding the array object
819 * array_type is a struct (usually MonoArray or MonoString)
820 * array_length_field is the field in the previous struct with the length
821 * index_reg is the vreg holding the index
823 #define MONO_EMIT_BOUNDS_CHECK(cfg, array_reg, array_type, array_length_field, index_reg) do { \
824 if (!(cfg->opt & MONO_OPT_UNSAFE)) { \
825 if (!(cfg->opt & MONO_OPT_ABCREM)) { \
826 MONO_EMIT_NULL_CHECK (cfg, array_reg); \
827 if (COMPILE_LLVM (cfg)) \
828 MONO_EMIT_DEFAULT_BOUNDS_CHECK ((cfg), (array_reg), G_STRUCT_OFFSET (array_type, array_length_field), (index_reg), TRUE); \
829 else \
830 MONO_ARCH_EMIT_BOUNDS_CHECK ((cfg), (array_reg), G_STRUCT_OFFSET (array_type, array_length_field), (index_reg)); \
831 } else { \
832 MonoInst *ins; \
833 MONO_INST_NEW ((cfg), ins, OP_BOUNDS_CHECK); \
834 ins->sreg1 = array_reg; \
835 ins->sreg2 = index_reg; \
836 ins->inst_imm = G_STRUCT_OFFSET (array_type, array_length_field); \
837 ins->flags |= MONO_INST_FAULT; \
838 MONO_ADD_INS ((cfg)->cbb, ins); \
839 (cfg)->flags |= MONO_CFG_HAS_ARRAY_ACCESS; \
840 (cfg)->cbb->has_array_access = TRUE; \
843 } while (0)
845 G_END_DECLS
847 #endif