2004-05-26 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / mini.h
1 #ifndef __MONO_MINI_H__
2 #define __MONO_MINI_H__
3
4 #include "config.h"
5 #include <glib.h>
6 #include <signal.h>
7 #include <mono/metadata/loader.h>
8 #include <mono/metadata/mempool.h>
9 #include <mono/utils/monobitset.h>
10 #include <mono/metadata/class.h>
11 #include <mono/metadata/object.h>
12 #include <mono/metadata/opcodes.h>
13 #include <mono/metadata/tabledefs.h>
14 #include <mono/metadata/profiler-private.h>
15
16 #include "mini-arch.h"
17 #include "regalloc.h"
18
19 #define MONO_USE_AOT_COMPILER
20
21 /* for 32 bit systems */
22 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
23 #define MINI_LS_WORD_OFFSET 0
24 #define MINI_MS_WORD_OFFSET 4
25 #define inst_ls_word data.op[0].const_val
26 #define inst_ms_word data.op[1].const_val
27 #else
28 #define MINI_LS_WORD_OFFSET 4
29 #define MINI_MS_WORD_OFFSET 0
30 #define inst_ls_word data.op[1].const_val
31 #define inst_ms_word data.op[0].const_val
32 #endif
33
34 /* Version number of the AOT file format */
35 #define MONO_AOT_FILE_VERSION "7"
36
37 #if 1
38 #define mono_bitset_test_fast(set,n) (((guint32*)set)[2+(n)/32] & (1 << ((n) % 32)))
39 #else
40 #define mono_bitset_test_fast(set,n) mono_bitset_test(set,n)
41 #endif
42
43 #if 0
44 #define mono_bitset_foreach_bit(set,b,n) \
45         for (b = 0; b < n; b++)\
46                 if (mono_bitset_test_fast(set,b))
47 #define mono_bitset_foreach_bit_rev(set,b,n) \
48         for (b = n - 1; b >= 0; b--)\
49                 if (mono_bitset_test_fast(set,b))
50 #else
51 #define mono_bitset_foreach_bit(set,b,n) \
52         for (b = mono_bitset_find_first (set, -1); b < n && b >= 0; b = mono_bitset_find_first (set, b))
53 #define mono_bitset_foreach_bit_rev(set,b,n) \
54         for (b = mono_bitset_find_last (set, n - 1); b >= 0; b = b ? mono_bitset_find_last (set, b) : -1)
55  
56 #endif
57
58 /*
59  * Pull the list of opcodes
60  */
61 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
62         a = i,
63
64 enum {
65 #include "mono/cil/opcode.def"
66         CEE_LASTOP
67 };
68 #undef OPDEF
69
70 #define MONO_VARINFO(cfg,varnum) ((cfg)->vars [varnum])
71
72 #define MONO_INST_NEW(cfg,dest,op) do { \
73                 (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst));       \
74                 (dest)->opcode = (op);  \
75         } while (0)
76
77 #define MONO_INST_NEW_CALL(cfg,dest,op) do {    \
78                 (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoCallInst));   \
79                 (dest)->inst.opcode = (op);     \
80         } while (0)
81
82 #define MONO_ADD_INS(b,inst) do {       \
83                 if ((b)->last_ins) {    \
84                         (b)->last_ins->next = (inst);   \
85                         (b)->last_ins = (inst); \
86                 } else {        \
87                         (b)->code = (b)->last_ins = (inst);     \
88                 }       \
89         } while (0)
90
91 typedef struct MonoInst MonoInst;
92 typedef struct MonoCallInst MonoCallInst;
93 typedef struct MonoEdge MonoEdge;
94 typedef struct MonoMethodVar MonoMethodVar;
95 typedef struct MonoBasicBlock MonoBasicBlock;
96 typedef struct MonoLMF MonoLMF;
97 typedef struct MonoSpillInfo MonoSpillInfo;
98 typedef struct MonoTraceSpec MonoTraceSpec;
99
100 extern guint32 mono_jit_tls_id;
101 extern MonoTraceSpec *mono_jit_trace_calls;
102 extern gboolean mono_break_on_exc;
103 extern int mono_exc_esp_offset;
104 extern gboolean mono_compile_aot;
105
106 struct MonoEdge {
107         MonoEdge *next;
108         MonoBasicBlock *bb;
109         /* add edge type? */
110 };
111
112 struct MonoSpillInfo {
113         MonoSpillInfo *next;
114         int offset;
115 };
116
117 /*
118  * The IR-level basic block.  
119  *
120  * A basic block can have multiple exits just fine, as long as the point of
121  * 'departure' is the last instruction in the basic block. Extended basic
122  * blocks, on the other hand, may have instructions that leave the block
123  * midstream. The important thing is that they cannot be _entered_
124  * midstream, ie, execution of a basic block (or extened bb) always start
125  * at the beginning of the block, never in the middle.
126  */
127 struct MonoBasicBlock {
128         MonoInst *last_ins;
129
130         /* Points to the start of the CIL code that initiated this BB */
131         unsigned char* cil_code;
132
133         /* Length of the CIL block */
134         gint32 cil_length;
135
136         /* The address of the generated code, used for fixups */
137         int native_offset;
138         int max_offset;
139         
140         gint32 dfn;
141
142         /* unique block number identification */
143         gint32 block_num;
144
145         /* Visited and reachable flags */
146         guint32 flags;
147
148         /* Basic blocks: incoming and outgoing counts and pointers */
149         gint16 out_count, in_count;
150         MonoBasicBlock **in_bb;
151         MonoBasicBlock **out_bb;
152
153         /* the next basic block in the order it appears in IL */
154         MonoBasicBlock *next_bb;
155
156         /*
157          * Before instruction selection it is the first tree in the
158          * forest and the first item in the list of trees. After
159          * instruction selection it is the first instruction and the
160          * first item in the list of instructions.
161          */
162         MonoInst *code;
163
164         /*
165          * SSA and loop based flags
166          */
167         MonoBitSet *dominators;
168         MonoBitSet *dfrontier;
169         MonoBasicBlock *idom;
170         GList *dominated;
171         /* fast dominator algorithm */
172         MonoBasicBlock *df_parent, *ancestor, *child, *label;
173         MonoEdge *bucket;
174         int size, sdom, idomn;
175         
176         /* loop nesting and recognition */
177         GList *loop_blocks;
178         gint8  nesting;
179
180         /* use for liveness analysis */
181         MonoBitSet *gen_set;
182         MonoBitSet *kill_set;
183         MonoBitSet *live_in_set;
184         MonoBitSet *live_out_set;
185
186         /* fields to deal with non-empty stack slots at bb boundary */
187         guint16 out_scount, in_scount;
188         MonoInst **out_stack;
189         MonoInst **in_stack;
190
191         /* we use that to prevent merging of bblock covered by different clauses*/
192         guint real_offset;
193
194         /*
195          * The region encodes whether the basic block is inside
196          * a finally, catch, filter or none of thoese.
197          *
198          * If the value is -1, then it is neither finally, catch nor filter
199          *
200          * Otherwise the format is:
201          *
202          *  Bits: |     0-3      |       4-7      |     8-31
203          *        |              |                |
204          *        | clause-flags |   MONO_REGION  | clause-index 
205          *
206          */
207         guint region;
208
209         /* The current symbolic register number, used in local register allocation. */
210         guint32 max_ireg, max_freg;
211 };
212
213 /* BBlock flags */
214 #define BB_VISITED 1
215 #define BB_REACHABLE 2
216
217 struct MonoInst {
218         union {
219                 union {
220                         MonoInst *src;
221                         MonoMethodVar *var;
222                         gssize const_val;
223                         gpointer p;
224                         MonoMethod *method;
225                         MonoMethodSignature *signature;
226                         MonoBasicBlock **many_blocks;
227                         MonoBasicBlock *target_block;
228                         MonoInst **args;
229                         MonoType *vtype;
230                         MonoClass *klass;
231                         int *phi_args;
232                 } op [2];
233                 gint64 i8const;
234                 double r8const;
235         } data;
236         guint16 opcode;
237         guint8  type; /* stack type */
238         guint   ssa_op : 3;
239         guint8  flags  : 5;
240         
241         /* used by the register allocator */
242         gint32 dreg, sreg1, sreg2, unused;
243         
244         MonoInst *next;
245         MonoClass *klass;
246         const unsigned char* cil_code; /* for debugging and bblock splitting */
247 };
248         
249 struct MonoCallInst {
250         MonoInst inst;
251         MonoMethodSignature *signature;
252         MonoMethod *method;
253         MonoInst **args;
254         MonoInst *out_args;
255         gconstpointer fptr;
256         guint stack_usage;
257         gboolean virtual;
258         regmask_t used_iregs;
259         regmask_t used_fregs;
260 };
261
262 /* 
263  * flags for MonoInst
264  * Note: some of the values overlap, because they can't appear
265  * in the same MonoInst.
266  */
267 enum {
268         MONO_INST_HAS_METHOD = 1,
269         /* temp local created by a DUP: used only within a BB */
270         MONO_INST_IS_TEMP    = 1,
271         MONO_INST_INIT       = 1, /* in localloc */
272         MONO_INST_IS_DEAD    = 2,
273         MONO_INST_TAILCALL   = 4,
274         MONO_INST_VOLATILE   = 4,
275         MONO_INST_BRLABEL    = 4,
276         MONO_INST_NOTYPECHECK    = 4,
277         MONO_INST_UNALIGNED  = 8,
278         /* the address of the variable has been taken */
279         MONO_INST_INDIRECT   = 16,
280         MONO_INST_NORANGECHECK   = 16
281 };
282
283 #define inst_c0 data.op[0].const_val
284 #define inst_c1 data.op[1].const_val
285 #define inst_i0 data.op[0].src
286 #define inst_i1 data.op[1].src
287 #define inst_p0 data.op[0].p
288 #define inst_p1 data.op[1].p
289 #define inst_l  data.i8const
290 #define inst_r  data.r8const
291 #define inst_left  data.op[0].src
292 #define inst_right data.op[1].src
293
294 #define inst_newa_len   data.op[0].src
295 #define inst_newa_class data.op[1].klass
296
297 #define inst_var    data.op[0].var
298 #define inst_vtype  data.op[1].vtype
299 /* in branch instructions */
300 #define inst_many_bb   data.op[1].many_blocks
301 #define inst_target_bb data.op[0].target_block
302 #define inst_true_bb   data.op[1].many_blocks[0]
303 #define inst_false_bb  data.op[1].many_blocks[1]
304
305 #define inst_basereg sreg1
306 #define inst_indexreg sreg2
307 #define inst_destbasereg dreg
308 #define inst_offset data.op[0].const_val
309 #define inst_imm    data.op[1].const_val
310
311 #define inst_phi_args   data.op[1].phi_args
312
313 /* instruction description for use in regalloc/scheduling */
314 enum {
315         MONO_INST_DEST,
316         MONO_INST_SRC1,
317         MONO_INST_SRC2,
318         MONO_INST_FLAGS,
319         MONO_INST_CLOB,
320         MONO_INST_COST,
321         MONO_INST_DELAY,
322         MONO_INST_RES,
323         MONO_INST_LEN,
324         MONO_INST_MAX
325 };
326
327 typedef union {
328         struct {
329                 guint16 tid; /* tree number */
330                 guint16 bid; /* block number */
331         } pos ;
332         guint32 abs_pos; 
333 } MonoPosition;
334
335 typedef struct {
336         MonoPosition first_use, last_use;
337 } MonoLiveRange;
338
339 /*
340  * Additional information about a variable
341  */
342 struct MonoMethodVar {
343         guint           idx; /* inside cfg->varinfo, cfg->vars */
344         guint           last_name;
345         MonoBitSet     *dfrontier;
346         MonoLiveRange   range; /* generated by liveness analysis */
347         int             reg; /* != -1 if allocated into a register */
348         int             spill_costs;
349         MonoBitSet     *def_in; /* used by SSA */
350         MonoInst       *def;    /* used by SSA */
351         MonoBasicBlock *def_bb; /* used by SSA */
352         GList          *uses;   /* used by SSA */
353         char            cpstate;  /* used by SSA conditional  constant propagation */
354 };
355
356 typedef struct {
357         gpointer          end_of_stack;
358         guint32           stack_size;
359         MonoLMF          *lmf;
360         MonoLMF          *first_lmf;
361         gpointer         signal_stack;
362         guint32          signal_stack_size;
363         void            (*abort_func) (MonoObject *object);
364 } MonoJitTlsData;
365
366 typedef enum {
367         MONO_PATCH_INFO_BB,
368         MONO_PATCH_INFO_ABS,
369         MONO_PATCH_INFO_LABEL,
370         MONO_PATCH_INFO_METHOD,
371         MONO_PATCH_INFO_METHOD_JUMP,
372         MONO_PATCH_INFO_METHOD_REL,
373         MONO_PATCH_INFO_METHODCONST,
374         MONO_PATCH_INFO_INTERNAL_METHOD,
375         MONO_PATCH_INFO_SWITCH,
376         MONO_PATCH_INFO_EXC,
377         MONO_PATCH_INFO_EXC_NAME,
378         MONO_PATCH_INFO_CLASS,
379         MONO_PATCH_INFO_IMAGE,
380         MONO_PATCH_INFO_FIELD,
381         MONO_PATCH_INFO_VTABLE,
382         MONO_PATCH_INFO_CLASS_INIT,
383         MONO_PATCH_INFO_SFLDA,
384         MONO_PATCH_INFO_LDSTR,
385         MONO_PATCH_INFO_LDTOKEN,
386         MONO_PATCH_INFO_TYPE_FROM_HANDLE,
387         MONO_PATCH_INFO_R4,
388         MONO_PATCH_INFO_R8,
389         MONO_PATCH_INFO_IP,
390         MONO_PATCH_INFO_IID,
391         MONO_PATCH_INFO_BB_OVF,
392         MONO_PATCH_INFO_EXC_OVF,
393         MONO_PATCH_INFO_WRAPPER
394 } MonoJumpInfoType;
395
396 /*
397  * We need to store the image which the token refers to along with the token,
398  * since the image might not be the same as the image of the method which
399  * contains the relocation, because of inlining.
400  */
401 typedef struct MonoJumpInfoToken {
402         MonoImage *image;
403         guint32 token;
404 } MonoJumpInfoToken;
405
406 typedef struct MonoJumpInfo MonoJumpInfo;
407 struct MonoJumpInfo {
408         MonoJumpInfo *next;
409         union {
410                 int i;
411                 guint8 *p;
412                 MonoInst *label;
413         } ip;
414
415         MonoJumpInfoType type;
416         union {
417                 gconstpointer   target;
418                 int             offset;
419                 MonoBasicBlock *bb;
420                 MonoBasicBlock **table;
421                 MonoInst       *inst;
422                 MonoMethod     *method;
423                 MonoClass      *klass;
424                 MonoClassField *field;
425                 MonoImage      *image;
426                 MonoVTable     *vtable;
427                 const char     *name;
428                 MonoJumpInfoToken  *token;
429         } data;
430
431         int table_size; /* use by switch */
432 };
433
434 /* optimization flags: keep up to date with the name array in driver.c */
435 enum {
436         MONO_OPT_PEEPHOLE = 1 << 0,
437         MONO_OPT_BRANCH   = 1 << 1,
438         MONO_OPT_INLINE   = 1 << 2,
439         MONO_OPT_CFOLD    = 1 << 3,
440         MONO_OPT_CONSPROP = 1 << 4,
441         MONO_OPT_COPYPROP = 1 << 5,
442         MONO_OPT_DEADCE   = 1 << 6,
443         MONO_OPT_LINEARS  = 1 << 7,
444         MONO_OPT_CMOV     = 1 << 8,
445         MONO_OPT_SHARED   = 1 << 9,
446         MONO_OPT_SCHED    = 1 << 10,
447         MONO_OPT_INTRINS  = 1 << 11,
448         MONO_OPT_TAILC    = 1 << 12,
449         MONO_OPT_LOOP     = 1 << 13,
450         MONO_OPT_FCMOV    = 1 << 14,
451         MONO_OPT_LEAF     = 1 << 15,
452         MONO_OPT_AOT      = 1 << 16,
453         MONO_OPT_PRECOMP  = 1 << 17,
454         MONO_OPT_ABCREM   = 1 << 18
455 };
456
457 /* Bit-fields in the MonoBasicBlock.region */
458 #define MONO_REGION_FINALLY  16
459 #define MONO_REGION_CATCH    32
460 #define MONO_REGION_FAULT    64         /* Currently unused */
461 #define MONO_REGION_FILTER  128
462
463 /*
464  * Control Flow Graph and compilation unit information
465  */
466 typedef struct {
467         MonoMethod      *method;
468         MonoMemPool     *mempool;
469         MonoInst       **varinfo;
470         MonoMethodVar  **vars;
471         MonoInst        *ret;
472         MonoBasicBlock  *bb_entry;
473         MonoBasicBlock  *bb_exit;
474         MonoBasicBlock  *bb_init;
475         MonoBasicBlock **bblocks;
476         GHashTable      *bb_hash;
477         MonoMemPool     *state_pool; /* used by instruction selection */
478         MonoBasicBlock  *cbb;        /* used by instruction selection */
479         MonoInst        *prev_ins;   /* in decompose */
480         MonoJumpInfo    *patch_info;
481         MonoJitInfo     *jit_info;
482         guint            num_bblocks;
483         guint            locals_start;
484         guint            num_varinfo; /* used items in varinfo */
485         guint            varinfo_count; /* total storage in varinfo */
486         gint             stack_offset;
487         MonoRegState    *rs;
488         MonoSpillInfo   *spill_info; /* machine register spills */
489         MonoSpillInfo   *spill_info_float; /* fp register spills */
490         gint             spill_count;
491         /* unsigned char   *cil_code; */
492
493         /* the exception object passed to catch/filter blocks */
494         MonoInst        *exvar;
495         
496         MonoInst        *domainvar; /* a cache for the current domain */
497
498         /* A hashtable of region ID-> SP var mappings */
499         /* An SP var is a place to store the stack pointer (used by handlers)*/
500         GHashTable      *spvars;
501
502         GList           *ldstr_list; /* used by AOT */
503         
504         MonoDomain      *domain;
505
506         unsigned char   *native_code;
507         guint            code_size;
508         guint            code_len;
509         guint            prolog_end;
510         guint            epilog_begin;
511         regmask_t        used_int_regs;
512         guint32          opt;
513         guint32          prof_options;
514         guint32          flags;
515         guint32          comp_done;
516         guint32          verbose_level;
517         guint32          stack_usage;
518         guint32          param_area;
519         guint32          frame_reg;
520         gint32           sig_cookie;
521         gboolean         disable_aot;
522         gboolean         disable_ssa;
523         gboolean         run_cctors;
524         gboolean         need_lmf_area;
525         gpointer         debug_info;
526         guint32          lmf_offset;
527         guint16          *intvars;
528         MonoProfileCoverageInfo *coverage_info;
529         MonoCompileArch  arch;
530 #ifdef __ia64
531         guint8           ins, locals, outs; /* reg stack region sizes */
532 #endif /* __ia64 */
533 } MonoCompile;
534
535 typedef enum {
536         MONO_CFG_HAS_ALLOCA = 1 << 0,
537         MONO_CFG_HAS_CALLS  = 1 << 1,
538         MONO_CFG_HAS_LDELEMA  = 1 << 2
539 } MonoCompileFlags;
540
541 typedef struct {
542         gulong methods_compiled;
543         gulong methods_aot;
544         gulong methods_lookups;
545         gulong method_trampolines;
546         gulong allocate_var;
547         gulong analyze_stack_repeat;
548         gulong cil_code_size;
549         gulong native_code_size;
550         gulong code_reallocs;
551         gulong max_code_size_ratio;
552         gulong biggest_method_size;
553         gulong allocated_code_size;
554         gulong inlineable_methods;
555         gulong inlined_methods;
556         gulong basic_blocks;
557         gulong max_basic_blocks;
558         MonoMethod *max_ratio_method;
559         MonoMethod *biggest_method;
560         gboolean enabled;
561 } MonoJitStats;
562
563 extern MonoJitStats mono_jit_stats;
564
565 /* values for MonoInst.ssa_op */
566 enum {
567         MONO_SSA_NOP,
568         MONO_SSA_LOAD,
569         MONO_SSA_STORE,
570         MONO_SSA_MAYBE_LOAD,
571         MONO_SSA_MAYBE_STORE
572 };
573
574 #define OP_CEQ    (256+CEE_CEQ)
575 #define OP_CLT    (256+CEE_CLT)
576 #define OP_CLT_UN (256+CEE_CLT_UN)
577 #define OP_CGT    (256+CEE_CGT)
578 #define OP_CGT_UN (256+CEE_CGT_UN)
579 #define OP_LOCALLOC (256+CEE_LOCALLOC)
580
581 /* opcodes: value assigned after all the CIL opcodes */
582 #ifdef MINI_OP
583 #undef MINI_OP
584 #endif
585 #define MINI_OP(a,b) a,
586 enum {
587         OP_START = MONO_CEE_LAST,
588 #include "mini-ops.h"
589         OP_LAST
590 };
591 #undef MINI_OP
592
593 /* make this depend on 32bit platform (use OP_LADD otherwise) */
594 #define OP_PADD CEE_ADD
595 #define OP_PNEG CEE_NEG
596 #define OP_PCONV_TO_U2 CEE_CONV_U2
597 #define OP_PCONV_TO_OVF_I1_UN CEE_CONV_OVF_I1_UN
598 #define OP_PCONV_TO_OVF_I1 CEE_CONV_OVF_I1
599 #define OP_PCEQ CEE_CEQ
600
601 typedef enum {
602         STACK_INV,
603         STACK_I4,
604         STACK_I8,
605         STACK_PTR,
606         STACK_R8,
607         STACK_MP,
608         STACK_OBJ,
609         STACK_VTYPE,
610         STACK_MAX
611 } MonoStackType;
612
613 typedef struct {
614         union {
615                 double   r8;
616                 gint32   i4;
617                 gint64   i8;
618                 gpointer p;
619                 MonoClass *klass;
620         } data;
621         int type;
622 } StackSlot;
623
624 enum {
625         MONO_COMP_DOM = 1,
626         MONO_COMP_IDOM = 2,
627         MONO_COMP_DFRONTIER = 4,
628         MONO_COMP_DOM_REV = 8,
629         MONO_COMP_LIVENESS = 16,
630         MONO_COMP_SSA = 32,
631         MONO_COMP_SSA_DEF_USE = 64,
632         MONO_COMP_REACHABILITY = 128,
633         MONO_COMP_LOOPS = 256
634 };
635
636 typedef enum {
637         MONO_GRAPH_CFG = 1,
638         MONO_GRAPH_DTREE = 2,
639         MONO_GRAPH_CFG_CODE = 4,
640         MONO_GRAPH_CFG_SSA = 8,
641         MONO_GRAPH_CFG_OPTCODE = 16
642 } MonoGraphOptions;
643
644 typedef struct {
645         const char *name;
646         gconstpointer func;
647         gconstpointer wrapper;
648         MonoMethodSignature *sig;
649 } MonoJitICallInfo;
650
651 typedef struct {
652         guint16 size;
653         guint16 offset;
654         guint8  pad;
655 } MonoJitArgumentInfo;
656
657 typedef void (*MonoInstFunc) (MonoInst *tree, gpointer data);
658
659 /* main function */
660 int         mono_main                      (int argc, char* argv[]);
661 void        mono_set_defaults              (int verbose_level, guint32 opts);
662 MonoDomain* mini_init                      (const char *filename);
663 void        mini_cleanup                   (MonoDomain *domain);
664
665 /* helper methods */
666 MonoJumpInfoToken * mono_jump_info_token_new (MonoMemPool *mp, MonoImage *image, guint32 token);
667 MonoInst* mono_find_spvar_for_region        (MonoCompile *cfg, int region);
668 void      mono_precompile_assemblies        (void);
669 int       mono_parse_default_optimizations  (const char* p);
670 void      mono_bblock_add_inst              (MonoBasicBlock *bb, MonoInst *inst);
671 void      mono_constant_fold                (MonoCompile *cfg);
672 void      mono_constant_fold_inst           (MonoInst *inst, gpointer data);
673 int       mono_is_power_of_two              (guint32 val);
674 void      mono_cprop_local                  (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst **acp, int acp_size);
675 MonoInst* mono_compile_create_var           (MonoCompile *cfg, MonoType *type, int opcode);
676 void      mono_blockset_print               (MonoCompile *cfg, MonoBitSet *set, const char *name, guint idom);
677 void      mono_print_tree                   (MonoInst *tree);
678 void      mono_print_tree_nl                (MonoInst *tree);
679 void      mono_print_code                   (MonoCompile *cfg);
680 void      mono_select_instructions          (MonoCompile *cfg);
681 const char* mono_inst_name                  (int op);
682 void      mono_inst_foreach                 (MonoInst *tree, MonoInstFunc func, gpointer data);
683 void      mono_disassemble_code             (guint8 *code, int size, char *id);
684 guint     mono_type_to_ldind                (MonoType *t);
685 guint     mono_type_to_stind                (MonoType *t);
686 void      mono_add_patch_info               (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target);
687 void      mono_remove_patch_info            (MonoCompile *cfg, int ip);
688 gpointer  mono_resolve_patch_target         (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors);
689 MonoLMF** mono_get_lmf_addr                 (void);
690 GList    *mono_varlist_insert_sorted        (MonoCompile *cfg, GList *list, MonoMethodVar *mv, gboolean sort_end);
691 GList    *mono_varlist_sort                 (MonoCompile *cfg, GList *list, int sort_type);
692 void      mono_analyze_liveness             (MonoCompile *cfg);
693 void      mono_linear_scan                  (MonoCompile *cfg, GList *vars, GList *regs, regmask_t *used_mask);
694 void      mono_create_jump_table            (MonoCompile *cfg, MonoInst *label, MonoBasicBlock **bbs, int num_blocks);
695 int       mono_compile_assembly             (MonoAssembly *ass, guint32 opts);
696 MonoCompile *mini_method_compile            (MonoMethod *method, guint32 opts, MonoDomain *domain, gboolean run_cctors, int parts);
697 void      mono_destroy_compile              (MonoCompile *cfg);
698 void      mono_aot_init                     (void);
699 MonoJitInfo*  mono_aot_get_method           (MonoDomain *domain,
700                                                                                          MonoMethod *method);
701 gboolean  mono_method_blittable             (MonoMethod *method);
702 gboolean  mono_method_same_domain           (MonoJitInfo *caller, MonoJitInfo *callee);
703 void      mono_register_opcode_emulation    (int opcode, const char* name, MonoMethodSignature *sig, gpointer func, gboolean no_throw);
704 void      mono_arch_register_lowlevel_calls (void);
705 void      mono_draw_graph                   (MonoCompile *cfg, MonoGraphOptions draw_options);
706 void      mono_add_varcopy_to_end           (MonoCompile *cfg, MonoBasicBlock *bb, int src, int dest);
707
708 int               mono_find_method_opcode      (MonoMethod *method);
709 MonoJitICallInfo *mono_find_jit_icall_by_name  (const char *name);
710 MonoJitICallInfo *mono_find_jit_icall_by_addr  (gconstpointer addr);
711 MonoJitICallInfo *mono_register_jit_icall      (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
712 gconstpointer     mono_icall_get_wrapper       (MonoJitICallInfo* callinfo);
713
714 gpointer          mono_create_jump_trampoline (MonoDomain *domain, 
715                                                                                            MonoMethod *method, 
716                                                                                            gboolean add_sync_wrapper);
717 gpointer          mono_create_class_init_trampoline (MonoVTable *vtable);
718 MonoVTable*       mono_find_class_init_trampoline_by_addr (gconstpointer addr);
719 gboolean          mono_running_on_valgrind (void);
720
721 /* methods that must be provided by the arch-specific port */
722 void      mono_arch_cpu_init                    (void);
723 guint32   mono_arch_cpu_optimizazions           (guint32 *exclude_mask);
724 void      mono_arch_instrument_mem_needs        (MonoMethod *method, int *stack, int *code);
725 void     *mono_arch_instrument_prolog           (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments);
726 void     *mono_arch_instrument_epilog           (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments);
727 MonoCallInst *mono_arch_call_opcode             (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual);
728 gint      mono_arch_get_opcode_for_method       (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args);
729 void      mono_codegen                          (MonoCompile *cfg);
730 const char *mono_arch_regname                   (int reg);
731 gpointer  mono_arch_get_throw_exception         (void);
732 gpointer  mono_arch_get_throw_exception_by_name (void);
733 gpointer  mono_arch_create_jit_trampoline       (MonoMethod *method);
734 MonoJitInfo *mono_arch_create_jump_trampoline      (MonoMethod *method);
735 gpointer  mono_arch_create_class_init_trampoline(MonoVTable *vtable);
736 GList    *mono_arch_get_allocatable_int_vars    (MonoCompile *cfg);
737 GList    *mono_arch_get_global_int_regs         (MonoCompile *cfg);
738 guint32   mono_arch_regalloc_cost               (MonoCompile *cfg, MonoMethodVar *vmv);
739 void      mono_arch_patch_code                  (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors);
740 void      mono_arch_flush_icache                (guint8 *code, gint size);
741 int       mono_arch_max_epilog_size             (MonoCompile *cfg);
742 guint8   *mono_arch_emit_prolog                 (MonoCompile *cfg);
743 void      mono_arch_emit_epilog                 (MonoCompile *cfg);
744 void      mono_arch_local_regalloc              (MonoCompile *cfg, MonoBasicBlock *bb);
745 void      mono_arch_output_basic_block          (MonoCompile *cfg, MonoBasicBlock *bb);
746 gboolean  mono_arch_has_unwind_info             (gconstpointer addr);
747 void      mono_arch_setup_jit_tls_data          (MonoJitTlsData *tls);
748 void      mono_arch_free_jit_tls_data           (MonoJitTlsData *tls);
749 void      mono_arch_emit_this_vret_args         (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg);
750 void      mono_arch_allocate_vars               (MonoCompile *m);
751 int       mono_arch_get_argument_info           (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info);
752 gboolean  mono_arch_print_tree                  (MonoInst *tree, int arity);
753 MonoJitInfo *mono_arch_find_jit_info            (MonoDomain *domain, 
754                                                  MonoJitTlsData *jit_tls, 
755                                                  MonoJitInfo *res, 
756                                                  MonoJitInfo *prev_ji, 
757                                                  MonoContext *ctx, 
758                                                  MonoContext *new_ctx, 
759                                                  char **trace, 
760                                                  MonoLMF **lmf, 
761                                                  int *native_offset,
762                                                  gboolean *managed);
763 gpointer mono_arch_get_call_filter              (void);
764 gpointer mono_arch_get_restore_context          (void);
765 gboolean mono_arch_handle_exception             (void *sigctx, gpointer obj, gboolean test_only);
766 gpointer mono_arch_ip_from_context              (void *sigctx);
767 void     mono_arch_flush_register_windows       (void);
768
769 /* Exception handling */
770 gboolean mono_handle_exception                  (MonoContext *ctx, gpointer obj, gboolean test_only);
771 void      mono_jit_walk_stack                   (MonoStackWalk func, gpointer user_data);
772 MonoArray *ves_icall_get_trace                  (MonoException *exc, gint32 skip, MonoBoolean need_file_info);
773 MonoBoolean ves_icall_get_frame_info            (gint32 skip, MonoBoolean need_file_info, 
774                                                  MonoReflectionMethod **method, 
775                                                  gint32 *iloffset, gint32 *native_offset,
776                                                  MonoString **file, gint32 *line, gint32 *column);
777
778 /* Dominator/SSA methods */
779 void        mono_compile_dominator_info         (MonoCompile *cfg, int dom_flags);
780 void        mono_compute_natural_loops          (MonoCompile *cfg);
781 MonoBitSet* mono_compile_iterated_dfrontier     (MonoCompile *cfg, MonoBitSet *set);
782 void        mono_ssa_compute                    (MonoCompile *cfg);
783 void        mono_ssa_remove                     (MonoCompile *cfg);
784 void        mono_ssa_cprop                      (MonoCompile *cfg);
785 void        mono_ssa_deadce                     (MonoCompile *cfg);
786 void        mono_ssa_strength_reduction         (MonoCompile *cfg);
787 void        mono_free_loop_info                 (MonoCompile *cfg);
788
789 /* debugging support */
790 void      mono_debug_init_method                (MonoCompile *cfg, MonoBasicBlock *start_block,
791                                                  guint32 breakpoint_id);
792 void      mono_debug_open_method                (MonoCompile *cfg);
793 void      mono_debug_close_method               (MonoCompile *cfg);
794 void      mono_debug_open_block                 (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address);
795 void      mono_debug_record_line_number         (MonoCompile *cfg, MonoInst *ins, guint32 address);
796 void      mono_debug_serialize_debug_info       (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len);
797 void      mono_debug_add_aot_method            (MonoDomain *domain,
798                                                                                                 MonoMethod *method, guint8 *code_start, 
799                                                                                                 guint8 *debug_info, guint32 debug_info_len);
800
801 /* Tracing */
802 MonoTraceSpec *mono_trace_parse_options         (MonoAssembly *assembly, char *options);
803 gboolean       mono_trace_eval                  (MonoMethod *method);
804
805 extern void
806 mono_perform_abc_removal (MonoCompile *cfg);
807
808 #endif /* __MONO_MINI_H__ */