Use tailcall interpreter if musttail is available

This commit is contained in:
John Hawthorn 2025-05-26 20:50:32 -07:00
parent 79da4ea176
commit 078b17da92
No known key found for this signature in database
GPG key ID: 515A00B761220D2F
2 changed files with 17 additions and 7 deletions

View file

@ -11,6 +11,8 @@
**********************************************************************/ **********************************************************************/
#include "ruby/internal/has/attribute.h"
typedef long OFFSET; typedef long OFFSET;
typedef unsigned long lindex_t; typedef unsigned long lindex_t;
typedef VALUE GENTRY; typedef VALUE GENTRY;
@ -60,18 +62,20 @@ error !
/************************************************/ /************************************************/
#elif OPT_TAILCALL_THREADED_CODE #elif OPT_TAILCALL_THREADED_CODE
/* Same as __attribute__((musttail)), but slightly wider support (GCC 15) */ #if !RBIMPL_HAS_ATTRIBUTE(musttail)
#define MUSTTAIL [[clang::musttail]] #error support for musttail attribute is required for tailcall threading
#endif
/* Declares that the function call MUST be tailcall optimized */
#define MUSTTAIL __attribute__((musttail))
#define LABEL(x) insn_func_##x #define LABEL(x) insn_func_##x
#define ELABEL(x) #define ELABEL(x)
#define LABEL_PTR(x) &LABEL(x) #define LABEL_PTR(x) &LABEL(x)
#if defined __has_attribute #if RBIMPL_HAS_ATTRIBUTE(preserve_none)
#if __has_attribute (preserve_none)
#define ATTR_PRESERVE_NONE __attribute__((preserve_none)) #define ATTR_PRESERVE_NONE __attribute__((preserve_none))
#endif #endif
#endif
#ifdef ATTR_PRESERVE_NONE #ifdef ATTR_PRESERVE_NONE
#define INSN_FUNC_CONV ATTR_PRESERVE_NONE #define INSN_FUNC_CONV ATTR_PRESERVE_NONE

View file

@ -10,6 +10,8 @@
**********************************************************************/ **********************************************************************/
#include "ruby/internal/has/attribute.h"
/* Compile options. /* Compile options.
* You can change these options at runtime by VM::CompileOption. * You can change these options at runtime by VM::CompileOption.
* Following definitions are default values. * Following definitions are default values.
@ -34,9 +36,13 @@
* 2: call (function call for each insn dispatch) * 2: call (function call for each insn dispatch)
* 3: call continuation (musttail attribute) * 3: call continuation (musttail attribute)
*/ */
//#ifndef OPT_THREADED_CODE #ifndef OPT_THREADED_CODE
#if RBIMPL_HAS_ATTRIBUTE(musttail)
#define OPT_THREADED_CODE 3 #define OPT_THREADED_CODE 3
//#endif #else
#define OPT_THREADED_CODE 0
#endif
#endif
#define OPT_DIRECT_THREADED_CODE (OPT_THREADED_CODE == 0) #define OPT_DIRECT_THREADED_CODE (OPT_THREADED_CODE == 0)
#define OPT_TOKEN_THREADED_CODE (OPT_THREADED_CODE == 1) #define OPT_TOKEN_THREADED_CODE (OPT_THREADED_CODE == 1)