Ruby 3.5.0dev (2025-01-10 revision 5fab31b15e32622c4b71d1d347a41937e9f9c212)
yjit.h (5fab31b15e32622c4b71d1d347a41937e9f9c212)
1#ifndef YJIT_H
2#define YJIT_H 1
3//
4// This file contains definitions YJIT exposes to the CRuby codebase
5//
6
7#include "ruby/internal/config.h"
8#include "ruby_assert.h" // for RUBY_DEBUG
9#include "vm_core.h"
10#include "method.h"
11
12// YJIT_STATS controls whether to support runtime counters in generated code
13// and in the interpreter.
14#ifndef YJIT_STATS
15# define YJIT_STATS RUBY_DEBUG
16#endif
17
18#if USE_YJIT
19
20// We generate x86 or arm64 assembly
21#if defined(_WIN32) ? defined(_M_AMD64) : (defined(__x86_64__) || defined(__aarch64__))
22// x86_64 platforms without mingw/msys or x64-mswin
23#else
24# error YJIT unsupported platform
25#endif
26
27// Expose these as declarations since we are building YJIT.
28extern uint64_t rb_yjit_call_threshold;
29extern uint64_t rb_yjit_cold_threshold;
30extern uint64_t rb_yjit_live_iseq_count;
31extern uint64_t rb_yjit_iseq_alloc_count;
32extern bool rb_yjit_enabled_p;
33void rb_yjit_incr_counter(const char *counter_name);
34void rb_yjit_invalidate_all_method_lookup_assumptions(void);
35void rb_yjit_cme_invalidate(rb_callable_method_entry_t *cme);
36void rb_yjit_collect_binding_alloc(void);
37void rb_yjit_collect_binding_set(void);
38void rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception);
39void rb_yjit_init(bool yjit_enabled);
40void rb_yjit_free_at_exit();
41void rb_yjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
42void rb_yjit_constant_state_changed(ID id);
43void rb_yjit_iseq_mark(void *payload);
44void rb_yjit_iseq_update_references(const rb_iseq_t *iseq);
45void rb_yjit_iseq_free(const rb_iseq_t *iseq);
46void rb_yjit_before_ractor_spawn(void);
47void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx);
48void rb_yjit_tracing_invalidate_all(void);
49void rb_yjit_show_usage(int help, int highlight, unsigned int width, int columns);
50void rb_yjit_lazy_push_frame(const VALUE *pc);
51void rb_yjit_invalidate_no_singleton_class(VALUE klass);
52void rb_yjit_invalidate_ep_is_bp(const rb_iseq_t *iseq);
53
54#else
55// !USE_YJIT
56// In these builds, YJIT could never be turned on. Provide dummy implementations.
57
58#define rb_yjit_enabled_p false
59static inline void rb_yjit_incr_counter(const char *counter_name) {}
60static inline void rb_yjit_invalidate_all_method_lookup_assumptions(void) {}
61static inline void rb_yjit_cme_invalidate(rb_callable_method_entry_t *cme) {}
62static inline void rb_yjit_collect_binding_alloc(void) {}
63static inline void rb_yjit_collect_binding_set(void) {}
64static inline void rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception) {}
65static inline void rb_yjit_init(bool yjit_enabled) {}
66static inline void rb_yjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) {}
67static inline void rb_yjit_constant_state_changed(ID id) {}
68static inline void rb_yjit_iseq_mark(void *payload) {}
69static inline void rb_yjit_iseq_update_references(const rb_iseq_t *iseq) {}
70static inline void rb_yjit_iseq_free(const rb_iseq_t *iseq) {}
71static inline void rb_yjit_before_ractor_spawn(void) {}
72static inline void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx) {}
73static inline void rb_yjit_tracing_invalidate_all(void) {}
74static inline void rb_yjit_lazy_push_frame(const VALUE *pc) {}
75static inline void rb_yjit_invalidate_no_singleton_class(VALUE klass) {}
76static inline void rb_yjit_invalidate_ep_is_bp(const rb_iseq_t *iseq) {}
77
78#endif // #if USE_YJIT
79
80#endif // #ifndef YJIT_H
Definition method.h:62
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40