ruby-changes:72935
From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Aug 2022 02:05:28 +0900 (JST)
Subject: [ruby-changes:72935] ee864beb7c (master): Simplify around `USE_YJIT` macro (#6240)
https://git.ruby-lang.org/ruby.git/commit/?id=ee864beb7c From ee864beb7c6730083da656b55f4a9eeaed78bfa8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 16 Aug 2022 02:05:12 +0900 Subject: Simplify around `USE_YJIT` macro (#6240) * Simplify around `USE_YJIT` macro - Use `USE_YJIT` macro only instead of `YJIT_BUILD`. - An intermediate macro `YJIT_SUPPORTED_P` is no longer used. * Bail out if YJIT is enabled on unsupported platforms --- iseq.c | 6 +++--- ruby.c | 20 ++++++++++---------- vm.c | 2 +- vm_core.h | 1 - yjit.h | 23 +++++++---------------- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/iseq.c b/iseq.c index 3d40b88a0d..f17a2d49b6 100644 --- a/iseq.c +++ b/iseq.c @@ -175,7 +175,7 @@ rb_iseq_free(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L175 iseq_clear_ic_references(iseq); struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq); mjit_free_iseq(iseq); /* Notify MJIT */ -#if YJIT_BUILD +#if USE_YJIT rb_yjit_iseq_free(body->yjit_payload); #endif ruby_xfree((void *)body->iseq_encoded); @@ -438,7 +438,7 @@ rb_iseq_update_references(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L438 #if USE_MJIT mjit_update_references(iseq); #endif -#if YJIT_BUILD +#if USE_YJIT rb_yjit_iseq_update_references(body->yjit_payload); #endif } @@ -526,7 +526,7 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L526 #if USE_MJIT mjit_mark_cc_entries(body); #endif -#if YJIT_BUILD +#if USE_YJIT rb_yjit_iseq_mark(body->yjit_payload); #endif } diff --git a/ruby.c b/ruby.c index 7c6742cac4..66feeb797e 100644 --- a/ruby.c +++ b/ruby.c @@ -111,7 +111,7 @@ void rb_warning_category_update(unsigned int mask, unsigned int bits); https://github.com/ruby/ruby/blob/trunk/ruby.c#L111 enum feature_flag_bits { EACH_FEATURES(DEFINE_FEATURE, COMMA), feature_debug_flag_first, -#if defined(MJIT_FORCE_ENABLE) || !YJIT_BUILD +#if defined(MJIT_FORCE_ENABLE) || !USE_YJIT DEFINE_FEATURE(jit) = feature_mjit, #else DEFINE_FEATURE(jit) = feature_yjit, @@ -248,7 +248,7 @@ usage(const char *name, int help, int highlight, int columns) https://github.com/ruby/ruby/blob/trunk/ruby.c#L248 #define M(shortopt, longopt, desc) RUBY_OPT_MESSAGE(shortopt, longopt, desc) -#if YJIT_BUILD +#if USE_YJIT # define PLATFORM_JIT_OPTION "--yjit" #else # define PLATFORM_JIT_OPTION "--mjit" @@ -278,7 +278,7 @@ usage(const char *name, int help, int highlight, int columns) https://github.com/ruby/ruby/blob/trunk/ruby.c#L278 #if USE_MJIT M("--mjit", "", "enable C compiler-based JIT compiler (experimental)"), #endif -#if YJIT_BUILD +#if USE_YJIT M("--yjit", "", "enable in-process JIT compiler (experimental)"), #endif M("-h", "", "show this message, --help for more info"), @@ -312,7 +312,7 @@ usage(const char *name, int help, int highlight, int columns) https://github.com/ruby/ruby/blob/trunk/ruby.c#L312 #if USE_MJIT M("mjit", "", "C compiler-based JIT compiler (default: disabled)"), #endif -#if YJIT_BUILD +#if USE_YJIT M("yjit", "", "in-process JIT compiler (default: disabled)"), #endif }; @@ -323,7 +323,7 @@ usage(const char *name, int help, int highlight, int columns) https://github.com/ruby/ruby/blob/trunk/ruby.c#L323 #if USE_MJIT extern const struct ruby_opt_message mjit_option_messages[]; #endif -#if YJIT_BUILD +#if USE_YJIT static const struct ruby_opt_message yjit_options[] = { #if YJIT_STATS M("--yjit-stats", "", "Enable collecting YJIT statistics"), @@ -365,7 +365,7 @@ usage(const char *name, int help, int highlight, int columns) https://github.com/ruby/ruby/blob/trunk/ruby.c#L365 for (i = 0; mjit_option_messages[i].str; ++i) SHOW(mjit_option_messages[i]); #endif -#if YJIT_BUILD +#if USE_YJIT printf("%s""YJIT options (experimental):%s\n", sb, se); for (i = 0; i < numberof(yjit_options); ++i) SHOW(yjit_options[i]); @@ -1047,7 +1047,7 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen https://github.com/ruby/ruby/blob/trunk/ruby.c#L1047 #define yjit_opt_match_arg(s, l, name) \ opt_match(s, l, name) && (*(s) && *(s+1) ? 1 : (rb_raise(rb_eRuntimeError, "--yjit-" name " needs an argument"), 0)) -#if YJIT_BUILD +#if USE_YJIT static bool setup_yjit_options(const char *s) { @@ -1452,7 +1452,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1452 #endif } else if (is_option_with_optarg("yjit", '-', true, false, false)) { -#if YJIT_BUILD +#if USE_YJIT FEATURE_SET(opt->features, FEATURE_BIT(yjit)); setup_yjit_options(s); #else @@ -1831,7 +1831,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1831 rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); if (!(FEATURE_SET_BITS(opt->features) & feature_jit_mask)) { -#if YJIT_BUILD +#if USE_YJIT if (!FEATURE_USED_P(opt->features, yjit) && getenv("RUBY_YJIT_ENABLE")) { FEATURE_SET(opt->features, FEATURE_BIT(yjit)); } @@ -1847,7 +1847,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1847 opt->mjit.on = TRUE; /* set mjit.on for ruby_show_version() API and check to call mjit_init() */ } #endif -#if YJIT_BUILD +#if USE_YJIT if (FEATURE_SET_P(opt->features, yjit)) { rb_yjit_init(); } diff --git a/vm.c b/vm.c index 3bba390e7c..4b1a30e7ca 100644 --- a/vm.c +++ b/vm.c @@ -3938,7 +3938,7 @@ Init_vm_objects(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L3938 } /* Stub for builtin function when not building YJIT units*/ -#if !YJIT_BUILD +#if !USE_YJIT void Init_builtin_yjit(void) {} #endif diff --git a/vm_core.h b/vm_core.h index c394862ecb..717f116800 100644 --- a/vm_core.h +++ b/vm_core.h @@ -495,7 +495,6 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L495 #if USE_YJIT // YJIT stores some data on each iseq. - // Note: Cannot use YJIT_BUILD here since yjit.h includes this header. void *yjit_payload; #endif }; diff --git a/yjit.h b/yjit.h index cf420df251..1f507f1b51 100644 --- a/yjit.h +++ b/yjit.h @@ -15,24 +15,15 @@ https://github.com/ruby/ruby/blob/trunk/yjit.h#L15 # define YJIT_STATS RUBY_DEBUG #endif -// We generate x86 assembly -#if (defined(__x86_64__) && !defined(_WIN32)) || (defined(_WIN32) && defined(_M_AMD64)) // x64 platforms without mingw/msys -# define YJIT_SUPPORTED_P 1 -#else -# define YJIT_SUPPORTED_P 0 -#endif +#if USE_YJIT -// Is the output binary going to include YJIT? -#if USE_MJIT && USE_YJIT && YJIT_SUPPORTED_P -# define YJIT_BUILD 1 +// We generate x86 assembly +#if defined(_WIN32) ? defined(_M_AMD64) : defined(__x86_64__) +// x86_64 platforms without mingw/msys or x64-mswin #else -# define YJIT_BUILD 0 +# error YJIT unsupported platform #endif -#undef YJIT_SUPPORTED_P - -#if YJIT_BUILD - // Expose these as declarations since we are building YJIT. bool rb_yjit_enabled_p(void); unsigned rb_yjit_call_threshold(void); @@ -54,7 +45,7 @@ void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic); https://github.com/ruby/ruby/blob/trunk/yjit.h#L45 void rb_yjit_tracing_invalidate_all(void); #else -// !YJIT_BUILD +// !USE_YJIT // In these builds, YJIT could never be turned on. Provide dummy implementations. static inline bool rb_yjit_enabled_p(void) { return false; } @@ -76,6 +67,6 @@ static inline void rb_yjit_before_ractor_spawn(void) {} https://github.com/ruby/ruby/blob/trunk/yjit.h#L67 static inline void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic) {} static inline void rb_yjit_tracing_invalidate_all(void) {} -#endif // #if YJIT_BUILD +#endif // #if USE_YJIT #endif // #ifndef YJIT_H -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/