1 /**
2 * \file
3 * Copyright 2002-2003 Ximian Inc
4 * Copyright 2003-2011 Novell Inc
5 * Copyright 2011 Xamarin Inc
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
7 */
8 #ifndef __MONO_MINI_H__
9 #define __MONO_MINI_H__
10
11 #include "config.h"
12 #include <glib.h>
13 #ifdef HAVE_SIGNAL_H
14 #include <signal.h>
15 #endif
16 #ifdef HAVE_SYS_TYPES_H
17 #include <sys/types.h>
18 #endif
19 #include <mono/metadata/loader.h>
20 #include <mono/metadata/mempool.h>
21 #include <mono/utils/monobitset.h>
22 #include <mono/metadata/class.h>
23 #include <mono/metadata/object.h>
24 #include <mono/metadata/opcodes.h>
25 #include <mono/metadata/tabledefs.h>
26 #include <mono/metadata/domain-internals.h>
27 #include "mono/metadata/class-internals.h"
28 #include "mono/metadata/object-internals.h"
29 #include <mono/metadata/profiler-private.h>
30 #include <mono/metadata/debug-helpers.h>
31 #include <mono/utils/mono-compiler.h>
32 #include <mono/utils/mono-machine.h>
33 #include <mono/utils/mono-stack-unwinding.h>
34 #include <mono/utils/mono-threads.h>
35 #include <mono/utils/mono-threads-coop.h>
36 #include <mono/utils/mono-tls.h>
37 #include <mono/utils/atomic.h>
38 #include <mono/utils/mono-conc-hashtable.h>
39 #include <mono/utils/mono-signal-handler.h>
40
41 #include "mini-arch.h"
42 #include "regalloc.h"
43 #include "mini-unwind.h"
44 #include "jit.h"
45 #include "cfgdump.h"
46
47 #include "mono/metadata/tabledefs.h"
48 #include "mono/metadata/marshal.h"
49 #include "mono/metadata/security-manager.h"
50 #include "mono/metadata/exception.h"
51 #include "mono/metadata/callspec.h"
52
53 /*
54 * The mini code should not have any compile time dependencies on the GC being used, so the same object file from mini/
55 * can be linked into both mono and mono-sgen.
56 */
57 #if !defined(MONO_DLL_EXPORT) || !defined(_MSC_VER)
58 #if defined(HAVE_BOEHM_GC) || defined(HAVE_SGEN_GC)
59 #error "The code in mini/ should not depend on these defines."
60 #endif
61 #endif
62
63 #ifndef __GNUC__
64 /*#define __alignof__(a) sizeof(a)*/
65 #define __alignof__(type) G_STRUCT_OFFSET(struct { char c; type x; }, x)
66 #endif
67
68 #if DISABLE_LOGGING
69 #define MINI_DEBUG(level,limit,code)
70 #else
71 #define MINI_DEBUG(level,limit,code) do {if (G_UNLIKELY ((level) >= (limit))) code} while (0)
72 #endif
73
74 #if !defined(DISABLE_TASKLETS) && defined(MONO_ARCH_SUPPORT_TASKLETS)
75 #if defined(__GNUC__)
76 #define MONO_SUPPORT_TASKLETS 1
77 #elif defined(HOST_WIN32)
78 #define MONO_SUPPORT_TASKLETS 1
79 // Replace some gnu intrinsics needed for tasklets with MSVC equivalents.
80 #define __builtin_extract_return_addr(x) x
81 #define __builtin_return_address(x) _ReturnAddress()
82 #define __builtin_frame_address(x) _AddressOfReturnAddress()
83 #endif
84 #endif
85
86 #if ENABLE_LLVM
87 #define COMPILE_LLVM(cfg) ((cfg)->compile_llvm)
88 #define LLVM_ENABLED TRUE
89 #else
90 #define COMPILE_LLVM(cfg) (0)
91 #define LLVM_ENABLED FALSE
92 #endif
93
94 #ifdef MONO_ARCH_SOFT_FLOAT_FALLBACK
95 #define COMPILE_SOFT_FLOAT(cfg) (!COMPILE_LLVM ((cfg)) && mono_arch_is_soft_float ())
96 #else
97 #define COMPILE_SOFT_FLOAT(cfg) (0)
98 #endif
99
100 #define NOT_IMPLEMENTED do { g_assert_not_reached (); } while (0)
101
102 /* for 32 bit systems */
103 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
104 #define MINI_LS_WORD_IDX 0
105 #define MINI_MS_WORD_IDX 1
106 #else
107 #define MINI_LS_WORD_IDX 1
108 #define MINI_MS_WORD_IDX 0
109 #endif
110 #define MINI_LS_WORD_OFFSET (MINI_LS_WORD_IDX * 4)
111 #define MINI_MS_WORD_OFFSET (MINI_MS_WORD_IDX * 4)
112 #define inst_ls_word data.op[MINI_LS_WORD_IDX].const_val
113 #define inst_ms_word data.op[MINI_MS_WORD_IDX].const_val
114
115 #define MONO_LVREG_LS(lvreg) ((lvreg) + 1)
116 #define MONO_LVREG_MS(lvreg) ((lvreg) + 2)
117
118 #ifndef DISABLE_AOT
119 #define MONO_USE_AOT_COMPILER
120 #endif
121
122 //TODO: This is x86/amd64 specific.
123 #define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))
124
125 /* Remap printf to g_print (we use a mix of these in the mini code) */
126 #ifdef HOST_ANDROID
127 #define printf g_print
128 #endif
129
130 #define MONO_TYPE_IS_PRIMITIVE(t) ((!(t)->byref && ((((t)->type >= MONO_TYPE_BOOLEAN && (t)->type <= MONO_TYPE_R8) || ((t)->type >= MONO_TYPE_I && (t)->type <= MONO_TYPE_U)))))
131
132 typedef struct
133 {
134 MonoClass *klass;
135 MonoMethod *method;
136 } MonoClassMethodPair;
137
138 typedef struct
139 {
140 MonoClass *klass;
141 MonoMethod *method;
142 gboolean is_virtual;
143 } MonoDelegateClassMethodPair;
144
145 typedef struct {
146 MonoJitInfo *ji;
147 MonoCodeManager *code_mp;
148 } MonoJitDynamicMethodInfo;
149
150 /* An extension of MonoGenericParamFull used in generic sharing */
151 typedef struct {
152 MonoGenericParamFull param;
153 MonoGenericParam *parent;
154 } MonoGSharedGenericParam;
155
156 /* Contains a list of ips which needs to be patched when a method is compiled */
157 typedef struct {
158 GSList *list;
159 } MonoJumpList;
160
161 /* Arch-specific */
162 typedef struct {
163 int dummy;
164 } MonoDynCallInfo;
165
166 /*
167 * Information about a stack frame.
168 * FIXME This typedef exists only to avoid tons of code rewriting
169 */
170 typedef MonoStackFrameInfo StackFrameInfo;
171
172 #if 0
173 #define mono_bitset_foreach_bit(set,b,n) \
174 for (b = 0; b < n; b++)\
175 if (mono_bitset_test_fast(set,b))
176 #else
177 #define mono_bitset_foreach_bit(set,b,n) \
178 for (b = mono_bitset_find_start (set); b < n && b >= 0; b = mono_bitset_find_first (set, b))
179 #endif
180
181 /*
182 * Pull the list of opcodes
183 */
184 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
185 a = i,
186
187 enum {
188 #include "mono/cil/opcode.def"
189 CEE_LASTOP
190 };
191 #undef OPDEF
192
193 #define MONO_VARINFO(cfg,varnum) (&(cfg)->vars [varnum])
194
195 #define MONO_INST_NULLIFY_SREGS(dest) do { \
196 (dest)->sreg1 = (dest)->sreg2 = (dest)->sreg3 = -1; \
197 } while (0)
198
199 #define MONO_INST_NEW(cfg,dest,op) do { \
200 (dest) = (MonoInst *)mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
201 (dest)->opcode = (op); \
202 (dest)->dreg = -1; \
203 MONO_INST_NULLIFY_SREGS ((dest)); \
204 (dest)->cil_code = (cfg)->ip; \
205 } while (0)
206
207 #define MONO_INST_NEW_CALL(cfg,dest,op) do { \
208 (dest) = (MonoCallInst *)mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoCallInst)); \
209 (dest)->inst.opcode = (op); \
210 (dest)->inst.dreg = -1; \
211 MONO_INST_NULLIFY_SREGS (&(dest)->inst); \
212 (dest)->inst.cil_code = (cfg)->ip; \
213 } while (0)
214
215 #define MONO_ADD_INS(b,inst) do { \
216 if ((b)->last_ins) { \
217 (b)->last_ins->next = (inst); \
218 (inst)->prev = (b)->last_ins; \
219 (b)->last_ins = (inst); \
220 } else { \
221 (b)->code = (b)->last_ins = (inst); \
222 } \
223 } while (0)
224
225 #define NULLIFY_INS(ins) do { \
226 (ins)->opcode = OP_NOP; \
227 (ins)->dreg = -1; \
228 MONO_INST_NULLIFY_SREGS ((ins)); \
229 } while (0)
230
231 /* Remove INS from BB */
232 #define MONO_REMOVE_INS(bb,ins) do { \
233 if ((ins)->prev) \
234 (ins)->prev->next = (ins)->next; \
235 if ((ins)->next) \
236 (ins)->next->prev = (ins)->prev; \
237 if ((bb)->code == (ins)) \
238 (bb)->code = (ins)->next; \
239 if ((bb)->last_ins == (ins)) \
240 (bb)->last_ins = (ins)->prev; \
241 } while (0)
242
243 /* Remove INS from BB and nullify it */
244 #define MONO_DELETE_INS(bb,ins) do { \
245 MONO_REMOVE_INS ((bb), (ins)); \
246 NULLIFY_INS ((ins)); \
247 } while (0)
248
249 /*
250 * this is used to determine when some branch optimizations are possible: we exclude FP compares
251 * because they have weird semantics with NaNs.
252 */
253 #define MONO_IS_COND_BRANCH_OP(ins) (((ins)->opcode >= OP_LBEQ && (ins)->opcode <= OP_LBLT_UN) || ((ins)->opcode >= OP_FBEQ && (ins)->opcode <= OP_FBLT_UN) || ((ins)->opcode >= OP_IBEQ && (ins)->opcode <= OP_IBLT_UN))
254 #define MONO_IS_COND_BRANCH_NOFP(ins) (MONO_IS_COND_BRANCH_OP(ins) && !(((ins)->opcode >= OP_FBEQ) && ((ins)->opcode <= OP_FBLT_UN)) && (!(ins)->inst_left || (ins)->inst_left->inst_left->type != STACK_R8))
255
256 #define MONO_IS_BRANCH_OP(ins) (MONO_IS_COND_BRANCH_OP(ins) || ((ins)->opcode == OP_BR) || ((ins)->opcode == OP_BR_REG) || ((ins)->opcode == OP_SWITCH))
257
258 #define MONO_IS_COND_EXC(ins) ((((ins)->opcode >= OP_COND_EXC_EQ) && ((ins)->opcode <= OP_COND_EXC_LT_UN)) || (((ins)->opcode >= OP_COND_EXC_IEQ) && ((ins)->opcode <= OP_COND_EXC_ILT_UN)))
259
260 #define MONO_IS_SETCC(ins) ((((ins)->opcode >= OP_CEQ) && ((ins)->opcode <= OP_CLT_UN)) || (((ins)->opcode >= OP_ICEQ) && ((ins)->opcode <= OP_ICLE_UN)) || (((ins)->opcode >= OP_LCEQ) && ((ins)->opcode <= OP_LCLT_UN)) || (((ins)->opcode >= OP_FCEQ) && ((ins)->opcode <= OP_FCLT_UN)))
261
262 #define MONO_HAS_CUSTOM_EMULATION(ins) (((ins)->opcode >= OP_FBEQ && (ins)->opcode <= OP_FBLT_UN) || ((ins)->opcode >= OP_FCEQ && (ins)->opcode <= OP_FCLT_UN))
263
264 #define MONO_IS_LOAD_MEMBASE(ins) (((ins)->opcode >= OP_LOAD_MEMBASE && (ins)->opcode <= OP_LOADV_MEMBASE) || ((ins)->opcode >= OP_ATOMIC_LOAD_I1 && (ins)->opcode <= OP_ATOMIC_LOAD_R8))
265 #define MONO_IS_STORE_MEMBASE(ins) (((ins)->opcode >= OP_STORE_MEMBASE_REG && (ins)->opcode <= OP_STOREV_MEMBASE) || ((ins)->opcode >= OP_ATOMIC_STORE_I1 && (ins)->opcode <= OP_ATOMIC_STORE_R8))
266 #define MONO_IS_STORE_MEMINDEX(ins) (((ins)->opcode >= OP_STORE_MEMINDEX) && ((ins)->opcode <= OP_STORER8_MEMINDEX))
267
268 // OP_DYN_CALL is not a MonoCallInst
269 #define MONO_IS_CALL(ins) (((ins->opcode >= OP_VOIDCALL) && (ins->opcode <= OP_VCALL2_MEMBASE)) || (ins->opcode == OP_TAILCALL))
270
271 #define MONO_IS_JUMP_TABLE(ins) (((ins)->opcode == OP_JUMP_TABLE) ? TRUE : ((((ins)->opcode == OP_AOTCONST) && (ins->inst_i1 == (gpointer)MONO_PATCH_INFO_SWITCH)) ? TRUE : ((ins)->opcode == OP_SWITCH) ? TRUE : ((((ins)->opcode == OP_GOT_ENTRY) && ((ins)->inst_right->inst_i1 == (gpointer)MONO_PATCH_INFO_SWITCH)) ? TRUE : FALSE)))
272
273 #define MONO_JUMP_TABLE_FROM_INS(ins) (((ins)->opcode == OP_JUMP_TABLE) ? (ins)->inst_p0 : (((ins)->opcode == OP_AOTCONST) && (ins->inst_i1 == (gpointer)MONO_PATCH_INFO_SWITCH) ? (ins)->inst_p0 : (((ins)->opcode == OP_SWITCH) ? (ins)->inst_p0 : ((((ins)->opcode == OP_GOT_ENTRY) && ((ins)->inst_right->inst_i1 == (gpointer)MONO_PATCH_INFO_SWITCH)) ? (ins)->inst_right->inst_p0 : NULL))))
274
275 /* FIXME: Add more instructions */
276 /* INEG sets the condition codes, and the OP_LNEG decomposition depends on this on x86 */
277 #define MONO_INS_HAS_NO_SIDE_EFFECT(ins) (MONO_IS_MOVE (ins) || (ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || MONO_IS_ZERO (ins) || (ins->opcode == OP_ADD_IMM) || (ins->opcode == OP_R8CONST) || (ins->opcode == OP_LADD_IMM) || (ins->opcode == OP_ISUB_IMM) || (ins->opcode == OP_IADD_IMM) || (ins->opcode == OP_LNEG) || (ins->opcode == OP_ISUB) || (ins->opcode == OP_CMOV_IGE) || (ins->opcode == OP_ISHL_IMM) || (ins->opcode == OP_ISHR_IMM) || (ins->opcode == OP_ISHR_UN_IMM) || (ins->opcode == OP_IAND_IMM) || (ins->opcode == OP_ICONV_TO_U1) || (ins->opcode == OP_ICONV_TO_I1) || (ins->opcode == OP_SEXT_I4) || (ins->opcode == OP_LCONV_TO_U1) || (ins->opcode == OP_ICONV_TO_U2) || (ins->opcode == OP_ICONV_TO_I2) || (ins->opcode == OP_LCONV_TO_I2) || (ins->opcode == OP_LDADDR) || (ins->opcode == OP_PHI) || (ins->opcode == OP_NOP) || (ins->opcode == OP_ZEXT_I4) || (ins->opcode == OP_NOT_NULL) || (ins->opcode == OP_IL_SEQ_POINT) || (ins->opcode == OP_XZERO))
278
279 #define MONO_INS_IS_PCONST_NULL(ins) ((ins)->opcode == OP_PCONST && (ins)->inst_p0 == 0)
280
281 #define MONO_METHOD_IS_FINAL(m) (((m)->flags & METHOD_ATTRIBUTE_FINAL) || ((m)->klass && (mono_class_get_flags ((m)->klass) & TYPE_ATTRIBUTE_SEALED)))
282
283
284 #ifdef MONO_ARCH_SIMD_INTRINSICS
285
286 #define MONO_IS_PHI(ins) (((ins)->opcode == OP_PHI) || ((ins)->opcode == OP_FPHI) || ((ins)->opcode == OP_VPHI) || ((ins)->opcode == OP_XPHI))
287 #define MONO_IS_MOVE(ins) (((ins)->opcode == OP_MOVE) || ((ins)->opcode == OP_FMOVE) || ((ins)->opcode == OP_VMOVE) || ((ins)->opcode == OP_XMOVE) || ((ins)->opcode == OP_RMOVE))
288 #define MONO_IS_NON_FP_MOVE(ins) (((ins)->opcode == OP_MOVE) || ((ins)->opcode == OP_VMOVE) || ((ins)->opcode == OP_XMOVE))
289 #define MONO_IS_REAL_MOVE(ins) (((ins)->opcode == OP_MOVE) || ((ins)->opcode == OP_FMOVE) || ((ins)->opcode == OP_XMOVE) || ((ins)->opcode == OP_RMOVE))
290 #define MONO_IS_ZERO(ins) (((ins)->opcode == OP_VZERO) || ((ins)->opcode == OP_XZERO))
291
292 #define MONO_CLASS_IS_SIMD(cfg, klass) (((cfg)->opt & MONO_OPT_SIMD) && (klass)->simd_type)
293
294 #else
295
296 #define MONO_IS_PHI(ins) (((ins)->opcode == OP_PHI) || ((ins)->opcode == OP_FPHI) || ((ins)->opcode == OP_VPHI))
297 #define MONO_IS_MOVE(ins) (((ins)->opcode == OP_MOVE) || ((ins)->opcode == OP_FMOVE) || ((ins)->opcode == OP_VMOVE) || ((ins)->opcode == OP_RMOVE))
298 #define MONO_IS_NON_FP_MOVE(ins) (((ins)->opcode == OP_MOVE) || ((ins)->opcode == OP_VMOVE))
299 /*A real MOVE is one that isn't decomposed such as a VMOVE or LMOVE*/
300 #define MONO_IS_REAL_MOVE(ins) (((ins)->opcode == OP_MOVE) || ((ins)->opcode == OP_FMOVE) || ((ins)->opcode == OP_RMOVE))
301 #define MONO_IS_ZERO(ins) ((ins)->opcode == OP_VZERO)
302
303 #define MONO_CLASS_IS_SIMD(cfg, klass) (0)
304
305 #endif
306
307 typedef struct MonoInstList MonoInstList;
308 typedef struct MonoInst MonoInst;
309 typedef struct MonoCallInst MonoCallInst;
310 typedef struct MonoCallArgParm MonoCallArgParm;
311 typedef struct MonoMethodVar MonoMethodVar;
312 typedef struct MonoBasicBlock MonoBasicBlock;
313 typedef struct MonoLMF MonoLMF;
314 typedef struct MonoSpillInfo MonoSpillInfo;
315
316 extern MonoCallSpec *mono_jit_trace_calls;
317 extern gboolean mono_break_on_exc;
318 extern gboolean mono_compile_aot;
319 extern gboolean mono_aot_only;
320 extern gboolean mono_llvm_only;
321 extern MonoAotMode mono_aot_mode;
322 extern MonoMethodDesc *mono_inject_async_exc_method;
323 extern int mono_inject_async_exc_pos;
324 extern MonoMethodDesc *mono_break_at_bb_method;
325 extern int mono_break_at_bb_bb_num;
326 extern gboolean mono_verify_all;
327 extern gboolean mono_do_x86_stack_align;
328 extern MONO_API const char *mono_build_date;
329 extern gboolean mono_do_signal_chaining;
330 extern gboolean mono_do_crash_chaining;
331 extern MONO_API gboolean mono_use_llvm;
332 extern MONO_API gboolean mono_use_interpreter;
333 extern gboolean mono_do_single_method_regression;
334 extern guint32 mono_single_method_regression_opt;
335 extern MonoMethod *mono_current_single_method;
336 extern GSList *mono_single_method_list;
337 extern GHashTable *mono_single_method_hash;
338 extern gboolean mono_using_xdebug;
339 extern int mini_verbose;
340 extern int valgrind_register;
341 extern GList* mono_aot_paths;
342
343 #define INS_INFO(opcode) (&ins_info [((opcode) - OP_START - 1) * 4])
344
345 extern const char ins_info[];
346 extern const gint8 ins_sreg_counts [];
347
348 #ifndef DISABLE_JIT
349 #define mono_inst_get_num_src_registers(ins) (ins_sreg_counts [(ins)->opcode - OP_START - 1])
350 #else
351 #define mono_inst_get_num_src_registers(ins) 0
352 #endif
353
354 #define mono_inst_get_src_registers(ins, regs) (((regs) [0] = (ins)->sreg1), ((regs) [1] = (ins)->sreg2), ((regs) [2] = (ins)->sreg3), mono_inst_get_num_src_registers ((ins)))
355
356 #define MONO_BB_FOR_EACH_INS(bb, ins) for ((ins) = (bb)->code; (ins); (ins) = (ins)->next)
357
358 #define MONO_BB_FOR_EACH_INS_SAFE(bb, n, ins) for ((ins) = (bb)->code, n = (ins) ? (ins)->next : NULL; (ins); (ins) = (n), (n) = (ins) ? (ins)->next : NULL)
359
360 #define MONO_BB_FOR_EACH_INS_REVERSE(bb, ins) for ((ins) = (bb)->last_ins; (ins); (ins) = (ins)->prev)
361
362 #define MONO_BB_FOR_EACH_INS_REVERSE_SAFE(bb, p, ins) for ((ins) = (bb)->last_ins, p = (ins) ? (ins)->prev : NULL; (ins); (ins) = (p), (p) = (ins) ? (ins)->prev : NULL)
363
364 #define mono_bb_first_ins(bb) (bb)->code
365
366 /*
367 * Iterate through all used registers in the instruction.
368 * Relies on the existing order of the MONO_INST enum: MONO_INST_{DREG,SREG1,SREG2,SREG3,LEN}
369 * INS is the instruction, IDX is the register index, REG is the pointer to a register.
370 */
371 #define MONO_INS_FOR_EACH_REG(ins, idx, reg) for ((idx) = INS_INFO ((ins)->opcode)[MONO_INST_DEST] != ' ' ? MONO_INST_DEST : \
372 (mono_inst_get_num_src_registers (ins) ? MONO_INST_SRC1 : MONO_INST_LEN); \
373 (reg) = (idx) == MONO_INST_DEST ? &(ins)->dreg : \
374 ((idx) == MONO_INST_SRC1 ? &(ins)->sreg1 : \
375 ((idx) == MONO_INST_SRC2 ? &(ins)->sreg2 : \
376 ((idx) == MONO_INST_SRC3 ? &(ins)->sreg3 : NULL))), \
377 idx < MONO_INST_LEN; \
378 (idx) = (idx) > mono_inst_get_num_src_registers (ins) + (INS_INFO ((ins)->opcode)[MONO_INST_DEST] != ' ') ? MONO_INST_LEN : (idx) + 1)
379
380 struct MonoSpillInfo {
381 int offset;
382 };
383
384 /*
385 * Information about a call site for the GC map creation code
386 */
387 typedef struct {
388 /* The next offset after the call instruction */
389 int pc_offset;
390 /* The basic block containing the call site */
391 MonoBasicBlock *bb;
392 /*
393 * The set of variables live at the call site.
394 * Has length cfg->num_varinfo in bits.
395 */
396 guint8 *liveness;
397 /*
398 * List of OP_GC_PARAM_SLOT_LIVENESS_DEF instructions defining the param slots
399 * used by this call.
400 */
401 GSList *param_slots;
402 } GCCallSite;
403
404 /*
405 * The IR-level extended basic block.
406 *
407 * A basic block can have multiple exits just fine, as long as the point of
408 * 'departure' is the last instruction in the basic block. Extended basic
409 * blocks, on the other hand, may have instructions that leave the block
410 * midstream. The important thing is that they cannot be _entered_
411 * midstream, ie, execution of a basic block (or extened bb) always start
412 * at the beginning of the block, never in the middle.
413 */
414 struct MonoBasicBlock {
415 MonoInst *last_ins;
416
417 /* the next basic block in the order it appears in IL */
418 MonoBasicBlock *next_bb;
419
420 /*
421 * Before instruction selection it is the first tree in the
422 * forest and the first item in the list of trees. After
423 * instruction selection it is the first instruction and the
424 * first item in the list of instructions.
425 */
426 MonoInst *code;
427
428 /* unique block number identification */
429 gint32 block_num;
430
431 gint32 dfn;
432
433 /* Basic blocks: incoming and outgoing counts and pointers */
434 /* Each bb should only appear once in each array */
435 gint16 out_count, in_count;
436 MonoBasicBlock **in_bb;
437 MonoBasicBlock **out_bb;
438
439 /* Points to the start of the CIL code that initiated this BB */
440 unsigned char* cil_code;
441
442 /* Length of the CIL block */
443 gint32 cil_length;
444
445 /* The offset of the generated code, used for fixups */
446 int native_offset;
447 /* The length of the generated code, doesn't include alignment padding */
448 int native_length;
449 /* The real native offset, which includes alignment padding too */
450 int real_native_offset;
451 int max_offset;
452 int max_length;
453
454 /* Visited and reachable flags */
455 guint32 flags;
456
457 /*
458 * SSA and loop based flags
459 */
460 MonoBitSet *dominators;
461 MonoBitSet *dfrontier;
462 MonoBasicBlock *idom;
463 GSList *dominated;
464 /* fast dominator algorithm */
465 MonoBasicBlock *df_parent, *ancestor, *child, *label;
466 int size, sdom, idomn;
467
468 /* loop nesting and recognition */
469 GList *loop_blocks;
470 gint8 nesting;
471 gint8 loop_body_start;
472
473 /*
474 * Whenever the bblock is rarely executed so it should be emitted after
475 * the function epilog.
476 */
477 guint out_of_line : 1;
478 /* Caches the result of uselessness calculation during optimize_branches */
479 guint not_useless : 1;
480 /* Whenever the decompose_array_access_opts () pass needs to process this bblock */
481 guint has_array_access : 1;
482 /* Whenever this bblock is extended, ie. it has branches inside it */
483 guint extended : 1;
484 /* Whenever this bblock contains a OP_JUMP_TABLE instruction */
485 guint has_jump_table : 1;
486 /* Whenever this bblock contains an OP_CALL_HANDLER instruction */
487 guint has_call_handler : 1;
488 /* Whenever this bblock starts a try block */
489 guint try_start : 1;
490
491 #ifdef ENABLE_LLVM
492 /* The offset of the CIL instruction in this bblock which ends a try block */
493 intptr_t try_end;
494 #endif
495
496 /*
497 * If this is set, extend the try range started by this bblock by an arch specific
498 * number of bytes to encompass the end of the previous bblock (e.g. a Monitor.Enter
499 * call).
500 */
501 guint extend_try_block : 1;
502
503 /* use for liveness analysis */
504 MonoBitSet *gen_set;
505 MonoBitSet *kill_set;
506 MonoBitSet *live_in_set;
507 MonoBitSet *live_out_set;
508
509 /* fields to deal with non-empty stack slots at bb boundary */
510 guint16 out_scount, in_scount;
511 MonoInst **out_stack;
512 MonoInst **in_stack;
513
514 /* we use that to prevent merging of bblocks covered by different clauses*/
515 guint real_offset;
516
517 GSList *seq_points;
518
519 // The MonoInst of the last sequence point for the current basic block.
520 MonoInst *last_seq_point;
521
522 // This will hold a list of last sequence points of incoming basic blocks
523 MonoInst **pred_seq_points;
524 guint num_pred_seq_points;
525
526 GSList *spill_slot_defs;
527
528 /* List of call sites in this bblock sorted by pc_offset */
529 GSList *gc_callsites;
530
531 /*
532 * If this is not null, the basic block is a try hole for all the clauses
533 * in the list previous to this element (including the element).
534 */
535 GList *clause_holes;
536
537 /*
538 * The region encodes whether the basic block is inside
539 * a finally, catch, filter or none of these.
540 *
541 * If the value is -1, then it is neither finally, catch nor filter
542 *
543 * Otherwise the format is:
544 *
545 * Bits: | 0-3 | 4-7 | 8-31
546 * | | |
547 * | clause-flags | MONO_REGION | clause-index
548 *
549 */
550 guint region;
551
552 /* The current symbolic register number, used in local register allocation. */
553 guint32 max_vreg;
554 };
555
556 /* BBlock flags */
557 enum {
558 BB_VISITED = 1 << 0,
559 BB_REACHABLE = 1 << 1,
560 BB_EXCEPTION_DEAD_OBJ = 1 << 2,
561 BB_EXCEPTION_UNSAFE = 1 << 3,
562 BB_EXCEPTION_HANDLER = 1 << 4,
563 /* for Native Client, mark the blocks that can be jumped to indirectly */
564 BB_INDIRECT_JUMP_TARGET = 1 << 5
565 };
566
567 typedef struct MonoMemcpyArgs {
568 int size, align;
569 } MonoMemcpyArgs;
570
571 typedef enum {
572 LLVMArgNone,
573 /* Scalar argument passed by value */
574 LLVMArgNormal,
575 /* Only in ainfo->pair_storage */
576 LLVMArgInIReg,
577 /* Only in ainfo->pair_storage */
578 LLVMArgInFPReg,
579 /* Valuetype passed in 1-2 consecutive register */
580 LLVMArgVtypeInReg,
581 LLVMArgVtypeByVal,
582 LLVMArgVtypeRetAddr, /* On on cinfo->ret */
583 LLVMArgGSharedVt,
584 /* Fixed size argument passed to/returned from gsharedvt method by ref */
585 LLVMArgGsharedvtFixed,
586 /* Fixed size vtype argument passed to/returned from gsharedvt method by ref */
587 LLVMArgGsharedvtFixedVtype,
588 /* Variable sized argument passed to/returned from gsharedvt method by ref */
589 LLVMArgGsharedvtVariable,
590 /* Vtype passed/returned as one int array argument */
591 LLVMArgAsIArgs,
592 /* Vtype passed as a set of fp arguments */
593 LLVMArgAsFpArgs,
594 /*
595 * Only for returns, a structure which
596 * consists of floats/doubles.
597 */
598 LLVMArgFpStruct,
599 LLVMArgVtypeByRef,
600 /* Vtype returned as an int */
601 LLVMArgVtypeAsScalar
602 } LLVMArgStorage;
603
604 typedef struct {
605 LLVMArgStorage storage;
606
607 /*
608 * Only if storage == ArgValuetypeInReg/LLVMArgAsFpArgs.
609 * This contains how the parts of the vtype are passed.
610 */
611 LLVMArgStorage pair_storage [8];
612 /*
613 * Only if storage == LLVMArgAsIArgs/LLVMArgAsFpArgs/LLVMArgFpStruct.
614 * If storage == LLVMArgAsFpArgs, this is the number of arguments
615 * used to pass the value.
616 * If storage == LLVMArgFpStruct, this is the number of fields
617 * in the structure.
618 */
619 int nslots;
620 /* Only if storage == LLVMArgAsIArgs/LLVMArgAsFpArgs/LLVMArgFpStruct (4/8) */
621 int esize;
622 /* Parameter index in the LLVM signature */
623 int pindex;
624 MonoType *type;
625 /* Only if storage == LLVMArgAsFpArgs. Dummy fp args to insert before this arg */
626 int ndummy_fpargs;
627 } LLVMArgInfo;
628
629 typedef struct {
630 LLVMArgInfo ret;
631 /* Whenever there is an rgctx argument */
632 gboolean rgctx_arg;
633 /* Whenever there is an IMT argument */
634 gboolean imt_arg;
635 /*
636 * The position of the vret arg in the argument list.
637 * Only if ret->storage == ArgVtypeRetAddr.
638 * Should be 0 or 1.
639 */
640 int vret_arg_index;
641 /* The indexes of various special arguments in the LLVM signature */
642 int vret_arg_pindex, this_arg_pindex, rgctx_arg_pindex, imt_arg_pindex;
643
644 /* Inline array of argument info */
645 /* args [0] is for the this argument if it exists */
646 LLVMArgInfo args [1];
647 } LLVMCallInfo;
648
649 #define MONO_MAX_SRC_REGS 3
650
651 struct MonoInst {
652 guint16 opcode;
653 guint8 type; /* stack type */
654 guint8 flags;
655
656 /* used by the register allocator */
657 gint32 dreg, sreg1, sreg2, sreg3;
658
659 MonoInst *next, *prev;
660
661 union {
662 union {
663 MonoInst *src;
664 MonoMethodVar *var;
665 mgreg_t const_val;
666 #if (SIZEOF_REGISTER > SIZEOF_VOID_P) && (G_BYTE_ORDER == G_BIG_ENDIAN)
667 struct {
668 gpointer p[SIZEOF_REGISTER/SIZEOF_VOID_P];
669 } pdata;
670 #else
671 gpointer p;
672 #endif
673 MonoMethod *method;
674 MonoMethodSignature *signature;
675 MonoBasicBlock **many_blocks;
676 MonoBasicBlock *target_block;
677 MonoInst **args;
678 MonoType *vtype;
679 MonoClass *klass;
680 int *phi_args;
681 MonoCallInst *call_inst;
682 GList *exception_clauses;
683 } op [2];
684 gint64 i8const;
685 double r8const;
686 } data;
687
688 const unsigned char* cil_code; /* for debugging and bblock splitting */
689
690 /* used mostly by the backend to store additional info it may need */
691 union {
692 gint32 reg3;
693 gint32 arg_info;
694 gint32 size;
695 MonoMemcpyArgs *memcpy_args; /* in OP_MEMSET and OP_MEMCPY */
696 gpointer data;
697 gint shift_amount;
698 gboolean is_pinvoke; /* for variables in the unmanaged marshal format */
699 gboolean record_cast_details; /* For CEE_CASTCLASS */
700 MonoInst *spill_var; /* for OP_MOVE_I4_TO_F/F_TO_I4 and OP_FCONV_TO_R8_X */
701 guint16 source_opcode; /*OP_XCONV_R8_TO_I4 needs to know which op was used to do proper widening*/
702 int pc_offset; /* OP_GC_LIVERANGE_START/END */
703
704 /*
705 * memory_barrier: MONO_MEMORY_BARRIER_{ACQ,REL,SEQ}
706 * atomic_load_*: MONO_MEMORY_BARRIER_{ACQ,SEQ}
707 * atomic_store_*: MONO_MEMORY_BARRIER_{REL,SEQ}
708 */
709 int memory_barrier_kind;
710 } backend;
711
712 MonoClass *klass;
713 };
714
715 struct MonoCallInst {
716 MonoInst inst;
717 MonoMethodSignature *signature;
718 MonoMethod *method;
719 MonoInst **args;
720 MonoInst *out_args;
721 MonoInst *vret_var;
722 gconstpointer fptr;
723 guint stack_usage;
724 guint stack_align_amount;
725 guint is_virtual : 1;
726 guint tail_call : 1;
727 /* If this is TRUE, 'fptr' points to a MonoJumpInfo instead of an address. */
728 guint fptr_is_patch : 1;
729 /*
730 * If this is true, then the call returns a vtype in a register using the same
731 * calling convention as OP_CALL.
732 */
733 guint vret_in_reg : 1;
734 /* Whenever vret_in_reg returns fp values */
735 guint vret_in_reg_fp : 1;
736 /* Whenever there is an IMT argument and it is dynamic */
737 guint dynamic_imt_arg : 1;
738 /* Whenever there is an RGCTX argument */
739 guint32 rgctx_reg : 1;
740 /* Whenever the call will need an unbox trampoline */
741 guint need_unbox_trampoline : 1;
742 regmask_t used_iregs;
743 regmask_t used_fregs;
744 GSList *out_ireg_args;
745 GSList *out_freg_args;
746 GSList *outarg_vts;
747 gpointer call_info;
748 #ifdef ENABLE_LLVM
749 LLVMCallInfo *cinfo;
750 int rgctx_arg_reg, imt_arg_reg;
751 #endif
752 #ifdef TARGET_ARM
753 /* See the comment in mini-arm.c!mono_arch_emit_call for RegTypeFP. */
754 GSList *float_args;
755 #endif
756 };
757
758 struct MonoCallArgParm {
759 MonoInst ins;
760 gint32 size;
761 gint32 offset;
762 gint32 offPrm;
763 };
764
765 /*
766 * flags for MonoInst
767 * Note: some of the values overlap, because they can't appear
768 * in the same MonoInst.
769 */
770 enum {
771 MONO_INST_HAS_METHOD = 1,
772 MONO_INST_INIT = 1, /* in localloc */
773 MONO_INST_SINGLE_STEP_LOC = 1, /* in SEQ_POINT */
774 MONO_INST_IS_DEAD = 2,
775 MONO_INST_TAILCALL = 4,
776 MONO_INST_VOLATILE = 4,
777 MONO_INST_NOTYPECHECK = 4,
778 MONO_INST_NONEMPTY_STACK = 4, /* in SEQ_POINT */
779 MONO_INST_UNALIGNED = 8,
780 MONO_INST_CFOLD_TAKEN = 8, /* On branches */
781 MONO_INST_CFOLD_NOT_TAKEN = 16, /* On branches */
782 MONO_INST_DEFINITION_HAS_SIDE_EFFECTS = 8,
783 /* the address of the variable has been taken */
784 MONO_INST_INDIRECT = 16,
785 MONO_INST_NORANGECHECK = 16,
786 /* On loads, the source address can be null */
787 MONO_INST_FAULT = 32,
788 /*
789 * On variables, identifies LMF variables. These variables have a dummy type (int), but
790 * require stack space for a MonoLMF struct.
791 */
792 MONO_INST_LMF = 32,
793 /* On loads, the source address points to a constant value */
794 MONO_INST_INVARIANT_LOAD = 64,
795 /* On variables, the variable needs GC tracking */
796 MONO_INST_GC_TRACK = 128,
797 /*
798 * Set on instructions during code emission which make calls, i.e. OP_CALL, OP_THROW.
799 * backend.pc_offset will be set to the pc offset at the end of the native call instructions.
800 */
801 MONO_INST_GC_CALLSITE = 128,
802 /* On comparisons, mark the branch following the condition as likely to be taken */
803 MONO_INST_LIKELY = 128,
804 };
805
806 #define inst_c0 data.op[0].const_val
807 #define inst_c1 data.op[1].const_val
808 #define inst_i0 data.op[0].src
809 #define inst_i1 data.op[1].src
810 #if (SIZEOF_REGISTER > SIZEOF_VOID_P) && (G_BYTE_ORDER == G_BIG_ENDIAN)
811 #define inst_p0 data.op[0].pdata.p[SIZEOF_REGISTER/SIZEOF_VOID_P - 1]
812 #define inst_p1 data.op[1].pdata.p[SIZEOF_REGISTER/SIZEOF_VOID_P - 1]
813 #else
814 #define inst_p0 data.op[0].p
815 #define inst_p1 data.op[1].p
816 #endif
817 #define inst_l data.i8const
818 #define inst_r data.r8const
819 #define inst_left data.op[0].src
820 #define inst_right data.op[1].src
821
822 #define inst_newa_len data.op[0].src
823 #define inst_newa_class data.op[1].klass
824
825 #define inst_var data.op[0].var
826 #define inst_vtype data.op[1].vtype
827 /* in branch instructions */
828 #define inst_many_bb data.op[1].many_blocks
829 #define inst_target_bb data.op[0].target_block
830 #define inst_true_bb data.op[1].many_blocks[0]
831 #define inst_false_bb data.op[1].many_blocks[1]
832
833 #define inst_basereg sreg1
834 #define inst_indexreg sreg2
835 #define inst_destbasereg dreg
836 #define inst_offset data.op[0].const_val
837 #define inst_imm data.op[1].const_val
838 #define inst_call data.op[1].call_inst
839
840 #define inst_phi_args data.op[1].phi_args
841 #define inst_eh_blocks data.op[1].exception_clauses
842
843 static inline void
mono_inst_set_src_registers(MonoInst * ins,int * regs)844 mono_inst_set_src_registers (MonoInst *ins, int *regs)
845 {
846 ins->sreg1 = regs [0];
847 ins->sreg2 = regs [1];
848 ins->sreg3 = regs [2];
849 }
850
851 /* instruction description for use in regalloc/scheduling */
852 enum {
853 MONO_INST_DEST,
854 MONO_INST_SRC1, /* we depend on the SRCs to be consecutive */
855 MONO_INST_SRC2,
856 MONO_INST_SRC3,
857 MONO_INST_LEN,
858 MONO_INST_CLOB,
859 /* Unused, commented out to reduce the size of the mdesc tables
860 MONO_INST_FLAGS,
861 MONO_INST_COST,
862 MONO_INST_DELAY,
863 MONO_INST_RES,
864 */
865 MONO_INST_MAX
866 };
867
868 typedef union {
869 struct {
870 guint16 tid; /* tree number */
871 guint16 bid; /* block number */
872 } pos ;
873 guint32 abs_pos;
874 } MonoPosition;
875
876 typedef struct {
877 MonoPosition first_use, last_use;
878 } MonoLiveRange;
879
880 typedef struct MonoLiveRange2 MonoLiveRange2;
881
882 struct MonoLiveRange2 {
883 int from, to;
884 MonoLiveRange2 *next;
885 };
886
887 typedef struct {
888 /* List of live ranges sorted by 'from' */
889 MonoLiveRange2 *range;
890 MonoLiveRange2 *last_range;
891 } MonoLiveInterval;
892
893 /*
894 * Additional information about a variable
895 */
896 struct MonoMethodVar {
897 guint idx; /* inside cfg->varinfo, cfg->vars */
898 MonoLiveRange range; /* generated by liveness analysis */
899 MonoLiveInterval *interval; /* generated by liveness analysis */
900 int reg; /* != -1 if allocated into a register */
901 int spill_costs;
902 MonoBitSet *def_in; /* used by SSA */
903 MonoInst *def; /* used by SSA */
904 MonoBasicBlock *def_bb; /* used by SSA */
905 GList *uses; /* used by SSA */
906 char cpstate; /* used by SSA conditional constant propagation */
907 /* The native offsets corresponding to the live range of the variable */
908 gint32 live_range_start, live_range_end;
909 /*
910 * cfg->varinfo [idx]->dreg could be replaced for OP_REGVAR, this contains the
911 * original vreg.
912 */
913 gint32 vreg;
914 };
915
916 typedef struct MonoJitTlsData MonoJitTlsData;
917
918 /* Generic sharing */
919
920 /*
921 * Flags for which contexts were used in inflating a generic.
922 */
923 enum {
924 MONO_GENERIC_CONTEXT_USED_CLASS = 1,
925 MONO_GENERIC_CONTEXT_USED_METHOD = 2
926 };
927
928 enum {
929 /* Cannot be 0 since this is stored in rgctx slots, and 0 means an unitialized rgctx slot */
930 MONO_GSHAREDVT_BOX_TYPE_VTYPE = 1,
931 MONO_GSHAREDVT_BOX_TYPE_REF = 2,
932 MONO_GSHAREDVT_BOX_TYPE_NULLABLE = 3
933 };
934
935 typedef enum {
936 MONO_RGCTX_INFO_STATIC_DATA,
937 MONO_RGCTX_INFO_KLASS,
938 MONO_RGCTX_INFO_ELEMENT_KLASS,
939 MONO_RGCTX_INFO_VTABLE,
940 MONO_RGCTX_INFO_TYPE,
941 MONO_RGCTX_INFO_REFLECTION_TYPE,
942 MONO_RGCTX_INFO_METHOD,
943 /* In llvmonly mode, this is a function descriptor */
944 MONO_RGCTX_INFO_GENERIC_METHOD_CODE,
945 MONO_RGCTX_INFO_GSHAREDVT_OUT_WRAPPER,
946 MONO_RGCTX_INFO_CLASS_FIELD,
947 MONO_RGCTX_INFO_METHOD_RGCTX,
948 MONO_RGCTX_INFO_METHOD_CONTEXT,
949 MONO_RGCTX_INFO_REMOTING_INVOKE_WITH_CHECK,
950 MONO_RGCTX_INFO_METHOD_DELEGATE_CODE,
951 MONO_RGCTX_INFO_CAST_CACHE,
952 MONO_RGCTX_INFO_ARRAY_ELEMENT_SIZE,
953 MONO_RGCTX_INFO_VALUE_SIZE,
954 /* +1 to avoid zero values in rgctx slots */
955 MONO_RGCTX_INFO_FIELD_OFFSET,
956 /* Either the code for a gsharedvt method, or the address for a gsharedvt-out trampoline for the method */
957 /* In llvmonly mode, this is a function descriptor */
958 MONO_RGCTX_INFO_METHOD_GSHAREDVT_OUT_TRAMPOLINE,
959 /* Same for virtual calls */
960 /* In llvmonly mode, this is a function descriptor */
961 MONO_RGCTX_INFO_METHOD_GSHAREDVT_OUT_TRAMPOLINE_VIRT,
962 /* Same for calli, associated with a signature */
963 MONO_RGCTX_INFO_SIG_GSHAREDVT_OUT_TRAMPOLINE_CALLI,
964 MONO_RGCTX_INFO_SIG_GSHAREDVT_IN_TRAMPOLINE_CALLI,
965 /* One of MONO_GSHAREDVT_BOX_TYPE */
966 MONO_RGCTX_INFO_CLASS_BOX_TYPE,
967 /* Resolves to a MonoGSharedVtMethodRuntimeInfo */
968 MONO_RGCTX_INFO_METHOD_GSHAREDVT_INFO,
969 MONO_RGCTX_INFO_LOCAL_OFFSET,
970 MONO_RGCTX_INFO_MEMCPY,
971 MONO_RGCTX_INFO_BZERO,
972 /* The address of Nullable<T>.Box () */
973 /* In llvmonly mode, this is a function descriptor */
974 MONO_RGCTX_INFO_NULLABLE_CLASS_BOX,
975 MONO_RGCTX_INFO_NULLABLE_CLASS_UNBOX,
976 /* MONO_PATCH_INFO_VCALL_METHOD */
977 /* In llvmonly mode, this is a function descriptor */
978 MONO_RGCTX_INFO_VIRT_METHOD_CODE,
979 /*
980 * MONO_PATCH_INFO_VCALL_METHOD
981 * Same as MONO_RGCTX_INFO_CLASS_BOX_TYPE, but for the class
982 * which implements the method.
983 */
984 MONO_RGCTX_INFO_VIRT_METHOD_BOX_TYPE,
985 /* Resolve to 2 (TRUE) or 1 (FALSE) */
986 MONO_RGCTX_INFO_CLASS_IS_REF_OR_CONTAINS_REFS
987 } MonoRgctxInfoType;
988
989 typedef struct _MonoRuntimeGenericContextInfoTemplate {
990 MonoRgctxInfoType info_type;
991 gpointer data;
992 struct _MonoRuntimeGenericContextInfoTemplate *next;
993 } MonoRuntimeGenericContextInfoTemplate;
994
995 typedef struct {
996 MonoClass *next_subclass;
997 MonoRuntimeGenericContextInfoTemplate *infos;
998 GSList *method_templates;
999 } MonoRuntimeGenericContextTemplate;
1000
1001 typedef struct {
1002 MonoVTable *class_vtable; /* must be the first element */
1003 MonoGenericInst *method_inst;
1004 gpointer infos [MONO_ZERO_LEN_ARRAY];
1005 } MonoMethodRuntimeGenericContext;
1006
1007 #define MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT (sizeof (MonoMethodRuntimeGenericContext) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
1008
1009 #define MONO_RGCTX_SLOT_MAKE_RGCTX(i) (i)
1010 #define MONO_RGCTX_SLOT_MAKE_MRGCTX(i) ((i) | 0x80000000)
1011 #define MONO_RGCTX_SLOT_INDEX(s) ((s) & 0x7fffffff)
1012 #define MONO_RGCTX_SLOT_IS_MRGCTX(s) (((s) & 0x80000000) ? TRUE : FALSE)
1013
1014 #define MONO_GSHAREDVT_DEL_INVOKE_VT_OFFSET -2
1015
1016 typedef struct {
1017 MonoMethod *method;
1018 MonoRuntimeGenericContextInfoTemplate *entries;
1019 int num_entries, count_entries;
1020 } MonoGSharedVtMethodInfo;
1021
1022 /* This is used by gsharedvt methods to allocate locals and compute local offsets */
1023 typedef struct {
1024 int locals_size;
1025 /*
1026 * The results of resolving the entries in MOonGSharedVtMethodInfo->entries.
1027 * We use this instead of rgctx slots since these can be loaded using a load instead
1028 * of a call to an rgctx fetch trampoline.
1029 */
1030 gpointer entries [MONO_ZERO_LEN_ARRAY];
1031 } MonoGSharedVtMethodRuntimeInfo;
1032
1033 typedef struct
1034 {
1035 MonoMethod *invoke;
1036 MonoMethod *method;
1037 MonoMethodSignature *invoke_sig;
1038 MonoMethodSignature *sig;
1039 gpointer method_ptr;
1040 gpointer invoke_impl;
1041 gpointer impl_this;
1042 gpointer impl_nothis;
1043 gboolean need_rgctx_tramp;
1044 } MonoDelegateTrampInfo;
1045
1046 /*
1047 * A function descriptor, which is a function address + argument pair.
1048 * In llvm-only mode, these are used instead of trampolines to pass
1049 * extra arguments to runtime functions/methods.
1050 */
1051 typedef struct
1052 {
1053 gpointer addr;
1054 gpointer arg;
1055 } MonoFtnDesc;
1056
1057 typedef enum {
1058 #define PATCH_INFO(a,b) MONO_PATCH_INFO_ ## a,
1059 #include "patch-info.h"
1060 #undef PATCH_INFO
1061 MONO_PATCH_INFO_NUM
1062 } MonoJumpInfoType;
1063
1064 /*
1065 * We need to store the image which the token refers to along with the token,
1066 * since the image might not be the same as the image of the method which
1067 * contains the relocation, because of inlining.
1068 */
1069 typedef struct MonoJumpInfoToken {
1070 MonoImage *image;
1071 guint32 token;
1072 gboolean has_context;
1073 MonoGenericContext context;
1074 } MonoJumpInfoToken;
1075
1076 typedef struct MonoJumpInfoBBTable {
1077 MonoBasicBlock **table;
1078 int table_size;
1079 } MonoJumpInfoBBTable;
1080
1081 typedef struct MonoJumpInfoRgctxEntry MonoJumpInfoRgctxEntry;
1082
1083 /* Contains information describing an LLVM IMT trampoline */
1084 typedef struct MonoJumpInfoImtTramp {
1085 MonoMethod *method;
1086 int vt_offset;
1087 } MonoJumpInfoImtTramp;
1088
1089 typedef struct MonoJumpInfoGSharedVtCall MonoJumpInfoGSharedVtCall;
1090
1091 /*
1092 * Represents the method which is called when a virtual call is made to METHOD
1093 * on a receiver of type KLASS.
1094 */
1095 typedef struct {
1096 /* Receiver class */
1097 MonoClass *klass;
1098 /* Virtual method */
1099 MonoMethod *method;
1100 } MonoJumpInfoVirtMethod;
1101
1102 typedef struct MonoJumpInfo MonoJumpInfo;
1103 struct MonoJumpInfo {
1104 MonoJumpInfo *next;
1105 /* Relocation type for patching */
1106 int relocation;
1107 union {
1108 int i;
1109 guint8 *p;
1110 MonoInst *label;
1111 } ip;
1112
1113 MonoJumpInfoType type;
1114 union {
1115 gconstpointer target;
1116 #if SIZEOF_VOID_P == 8
1117 gint64 offset;
1118 #else
1119 int offset;
1120 #endif
1121 int index;
1122 MonoBasicBlock *bb;
1123 MonoInst *inst;
1124 MonoMethod *method;
1125 MonoClass *klass;
1126 MonoClassField *field;
1127 MonoImage *image;
1128 MonoVTable *vtable;
1129 const char *name;
1130 MonoJumpInfoToken *token;
1131 MonoJumpInfoBBTable *table;
1132 MonoJumpInfoRgctxEntry *rgctx_entry;
1133 MonoJumpInfoImtTramp *imt_tramp;
1134 MonoJumpInfoGSharedVtCall *gsharedvt;
1135 MonoGSharedVtMethodInfo *gsharedvt_method;
1136 MonoMethodSignature *sig;
1137 MonoDelegateClassMethodPair *del_tramp;
1138 /* MONO_PATCH_INFO_VIRT_METHOD */
1139 MonoJumpInfoVirtMethod *virt_method;
1140 } data;
1141 };
1142
1143 /*
1144 * Contains information for computing the
1145 * property given by INFO_TYPE of the runtime
1146 * object described by DATA.
1147 */
1148 struct MonoJumpInfoRgctxEntry {
1149 MonoMethod *method;
1150 gboolean in_mrgctx;
1151 MonoJumpInfo *data; /* describes the data to be loaded */
1152 MonoRgctxInfoType info_type;
1153 };
1154
1155 /* Contains information about a gsharedvt call */
1156 struct MonoJumpInfoGSharedVtCall {
1157 /* The original signature of the call */
1158 MonoMethodSignature *sig;
1159 /* The method which is called */
1160 MonoMethod *method;
1161 };
1162
1163 typedef enum {
1164 MONO_TRAMPOLINE_JIT,
1165 MONO_TRAMPOLINE_JUMP,
1166 MONO_TRAMPOLINE_RGCTX_LAZY_FETCH,
1167 MONO_TRAMPOLINE_AOT,
1168 MONO_TRAMPOLINE_AOT_PLT,
1169 MONO_TRAMPOLINE_DELEGATE,
1170 MONO_TRAMPOLINE_RESTORE_STACK_PROT,
1171 MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING,
1172 MONO_TRAMPOLINE_VCALL,
1173 MONO_TRAMPOLINE_NUM
1174 } MonoTrampolineType;
1175
1176 /* These trampolines return normally to their caller */
1177 #define MONO_TRAMPOLINE_TYPE_MUST_RETURN(t) \
1178 ((t) == MONO_TRAMPOLINE_RESTORE_STACK_PROT || \
1179 (t) == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
1180
1181 /* These trampolines receive an argument directly in a register */
1182 #define MONO_TRAMPOLINE_TYPE_HAS_ARG(t) \
1183 (FALSE)
1184
1185 /* optimization flags */
1186 #define OPTFLAG(id,shift,name,descr) MONO_OPT_ ## id = 1 << shift,
1187 enum {
1188 #include "optflags-def.h"
1189 MONO_OPT_LAST
1190 };
1191
1192 /*
1193 * This structure represents a JIT backend.
1194 */
1195 typedef struct {
1196 guint have_card_table_wb : 1;
1197 guint have_op_generic_class_init : 1;
1198 guint emulate_mul_div : 1;
1199 guint emulate_div : 1;
1200 guint emulate_long_shift_opts : 1;
1201 guint have_objc_get_selector : 1;
1202 guint have_generalized_imt_trampoline : 1;
1203 guint have_liverange_ops: 1;
1204 guint have_op_tail_call : 1;
1205 guint have_dummy_init : 1;
1206 guint gshared_supported : 1;
1207 guint use_fpstack : 1;
1208 guint ilp32 : 1;
1209 guint need_got_var : 1;
1210 guint need_div_check : 1;
1211 guint no_unaligned_access : 1;
1212 guint disable_div_with_mul : 1;
1213 int monitor_enter_adjustment;
1214 int dyn_call_param_area;
1215 } MonoBackend;
1216
1217 /* Flags for mini_method_compile () */
1218 typedef enum {
1219 /* Whenever to run cctors during JITting */
1220 JIT_FLAG_RUN_CCTORS = (1 << 0),
1221 /* Whenever this is an AOT compilation */
1222 JIT_FLAG_AOT = (1 << 1),
1223 /* Whenever this is a full AOT compilation */
1224 JIT_FLAG_FULL_AOT = (1 << 2),
1225 /* Whenever to compile with LLVM */
1226 JIT_FLAG_LLVM = (1 << 3),
1227 /* Whenever to disable direct calls to icall functions */
1228 JIT_FLAG_NO_DIRECT_ICALLS = (1 << 4),
1229 /* Emit explicit null checks */
1230 JIT_FLAG_EXPLICIT_NULL_CHECKS = (1 << 5),
1231 /* Whenever to compile in llvm-only mode */
1232 JIT_FLAG_LLVM_ONLY = (1 << 6),
1233 /* Whenever calls to pinvoke functions are made directly */
1234 JIT_FLAG_DIRECT_PINVOKE = (1 << 7),
1235 /* Whenever this is a compile-all run and the result should be discarded */
1236 JIT_FLAG_DISCARD_RESULTS = (1 << 8),
1237 } JitFlags;
1238
1239 /* Bit-fields in the MonoBasicBlock.region */
1240 #define MONO_REGION_TRY 0
1241 #define MONO_REGION_FINALLY 16
1242 #define MONO_REGION_CATCH 32
1243 #define MONO_REGION_FAULT 64 /* Currently unused */
1244 #define MONO_REGION_FILTER 128
1245
1246 #define MONO_BBLOCK_IS_IN_REGION(bblock, regtype) (((bblock)->region & (0xf << 4)) == (regtype))
1247
1248 #define MONO_REGION_FLAGS(region) ((region) & 0x7)
1249 #define MONO_REGION_CLAUSE_INDEX(region) (((region) >> 8) - 1)
1250
1251 #define get_vreg_to_inst(cfg, vreg) ((vreg) < (cfg)->vreg_to_inst_len ? (cfg)->vreg_to_inst [(vreg)] : NULL)
1252
1253 #define vreg_is_volatile(cfg, vreg) (G_UNLIKELY (get_vreg_to_inst ((cfg), (vreg)) && (get_vreg_to_inst ((cfg), (vreg))->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT))))
1254
1255 #define vreg_is_ref(cfg, vreg) ((vreg) < (cfg)->vreg_is_ref_len ? (cfg)->vreg_is_ref [(vreg)] : 0)
1256 #define vreg_is_mp(cfg, vreg) ((vreg) < (cfg)->vreg_is_mp_len ? (cfg)->vreg_is_mp [(vreg)] : 0)
1257
1258 /*
1259 * Control Flow Graph and compilation unit information
1260 */
1261 typedef struct {
1262 MonoMethod *method;
1263 MonoMethodHeader *header;
1264 MonoMemPool *mempool;
1265 MonoInst **varinfo;
1266 MonoMethodVar *vars;
1267 MonoInst *ret;
1268 MonoBasicBlock *bb_entry;
1269 MonoBasicBlock *bb_exit;
1270 MonoBasicBlock *bb_init;
1271 MonoBasicBlock **bblocks;
1272 MonoBasicBlock **cil_offset_to_bb;
1273 MonoMemPool *state_pool; /* used by instruction selection */
1274 MonoBasicBlock *cbb; /* used by instruction selection */
1275 MonoInst *prev_ins; /* in decompose */
1276 MonoJumpInfo *patch_info;
1277 MonoJitInfo *jit_info;
1278 MonoJitDynamicMethodInfo *dynamic_info;
1279 guint num_bblocks, max_block_num;
1280 guint locals_start;
1281 guint num_varinfo; /* used items in varinfo */
1282 guint varinfo_count; /* total storage in varinfo */
1283 gint stack_offset;
1284 gint max_ireg;
1285 gint cil_offset_to_bb_len;
1286 MonoRegState *rs;
1287 MonoSpillInfo *spill_info [16]; /* machine register spills */
1288 gint spill_count;
1289 gint spill_info_len [16];
1290 /* unsigned char *cil_code; */
1291 MonoMethod *inlined_method; /* the method which is currently inlined */
1292 MonoInst *domainvar; /* a cache for the current domain */
1293 MonoInst *got_var; /* Global Offset Table variable */
1294 MonoInst **locals;
1295 MonoInst *rgctx_var; /* Runtime generic context variable (for static generic methods) */
1296 MonoInst **args;
1297 MonoType **arg_types;
1298 MonoMethod *current_method; /* The method currently processed by method_to_ir () */
1299 MonoMethod *method_to_register; /* The method to register in JIT info tables */
1300 MonoGenericContext *generic_context;
1301 MonoInst *this_arg;
1302
1303 MonoBackend *backend;
1304
1305 /*
1306 * This variable represents the hidden argument holding the vtype
1307 * return address. If the method returns something other than a vtype, or
1308 * the vtype is returned in registers this is NULL.
1309 */
1310 MonoInst *vret_addr;
1311
1312 /*
1313 * This is used to initialize the cil_code field of MonoInst's.
1314 */
1315 const unsigned char *ip;
1316
1317 struct MonoAliasingInformation *aliasing_info;
1318
1319 /* A hashtable of region ID-> SP var mappings */
1320 /* An SP var is a place to store the stack pointer (used by handlers)*/
1321 /*
1322 * FIXME We can potentially get rid of this, since it was mainly used
1323 * for hijacking return address for handler.
1324 */
1325 GHashTable *spvars;
1326
1327 /*
1328 * A hashtable of region ID -> EX var mappings
1329 * An EX var stores the exception object passed to catch/filter blocks
1330 * For finally blocks, it is set to TRUE if we should throw an abort
1331 * once the execution of the finally block is over.
1332 */
1333 GHashTable *exvars;
1334
1335 GList *ldstr_list; /* used by AOT */
1336
1337 MonoDomain *domain;
1338
1339 guint real_offset;
1340 GHashTable *cbb_hash;
1341
1342 /* The current virtual register number */
1343 guint32 next_vreg;
1344
1345 MonoGenericSharingContext gsctx;
1346 MonoGenericContext *gsctx_context;
1347
1348 MonoGSharedVtMethodInfo *gsharedvt_info;
1349
1350 /* Points to the gsharedvt locals area at runtime */
1351 MonoInst *gsharedvt_locals_var;
1352
1353 /* The localloc instruction used to initialize gsharedvt_locals_var */
1354 MonoInst *gsharedvt_locals_var_ins;
1355
1356 /* Points to a MonoGSharedVtMethodRuntimeInfo at runtime */
1357 MonoInst *gsharedvt_info_var;
1358
1359 /* For native-to-managed wrappers, CEE_MONO_JIT_(AT|DE)TACH opcodes */
1360 MonoInst *orig_domain_var;
1361
1362 MonoInst *lmf_var;
1363 MonoInst *lmf_addr_var;
1364
1365 MonoInst *stack_inbalance_var;
1366
1367 unsigned char *cil_start;
1368 unsigned char *native_code;
1369 guint code_size;
1370 guint code_len;
1371 guint prolog_end;
1372 guint epilog_begin;
1373 guint epilog_end;
1374 regmask_t used_int_regs;
1375 guint32 opt;
1376 guint32 flags;
1377 guint32 comp_done;
1378 guint32 verbose_level;
1379 guint32 stack_usage;
1380 guint32 param_area;
1381 guint32 frame_reg;
1382 gint32 sig_cookie;
1383 guint disable_aot : 1;
1384 guint disable_ssa : 1;
1385 guint disable_llvm : 1;
1386 guint enable_extended_bblocks : 1;
1387 guint run_cctors : 1;
1388 guint need_lmf_area : 1;
1389 guint compile_aot : 1;
1390 guint full_aot : 1;
1391 guint compile_llvm : 1;
1392 guint got_var_allocated : 1;
1393 guint ret_var_is_local : 1;
1394 guint ret_var_set : 1;
1395 guint unverifiable : 1;
1396 guint skip_visibility : 1;
1397 guint disable_reuse_registers : 1;
1398 guint disable_reuse_stack_slots : 1;
1399 guint disable_reuse_ref_stack_slots : 1;
1400 guint disable_ref_noref_stack_slot_share : 1;
1401 guint disable_initlocals_opt : 1;
1402 guint disable_initlocals_opt_refs : 1;
1403 guint disable_omit_fp : 1;
1404 guint disable_vreg_to_lvreg : 1;
1405 guint disable_deadce_vars : 1;
1406 guint disable_out_of_line_bblocks : 1;
1407 guint disable_direct_icalls : 1;
1408 guint disable_gc_safe_points : 1;
1409 guint direct_pinvoke : 1;
1410 guint create_lmf_var : 1;
1411 /*
1412 * When this is set, the code to push/pop the LMF from the LMF stack is generated as IR
1413 * instead of being generated in emit_prolog ()/emit_epilog ().
1414 */
1415 guint lmf_ir : 1;
1416 /*
1417 * Whenever to use the mono_lmf TLS variable instead of indirection through the
1418 * mono_lmf_addr TLS variable.
1419 */
1420 guint gen_write_barriers : 1;
1421 guint init_ref_vars : 1;
1422 guint extend_live_ranges : 1;
1423 guint compute_precise_live_ranges : 1;
1424 guint has_got_slots : 1;
1425 guint uses_rgctx_reg : 1;
1426 guint uses_vtable_reg : 1;
1427 guint uses_simd_intrinsics : 1;
1428 guint keep_cil_nops : 1;
1429 guint gen_seq_points : 1;
1430 /* Generate seq points for use by the debugger */
1431 guint gen_sdb_seq_points : 1;
1432 guint explicit_null_checks : 1;
1433 guint compute_gc_maps : 1;
1434 guint soft_breakpoints : 1;
1435 guint arch_eh_jit_info : 1;
1436 guint has_emulated_ops : 1;
1437 guint has_indirection : 1;
1438 guint has_atomic_add_i4 : 1;
1439 guint has_atomic_exchange_i4 : 1;
1440 guint has_atomic_cas_i4 : 1;
1441 guint check_pinvoke_callconv : 1;
1442 guint has_unwind_info_for_epilog : 1;
1443 guint disable_inline : 1;
1444 /* Disable inlining into caller */
1445 guint no_inline : 1;
1446 guint gshared : 1;
1447 guint gsharedvt : 1;
1448 guint r4fp : 1;
1449 guint llvm_only : 1;
1450 int r4_stack_type;
1451 gpointer debug_info;
1452 guint32 lmf_offset;
1453 guint16 *intvars;
1454 MonoProfilerCoverageInfo *coverage_info;
1455 GHashTable *token_info_hash;
1456 MonoCompileArch arch;
1457 guint32 inline_depth;
1458 /* Size of memory reserved for thunks */
1459 int thunk_area;
1460 /* Thunks */
1461 guint8 *thunks;
1462 /* Offset between the start of code and the thunks area */
1463 int thunks_offset;
1464 MonoExceptionType exception_type; /* MONO_EXCEPTION_* */
1465 guint32 exception_data;
1466 char* exception_message;
1467 gpointer exception_ptr;
1468
1469 guint8 * encoded_unwind_ops;
1470 guint32 encoded_unwind_ops_len;
1471 GSList* unwind_ops;
1472
1473 GList* dont_inline;
1474
1475 /* Fields used by the local reg allocator */
1476 void* reginfo;
1477 int reginfo_len;
1478
1479 /* Maps vregs to their associated MonoInst's */
1480 /* vregs with an associated MonoInst are 'global' while others are 'local' */
1481 MonoInst **vreg_to_inst;
1482
1483 /* Size of above array */
1484 guint32 vreg_to_inst_len;
1485
1486 /* Marks vregs which hold a GC ref */
1487 /* FIXME: Use a bitmap */
1488 gboolean *vreg_is_ref;
1489
1490 /* Size of above array */
1491 guint32 vreg_is_ref_len;
1492
1493 /* Marks vregs which hold a managed pointer */
1494 /* FIXME: Use a bitmap */
1495 gboolean *vreg_is_mp;
1496
1497 /* Size of above array */
1498 guint32 vreg_is_mp_len;
1499
1500 /*
1501 * The original method to compile, differs from 'method' when doing generic
1502 * sharing.
1503 */
1504 MonoMethod *orig_method;
1505
1506 /* Patches which describe absolute addresses embedded into the native code */
1507 GHashTable *abs_patches;
1508
1509 /* If the arch passes valuetypes by address, then for methods
1510 which use JMP the arch code should use these local
1511 variables to store the addresses of incoming valuetypes.
1512 The addresses should be stored in mono_arch_emit_prolog()
1513 and can be used when emitting code for OP_JMP. See
1514 mini-ppc.c. */
1515 MonoInst **tailcall_valuetype_addrs;
1516
1517 /* Used to implement move_i4_to_f on archs that can't do raw
1518 copy between an ireg and a freg. This is an int32 var.*/
1519 MonoInst *iconv_raw_var;
1520
1521 /* Used to implement fconv_to_r8_x. This is a double (8 bytes) var.*/
1522 MonoInst *fconv_to_r8_x_var;
1523
1524 /*Use to implement simd constructors. This is a vector (16 bytes) var.*/
1525 MonoInst *simd_ctor_var;
1526
1527 /* Used to implement dyn_call */
1528 MonoInst *dyn_call_var;
1529
1530 /*
1531 * List of sequence points represented as IL offset+native offset pairs.
1532 * Allocated using glib.
1533 * IL offset can be -1 or 0xffffff to refer to the sequence points
1534 * inside the prolog and epilog used to implement method entry/exit events.
1535 */
1536 GPtrArray *seq_points;
1537
1538 /* The encoded sequence point info */
1539 struct MonoSeqPointInfo *seq_point_info;
1540
1541 /* Method headers which need to be freed after compilation */
1542 GSList *headers_to_free;
1543
1544 /* Used by AOT */
1545 guint32 got_offset, ex_info_offset, method_info_offset, method_index;
1546 /* Symbol used to refer to this method in generated assembly */
1547 char *asm_symbol;
1548 char *asm_debug_symbol;
1549 char *llvm_method_name;
1550 int castclass_cache_index;
1551
1552 MonoJitExceptionInfo *llvm_ex_info;
1553 guint32 llvm_ex_info_len;
1554 int llvm_this_reg, llvm_this_offset;
1555
1556 GSList *try_block_holes;
1557
1558 /* DWARF location list for 'this' */
1559 GSList *this_loclist;
1560
1561 /* DWARF location list for 'rgctx_var' */
1562 GSList *rgctx_loclist;
1563
1564 int *gsharedvt_vreg_to_idx;
1565
1566 GSList *signatures;
1567
1568 /* GC Maps */
1569
1570 /* The offsets of the locals area relative to the frame pointer */
1571 gint locals_min_stack_offset, locals_max_stack_offset;
1572
1573 /* The current CFA rule */
1574 int cur_cfa_reg, cur_cfa_offset;
1575
1576 /* The final CFA rule at the end of the prolog */
1577 int cfa_reg, cfa_offset;
1578
1579 /* Points to a MonoCompileGC */
1580 gpointer gc_info;
1581
1582 /*
1583 * The encoded GC map along with its size. This contains binary data so it can be saved in an AOT
1584 * image etc, but it requires a 4 byte alignment.
1585 */
1586 guint8 *gc_map;
1587 guint32 gc_map_size;
1588
1589 /* Error handling */
1590 MonoError error;
1591
1592 /* pointer to context datastructure used for graph dumping */
1593 MonoGraphDumper *gdump_ctx;
1594
1595 /* Stats */
1596 int stat_allocate_var;
1597 int stat_locals_stack_size;
1598 int stat_basic_blocks;
1599 int stat_cil_code_size;
1600 int stat_n_regvars;
1601 int stat_inlineable_methods;
1602 int stat_inlined_methods;
1603 int stat_code_reallocs;
1604
1605 MonoProfilerCallInstrumentationFlags prof_flags;
1606
1607 /* For deduplication */
1608 gboolean skip;
1609 } MonoCompile;
1610
1611 #define MONO_CFG_PROFILE(cfg, flag) \
1612 G_UNLIKELY ((cfg)->prof_flags & MONO_PROFILER_CALL_INSTRUMENTATION_ ## flag)
1613
1614 #define MONO_CFG_PROFILE_CALL_CONTEXT(cfg) \
1615 (MONO_CFG_PROFILE (cfg, ENTER_CONTEXT) || MONO_CFG_PROFILE (cfg, LEAVE_CONTEXT))
1616
1617 typedef enum {
1618 MONO_CFG_HAS_ALLOCA = 1 << 0,
1619 MONO_CFG_HAS_CALLS = 1 << 1,
1620 MONO_CFG_HAS_LDELEMA = 1 << 2,
1621 MONO_CFG_HAS_VARARGS = 1 << 3,
1622 MONO_CFG_HAS_TAIL = 1 << 4,
1623 MONO_CFG_HAS_FPOUT = 1 << 5, /* there are fp values passed in int registers */
1624 MONO_CFG_HAS_SPILLUP = 1 << 6, /* spill var slots are allocated from bottom to top */
1625 MONO_CFG_HAS_CHECK_THIS = 1 << 7,
1626 MONO_CFG_HAS_ARRAY_ACCESS = 1 << 8,
1627 MONO_CFG_HAS_TYPE_CHECK = 1 << 9
1628 } MonoCompileFlags;
1629
1630 typedef struct {
1631 gint32 methods_compiled;
1632 gint32 methods_aot;
1633 gint32 methods_lookups;
1634 gint32 allocate_var;
1635 gint32 cil_code_size;
1636 gint32 native_code_size;
1637 gint32 code_reallocs;
1638 gint32 max_code_size_ratio;
1639 gint32 biggest_method_size;
1640 gint32 allocated_code_size;
1641 gint32 allocated_seq_points_size;
1642 gint32 inlineable_methods;
1643 gint32 inlined_methods;
1644 gint32 basic_blocks;
1645 gint32 max_basic_blocks;
1646 gint32 locals_stack_size;
1647 gint32 regvars;
1648 gint32 generic_virtual_invocations;
1649 gint32 alias_found;
1650 gint32 alias_removed;
1651 gint32 loads_eliminated;
1652 gint32 stores_eliminated;
1653 gint32 optimized_divisions;
1654 gint32 methods_with_llvm;
1655 gint32 methods_without_llvm;
1656 char *max_ratio_method;
1657 char *biggest_method;
1658 gdouble jit_method_to_ir;
1659 gdouble jit_liveness_handle_exception_clauses;
1660 gdouble jit_handle_out_of_line_bblock;
1661 gdouble jit_decompose_long_opts;
1662 gdouble jit_decompose_typechecks;
1663 gdouble jit_local_cprop;
1664 gdouble jit_local_emulate_ops;
1665 gdouble jit_optimize_branches;
1666 gdouble jit_handle_global_vregs;
1667 gdouble jit_local_deadce;
1668 gdouble jit_local_alias_analysis;
1669 gdouble jit_if_conversion;
1670 gdouble jit_bb_ordering;
1671 gdouble jit_compile_dominator_info;
1672 gdouble jit_compute_natural_loops;
1673 gdouble jit_insert_safepoints;
1674 gdouble jit_ssa_compute;
1675 gdouble jit_ssa_cprop;
1676 gdouble jit_ssa_deadce;
1677 gdouble jit_perform_abc_removal;
1678 gdouble jit_ssa_remove;
1679 gdouble jit_local_cprop2;
1680 gdouble jit_handle_global_vregs2;
1681 gdouble jit_local_deadce2;
1682 gdouble jit_optimize_branches2;
1683 gdouble jit_decompose_vtype_opts;
1684 gdouble jit_decompose_array_access_opts;
1685 gdouble jit_liveness_handle_exception_clauses2;
1686 gdouble jit_analyze_liveness;
1687 gdouble jit_linear_scan;
1688 gdouble jit_arch_allocate_vars;
1689 gdouble jit_spill_global_vars;
1690 gdouble jit_local_cprop3;
1691 gdouble jit_local_deadce3;
1692 gdouble jit_codegen;
1693 gdouble jit_create_jit_info;
1694 gdouble jit_gc_create_gc_map;
1695 gdouble jit_save_seq_point_info;
1696 gdouble jit_time;
1697 gboolean enabled;
1698 } MonoJitStats;
1699
1700 extern MonoJitStats mono_jit_stats;
1701
1702 /* opcodes: value assigned after all the CIL opcodes */
1703 #ifdef MINI_OP
1704 #undef MINI_OP
1705 #endif
1706 #ifdef MINI_OP3
1707 #undef MINI_OP3
1708 #endif
1709 #define MINI_OP(a,b,dest,src1,src2) a,
1710 #define MINI_OP3(a,b,dest,src1,src2,src3) a,
1711 enum {
1712 OP_START = MONO_CEE_LAST - 1,
1713 #include "mini-ops.h"
1714 OP_LAST
1715 };
1716 #undef MINI_OP
1717 #undef MINI_OP3
1718
1719 #if SIZEOF_VOID_P == 8
1720 #define OP_PCONST OP_I8CONST
1721 #define OP_DUMMY_PCONST OP_DUMMY_I8CONST
1722 #define OP_PADD OP_LADD
1723 #define OP_PADD_IMM OP_LADD_IMM
1724 #define OP_PSUB_IMM OP_LSUB_IMM
1725 #define OP_PAND_IMM OP_LAND_IMM
1726 #define OP_PXOR_IMM OP_LXOR_IMM
1727 #define OP_PSUB OP_LSUB
1728 #define OP_PMUL OP_LMUL
1729 #define OP_PMUL_IMM OP_LMUL_IMM
1730 #define OP_PNEG OP_LNEG
1731 #define OP_PCONV_TO_I1 OP_LCONV_TO_I1
1732 #define OP_PCONV_TO_U1 OP_LCONV_TO_U1
1733 #define OP_PCONV_TO_I2 OP_LCONV_TO_I2
1734 #define OP_PCONV_TO_U2 OP_LCONV_TO_U2
1735 #define OP_PCONV_TO_OVF_I1_UN OP_LCONV_TO_OVF_I1_UN
1736 #define OP_PCONV_TO_OVF_I1 OP_LCONV_TO_OVF_I1
1737 #define OP_PBEQ OP_LBEQ
1738 #define OP_PCEQ OP_LCEQ
1739 #define OP_PBNE_UN OP_LBNE_UN
1740 #define OP_PBGE_UN OP_LBGE_UN
1741 #define OP_PBLT_UN OP_LBLT_UN
1742 #define OP_PBGE OP_LBGE
1743 #define OP_STOREP_MEMBASE_REG OP_STOREI8_MEMBASE_REG
1744 #define OP_STOREP_MEMBASE_IMM OP_STOREI8_MEMBASE_IMM
1745 #else
1746 #define OP_PCONST OP_ICONST
1747 #define OP_DUMMY_PCONST OP_DUMMY_ICONST
1748 #define OP_PADD OP_IADD
1749 #define OP_PADD_IMM OP_IADD_IMM
1750 #define OP_PSUB_IMM OP_ISUB_IMM
1751 #define OP_PAND_IMM OP_IAND_IMM
1752 #define OP_PXOR_IMM OP_IXOR_IMM
1753 #define OP_PSUB OP_ISUB
1754 #define OP_PMUL OP_IMUL
1755 #define OP_PMUL_IMM OP_IMUL_IMM
1756 #define OP_PNEG OP_INEG
1757 #define OP_PCONV_TO_I1 OP_ICONV_TO_I1
1758 #define OP_PCONV_TO_U1 OP_ICONV_TO_U1
1759 #define OP_PCONV_TO_I2 OP_ICONV_TO_I2
1760 #define OP_PCONV_TO_U2 OP_ICONV_TO_U2
1761 #define OP_PCONV_TO_OVF_I1_UN OP_ICONV_TO_OVF_I1_UN
1762 #define OP_PCONV_TO_OVF_I1 OP_ICONV_TO_OVF_I1
1763 #define OP_PBEQ OP_IBEQ
1764 #define OP_PCEQ OP_ICEQ
1765 #define OP_PBNE_UN OP_IBNE_UN
1766 #define OP_PBGE_UN OP_IBGE_UN
1767 #define OP_PBLT_UN OP_IBLT_UN
1768 #define OP_PBGE OP_IBGE
1769 #define OP_STOREP_MEMBASE_REG OP_STOREI4_MEMBASE_REG
1770 #define OP_STOREP_MEMBASE_IMM OP_STOREI4_MEMBASE_IMM
1771 #endif
1772
1773 /* Opcodes to load/store regsize quantities */
1774 #if defined (__mono_ilp32__)
1775 #define OP_LOADR_MEMBASE OP_LOADI8_MEMBASE
1776 #define OP_STORER_MEMBASE_REG OP_STOREI8_MEMBASE_REG
1777 #else
1778 #define OP_LOADR_MEMBASE OP_LOAD_MEMBASE
1779 #define OP_STORER_MEMBASE_REG OP_STORE_MEMBASE_REG
1780 #endif
1781
1782 typedef enum {
1783 STACK_INV,
1784 STACK_I4,
1785 STACK_I8,
1786 STACK_PTR,
1787 STACK_R8,
1788 STACK_MP,
1789 STACK_OBJ,
1790 STACK_VTYPE,
1791 STACK_R4,
1792 STACK_MAX
1793 } MonoStackType;
1794
1795 typedef struct {
1796 union {
1797 double r8;
1798 gint32 i4;
1799 gint64 i8;
1800 gpointer p;
1801 MonoClass *klass;
1802 } data;
1803 int type;
1804 } StackSlot;
1805
1806 extern const char MONO_ARCH_CPU_SPEC [];
1807 #define MONO_ARCH_CPU_SPEC_IDX_COMBINE(a) a ## _idx
1808 #define MONO_ARCH_CPU_SPEC_IDX(a) MONO_ARCH_CPU_SPEC_IDX_COMBINE(a)
1809 extern const guint16 MONO_ARCH_CPU_SPEC_IDX(MONO_ARCH_CPU_SPEC) [];
1810 #define ins_get_spec(op) ((const char*)&MONO_ARCH_CPU_SPEC + MONO_ARCH_CPU_SPEC_IDX(MONO_ARCH_CPU_SPEC)[(op) - OP_LOAD])
1811
1812 enum {
1813 MONO_COMP_DOM = 1,
1814 MONO_COMP_IDOM = 2,
1815 MONO_COMP_DFRONTIER = 4,
1816 MONO_COMP_DOM_REV = 8,
1817 MONO_COMP_LIVENESS = 16,
1818 MONO_COMP_SSA = 32,
1819 MONO_COMP_SSA_DEF_USE = 64,
1820 MONO_COMP_REACHABILITY = 128,
1821 MONO_COMP_LOOPS = 256
1822 };
1823
1824 typedef enum {
1825 MONO_GRAPH_CFG = 1,
1826 MONO_GRAPH_DTREE = 2,
1827 MONO_GRAPH_CFG_CODE = 4,
1828 MONO_GRAPH_CFG_SSA = 8,
1829 MONO_GRAPH_CFG_OPTCODE = 16
1830 } MonoGraphOptions;
1831
1832 typedef struct {
1833 guint16 size;
1834 guint16 offset;
1835 guint8 pad;
1836 } MonoJitArgumentInfo;
1837
1838 typedef struct {
1839 gboolean handle_sigint;
1840 gboolean keep_delegates;
1841 gboolean reverse_pinvoke_exceptions;
1842 gboolean collect_pagefault_stats;
1843 gboolean break_on_unverified;
1844 gboolean better_cast_details;
1845 gboolean mdb_optimizations;
1846 gboolean no_gdb_backtrace;
1847 gboolean suspend_on_native_crash;
1848 gboolean suspend_on_exception;
1849 gboolean suspend_on_unhandled;
1850 gboolean dyn_runtime_invoke;
1851 gboolean gdb;
1852 gboolean lldb;
1853 gboolean use_fallback_tls;
1854 /*
1855 * Whenever data such as next sequence points and flags is required.
1856 * Next sequence points and flags are required by the debugger agent.
1857 */
1858 gboolean gen_sdb_seq_points;
1859 gboolean no_seq_points_compact_data;
1860 /*
1861 * Setting single_imm_size should guarantee that each time managed code is compiled
1862 * the same instructions and registers are used, regardless of the size of used values.
1863 */
1864 gboolean single_imm_size;
1865 gboolean explicit_null_checks;
1866 /*
1867 * Fill stack frames with 0x2a in method prologs. This helps with the
1868 * debugging of the stack marking code in the GC.
1869 */
1870 gboolean init_stacks;
1871
1872 /*
1873 * Whenever to implement single stepping and breakpoints without signals in the
1874 * soft debugger. This is useful on platforms without signals, like the ps3, or during
1875 * runtime debugging, since it avoids SIGSEGVs when a single step location or breakpoint
1876 * is hit.
1877 */
1878 gboolean soft_breakpoints;
1879 /*
1880 * Whenever to break in the debugger using G_BREAKPOINT on unhandled exceptions.
1881 */
1882 gboolean break_on_exc;
1883 /*
1884 * Load AOT JIT info eagerly.
1885 */
1886 gboolean load_aot_jit_info_eagerly;
1887 /*
1888 * Check for pinvoke calling convention mismatches.
1889 */
1890 gboolean check_pinvoke_callconv;
1891 /*
1892 * Translate Debugger.Break () into a native breakpoint signal
1893 */
1894 gboolean native_debugger_break;
1895 /*
1896 * Disabling the frame pointer emit optimization can allow debuggers to more easily
1897 * identify the stack on some platforms
1898 */
1899 gboolean disable_omit_fp;
1900 } MonoDebugOptions;
1901
1902 enum {
1903 BRANCH_NOT_TAKEN,
1904 BRANCH_TAKEN,
1905 BRANCH_UNDEF
1906 };
1907
1908 typedef enum {
1909 CMP_EQ,
1910 CMP_NE,
1911 CMP_LE,
1912 CMP_GE,
1913 CMP_LT,
1914 CMP_GT,
1915 CMP_LE_UN,
1916 CMP_GE_UN,
1917 CMP_LT_UN,
1918 CMP_GT_UN
1919 } CompRelation;
1920
1921 typedef enum {
1922 CMP_TYPE_L,
1923 CMP_TYPE_I,
1924 CMP_TYPE_F
1925 } CompType;
1926
1927 /* Implicit exceptions */
1928 enum {
1929 MONO_EXC_INDEX_OUT_OF_RANGE,
1930 MONO_EXC_OVERFLOW,
1931 MONO_EXC_ARITHMETIC,
1932 MONO_EXC_DIVIDE_BY_ZERO,
1933 MONO_EXC_INVALID_CAST,
1934 MONO_EXC_NULL_REF,
1935 MONO_EXC_ARRAY_TYPE_MISMATCH,
1936 MONO_EXC_ARGUMENT,
1937 MONO_EXC_INTRINS_NUM
1938 };
1939
1940 enum {
1941 MINI_TOKEN_SOURCE_CLASS,
1942 MINI_TOKEN_SOURCE_METHOD,
1943 MINI_TOKEN_SOURCE_FIELD
1944 };
1945
1946 /*
1947 * Information about a trampoline function.
1948 */
1949 typedef struct
1950 {
1951 /*
1952 * The native code of the trampoline. Not owned by this structure.
1953 */
1954 guint8 *code;
1955 guint32 code_size;
1956 /*
1957 * The name of the trampoline which can be used in AOT/xdebug. Owned by this
1958 * structure.
1959 */
1960 char *name;
1961 /*
1962 * Patches required by the trampoline when aot-ing. Owned by this structure.
1963 */
1964 MonoJumpInfo *ji;
1965 /*
1966 * Unwind information. Owned by this structure.
1967 */
1968 GSList *unwind_ops;
1969
1970 /*
1971 * Encoded unwind info loaded from AOT images
1972 */
1973 guint8 *uw_info;
1974 guint32 uw_info_len;
1975 /* Whenever uw_info is owned by this structure */
1976 gboolean owns_uw_info;
1977 } MonoTrampInfo;
1978
1979 typedef void (*MonoInstFunc) (MonoInst *tree, gpointer data);
1980
1981 enum {
1982 FILTER_IL_SEQ_POINT = 1 << 0,
1983 FILTER_NOP = 1 << 1,
1984 };
1985
1986 static inline gboolean
mono_inst_filter(MonoInst * ins,int filter)1987 mono_inst_filter (MonoInst *ins, int filter)
1988 {
1989 if (!ins || !filter)
1990 return FALSE;
1991
1992 if ((filter & FILTER_IL_SEQ_POINT) && ins->opcode == OP_IL_SEQ_POINT)
1993 return TRUE;
1994
1995 if ((filter & FILTER_NOP) && ins->opcode == OP_NOP)
1996 return TRUE;
1997
1998 return FALSE;
1999 }
2000
2001 static inline MonoInst*
mono_inst_next(MonoInst * ins,int filter)2002 mono_inst_next (MonoInst *ins, int filter)
2003 {
2004 do {
2005 ins = ins->next;
2006 } while (mono_inst_filter (ins, filter));
2007
2008 return ins;
2009 }
2010
2011 static inline MonoInst*
mono_inst_prev(MonoInst * ins,int filter)2012 mono_inst_prev (MonoInst *ins, int filter)
2013 {
2014 do {
2015 ins = ins->prev;
2016 } while (mono_inst_filter (ins, filter));
2017
2018 return ins;
2019 }
2020
2021 static inline MonoInst*
mono_bb_first_inst(MonoBasicBlock * bb,int filter)2022 mono_bb_first_inst (MonoBasicBlock *bb, int filter)
2023 {
2024 MonoInst *ins = bb->code;
2025 if (mono_inst_filter (ins, filter))
2026 ins = mono_inst_next (ins, filter);
2027
2028 return ins;
2029 }
2030
2031 static inline MonoInst*
mono_bb_last_inst(MonoBasicBlock * bb,int filter)2032 mono_bb_last_inst (MonoBasicBlock *bb, int filter)
2033 {
2034 MonoInst *ins = bb->last_ins;
2035 if (mono_inst_filter (ins, filter))
2036 ins = mono_inst_prev (ins, filter);
2037
2038 return ins;
2039 }
2040
2041 /* profiler support */
2042 void mini_add_profiler_argument (const char *desc);
2043 void mini_profiler_emit_enter (MonoCompile *cfg);
2044 void mini_profiler_emit_leave (MonoCompile *cfg, MonoInst *ret);
2045 void mini_profiler_emit_tail_call (MonoCompile *cfg, MonoMethod *target);
2046 void mini_profiler_context_enable (void);
2047 gpointer mini_profiler_context_get_this (MonoProfilerCallContext *ctx);
2048 gpointer mini_profiler_context_get_argument (MonoProfilerCallContext *ctx, guint32 pos);
2049 gpointer mini_profiler_context_get_local (MonoProfilerCallContext *ctx, guint32 pos);
2050 gpointer mini_profiler_context_get_result (MonoProfilerCallContext *ctx);
2051 void mini_profiler_context_free_buffer (gpointer buffer);
2052
2053 /* graph dumping */
2054 void mono_cfg_dump_create_context (MonoCompile *cfg);
2055 void mono_cfg_dump_begin_group (MonoCompile *cfg);
2056 void mono_cfg_dump_close_group (MonoCompile *cfg);
2057 void mono_cfg_dump_ir (MonoCompile *cfg, const char *phase_name);
2058
2059 /* helper methods */
2060 void mono_set_bisect_methods (guint32 opt, const char *method_list_filename);
2061 guint32 mono_get_optimizations_for_method (MonoMethod *method, guint32 default_opt);
2062 char* mono_opt_descr (guint32 flags);
2063 void mono_set_verbose_level (guint32 level);
2064 MonoJumpInfoToken* mono_jump_info_token_new (MonoMemPool *mp, MonoImage *image, guint32 token);
2065 MonoJumpInfoToken* mono_jump_info_token_new2 (MonoMemPool *mp, MonoImage *image, guint32 token, MonoGenericContext *context);
2066 MonoInst* mono_find_spvar_for_region (MonoCompile *cfg, int region);
2067 MonoInst* mono_find_exvar_for_offset (MonoCompile *cfg, int offset);
2068 int mono_get_block_region_notry (MonoCompile *cfg, int region) MONO_LLVM_INTERNAL;
2069
2070 void mono_bblock_add_inst (MonoBasicBlock *bb, MonoInst *inst) MONO_LLVM_INTERNAL;
2071 void mono_bblock_insert_after_ins (MonoBasicBlock *bb, MonoInst *ins, MonoInst *ins_to_insert);
2072 void mono_bblock_insert_before_ins (MonoBasicBlock *bb, MonoInst *ins, MonoInst *ins_to_insert);
2073 void mono_verify_bblock (MonoBasicBlock *bb);
2074 void mono_verify_cfg (MonoCompile *cfg);
2075 void mono_constant_fold (MonoCompile *cfg);
2076 MonoInst* mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoInst *arg2, gboolean overwrite);
2077 int mono_eval_cond_branch (MonoInst *branch);
2078 int mono_is_power_of_two (guint32 val) MONO_LLVM_INTERNAL;
2079 void mono_cprop_local (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst **acp, int acp_size);
2080 MonoInst* mono_compile_create_var (MonoCompile *cfg, MonoType *type, int opcode);
2081 MonoInst* mono_compile_create_var_for_vreg (MonoCompile *cfg, MonoType *type, int opcode, int vreg);
2082 void mono_compile_make_var_load (MonoCompile *cfg, MonoInst *dest, gssize var_index);
2083 MonoInst* mini_get_int_to_float_spill_area (MonoCompile *cfg);
2084 MonoType* mono_type_from_stack_type (MonoInst *ins);
2085 guint32 mono_alloc_ireg (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2086 guint32 mono_alloc_lreg (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2087 guint32 mono_alloc_freg (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2088 guint32 mono_alloc_preg (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2089 guint32 mono_alloc_dreg (MonoCompile *cfg, MonoStackType stack_type);
2090 guint32 mono_alloc_ireg_ref (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2091 guint32 mono_alloc_ireg_mp (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2092 guint32 mono_alloc_ireg_copy (MonoCompile *cfg, guint32 vreg) MONO_LLVM_INTERNAL;
2093 void mono_mark_vreg_as_ref (MonoCompile *cfg, int vreg);
2094 void mono_mark_vreg_as_mp (MonoCompile *cfg, int vreg);
2095
2096 void mono_link_bblock (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to);
2097 void mono_unlink_bblock (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to);
2098 gboolean mono_bblocks_linked (MonoBasicBlock *bb1, MonoBasicBlock *bb2);
2099 void mono_remove_bblock (MonoCompile *cfg, MonoBasicBlock *bb);
2100 void mono_nullify_basic_block (MonoBasicBlock *bb);
2101 void mono_merge_basic_blocks (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *bbn);
2102 void mono_optimize_branches (MonoCompile *cfg);
2103
2104 void mono_blockset_print (MonoCompile *cfg, MonoBitSet *set, const char *name, guint idom);
2105 const char*mono_ji_type_to_string (MonoJumpInfoType type) MONO_LLVM_INTERNAL;
2106 void mono_print_ji (const MonoJumpInfo *ji);
2107 void mono_print_ins_index (int i, MonoInst *ins);
2108 GString *mono_print_ins_index_strbuf (int i, MonoInst *ins);
2109 void mono_print_ins (MonoInst *ins);
2110 void mono_print_bb (MonoBasicBlock *bb, const char *msg);
2111 void mono_print_code (MonoCompile *cfg, const char *msg);
2112 MONO_API void mono_print_method_from_ip (void *ip);
2113 MONO_API char *mono_pmip (void *ip);
2114 gboolean mono_debug_count (void);
2115 MONO_LLVM_INTERNAL const char* mono_inst_name (int op);
2116 int mono_op_to_op_imm (int opcode);
2117 int mono_op_imm_to_op (int opcode);
2118 int mono_load_membase_to_load_mem (int opcode);
2119 guint mono_type_to_load_membase (MonoCompile *cfg, MonoType *type);
2120 guint mono_type_to_store_membase (MonoCompile *cfg, MonoType *type);
2121 guint32 mono_type_to_stloc_coerce (MonoType *type);
2122 guint mini_type_to_stind (MonoCompile* cfg, MonoType *type);
2123 MonoJitInfo* mini_lookup_method (MonoDomain *domain, MonoMethod *method, MonoMethod *shared);
2124 guint32 mono_reverse_branch_op (guint32 opcode);
2125 void mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id);
2126 void mono_add_patch_info (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target) MONO_LLVM_INTERNAL;
2127 void mono_add_patch_info_rel (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target, int relocation) MONO_LLVM_INTERNAL;
2128 void mono_remove_patch_info (MonoCompile *cfg, int ip);
2129 MonoJumpInfo* mono_patch_info_dup_mp (MonoMemPool *mp, MonoJumpInfo *patch_info);
2130 guint mono_patch_info_hash (gconstpointer data);
2131 gint mono_patch_info_equal (gconstpointer ka, gconstpointer kb);
2132 MonoJumpInfo *mono_patch_info_list_prepend (MonoJumpInfo *list, int ip, MonoJumpInfoType type, gconstpointer target);
2133 gpointer mono_resolve_patch_target (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors, MonoError *error) MONO_LLVM_INTERNAL;
2134 gpointer mono_jit_find_compiled_method_with_jit_info (MonoDomain *domain, MonoMethod *method, MonoJitInfo **ji);
2135 gpointer mono_jit_find_compiled_method (MonoDomain *domain, MonoMethod *method);
2136 gpointer mono_jit_compile_method (MonoMethod *method, MonoError *error);
2137 gpointer mono_jit_compile_method_jit_only (MonoMethod *method, MonoError *error);
2138 gpointer mono_jit_compile_method_inner (MonoMethod *method, MonoDomain *target_domain, int opt, MonoError *error);
2139 MonoInst* mono_create_tls_get (MonoCompile *cfg, MonoTlsKey key);
2140 GList *mono_varlist_insert_sorted (MonoCompile *cfg, GList *list, MonoMethodVar *mv, int sort_type);
2141 GList *mono_varlist_sort (MonoCompile *cfg, GList *list, int sort_type);
2142 void mono_analyze_liveness (MonoCompile *cfg);
2143 void mono_analyze_liveness_gc (MonoCompile *cfg);
2144 void mono_linear_scan (MonoCompile *cfg, GList *vars, GList *regs, regmask_t *used_mask);
2145 void mono_global_regalloc (MonoCompile *cfg);
2146 void mono_create_jump_table (MonoCompile *cfg, MonoInst *label, MonoBasicBlock **bbs, int num_blocks);
2147 MonoCompile *mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, JitFlags flags, int parts, int aot_method_index);
2148 void mono_destroy_compile (MonoCompile *cfg);
2149 void mono_empty_compile (MonoCompile *cfg);
2150 MonoJitICallInfo *mono_find_jit_opcode_emulation (int opcode);
2151 void mono_print_ins_index (int i, MonoInst *ins);
2152 void mono_print_ins (MonoInst *ins);
2153 gboolean mini_assembly_can_skip_verification (MonoDomain *domain, MonoMethod *method);
2154 gboolean mono_compile_is_broken (MonoCompile *cfg, MonoMethod *method, gboolean fail_compile);
2155 MonoInst *mono_get_got_var (MonoCompile *cfg);
2156 void mono_add_seq_point (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, int native_offset);
2157 void mono_add_var_location (MonoCompile *cfg, MonoInst *var, gboolean is_reg, int reg, int offset, int from, int to);
2158 MonoInst* mono_emit_jit_icall (MonoCompile *cfg, gconstpointer func, MonoInst **args);
2159 MonoInst* mono_emit_jit_icall_by_info (MonoCompile *cfg, int il_offset, MonoJitICallInfo *info, MonoInst **args);
2160 MonoInst* mono_emit_method_call (MonoCompile *cfg, MonoMethod *method, MonoInst **args, MonoInst *this_ins);
2161 void mono_create_helper_signatures (void);
2162 MonoInst* mono_emit_native_call (MonoCompile *cfg, gconstpointer func, MonoMethodSignature *sig, MonoInst **args);
2163 gboolean mini_should_insert_breakpoint (MonoMethod *method);
2164
2165 gboolean mini_class_is_system_array (MonoClass *klass);
2166 MonoMethodSignature *mono_get_element_address_signature (int arity);
2167 MonoJitICallInfo *mono_get_element_address_icall (int rank);
2168 MonoJitICallInfo *mono_get_array_new_va_icall (int rank);
2169
2170 void mono_linterval_add_range (MonoCompile *cfg, MonoLiveInterval *interval, int from, int to);
2171 void mono_linterval_print (MonoLiveInterval *interval);
2172 void mono_linterval_print_nl (MonoLiveInterval *interval);
2173 gboolean mono_linterval_covers (MonoLiveInterval *interval, int pos);
2174 gint32 mono_linterval_get_intersect_pos (MonoLiveInterval *i1, MonoLiveInterval *i2);
2175 void mono_linterval_split (MonoCompile *cfg, MonoLiveInterval *interval, MonoLiveInterval **i1, MonoLiveInterval **i2, int pos);
2176 void mono_liveness_handle_exception_clauses (MonoCompile *cfg);
2177
2178 gpointer mono_realloc_native_code (MonoCompile *cfg);
2179
2180 extern MonoDebugOptions debug_options;
2181
2182 static inline MonoMethod*
jinfo_get_method(MonoJitInfo * ji)2183 jinfo_get_method (MonoJitInfo *ji)
2184 {
2185 return mono_jit_info_get_method (ji);
2186 }
2187
2188 void mono_xdebug_init (const char *xdebug_opts);
2189 void mono_save_xdebug_info (MonoCompile *cfg);
2190 void mono_save_trampoline_xdebug_info (MonoTrampInfo *info);
2191 /* This is an exported function */
2192 void mono_xdebug_flush (void);
2193
2194 gboolean mono_method_same_domain (MonoJitInfo *caller, MonoJitInfo *callee);
2195 void mono_register_opcode_emulation (int opcode, const char* name, const char *sigstr, gpointer func, gboolean no_throw);
2196 void mono_draw_graph (MonoCompile *cfg, MonoGraphOptions draw_options);
2197 void mono_add_ins_to_end (MonoBasicBlock *bb, MonoInst *inst);
2198 gpointer mono_create_ftnptr (MonoDomain *domain, gpointer addr);
2199
2200 void mono_replace_ins (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, MonoInst **prev, MonoBasicBlock *first_bb, MonoBasicBlock *last_bb);
2201
2202 int mono_find_method_opcode (MonoMethod *method);
2203 MonoJitICallInfo *mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
2204 gconstpointer mono_icall_get_wrapper (MonoJitICallInfo* callinfo) MONO_LLVM_INTERNAL;
2205 gconstpointer mono_icall_get_wrapper_full (MonoJitICallInfo* callinfo, gboolean do_compile);
2206 void mini_register_opcode_emulation (int opcode, const char *name, const char *sigstr, gpointer func, const char *symbol, gboolean no_throw);
2207
2208 void mono_trampolines_init (void);
2209 void mono_trampolines_cleanup (void);
2210 guint8 * mono_get_trampoline_code (MonoTrampolineType tramp_type);
2211 gpointer mono_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len);
2212 gpointer mono_create_jump_trampoline (MonoDomain *domain,
2213 MonoMethod *method,
2214 gboolean add_sync_wrapper,
2215 MonoError *error);
2216 gpointer mono_create_class_init_trampoline (MonoVTable *vtable);
2217 gpointer mono_create_jit_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error) MONO_LLVM_INTERNAL;
2218 gpointer mono_create_jit_trampoline_from_token (MonoImage *image, guint32 token);
2219 gpointer mono_create_delegate_trampoline (MonoDomain *domain, MonoClass *klass);
2220 MonoDelegateTrampInfo* mono_create_delegate_trampoline_info (MonoDomain *domain, MonoClass *klass, MonoMethod *method);
2221 gpointer mono_create_delegate_virtual_trampoline (MonoDomain *domain, MonoClass *klass, MonoMethod *method);
2222 gpointer mono_create_rgctx_lazy_fetch_trampoline (guint32 offset);
2223 gpointer mono_create_monitor_enter_trampoline (void);
2224 gpointer mono_create_monitor_enter_v4_trampoline (void);
2225 gpointer mono_create_monitor_exit_trampoline (void);
2226 gpointer mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr);
2227 MonoVTable* mono_find_class_init_trampoline_by_addr (gconstpointer addr);
2228 guint32 mono_find_rgctx_lazy_fetch_trampoline_by_addr (gconstpointer addr);
2229 gpointer mono_magic_trampoline (mgreg_t *regs, guint8 *code, gpointer arg, guint8* tramp);
2230 #ifndef DISABLE_REMOTING
2231 gpointer mono_generic_virtual_remoting_trampoline (mgreg_t *regs, guint8 *code, MonoMethod *m, guint8 *tramp);
2232 #endif
2233 gpointer mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *tramp_data, guint8* tramp);
2234 gpointer mono_aot_trampoline (mgreg_t *regs, guint8 *code, guint8 *token_info,
2235 guint8* tramp);
2236 gpointer mono_aot_plt_trampoline (mgreg_t *regs, guint8 *code, guint8 *token_info,
2237 guint8* tramp);
2238 void mono_class_init_trampoline (mgreg_t *regs, guint8 *code, MonoVTable *vtable, guint8 *tramp);
2239 void mono_generic_class_init_trampoline (mgreg_t *regs, guint8 *code, MonoVTable *vtable, guint8 *tramp);
2240 void mono_monitor_enter_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp);
2241 void mono_monitor_enter_v4_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp);
2242 void mono_monitor_exit_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp);
2243 gconstpointer mono_get_trampoline_func (MonoTrampolineType tramp_type);
2244 gpointer mini_get_vtable_trampoline (MonoVTable *vt, int slot_index);
2245 const char* mono_get_generic_trampoline_simple_name (MonoTrampolineType tramp_type);
2246 char* mono_get_generic_trampoline_name (MonoTrampolineType tramp_type);
2247 char* mono_get_rgctx_fetch_trampoline_name (int slot);
2248 gpointer mini_get_nullified_class_init_trampoline (void);
2249 gpointer mini_get_single_step_trampoline (void);
2250 gpointer mini_get_breakpoint_trampoline (void);
2251 gpointer mini_add_method_trampoline (MonoMethod *m, gpointer compiled_method, gboolean add_static_rgctx_tramp, gboolean add_unbox_tramp);
2252 gpointer mini_add_method_wrappers_llvmonly (MonoMethod *m, gpointer compiled_method, gboolean caller_gsharedvt, gboolean add_unbox_tramp, gpointer *out_arg);
2253 gboolean mini_jit_info_is_gsharedvt (MonoJitInfo *ji);
2254 gpointer* mini_resolve_imt_method (MonoVTable *vt, gpointer *vtable_slot, MonoMethod *imt_method, MonoMethod **impl_method, gpointer *out_aot_addr,
2255 gboolean *out_need_rgctx_tramp, MonoMethod **variant_iface,
2256 MonoError *error);
2257 MonoFtnDesc *mini_create_llvmonly_ftndesc (MonoDomain *domain, gpointer addr, gpointer arg);
2258
2259 void* mono_global_codeman_reserve (int size);
2260 void mono_global_codeman_foreach (MonoCodeManagerFunc func, void *user_data);
2261 const char *mono_regname_full (int reg, int bank);
2262 gint32* mono_allocate_stack_slots (MonoCompile *cfg, gboolean backward, guint32 *stack_size, guint32 *stack_align);
2263 void mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb);
2264 MonoInst *mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, const char * exname);
2265 void mono_remove_critical_edges (MonoCompile *cfg);
2266 gboolean mono_is_regsize_var (MonoType *t);
2267 void mini_emit_memcpy (MonoCompile *cfg, int destreg, int doffset, int srcreg, int soffset, int size, int align);
2268 void mini_emit_memset (MonoCompile *cfg, int destreg, int offset, int size, int val, int align);
2269 void mini_emit_stobj (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoClass *klass, gboolean native);
2270 void mini_emit_initobj (MonoCompile *cfg, MonoInst *dest, const guchar *ip, MonoClass *klass);
2271 MonoInst* mini_emit_ldelema_1_ins (MonoCompile *cfg, MonoClass *klass, MonoInst *arr, MonoInst *index, gboolean bcheck);
2272 MonoInst* mini_emit_get_gsharedvt_info_klass (MonoCompile *cfg, MonoClass *klass, MonoRgctxInfoType rgctx_type);
2273 MonoInst* mini_emit_calli (MonoCompile *cfg, MonoMethodSignature *sig, MonoInst **args, MonoInst *addr, MonoInst *imt_arg, MonoInst *rgctx_arg);
2274 MonoInst* mini_emit_memory_barrier (MonoCompile *cfg, int kind);
2275 void mini_emit_write_barrier (MonoCompile *cfg, MonoInst *ptr, MonoInst *value);
2276 MonoInst* mini_emit_memory_load (MonoCompile *cfg, MonoType *type, MonoInst *src, int offset, int ins_flag);
2277 void mini_emit_memory_store (MonoCompile *cfg, MonoType *type, MonoInst *dest, MonoInst *value, int ins_flag);
2278 void mini_emit_memory_copy_bytes (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoInst *size, int ins_flag);
2279 void mini_emit_memory_init_bytes (MonoCompile *cfg, MonoInst *dest, MonoInst *value, MonoInst *size, int ins_flag);
2280 void mini_emit_memory_copy (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoClass *klass, gboolean native, int ins_flag);
2281
2282 MonoMethod* mini_get_memcpy_method (void);
2283 MonoMethod* mini_get_memset_method (void);
2284 int mini_class_check_context_used (MonoCompile *cfg, MonoClass *klass);
2285
2286 CompRelation mono_opcode_to_cond (int opcode) MONO_LLVM_INTERNAL;
2287 CompType mono_opcode_to_type (int opcode, int cmp_opcode);
2288 CompRelation mono_negate_cond (CompRelation cond);
2289 int mono_op_imm_to_op (int opcode);
2290 void mono_decompose_op_imm (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins);
2291 void mono_peephole_ins (MonoBasicBlock *bb, MonoInst *ins);
2292 MonoUnwindOp *mono_create_unwind_op (int when,
2293 int tag, int reg,
2294 int val);
2295 void mono_emit_unwind_op (MonoCompile *cfg, int when,
2296 int tag, int reg,
2297 int val);
2298 MonoTrampInfo* mono_tramp_info_create (const char *name, guint8 *code, guint32 code_size, MonoJumpInfo *ji, GSList *unwind_ops);
2299 void mono_tramp_info_free (MonoTrampInfo *info);
2300 void mono_aot_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain);
2301 void mono_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain);
2302 int mini_exception_id_by_name (const char *name);
2303 gboolean mini_type_is_hfa (MonoType *t, int *out_nfields, int *out_esize) MONO_LLVM_INTERNAL;
2304
2305 int mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_bblock, MonoBasicBlock *end_bblock,
2306 MonoInst *return_var, MonoInst **inline_args,
2307 guint inline_offset, gboolean is_virtual_call);
2308
2309 //the following methods could just be renamed/moved from method-to-ir.c
2310 int mini_inline_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **sp, guchar *ip,
2311 guint real_offset, gboolean inline_always);
2312
2313 MonoInst* mini_emit_get_rgctx_klass (MonoCompile *cfg, int context_used, MonoClass *klass, MonoRgctxInfoType rgctx_type);
2314 MonoInst* mini_emit_runtime_constant (MonoCompile *cfg, MonoJumpInfoType patch_type, gpointer data);
2315 void mini_save_cast_details (MonoCompile *cfg, MonoClass *klass, int obj_reg, gboolean null_check);
2316 void mini_reset_cast_details (MonoCompile *cfg);
2317 void mini_emit_class_check (MonoCompile *cfg, int klass_reg, MonoClass *klass);
2318
2319 gboolean mini_class_has_reference_variant_generic_argument (MonoCompile *cfg, MonoClass *klass, int context_used);
2320
2321 MonoInst *mono_decompose_opcode (MonoCompile *cfg, MonoInst *ins);
2322 void mono_decompose_long_opts (MonoCompile *cfg);
2323 void mono_decompose_vtype_opts (MonoCompile *cfg);
2324 void mono_decompose_array_access_opts (MonoCompile *cfg);
2325 void mono_decompose_soft_float (MonoCompile *cfg);
2326 void mono_local_emulate_ops (MonoCompile *cfg);
2327 void mono_handle_global_vregs (MonoCompile *cfg);
2328 void mono_spill_global_vars (MonoCompile *cfg, gboolean *need_local_opts);
2329 void mono_allocate_gsharedvt_vars (MonoCompile *cfg);
2330 void mono_if_conversion (MonoCompile *cfg);
2331
2332 /* Delegates */
2333 gpointer mini_get_delegate_arg (MonoMethod *method, gpointer method_ptr);
2334 void mini_init_delegate (MonoDelegate *del);
2335 char* mono_get_delegate_virtual_invoke_impl_name (gboolean load_imt_reg, int offset);
2336 gpointer mono_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method);
2337
2338 /* methods that must be provided by the arch-specific port */
2339 void mono_arch_init (void);
2340 void mono_arch_finish_init (void);
2341 void mono_arch_cleanup (void);
2342 void mono_arch_cpu_init (void);
2343 guint32 mono_arch_cpu_optimizations (guint32 *exclude_mask);
2344 void mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code);
2345 void *mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments);
2346 void *mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments);
2347 void *mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers);
2348 void mono_codegen (MonoCompile *cfg);
2349 void mono_call_inst_add_outarg_reg (MonoCompile *cfg, MonoCallInst *call, int vreg, int hreg, int bank) MONO_LLVM_INTERNAL;
2350 void mono_call_inst_add_outarg_vt (MonoCompile *cfg, MonoCallInst *call, MonoInst *outarg_vt);
2351 const char *mono_arch_regname (int reg);
2352 const char *mono_arch_fregname (int reg);
2353 void mono_arch_exceptions_init (void);
2354 guchar* mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot);
2355 gpointer mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot);
2356 gpointer mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot);
2357 gpointer mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info);
2358 guint8* mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot);
2359 gpointer mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot);
2360 gpointer mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot);
2361 guint8 *mono_arch_create_llvm_native_thunk (MonoDomain *domain, guint8* addr) MONO_LLVM_INTERNAL;
2362 gpointer mono_arch_get_get_tls_tramp (void);
2363 GList *mono_arch_get_allocatable_int_vars (MonoCompile *cfg);
2364 GList *mono_arch_get_global_int_regs (MonoCompile *cfg);
2365 GList *mono_arch_get_global_fp_regs (MonoCompile *cfg);
2366 GList *mono_arch_get_iregs_clobbered_by_call (MonoCallInst *call);
2367 GList *mono_arch_get_fregs_clobbered_by_call (MonoCallInst *call);
2368 guint32 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv);
2369 void mono_arch_patch_code (MonoCompile *cfg, MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors, MonoError *error);
2370 void mono_arch_patch_code_new (MonoCompile *cfg, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gpointer target);
2371 void mono_arch_flush_icache (guint8 *code, gint size);
2372 int mono_arch_max_epilog_size (MonoCompile *cfg);
2373 guint8 *mono_arch_emit_prolog (MonoCompile *cfg);
2374 void mono_arch_emit_epilog (MonoCompile *cfg);
2375 void mono_arch_emit_exceptions (MonoCompile *cfg);
2376 void mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb);
2377 void mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb);
2378 void mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb);
2379 void mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb);
2380 void mono_arch_free_jit_tls_data (MonoJitTlsData *tls);
2381 void mono_arch_fill_argument_info (MonoCompile *cfg);
2382 void mono_arch_allocate_vars (MonoCompile *m);
2383 int mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info);
2384 void mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call);
2385 void mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src);
2386 void mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val);
2387 MonoDynCallInfo *mono_arch_dyn_call_prepare (MonoMethodSignature *sig);
2388 void mono_arch_dyn_call_free (MonoDynCallInfo *info);
2389 int mono_arch_dyn_call_get_buf_size (MonoDynCallInfo *info);
2390 void mono_arch_start_dyn_call (MonoDynCallInfo *info, gpointer **args, guint8 *ret, guint8 *buf);
2391 void mono_arch_finish_dyn_call (MonoDynCallInfo *info, guint8 *buf);
2392 MonoInst *mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args);
2393 void mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins);
2394 void mono_arch_decompose_long_opts (MonoCompile *cfg, MonoInst *ins);
2395 GSList* mono_arch_get_delegate_invoke_impls (void);
2396 LLVMCallInfo* mono_arch_get_llvm_call_info (MonoCompile *cfg, MonoMethodSignature *sig) MONO_LLVM_INTERNAL;
2397 guint8* mono_arch_emit_load_got_addr (guint8 *start, guint8 *code, MonoCompile *cfg, MonoJumpInfo **ji);
2398 guint8* mono_arch_emit_load_aotconst (guint8 *start, guint8 *code, MonoJumpInfo **ji, MonoJumpInfoType tramp_type, gconstpointer target);
2399 GSList* mono_arch_get_cie_program (void);
2400 void mono_arch_set_target (char *mtriple);
2401 gboolean mono_arch_gsharedvt_sig_supported (MonoMethodSignature *sig);
2402 gpointer mono_arch_get_gsharedvt_trampoline (MonoTrampInfo **info, gboolean aot);
2403 gpointer mono_arch_get_gsharedvt_call_info (gpointer addr, MonoMethodSignature *normal_sig, MonoMethodSignature *gsharedvt_sig, gboolean gsharedvt_in, gint32 vcall_offset, gboolean calli);
2404 gboolean mono_arch_opcode_needs_emulation (MonoCompile *cfg, int opcode);
2405 gboolean mono_arch_tail_call_supported (MonoCompile *cfg, MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig);
2406 int mono_arch_translate_tls_offset (int offset);
2407 gboolean mono_arch_opcode_supported (int opcode);
2408 void mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func);
2409 gboolean mono_arch_have_fast_tls (void);
2410
2411 #ifdef MONO_ARCH_SOFT_FLOAT_FALLBACK
2412 gboolean mono_arch_is_soft_float (void);
2413 #else
2414 static inline MONO_ALWAYS_INLINE gboolean
mono_arch_is_soft_float(void)2415 mono_arch_is_soft_float (void)
2416 {
2417 return FALSE;
2418 }
2419 #endif
2420
2421 /* Soft Debug support */
2422 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
2423 void mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip);
2424 void mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip);
2425 void mono_arch_start_single_stepping (void);
2426 void mono_arch_stop_single_stepping (void);
2427 gboolean mono_arch_is_single_step_event (void *info, void *sigctx);
2428 gboolean mono_arch_is_breakpoint_event (void *info, void *sigctx);
2429 void mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji);
2430 void mono_arch_skip_single_step (MonoContext *ctx);
2431 gpointer mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code);
2432 #endif
2433
2434 gboolean
2435 mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls,
2436 MonoJitInfo *ji, MonoContext *ctx,
2437 MonoContext *new_ctx, MonoLMF **lmf,
2438 mgreg_t **save_locations,
2439 StackFrameInfo *frame_info);
2440 gpointer mono_arch_get_throw_exception_by_name (void);
2441 gpointer mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot);
2442 gpointer mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot);
2443 gpointer mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot);
2444 gpointer mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot);
2445 gpointer mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot);
2446 gpointer mono_arch_get_throw_pending_exception (MonoTrampInfo **info, gboolean aot);
2447 gboolean mono_arch_handle_exception (void *sigctx, gpointer obj);
2448 void mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo, gpointer fault_addr, gboolean stack_ovf);
2449 gboolean mono_handle_soft_stack_ovf (MonoJitTlsData *jit_tls, MonoJitInfo *ji, void *ctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo, guint8* fault_addr);
2450 void mono_handle_hard_stack_ovf (MonoJitTlsData *jit_tls, MonoJitInfo *ji, void *ctx, guint8* fault_addr);
2451 gpointer mono_arch_ip_from_context (void *sigctx);
2452 mgreg_t mono_arch_context_get_int_reg (MonoContext *ctx, int reg);
2453 void mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val);
2454 void mono_arch_flush_register_windows (void);
2455 gboolean mono_arch_is_inst_imm (gint64 imm);
2456 gboolean mono_arch_is_int_overflow (void *sigctx, void *info);
2457 void mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg);
2458 guint32 mono_arch_get_patch_offset (guint8 *code);
2459 gpointer*mono_arch_get_delegate_method_ptr_addr (guint8* code, mgreg_t *regs);
2460 void mono_arch_create_vars (MonoCompile *cfg) MONO_LLVM_INTERNAL;
2461 void mono_arch_save_unwind_info (MonoCompile *cfg);
2462 void mono_arch_register_lowlevel_calls (void);
2463 gpointer mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr);
2464 gpointer mono_arch_get_static_rgctx_trampoline (gpointer arg, gpointer addr);
2465 gpointer mono_arch_get_llvm_imt_trampoline (MonoDomain *domain, MonoMethod *method, int vt_offset);
2466 gpointer mono_arch_get_gsharedvt_arg_trampoline (MonoDomain *domain, gpointer arg, gpointer addr);
2467 void mono_arch_patch_callsite (guint8 *method_start, guint8 *code, guint8 *addr);
2468 void mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr);
2469 void mono_arch_nullify_class_init_trampoline(guint8 *code, mgreg_t *regs);
2470 int mono_arch_get_this_arg_reg (guint8 *code);
2471 gpointer mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code);
2472 gpointer mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target);
2473 gpointer mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method, int offset, gboolean load_imt_reg);
2474 gpointer mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len);
2475 MonoMethod* mono_arch_find_imt_method (mgreg_t *regs, guint8 *code);
2476 MonoVTable* mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code);
2477 gpointer mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count, gpointer fail_tramp);
2478 void mono_arch_notify_pending_exc (MonoThreadInfo *info);
2479 guint8* mono_arch_get_call_target (guint8 *code);
2480 guint32 mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code);
2481 GSList *mono_arch_get_trampolines (gboolean aot);
2482 gpointer mono_arch_get_enter_icall_trampoline (MonoTrampInfo **info);
2483
2484 /*New interruption machinery */
2485 void
2486 mono_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data);
2487
2488 void
2489 mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data);
2490
2491 gboolean
2492 mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info, /*optional*/ void *sigctx);
2493
2494
2495 /* Exception handling */
2496 typedef gboolean (*MonoJitStackWalk) (StackFrameInfo *frame, MonoContext *ctx, gpointer data);
2497
2498 void mono_exceptions_init (void);
2499 gboolean mono_handle_exception (MonoContext *ctx, MonoObject *obj);
2500 void mono_handle_native_crash (const char *signal, void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo);
2501 MONO_API void mono_print_thread_dump (void *sigctx);
2502 MONO_API void mono_print_thread_dump_from_ctx (MonoContext *ctx);
2503 void mono_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnwindOptions unwind_options, void *user_data);
2504 void mono_walk_stack_with_state (MonoJitStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions unwind_options, void *user_data);
2505 void mono_walk_stack (MonoJitStackWalk func, MonoUnwindOptions options, void *user_data);
2506 gboolean mono_thread_state_init_from_sigctx (MonoThreadUnwindState *ctx, void *sigctx);
2507 void mono_thread_state_init (MonoThreadUnwindState *ctx);
2508 gboolean mono_thread_state_init_from_current (MonoThreadUnwindState *ctx);
2509 gboolean mono_thread_state_init_from_monoctx (MonoThreadUnwindState *ctx, MonoContext *mctx);
2510
2511 void mono_setup_altstack (MonoJitTlsData *tls);
2512 void mono_free_altstack (MonoJitTlsData *tls);
2513 gpointer mono_altstack_restore_prot (mgreg_t *regs, guint8 *code, gpointer *tramp_data, guint8* tramp);
2514 MonoJitInfo* mini_jit_info_table_find (MonoDomain *domain, char *addr, MonoDomain **out_domain);
2515 MonoJitInfo* mini_jit_info_table_find_ext (MonoDomain *domain, char *addr, gboolean allow_trampolines, MonoDomain **out_domain);
2516 void mono_resume_unwind (MonoContext *ctx) MONO_LLVM_INTERNAL;
2517
2518 MonoJitInfo * mono_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *res, MonoJitInfo *prev_ji, MonoContext *ctx, MonoContext *new_ctx, char **trace, MonoLMF **lmf, int *native_offset, gboolean *managed);
2519
2520 typedef gboolean (*MonoExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
2521 MONO_API gboolean mono_exception_walk_trace (MonoException *ex, MonoExceptionFrameWalk func, gpointer user_data);
2522 void mono_restore_context (MonoContext *ctx);
2523 guint8* mono_jinfo_get_unwind_info (MonoJitInfo *ji, guint32 *unwind_info_len);
2524 int mono_jinfo_get_epilog_size (MonoJitInfo *ji);
2525 void mono_llvm_rethrow_exception (MonoObject *ex);
2526 void mono_llvm_throw_exception (MonoObject *ex);
2527 void mono_llvm_throw_corlib_exception (guint32 ex_token_index);
2528 void mono_llvm_resume_exception (void);
2529 void mono_llvm_clear_exception (void);
2530 MonoObject *mono_llvm_load_exception (void);
2531 void mono_llvm_reset_exception (void);
2532 void mono_llvm_raise_exception (MonoException *e);
2533 void mono_llvm_reraise_exception (MonoException *e);
2534 gint32 mono_llvm_match_exception (MonoJitInfo *jinfo, guint32 region_start, guint32 region_end, gpointer rgctx, MonoObject *this_obj);
2535
2536 gboolean
2537 mono_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls,
2538 MonoJitInfo *prev_ji, MonoContext *ctx,
2539 MonoContext *new_ctx, char **trace, MonoLMF **lmf,
2540 mgreg_t **save_locations,
2541 StackFrameInfo *frame);
2542
2543 gpointer mono_get_throw_exception (void);
2544 gpointer mono_get_rethrow_exception (void);
2545 gpointer mono_get_call_filter (void);
2546 gpointer mono_get_restore_context (void);
2547 gpointer mono_get_throw_exception_by_name (void);
2548 gpointer mono_get_throw_corlib_exception (void);
2549 gpointer mono_get_throw_exception_addr (void);
2550 MonoArray *ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info);
2551 MonoBoolean ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
2552 MonoReflectionMethod **method,
2553 gint32 *iloffset, gint32 *native_offset,
2554 MonoString **file, gint32 *line, gint32 *column);
2555 void mono_set_cast_details (MonoClass *from, MonoClass *to);
2556
2557 void mono_decompose_typechecks (MonoCompile *cfg);
2558 /* Dominator/SSA methods */
2559 void mono_compile_dominator_info (MonoCompile *cfg, int dom_flags);
2560 void mono_compute_natural_loops (MonoCompile *cfg);
2561 MonoBitSet* mono_compile_iterated_dfrontier (MonoCompile *cfg, MonoBitSet *set);
2562 void mono_ssa_compute (MonoCompile *cfg);
2563 void mono_ssa_remove (MonoCompile *cfg);
2564 void mono_ssa_remove_gsharedvt (MonoCompile *cfg);
2565 void mono_ssa_cprop (MonoCompile *cfg);
2566 void mono_ssa_deadce (MonoCompile *cfg);
2567 void mono_ssa_strength_reduction (MonoCompile *cfg);
2568 void mono_free_loop_info (MonoCompile *cfg);
2569 void mono_ssa_loop_invariant_code_motion (MonoCompile *cfg);
2570
2571 void mono_ssa_compute2 (MonoCompile *cfg);
2572 void mono_ssa_remove2 (MonoCompile *cfg);
2573 void mono_ssa_cprop2 (MonoCompile *cfg);
2574 void mono_ssa_deadce2 (MonoCompile *cfg);
2575
2576 /* debugging support */
2577 void mono_debug_init_method (MonoCompile *cfg, MonoBasicBlock *start_block,
2578 guint32 breakpoint_id);
2579 void mono_debug_open_method (MonoCompile *cfg);
2580 void mono_debug_close_method (MonoCompile *cfg);
2581 void mono_debug_free_method (MonoCompile *cfg);
2582 void mono_debug_open_block (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address);
2583 void mono_debug_record_line_number (MonoCompile *cfg, MonoInst *ins, guint32 address);
2584 void mono_debug_serialize_debug_info (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len);
2585 void mono_debug_add_aot_method (MonoDomain *domain,
2586 MonoMethod *method, guint8 *code_start,
2587 guint8 *debug_info, guint32 debug_info_len);
2588 MONO_API void mono_debug_print_vars (gpointer ip, gboolean only_arguments);
2589 MONO_API void mono_debugger_run_finally (MonoContext *start_ctx);
2590
2591 MONO_API gboolean mono_breakpoint_clean_code (guint8 *method_start, guint8 *code, int offset, guint8 *buf, int size);
2592
2593 /* Tracing */
2594 MonoCallSpec *mono_trace_set_options (const char *options);
2595 gboolean mono_trace_eval (MonoMethod *method);
2596
2597 extern void
2598 mono_perform_abc_removal (MonoCompile *cfg);
2599 extern void
2600 mono_perform_abc_removal (MonoCompile *cfg);
2601 extern void
2602 mono_local_cprop (MonoCompile *cfg);
2603 extern void
2604 mono_local_cprop (MonoCompile *cfg);
2605 extern void
2606 mono_local_deadce (MonoCompile *cfg);
2607 void
2608 mono_local_alias_analysis (MonoCompile *cfg);
2609
2610 /* Generic sharing */
2611
2612 void
2613 mono_set_generic_sharing_supported (gboolean supported);
2614
2615 void
2616 mono_set_generic_sharing_vt_supported (gboolean supported);
2617
2618 void
2619 mono_set_partial_sharing_supported (gboolean supported);
2620
2621 gboolean
2622 mono_class_generic_sharing_enabled (MonoClass *klass);
2623
2624 gpointer
2625 mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot, MonoError *error);
2626
2627 gpointer
2628 mono_method_fill_runtime_generic_context (MonoMethodRuntimeGenericContext *mrgctx, guint32 slot, MonoError *error);
2629
2630 MonoMethodRuntimeGenericContext*
2631 mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst);
2632
2633 const char*
2634 mono_rgctx_info_type_to_str (MonoRgctxInfoType type);
2635
2636 MonoJumpInfoType
2637 mini_rgctx_info_type_to_patch_info_type (MonoRgctxInfoType info_type);
2638
2639 gboolean
2640 mono_method_needs_static_rgctx_invoke (MonoMethod *method, gboolean allow_type_vars);
2641
2642 int
2643 mono_class_rgctx_get_array_size (int n, gboolean mrgctx);
2644
2645 guint32
2646 mono_method_lookup_or_register_info (MonoMethod *method, gboolean in_mrgctx, gpointer data,
2647 MonoRgctxInfoType info_type, MonoGenericContext *generic_context);
2648
2649 MonoGenericContext
2650 mono_method_construct_object_context (MonoMethod *method);
2651
2652 MonoMethod*
2653 mono_method_get_declaring_generic_method (MonoMethod *method);
2654
2655 int
2656 mono_generic_context_check_used (MonoGenericContext *context);
2657
2658 int
2659 mono_class_check_context_used (MonoClass *klass);
2660
2661 gboolean
2662 mono_generic_context_is_sharable (MonoGenericContext *context, gboolean allow_type_vars);
2663
2664 gboolean
2665 mono_generic_context_is_sharable_full (MonoGenericContext *context, gboolean allow_type_vars, gboolean allow_partial);
2666
2667 gboolean
2668 mono_method_is_generic_impl (MonoMethod *method);
2669
2670 gboolean
2671 mono_method_is_generic_sharable (MonoMethod *method, gboolean allow_type_vars);
2672
2673 gboolean
2674 mono_method_is_generic_sharable_full (MonoMethod *method, gboolean allow_type_vars, gboolean allow_partial, gboolean allow_gsharedvt);
2675
2676 gboolean
2677 mini_class_is_generic_sharable (MonoClass *klass);
2678
2679 gboolean
2680 mini_generic_inst_is_sharable (MonoGenericInst *inst, gboolean allow_type_vars, gboolean allow_partial);
2681
2682 gboolean
2683 mono_is_partially_sharable_inst (MonoGenericInst *inst);
2684
2685 gboolean
2686 mini_is_gsharedvt_gparam (MonoType *t);
2687
2688 MonoGenericContext* mini_method_get_context (MonoMethod *method);
2689
2690 int mono_method_check_context_used (MonoMethod *method);
2691
2692 gboolean mono_generic_context_equal_deep (MonoGenericContext *context1, MonoGenericContext *context2);
2693
2694 gpointer mono_helper_get_rgctx_other_ptr (MonoClass *caller_class, MonoVTable *vtable,
2695 guint32 token, guint32 token_source, guint32 rgctx_type,
2696 gint32 rgctx_index);
2697
2698 void mono_generic_sharing_init (void);
2699 void mono_generic_sharing_cleanup (void);
2700
2701 MonoClass* mini_class_get_container_class (MonoClass *klass);
2702 MonoGenericContext* mini_class_get_context (MonoClass *klass);
2703
2704 MonoType* mini_get_underlying_type (MonoType *type) MONO_LLVM_INTERNAL;
2705 MonoType* mini_type_get_underlying_type (MonoType *type);
2706 MonoClass* mini_get_class (MonoMethod *method, guint32 token, MonoGenericContext *context);
2707 MonoMethod* mini_get_shared_method (MonoMethod *method);
2708 MonoMethod* mini_get_shared_method_to_register (MonoMethod *method);
2709 MonoMethod* mini_get_shared_method_full (MonoMethod *method, gboolean all_vt, gboolean is_gsharedvt);
2710 MonoType* mini_get_shared_gparam (MonoType *t, MonoType *constraint);
2711 int mini_get_rgctx_entry_slot (MonoJumpInfoRgctxEntry *entry);
2712
2713 int mini_type_stack_size (MonoType *t, int *align);
2714 int mini_type_stack_size_full (MonoType *t, guint32 *align, gboolean pinvoke);
2715 void type_to_eval_stack_type (MonoCompile *cfg, MonoType *type, MonoInst *inst);
2716 guint mono_type_to_regmove (MonoCompile *cfg, MonoType *type) MONO_LLVM_INTERNAL;
2717
2718 void mono_cfg_add_try_hole (MonoCompile *cfg, MonoExceptionClause *clause, guint8 *start, MonoBasicBlock *bb);
2719
2720 void mono_cfg_set_exception (MonoCompile *cfg, int type);
2721 void mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg);
2722
2723 #define MONO_TIME_TRACK(a, phase) \
2724 { \
2725 GTimer *timer = mono_time_track_start (); \
2726 (phase) ; \
2727 mono_time_track_end (&(a), timer); \
2728 }
2729
2730 GTimer *mono_time_track_start (void);
2731 void mono_time_track_end (gdouble *time, GTimer *timer);
2732
2733 void mono_update_jit_stats (MonoCompile *cfg);
2734
2735 gboolean mini_type_is_reference (MonoType *type);
2736 gboolean mini_type_is_vtype (MonoType *t) MONO_LLVM_INTERNAL;
2737 gboolean mini_type_var_is_vt (MonoType *type) MONO_LLVM_INTERNAL;
2738 gboolean mini_is_gsharedvt_type (MonoType *t);
2739 gboolean mini_is_gsharedvt_klass (MonoClass *klass) MONO_LLVM_INTERNAL;
2740 gboolean mini_is_gsharedvt_signature (MonoMethodSignature *sig);
2741 gboolean mini_is_gsharedvt_variable_type (MonoType *t) MONO_LLVM_INTERNAL;
2742 gboolean mini_is_gsharedvt_variable_klass (MonoClass *klass) MONO_LLVM_INTERNAL;
2743 gboolean mini_is_gsharedvt_sharable_method (MonoMethod *method);
2744 gboolean mini_is_gsharedvt_variable_signature (MonoMethodSignature *sig);
2745 gboolean mini_is_gsharedvt_sharable_inst (MonoGenericInst *inst);
2746 gpointer mini_method_get_rgctx (MonoMethod *m);
2747 void mini_init_gsctx (MonoDomain *domain, MonoMemPool *mp, MonoGenericContext *context, MonoGenericSharingContext *gsctx);
2748
2749 gpointer mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSignature *normal_sig, MonoMethodSignature *gsharedvt_sig,
2750 gint32 vcall_offset, gboolean calli);
2751 MonoMethod* mini_get_gsharedvt_in_sig_wrapper (MonoMethodSignature *sig);
2752 MonoMethod* mini_get_gsharedvt_out_sig_wrapper (MonoMethodSignature *sig);
2753 MonoMethodSignature* mini_get_gsharedvt_out_sig_wrapper_signature (gboolean has_this, gboolean has_ret, int param_count);
2754 gboolean mini_gsharedvt_runtime_invoke_supported (MonoMethodSignature *sig);
2755 MonoMethod* mini_get_interp_in_wrapper (MonoMethodSignature *sig);
2756
2757 /* SIMD support */
2758
2759 /*
2760 This enum MUST be kept in sync with its managed mirror Mono.Simd.AccelMode.
2761 */
2762 enum {
2763 SIMD_VERSION_SSE1 = 1 << 0,
2764 SIMD_VERSION_SSE2 = 1 << 1,
2765 SIMD_VERSION_SSE3 = 1 << 2,
2766 SIMD_VERSION_SSSE3 = 1 << 3,
2767 SIMD_VERSION_SSE41 = 1 << 4,
2768 SIMD_VERSION_SSE42 = 1 << 5,
2769 SIMD_VERSION_SSE4a = 1 << 6,
2770 SIMD_VERSION_ALL = SIMD_VERSION_SSE1 | SIMD_VERSION_SSE2 |
2771 SIMD_VERSION_SSE3 | SIMD_VERSION_SSSE3 |
2772 SIMD_VERSION_SSE41 | SIMD_VERSION_SSE42 |
2773 SIMD_VERSION_SSE4a,
2774
2775 /* this value marks the end of the bit indexes used in
2776 * this emum.
2777 */
2778 SIMD_VERSION_INDEX_END = 6
2779 };
2780
2781 enum {
2782 SIMD_COMP_EQ,
2783 SIMD_COMP_LT,
2784 SIMD_COMP_LE,
2785 SIMD_COMP_UNORD,
2786 SIMD_COMP_NEQ,
2787 SIMD_COMP_NLT,
2788 SIMD_COMP_NLE,
2789 SIMD_COMP_ORD
2790 };
2791
2792 enum {
2793 SIMD_PREFETCH_MODE_NTA,
2794 SIMD_PREFETCH_MODE_0,
2795 SIMD_PREFETCH_MODE_1,
2796 SIMD_PREFETCH_MODE_2,
2797 };
2798
2799 const char *mono_arch_xregname (int reg);
2800 void mono_simd_simplify_indirection (MonoCompile *cfg);
2801 MonoInst* mono_emit_simd_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args);
2802 MonoInst* mono_emit_simd_field_load (MonoCompile *cfg, MonoClassField *field, MonoInst *addr);
2803 guint32 mono_arch_cpu_enumerate_simd_versions (void);
2804 void mono_simd_intrinsics_init (void);
2805
2806 gboolean mono_class_is_magic_int (MonoClass *klass);
2807 gboolean mono_class_is_magic_float (MonoClass *klass);
2808 MonoInst* mono_emit_native_types_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args);
2809 MonoType* mini_native_type_replace_type (MonoType *type) MONO_LLVM_INTERNAL;
2810
2811 #ifdef __linux__
2812 #define XDEBUG_ENABLED 1
2813 #endif
2814
2815 #ifdef __linux__
2816 /* maybe enable also for other systems? */
2817 #define ENABLE_JIT_MAP 1
2818 void mono_enable_jit_map (void);
2819 void mono_emit_jit_map (MonoJitInfo *jinfo);
2820 void mono_emit_jit_tramp (void *start, int size, const char *desc);
2821 gboolean mono_jit_map_is_enabled (void);
2822 #else
2823 #define mono_enable_jit_map()
2824 #define mono_emit_jit_map(ji)
2825 #define mono_emit_jit_tramp(s,z,d)
2826 #define mono_jit_map_is_enabled() (0)
2827 #endif
2828
2829 /*
2830 * Per-OS implementation functions.
2831 */
2832 void mono_runtime_install_handlers (void);
2833 gboolean mono_runtime_install_custom_handlers (const char *handlers);
2834 void mono_runtime_install_custom_handlers_usage (void);
2835 void mono_runtime_cleanup_handlers (void);
2836 void mono_runtime_setup_stat_profiler (void);
2837 void mono_runtime_shutdown_stat_profiler (void);
2838 void mono_runtime_posix_install_handlers (void);
2839 void mono_gdb_render_native_backtraces (pid_t crashed_pid);
2840
2841 void mono_cross_helpers_run (void);
2842
2843 /*
2844 * Signal handling
2845 */
2846
2847 #if defined(DISABLE_HW_TRAPS) || defined(MONO_ARCH_DISABLE_HW_TRAPS)
2848 // Signal handlers not available
2849 #define MONO_ARCH_NEED_DIV_CHECK 1
2850 #endif
2851
2852 void MONO_SIG_HANDLER_SIGNATURE (mono_sigfpe_signal_handler) ;
2853 void MONO_SIG_HANDLER_SIGNATURE (mono_sigill_signal_handler) ;
2854 void MONO_SIG_HANDLER_SIGNATURE (mono_sigsegv_signal_handler);
2855 void MONO_SIG_HANDLER_SIGNATURE (mono_sigint_signal_handler) ;
2856 gboolean MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal);
2857
2858 #ifdef MONO_ARCH_VARARG_ICALLS
2859 #define ARCH_VARARG_ICALLS 1
2860 #else
2861 #define ARCH_VARARG_ICALLS 0
2862 #endif
2863
2864 #if defined (HOST_WASM)
2865
2866 #define MONO_RETURN_ADDRESS_N(N) NULL
2867 #define MONO_RETURN_ADDRESS() MONO_RETURN_ADDRESS_N(0)
2868
2869
2870 #elif defined (__GNUC__)
2871
2872 #define MONO_RETURN_ADDRESS_N(N) (__builtin_extract_return_addr (__builtin_return_address (N)))
2873 #define MONO_RETURN_ADDRESS() MONO_RETURN_ADDRESS_N(0)
2874
2875 #elif defined(_MSC_VER)
2876
2877 #include <intrin.h>
2878 #pragma intrinsic(_ReturnAddress)
2879
2880 #define MONO_RETURN_ADDRESS() _ReturnAddress()
2881 #define MONO_RETURN_ADDRESS_N(N) NULL
2882
2883 #else
2884
2885 #error "Missing return address intrinsics implementation"
2886
2887 #endif
2888
2889 #endif /* __MONO_MINI_H__ */
2890