1 #ifndef __MONO_MINI_H__
2 #define __MONO_MINI_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/class-internals.h"
16 #include "mono/metadata/object-internals.h"
17 #include <mono/metadata/profiler-private.h>
18 #include <mono/utils/mono-compiler.h>
20 #include "mini-arch.h"
25 #define G_LIKELY(a) (a)
26 #define G_UNLIKELY(a) (a)
30 #define MINI_DEBUG(level,limit,code)
32 #define MINI_DEBUG(level,limit,code) do {if (G_UNLIKELY ((level) >= (limit))) code} while (0)
36 #define MONO_USE_AOT_COMPILER
39 /* for 32 bit systems */
40 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
41 #define MINI_LS_WORD_OFFSET 0
42 #define MINI_MS_WORD_OFFSET 4
43 #define inst_ls_word data.op[0].const_val
44 #define inst_ms_word data.op[1].const_val
46 #define MINI_LS_WORD_OFFSET 4
47 #define MINI_MS_WORD_OFFSET 0
48 #define inst_ls_word data.op[1].const_val
49 #define inst_ms_word data.op[0].const_val
52 /* Version number of the AOT file format */
53 #define MONO_AOT_FILE_VERSION "29"
56 #define mono_bitset_foreach_bit(set,b,n) \
57 for (b = 0; b < n; b++)\
58 if (mono_bitset_test_fast(set,b))
59 #define mono_bitset_foreach_bit_rev(set,b,n) \
60 for (b = n - 1; b >= 0; b--)\
61 if (mono_bitset_test_fast(set,b))
63 #define mono_bitset_foreach_bit(set,b,n) \
64 for (b = mono_bitset_find_start (set); b < n && b >= 0; b = mono_bitset_find_first (set, b))
65 #define mono_bitset_foreach_bit_rev(set,b,n) \
66 for (b = mono_bitset_find_last (set, n - 1); b >= 0; b = b ? mono_bitset_find_last (set, b) : -1)
71 * Pull the list of opcodes
73 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
77 #include "mono/cil/opcode.def"
82 #define MONO_VARINFO(cfg,varnum) ((cfg)->vars [varnum])
84 #define MONO_INST_NEW(cfg,dest,op) do { \
85 (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
86 (dest)->opcode = (op); \
89 #define MONO_INST_NEW_CALL(cfg,dest,op) do { \
90 (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoCallInst)); \
91 (dest)->inst.opcode = (op); \
94 #define MONO_INST_NEW_CALL_ARG(cfg,dest,op) do { \
95 (dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoCallArgParm)); \
96 (dest)->ins.opcode = (op); \
99 #define MONO_ADD_INS(b,inst) do { \
100 if ((b)->last_ins) { \
101 (b)->last_ins->next = (inst); \
102 (b)->last_ins = (inst); \
104 (b)->code = (b)->last_ins = (inst); \
108 typedef struct MonoInst MonoInst;
109 typedef struct MonoCallInst MonoCallInst;
110 typedef struct MonoCallArgParm MonoCallArgParm;
111 typedef struct MonoEdge MonoEdge;
112 typedef struct MonoMethodVar MonoMethodVar;
113 typedef struct MonoBasicBlock MonoBasicBlock;
114 typedef struct MonoLMF MonoLMF;
115 typedef struct MonoSpillInfo MonoSpillInfo;
116 typedef struct MonoTraceSpec MonoTraceSpec;
118 extern guint32 mono_jit_tls_id;
119 extern MonoTraceSpec *mono_jit_trace_calls;
120 extern gboolean mono_break_on_exc;
121 extern int mono_exc_esp_offset;
123 #define mono_compile_aot 0
125 extern gboolean mono_compile_aot;
127 extern gboolean mono_use_security_manager;
135 struct MonoSpillInfo {
136 #ifndef MONO_ARCH_HAS_XP_REGALLOC
143 * This structure contains the information maintained by the verifier for each CIL
144 * stack slot. This information is also available in MonoInst, but the verifier needs to
145 * update the type information during stack merges, which could lead to problems if done
146 * on MonoInsts, so we use a dedicated structure instead.
154 * The IR-level basic block.
156 * A basic block can have multiple exits just fine, as long as the point of
157 * 'departure' is the last instruction in the basic block. Extended basic
158 * blocks, on the other hand, may have instructions that leave the block
159 * midstream. The important thing is that they cannot be _entered_
160 * midstream, ie, execution of a basic block (or extened bb) always start
161 * at the beginning of the block, never in the middle.
163 struct MonoBasicBlock {
166 /* the next basic block in the order it appears in IL */
167 MonoBasicBlock *next_bb;
170 * Before instruction selection it is the first tree in the
171 * forest and the first item in the list of trees. After
172 * instruction selection it is the first instruction and the
173 * first item in the list of instructions.
177 /* unique block number identification */
182 /* Basic blocks: incoming and outgoing counts and pointers */
183 /* Each bb should only appear once in each array */
184 gint16 out_count, in_count;
185 MonoBasicBlock **in_bb;
186 MonoBasicBlock **out_bb;
188 /* Points to the start of the CIL code that initiated this BB */
189 unsigned char* cil_code;
191 /* Length of the CIL block */
194 /* The address of the generated code, used for fixups */
198 /* Visited and reachable flags */
202 * SSA and loop based flags
204 MonoBitSet *dominators;
205 MonoBitSet *dfrontier;
206 MonoBasicBlock *idom;
208 /* fast dominator algorithm */
209 MonoBasicBlock *df_parent, *ancestor, *child, *label;
211 int size, sdom, idomn;
213 /* loop nesting and recognition */
216 gint8 loop_body_start;
219 * Whenever the bblock is rarely executed so it should be emitted after
220 * the function epilog.
222 guint out_of_line : 1;
223 /* Caches the result of uselessness calculation during optimize_branches */
224 guint not_useless : 1;
226 /* use for liveness analysis */
228 MonoBitSet *kill_set;
229 MonoBitSet *live_in_set;
230 MonoBitSet *live_out_set;
232 /* fields to deal with non-empty stack slots at bb boundary */
233 guint16 out_scount, in_scount;
234 MonoInst **out_stack;
236 MonoStackSlot *stack_state; /* Verification stack state on enter to bblock */
238 /* we use that to prevent merging of bblock covered by different clauses*/
242 * The region encodes whether the basic block is inside
243 * a finally, catch, filter or none of thoese.
245 * If the value is -1, then it is neither finally, catch nor filter
247 * Otherwise the format is:
249 * Bits: | 0-3 | 4-7 | 8-31
251 * | clause-flags | MONO_REGION | clause-index
256 /* The current symbolic register number, used in local register allocation. */
257 guint32 max_ireg, max_freg;
263 BB_REACHABLE = 1 << 1,
264 BB_EXCEPTION_DEAD_OBJ = 1 << 2,
265 BB_EXCEPTION_UNSAFE = 1 << 3,
266 BB_EXCEPTION_HANDLER = 1 << 4
277 MonoMethodSignature *signature;
278 MonoBasicBlock **many_blocks;
279 MonoBasicBlock *target_block;
284 MonoCallInst *call_inst;
290 guint8 type; /* stack type */
294 /* used by the register allocator */
295 gint32 dreg, sreg1, sreg2;
296 /* used mostly by the backend to store additional info it may need */
300 gint32 size; /* in OP_MEMSET and OP_MEMCPY */
302 gboolean is_pinvoke; /* for variables in the unmanaged marshal format */
308 const unsigned char* cil_code; /* for debugging and bblock splitting */
311 struct MonoCallInst {
313 MonoMethodSignature *signature;
320 regmask_t used_iregs;
321 regmask_t used_fregs;
322 #if defined(MONO_ARCH_HAS_XP_LOCAL_REGALLOC)
323 GSList *out_ireg_args;
324 GSList *out_freg_args;
328 struct MonoCallArgParm {
337 * Note: some of the values overlap, because they can't appear
338 * in the same MonoInst.
341 MONO_INST_HAS_METHOD = 1,
342 /* temp local created by a DUP: used only within a BB */
343 MONO_INST_IS_TEMP = 1,
344 MONO_INST_INIT = 1, /* in localloc */
345 MONO_INST_IS_DEAD = 2,
346 MONO_INST_TAILCALL = 4,
347 MONO_INST_VOLATILE = 4,
348 MONO_INST_BRLABEL = 4,
349 MONO_INST_NOTYPECHECK = 4,
350 MONO_INST_UNALIGNED = 8,
351 MONO_INST_DEFINITION_HAS_SIDE_EFFECTS = 8,
352 /* the address of the variable has been taken */
353 MONO_INST_INDIRECT = 16,
354 MONO_INST_NORANGECHECK = 16
357 #define inst_c0 data.op[0].const_val
358 #define inst_c1 data.op[1].const_val
359 #define inst_i0 data.op[0].src
360 #define inst_i1 data.op[1].src
361 #define inst_p0 data.op[0].p
362 #define inst_p1 data.op[1].p
363 #define inst_l data.i8const
364 #define inst_r data.r8const
365 #define inst_left data.op[0].src
366 #define inst_right data.op[1].src
368 #define inst_newa_len data.op[0].src
369 #define inst_newa_class data.op[1].klass
371 #define inst_var data.op[0].var
372 #define inst_vtype data.op[1].vtype
373 /* in branch instructions */
374 #define inst_many_bb data.op[1].many_blocks
375 #define inst_target_bb data.op[0].target_block
376 #define inst_true_bb data.op[1].many_blocks[0]
377 #define inst_false_bb data.op[1].many_blocks[1]
379 #define inst_basereg sreg1
380 #define inst_indexreg sreg2
381 #define inst_destbasereg dreg
382 #define inst_offset data.op[0].const_val
383 #define inst_imm data.op[1].const_val
384 #define inst_call data.op[1].call_inst
386 #define inst_phi_args data.op[1].phi_args
388 /* instruction description for use in regalloc/scheduling */
404 guint16 tid; /* tree number */
405 guint16 bid; /* block number */
411 MonoPosition first_use, last_use;
415 * Additional information about a variable
417 struct MonoMethodVar {
418 guint idx; /* inside cfg->varinfo, cfg->vars */
420 MonoBitSet *dfrontier;
421 MonoLiveRange range; /* generated by liveness analysis */
422 int reg; /* != -1 if allocated into a register */
424 MonoBitSet *def_in; /* used by SSA */
425 MonoInst *def; /* used by SSA */
426 MonoBasicBlock *def_bb; /* used by SSA */
427 GList *uses; /* used by SSA */
428 char cpstate; /* used by SSA conditional constant propagation */
432 gpointer end_of_stack;
436 gpointer signal_stack;
437 guint32 signal_stack_size;
438 void (*abort_func) (MonoObject *object);
444 MONO_PATCH_INFO_LABEL,
445 MONO_PATCH_INFO_METHOD,
446 MONO_PATCH_INFO_METHOD_JUMP,
447 MONO_PATCH_INFO_METHOD_REL,
448 MONO_PATCH_INFO_METHODCONST,
449 MONO_PATCH_INFO_INTERNAL_METHOD,
450 MONO_PATCH_INFO_SWITCH,
452 MONO_PATCH_INFO_EXC_NAME,
453 MONO_PATCH_INFO_CLASS,
454 MONO_PATCH_INFO_IMAGE,
455 MONO_PATCH_INFO_FIELD,
456 MONO_PATCH_INFO_VTABLE,
457 MONO_PATCH_INFO_CLASS_INIT,
458 MONO_PATCH_INFO_SFLDA,
459 MONO_PATCH_INFO_LDSTR,
460 MONO_PATCH_INFO_LDTOKEN,
461 MONO_PATCH_INFO_TYPE_FROM_HANDLE,
466 MONO_PATCH_INFO_ADJUSTED_IID,
467 MONO_PATCH_INFO_BB_OVF,
468 MONO_PATCH_INFO_EXC_OVF,
469 MONO_PATCH_INFO_WRAPPER,
470 MONO_PATCH_INFO_GOT_OFFSET,
471 MONO_PATCH_INFO_DECLSEC,
476 * We need to store the image which the token refers to along with the token,
477 * since the image might not be the same as the image of the method which
478 * contains the relocation, because of inlining.
480 typedef struct MonoJumpInfoToken {
485 typedef struct MonoJumpInfoBBTable {
486 MonoBasicBlock **table;
488 } MonoJumpInfoBBTable;
490 typedef struct MonoJumpInfo MonoJumpInfo;
491 struct MonoJumpInfo {
499 MonoJumpInfoType type;
501 gconstpointer target;
502 #if SIZEOF_VOID_P == 8
511 MonoClassField *field;
515 MonoJumpInfoToken *token;
516 MonoJumpInfoBBTable *table;
521 MONO_TRAMPOLINE_GENERIC,
522 MONO_TRAMPOLINE_JUMP,
523 MONO_TRAMPOLINE_CLASS_INIT,
525 MONO_TRAMPOLINE_AOT_PLT,
526 MONO_TRAMPOLINE_DELEGATE,
528 } MonoTrampolineType;
530 /* optimization flags */
531 #define OPTFLAG(id,shift,name,descr) MONO_OPT_ ## id = 1 << shift,
533 #include "optflags-def.h"
537 /* Bit-fields in the MonoBasicBlock.region */
538 #define MONO_REGION_TRY 0
539 #define MONO_REGION_FINALLY 16
540 #define MONO_REGION_CATCH 32
541 #define MONO_REGION_FAULT 64 /* Currently unused */
542 #define MONO_REGION_FILTER 128
544 #define MONO_BBLOCK_IS_IN_REGION(bblock, regtype) (((bblock)->region & (0xf << 4)) == (regtype))
547 * Control Flow Graph and compilation unit information
551 MonoMemPool *mempool;
553 MonoMethodVar **vars;
555 MonoBasicBlock *bb_entry;
556 MonoBasicBlock *bb_exit;
557 MonoBasicBlock *bb_init;
558 MonoBasicBlock **bblocks;
560 MonoMemPool *state_pool; /* used by instruction selection */
561 MonoBasicBlock *cbb; /* used by instruction selection */
562 MonoInst *prev_ins; /* in decompose */
563 MonoJumpInfo *patch_info;
564 MonoJitInfo *jit_info;
565 MonoJitDynamicMethodInfo *dynamic_info;
568 guint num_varinfo; /* used items in varinfo */
569 guint varinfo_count; /* total storage in varinfo */
573 MonoSpillInfo *spill_info; /* machine register spills */
574 MonoSpillInfo *spill_info_float; /* fp register spills */
576 gint spill_info_len, spill_info_float_len;
577 /* unsigned char *cil_code; */
578 MonoMethod *inlined_method; /* the method which is currently inlined */
579 MonoInst *domainvar; /* a cache for the current domain */
580 MonoInst *got_var; /* Global Offset Table variable */
582 struct MonoAliasingInformation *aliasing_info;
584 /* A hashtable of region ID-> SP var mappings */
585 /* An SP var is a place to store the stack pointer (used by handlers)*/
588 /* A hashtable of region ID -> EX var mappings */
589 /* An EX var stores the exception object passed to catch/filter blocks */
592 GList *ldstr_list; /* used by AOT */
596 unsigned char *native_code;
601 regmask_t used_int_regs;
603 guint32 prof_options;
606 guint32 verbose_level;
611 guint disable_aot : 1;
612 guint disable_ssa : 1;
613 guint run_cctors : 1;
614 guint need_lmf_area : 1;
615 guint compile_aot : 1;
616 guint got_var_allocated : 1;
617 guint ret_var_is_local : 1;
618 guint dont_verify_stack_merge : 1;
619 guint unverifiable : 1;
620 guint skip_visibility : 1;
624 MonoProfileCoverageInfo *coverage_info;
625 MonoCompileArch arch;
626 guint32 exception_type; /* MONO_EXCEPTION_* */
627 guint32 exception_data;
628 char* exception_message;
630 /* Fields used by the local reg allocator */
633 void* reverse_inst_list;
634 int reginfo_len, reginfof_len;
635 int reverse_inst_list_len;
639 MONO_CFG_HAS_ALLOCA = 1 << 0,
640 MONO_CFG_HAS_CALLS = 1 << 1,
641 MONO_CFG_HAS_LDELEMA = 1 << 2,
642 MONO_CFG_HAS_VARARGS = 1 << 3,
643 MONO_CFG_HAS_TAIL = 1 << 4,
644 MONO_CFG_HAS_FPOUT = 1 << 5, /* there are fp values passed in int registers */
645 MONO_CFG_HAS_SPILLUP = 1 << 6 /* spill var slots are allocated from bottom to top */
649 gulong methods_compiled;
651 gulong methods_lookups;
652 gulong method_trampolines;
654 gulong analyze_stack_repeat;
655 gulong cil_code_size;
656 gulong native_code_size;
657 gulong code_reallocs;
658 gulong max_code_size_ratio;
659 gulong biggest_method_size;
660 gulong allocated_code_size;
661 gulong inlineable_methods;
662 gulong inlined_methods;
664 gulong max_basic_blocks;
665 gulong cas_declsec_check;
666 gulong cas_linkdemand_icall;
667 gulong cas_linkdemand_pinvoke;
668 gulong cas_linkdemand_aptc;
669 gulong cas_linkdemand;
670 gulong cas_demand_generation;
671 MonoMethod *max_ratio_method;
672 MonoMethod *biggest_method;
676 extern MonoJitStats mono_jit_stats;
678 /* values for MonoInst.ssa_op */
681 MONO_SSA_ADDRESS_TAKEN = 1,
684 MONO_SSA_LOAD_STORE = MONO_SSA_LOAD|MONO_SSA_STORE,
685 MONO_SSA_INDIRECT_LOAD = MONO_SSA_LOAD|MONO_SSA_ADDRESS_TAKEN,
686 MONO_SSA_INDIRECT_STORE = MONO_SSA_STORE|MONO_SSA_ADDRESS_TAKEN,
687 MONO_SSA_INDIRECT_LOAD_STORE =
688 MONO_SSA_LOAD|MONO_SSA_STORE|MONO_SSA_ADDRESS_TAKEN
691 #define OP_CEQ (256+CEE_CEQ)
692 #define OP_CLT (256+CEE_CLT)
693 #define OP_CLT_UN (256+CEE_CLT_UN)
694 #define OP_CGT (256+CEE_CGT)
695 #define OP_CGT_UN (256+CEE_CGT_UN)
696 #define OP_LOCALLOC (256+CEE_LOCALLOC)
698 /* opcodes: value assigned after all the CIL opcodes */
702 #define MINI_OP(a,b) a,
704 OP_START = MONO_CEE_LAST,
705 #include "mini-ops.h"
710 #if SIZEOF_VOID_P == 8
711 #define OP_PCONST OP_I8CONST
712 #define OP_PADD OP_LADD
713 #define OP_PNEG OP_LNEG
714 #define OP_PCONV_TO_U2 OP_LCONV_TO_U2
715 #define OP_PCONV_TO_OVF_I1_UN OP_LCONV_TO_OVF_I1_UN
716 #define OP_PCONV_TO_OVF_I1 OP_LCONV_TO_OVF_I1
717 #define OP_PCEQ CEE_CEQ
718 #define OP_STOREP_MEMBASE_REG OP_STOREI8_MEMBASE_REG
719 #define OP_STOREP_MEMBASE_IMM OP_STOREI8_MEMBASE_IMM
721 #define OP_PCONST OP_ICONST
722 #define OP_PADD CEE_ADD
723 #define OP_PNEG CEE_NEG
724 #define OP_PCONV_TO_U2 CEE_CONV_U2
725 #define OP_PCONV_TO_OVF_I1_UN CEE_CONV_OVF_I1_UN
726 #define OP_PCONV_TO_OVF_I1 CEE_CONV_OVF_I1
727 #define OP_PCEQ CEE_CEQ
728 #define OP_STOREP_MEMBASE_REG OP_STOREI4_MEMBASE_REG
729 #define OP_STOREP_MEMBASE_IMM OP_STOREI4_MEMBASE_IMM
755 #if HAVE_ARRAY_ELEM_INIT
756 extern const guint8 mono_burg_arity [];
758 extern guint8 mono_burg_arity [];
764 MONO_COMP_DFRONTIER = 4,
765 MONO_COMP_DOM_REV = 8,
766 MONO_COMP_LIVENESS = 16,
768 MONO_COMP_SSA_DEF_USE = 64,
769 MONO_COMP_REACHABILITY = 128,
770 MONO_COMP_LOOPS = 256
775 MONO_GRAPH_DTREE = 2,
776 MONO_GRAPH_CFG_CODE = 4,
777 MONO_GRAPH_CFG_SSA = 8,
778 MONO_GRAPH_CFG_OPTCODE = 16
785 } MonoJitArgumentInfo;
788 gboolean handle_sigint;
789 gboolean keep_delegates;
790 gboolean collect_pagefault_stats;
791 gboolean break_on_unverified;
800 /* Implicit exceptions */
802 MONO_EXC_INDEX_OUT_OF_RANGE,
805 MONO_EXC_DIVIDE_BY_ZERO,
806 MONO_EXC_INVALID_CAST,
808 MONO_EXC_ARRAY_TYPE_MISMATCH,
812 typedef void (*MonoInstFunc) (MonoInst *tree, gpointer data);
815 int mono_main (int argc, char* argv[]);
816 void mono_set_defaults (int verbose_level, guint32 opts);
817 MonoDomain* mini_init (const char *filename);
818 void mini_cleanup (MonoDomain *domain);
821 MonoJumpInfoToken * mono_jump_info_token_new (MonoMemPool *mp, MonoImage *image, guint32 token);
822 MonoInst* mono_find_spvar_for_region (MonoCompile *cfg, int region);
823 void mono_precompile_assemblies (void);
824 int mono_parse_default_optimizations (const char* p);
825 void mono_bblock_add_inst (MonoBasicBlock *bb, MonoInst *inst);
826 void mono_constant_fold (MonoCompile *cfg);
827 void mono_constant_fold_inst (MonoInst *inst, gpointer data);
828 int mono_eval_cond_branch (MonoInst *branch);
829 int mono_is_power_of_two (guint32 val);
830 void mono_cprop_local (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst **acp, int acp_size);
831 MonoInst* mono_compile_create_var (MonoCompile *cfg, MonoType *type, int opcode);
832 void mono_compile_make_var_load (MonoCompile *cfg, MonoInst *dest, gssize var_index);
833 MonoInst* mono_compile_create_var_load (MonoCompile *cfg, gssize var_index);
834 MonoInst* mono_compile_create_var_store (MonoCompile *cfg, gssize var_index, MonoInst *value);
835 MonoType* mono_type_from_stack_type (MonoInst *ins);
836 void mono_blockset_print (MonoCompile *cfg, MonoBitSet *set, const char *name, guint idom);
837 void mono_print_tree (MonoInst *tree);
838 void mono_print_tree_nl (MonoInst *tree);
839 void mono_print_code (MonoCompile *cfg);
840 void mono_print_method_from_ip (void *ip);
841 char *mono_pmip (void *ip);
842 void mono_select_instructions (MonoCompile *cfg);
843 const char* mono_inst_name (int op);
844 void mono_inst_foreach (MonoInst *tree, MonoInstFunc func, gpointer data);
845 void mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id);
846 void mono_add_patch_info (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target);
847 void mono_remove_patch_info (MonoCompile *cfg, int ip);
848 MonoJumpInfo* mono_patch_info_dup_mp (MonoMemPool *mp, MonoJumpInfo *patch_info);
849 guint mono_patch_info_hash (gconstpointer data);
850 gint mono_patch_info_equal (gconstpointer ka, gconstpointer kb);
851 gpointer mono_resolve_patch_target (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors);
852 MonoLMF** mono_get_lmf_addr (void);
853 void mono_jit_thread_attach (MonoDomain *domain);
854 guint32 mono_get_jit_tls_key (void);
855 gint32 mono_get_lmf_tls_offset (void);
856 GList *mono_varlist_insert_sorted (MonoCompile *cfg, GList *list, MonoMethodVar *mv, gboolean sort_end);
857 GList *mono_varlist_sort (MonoCompile *cfg, GList *list, int sort_type);
858 void mono_analyze_liveness (MonoCompile *cfg);
859 void mono_linear_scan (MonoCompile *cfg, GList *vars, GList *regs, regmask_t *used_mask);
860 void mono_create_jump_table (MonoCompile *cfg, MonoInst *label, MonoBasicBlock **bbs, int num_blocks);
861 int mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options);
862 MonoCompile *mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, gboolean run_cctors, gboolean compile_aot, int parts);
863 void mono_destroy_compile (MonoCompile *cfg);
864 MonoJitICallInfo *mono_find_jit_opcode_emulation (int opcode);
867 void mono_aot_init (void);
868 MonoJitInfo* mono_aot_get_method (MonoDomain *domain,
870 gpointer mono_aot_get_method_from_token (MonoDomain *domain, MonoImage *image, guint32 token);
871 gboolean mono_aot_is_got_entry (guint8 *code, guint8 *addr);
872 guint8* mono_aot_get_plt_entry (guint8 *code);
873 gboolean mono_aot_init_vtable (MonoVTable *vtable);
874 gboolean mono_aot_get_cached_class_info (MonoClass *klass, MonoCachedClassInfo *res);
875 gboolean mono_aot_get_class_from_name (MonoImage *image, const char *name_space, const char *name, MonoClass **klass);
876 MonoJitInfo* mono_aot_find_jit_info (MonoDomain *domain, MonoImage *image, gpointer addr);
877 void mono_aot_set_make_unreadable (gboolean unreadable);
878 gboolean mono_aot_is_pagefault (void *ptr);
879 void mono_aot_handle_pagefault (void *ptr);
880 guint32 mono_aot_get_n_pagefaults (void);
881 gpointer mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code);
883 gboolean mono_method_blittable (MonoMethod *method);
884 gboolean mono_method_same_domain (MonoJitInfo *caller, MonoJitInfo *callee);
886 void mono_register_opcode_emulation (int opcode, const char* name, const char *sigstr, gpointer func, gboolean no_throw);
887 void mono_draw_graph (MonoCompile *cfg, MonoGraphOptions draw_options);
888 void mono_add_varcopy_to_end (MonoCompile *cfg, MonoBasicBlock *bb, int src, int dest);
889 void mono_add_ins_to_end (MonoBasicBlock *bb, MonoInst *inst);
890 gpointer mono_create_ftnptr (MonoDomain *domain, gpointer addr);
892 int mono_find_method_opcode (MonoMethod *method);
893 MonoJitICallInfo *mono_find_jit_icall_by_name (const char *name);
894 MonoJitICallInfo *mono_find_jit_icall_by_addr (gconstpointer addr);
895 MonoJitICallInfo *mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
896 gconstpointer mono_icall_get_wrapper (MonoJitICallInfo* callinfo);
898 guint8 * mono_get_trampoline_code (MonoTrampolineType tramp_type);
899 gpointer mono_create_jump_trampoline (MonoDomain *domain,
901 gboolean add_sync_wrapper);
902 gpointer mono_create_class_init_trampoline (MonoVTable *vtable);
903 gpointer mono_create_jit_trampoline (MonoMethod *method);
904 gpointer mono_create_jit_trampoline_from_token (MonoImage *image, guint32 token);
905 MonoVTable* mono_find_class_init_trampoline_by_addr (gconstpointer addr);
906 gpointer mono_magic_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp);
907 gpointer mono_delegate_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp);
908 gpointer mono_aot_trampoline (gssize *regs, guint8 *code, guint8 *token_info,
910 gpointer mono_aot_plt_trampoline (gssize *regs, guint8 *code, guint8 *token_info,
912 void mono_class_init_trampoline (gssize *regs, guint8 *code, MonoVTable *vtable, guint8 *tramp);
914 gboolean mono_running_on_valgrind (void);
915 void* mono_global_codeman_reserve (int size);
916 const char *mono_regname_full (int reg, gboolean fp);
917 gint32* mono_allocate_stack_slots_full (MonoCompile *cfg, gboolean backward, guint32 *stack_size, guint32 *stack_align);
918 gint32* mono_allocate_stack_slots (MonoCompile *cfg, guint32 *stack_size, guint32 *stack_align);
919 void mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb);
920 MonoInst *mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, const char * exname);
922 /* methods that must be provided by the arch-specific port */
923 void mono_arch_cpu_init (void);
924 guint32 mono_arch_cpu_optimizazions (guint32 *exclude_mask);
925 void mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code);
926 void *mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments);
927 void *mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments);
928 MonoCallInst *mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual);
929 MonoInst *mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args);
930 void mono_codegen (MonoCompile *cfg);
931 void mono_call_inst_add_outarg_reg (MonoCompile *cfg, MonoCallInst *call, int vreg, int hreg, gboolean fp);
932 const char *mono_arch_regname (int reg);
933 const char *mono_arch_fregname (int reg);
934 gpointer mono_arch_get_throw_exception (void);
935 gpointer mono_arch_get_rethrow_exception (void);
936 gpointer mono_arch_get_throw_exception_by_name (void);
937 gpointer mono_arch_get_throw_corlib_exception (void);
938 guchar* mono_arch_create_trampoline_code (MonoTrampolineType tramp_type);
939 gpointer mono_arch_create_jit_trampoline (MonoMethod *method);
940 MonoJitInfo *mono_arch_create_jump_trampoline (MonoMethod *method);
941 gpointer mono_arch_create_class_init_trampoline(MonoVTable *vtable);
942 GList *mono_arch_get_allocatable_int_vars (MonoCompile *cfg);
943 GList *mono_arch_get_global_int_regs (MonoCompile *cfg);
944 guint32 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv);
945 void mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors);
946 void mono_arch_flush_icache (guint8 *code, gint size);
947 int mono_arch_max_epilog_size (MonoCompile *cfg);
948 guint8 *mono_arch_emit_prolog (MonoCompile *cfg);
949 void mono_arch_emit_epilog (MonoCompile *cfg);
950 void mono_arch_emit_exceptions (MonoCompile *cfg);
951 void mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb);
952 void mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb);
953 gboolean mono_arch_has_unwind_info (gconstpointer addr);
954 void mono_arch_setup_jit_tls_data (MonoJitTlsData *tls);
955 void mono_arch_free_jit_tls_data (MonoJitTlsData *tls);
956 void mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg);
957 void mono_arch_allocate_vars (MonoCompile *m);
958 int mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info);
959 gboolean mono_arch_print_tree (MonoInst *tree, int arity);
960 MonoJitInfo *mono_arch_find_jit_info (MonoDomain *domain,
961 MonoJitTlsData *jit_tls,
963 MonoJitInfo *prev_ji,
965 MonoContext *new_ctx,
970 gpointer mono_arch_get_call_filter (void);
971 gpointer mono_arch_get_restore_context (void);
972 gboolean mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only);
973 gpointer mono_arch_ip_from_context (void *sigctx);
974 void mono_arch_sigctx_to_monoctx (void *sigctx, MonoContext *ctx);
975 void mono_arch_monoctx_to_sigctx (MonoContext *mctx, void *ctx);
976 void mono_arch_flush_register_windows (void);
977 gboolean mono_arch_is_inst_imm (gint64 imm);
978 MonoInst* mono_arch_get_domain_intrinsic (MonoCompile* cfg);
979 MonoInst* mono_arch_get_thread_intrinsic (MonoCompile* cfg);
980 gboolean mono_arch_is_int_overflow (void *sigctx, void *info);
981 void mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg);
982 guint32 mono_arch_get_patch_offset (guint8 *code);
983 gpointer*mono_arch_get_vcall_slot_addr (guint8* code, gpointer *regs);
984 gpointer*mono_arch_get_delegate_method_ptr_addr (guint8* code, gpointer *regs);
985 void mono_arch_create_vars (MonoCompile *cfg);
986 void mono_arch_save_unwind_info (MonoCompile *cfg);
987 void mono_arch_register_lowlevel_calls (void);
988 gpointer mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr);
989 void mono_arch_patch_callsite (guint8 *code, guint8 *addr);
990 void mono_arch_patch_plt_entry (guint8 *code, guint8 *addr);
991 void mono_arch_nullify_class_init_trampoline(guint8 *code, gssize *regs);
992 void mono_arch_nullify_plt_entry (guint8 *code);
993 void mono_arch_patch_delegate_trampoline (guint8 *code, guint8 *tramp, gssize *regs, guint8 *addr);
994 gpointer mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len);
996 /* Exception handling */
997 gboolean mono_handle_exception (MonoContext *ctx, gpointer obj,
998 gpointer original_ip, gboolean test_only);
999 void mono_handle_native_sigsegv (int signal, void *sigctx);
1000 void mono_print_thread_dump (void *sigctx);
1001 void mono_jit_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
1002 void mono_jit_walk_stack_from_ctx (MonoStackWalk func, MonoContext *ctx, gboolean do_il_offset, gpointer user_data);
1003 void mono_setup_altstack (MonoJitTlsData *tls);
1004 void mono_free_altstack (MonoJitTlsData *tls);
1006 /* the new function to do stack walks */
1007 typedef gboolean (*MonoStackFrameWalk) (MonoDomain *domain, MonoContext *ctx, MonoJitInfo *ji, gpointer data);
1008 void mono_walk_stack (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoContext *start_ctx, MonoStackFrameWalk func, gpointer user_data);
1010 MonoArray *ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info);
1011 MonoBoolean ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
1012 MonoReflectionMethod **method,
1013 gint32 *iloffset, gint32 *native_offset,
1014 MonoString **file, gint32 *line, gint32 *column);
1015 MonoString *ves_icall_System_Exception_get_trace (MonoException *exc);
1017 /* Dominator/SSA methods */
1018 void mono_compile_dominator_info (MonoCompile *cfg, int dom_flags);
1019 void mono_compute_natural_loops (MonoCompile *cfg);
1020 MonoBitSet* mono_compile_iterated_dfrontier (MonoCompile *cfg, MonoBitSet *set);
1021 void mono_ssa_compute (MonoCompile *cfg);
1022 void mono_ssa_remove (MonoCompile *cfg);
1023 void mono_ssa_cprop (MonoCompile *cfg);
1024 void mono_ssa_deadce (MonoCompile *cfg);
1025 void mono_ssa_strength_reduction (MonoCompile *cfg);
1026 void mono_free_loop_info (MonoCompile *cfg);
1028 /* debugging support */
1029 void mono_debug_init_method (MonoCompile *cfg, MonoBasicBlock *start_block,
1030 guint32 breakpoint_id);
1031 void mono_debug_open_method (MonoCompile *cfg);
1032 void mono_debug_close_method (MonoCompile *cfg);
1033 void mono_debug_open_block (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address);
1034 void mono_debug_record_line_number (MonoCompile *cfg, MonoInst *ins, guint32 address);
1035 void mono_debug_serialize_debug_info (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len);
1036 void mono_debug_add_aot_method (MonoDomain *domain,
1037 MonoMethod *method, guint8 *code_start,
1038 guint8 *debug_info, guint32 debug_info_len);
1039 void mono_debug_add_icall_wrapper (MonoMethod *method, MonoJitICallInfo* info);
1040 void mono_debug_print_vars (gpointer ip, gboolean only_arguments);
1041 void mono_debugger_run_finally (MonoContext *start_ctx);
1043 /* Mono Debugger support */
1044 void mono_debugger_init (void);
1045 int mono_debugger_main (MonoDomain *domain, MonoAssembly *assembly, int argc, char **argv);
1049 MonoTraceSpec *mono_trace_parse_options (char *options);
1050 void mono_trace_set_assembly (MonoAssembly *assembly);
1051 gboolean mono_trace_eval (MonoMethod *method);
1054 mono_perform_abc_removal (MonoCompile *cfg);
1056 mono_perform_ssapre (MonoCompile *cfg);
1058 mono_local_cprop (MonoCompile *cfg);
1060 /* CAS - stack walk */
1061 MonoSecurityFrame* ves_icall_System_Security_SecurityFrame_GetSecurityFrame (gint32 skip);
1062 MonoArray* ves_icall_System_Security_SecurityFrame_GetSecurityStack (gint32 skip);
1064 #endif /* __MONO_MINI_H__ */