* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / yjit.c
blob39ade5f1e230f2201555ea83f712e2f18bde5d5d
1 // YJIT combined compilation unit. This setup allows spreading functions
2 // across different files without having to worry about putting things
3 // in headers and prefixing function names.
4 #include "internal.h"
5 #include "vm_core.h"
6 #include "vm_callinfo.h"
7 #include "builtin.h"
8 #include "insns.inc"
9 #include "insns_info.inc"
10 #include "vm_sync.h"
11 #include "yjit.h"
13 #ifndef YJIT_CHECK_MODE
14 # define YJIT_CHECK_MODE 0
15 #endif
17 // >= 1: print when output code invalidation happens
18 // >= 2: dump list of instructions when regions compile
19 #ifndef YJIT_DUMP_MODE
20 # define YJIT_DUMP_MODE 0
21 #endif
23 // USE_MJIT comes from configure options
24 #define JIT_ENABLED USE_MJIT
26 // Check if we need to include YJIT in the build
27 #if JIT_ENABLED && YJIT_SUPPORTED_P
29 #include "yjit_asm.c"
31 // Code block into which we write machine code
32 static codeblock_t block;
33 static codeblock_t *cb = NULL;
35 // Code block into which we write out-of-line machine code
36 static codeblock_t outline_block;
37 static codeblock_t *ocb = NULL;
39 #if YJIT_STATS
40 // Comments for generated code
41 struct yjit_comment {
42 uint32_t offset;
43 const char *comment;
46 typedef rb_darray(struct yjit_comment) yjit_comment_array_t;
47 static yjit_comment_array_t yjit_code_comments;
49 // Counters for generated code
50 #define YJIT_DECLARE_COUNTERS(...) struct rb_yjit_runtime_counters { \
51 int64_t __VA_ARGS__; \
52 }; \
53 static char yjit_counter_names[] = #__VA_ARGS__;
55 YJIT_DECLARE_COUNTERS(
56 exec_instruction,
58 send_keywords,
59 send_kw_splat,
60 send_args_splat,
61 send_block_arg,
62 send_ivar_set_method,
63 send_zsuper_method,
64 send_undef_method,
65 send_optimized_method,
66 send_optimized_method_send,
67 send_optimized_method_call,
68 send_optimized_method_block_call,
69 send_missing_method,
70 send_bmethod,
71 send_refined_method,
72 send_cfunc_argc_mismatch,
73 send_cfunc_toomany_args,
74 send_cfunc_tracing,
75 send_cfunc_kwargs,
76 send_attrset_kwargs,
77 send_iseq_tailcall,
78 send_iseq_arity_error,
79 send_iseq_only_keywords,
80 send_iseq_kwargs_req_and_opt_missing,
81 send_iseq_kwargs_mismatch,
82 send_iseq_complex_callee,
83 send_not_implemented_method,
84 send_getter_arity,
85 send_se_cf_overflow,
86 send_se_protected_check_failed,
88 traced_cfunc_return,
90 invokesuper_me_changed,
91 invokesuper_block,
93 leave_se_interrupt,
94 leave_interp_return,
95 leave_start_pc_non_zero,
97 getivar_se_self_not_heap,
98 getivar_idx_out_of_range,
99 getivar_megamorphic,
101 setivar_se_self_not_heap,
102 setivar_idx_out_of_range,
103 setivar_val_heapobject,
104 setivar_name_not_mapped,
105 setivar_not_object,
106 setivar_frozen,
108 oaref_argc_not_one,
109 oaref_arg_not_fixnum,
111 opt_getinlinecache_miss,
113 binding_allocations,
114 binding_set,
116 vm_insns_count,
117 compiled_iseq_count,
118 compiled_block_count,
119 compilation_failure,
121 exit_from_branch_stub,
123 invalidation_count,
124 invalidate_method_lookup,
125 invalidate_bop_redefined,
126 invalidate_ractor_spawn,
127 invalidate_constant_state_bump,
128 invalidate_constant_ic_fill,
130 constant_state_bumps,
132 expandarray_splat,
133 expandarray_postarg,
134 expandarray_not_array,
135 expandarray_rhs_too_small,
137 gbpp_block_param_modified,
138 gbpp_block_handler_not_iseq,
140 // Member with known name for iterating over counters
141 last_member
144 static struct rb_yjit_runtime_counters yjit_runtime_counters = { 0 };
145 #undef YJIT_DECLARE_COUNTERS
147 #endif // YJIT_STATS
149 // The number of bytes counting from the beginning of the inline code block
150 // that should not be changed. After patching for global invalidation, no one
151 // should make changes to the invalidated code region anymore. This is used to
152 // break out of invalidation race when there are multiple ractors.
153 static uint32_t yjit_codepage_frozen_bytes = 0;
155 #include "yjit_utils.c"
156 #include "yjit_core.c"
157 #include "yjit_iface.c"
158 #include "yjit_codegen.c"
160 #else
161 // !JIT_ENABLED || !YJIT_SUPPORTED_P
162 // In these builds, YJIT could never be turned on. Provide dummy
163 // implementations for YJIT functions exposed to the rest of the code base.
164 // See yjit.h.
166 void Init_builtin_yjit(void) {}
167 bool rb_yjit_enabled_p(void) { return false; }
168 unsigned rb_yjit_call_threshold(void) { return UINT_MAX; }
169 void rb_yjit_invalidate_all_method_lookup_assumptions(void) {};
170 void rb_yjit_method_lookup_change(VALUE klass, ID mid) {};
171 void rb_yjit_cme_invalidate(VALUE cme) {}
172 void rb_yjit_collect_vm_usage_insn(int insn) {}
173 void rb_yjit_collect_binding_alloc(void) {}
174 void rb_yjit_collect_binding_set(void) {}
175 bool rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec) { return false; }
176 void rb_yjit_init(struct rb_yjit_options *options) {}
177 void rb_yjit_bop_redefined(VALUE klass, const rb_method_entry_t *me, enum ruby_basic_operators bop) {}
178 void rb_yjit_constant_state_changed(void) {}
179 void rb_yjit_iseq_mark(const struct rb_iseq_constant_body *body) {}
180 void rb_yjit_iseq_update_references(const struct rb_iseq_constant_body *body) {}
181 void rb_yjit_iseq_free(const struct rb_iseq_constant_body *body) {}
182 void rb_yjit_before_ractor_spawn(void) {}
183 void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic) {}
184 void rb_yjit_tracing_invalidate_all(void) {}
186 #endif // if JIT_ENABLED && YJIT_SUPPORTED_P