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