-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
JIT: Fix compiler warning from visibility attribute in typedef #139981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
JIT: Fix compiler warning from visibility attribute in typedef #139981
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Basically the same as my PR #140286 I've just closed since @Fidget-Spinner made me aware of yours :)
Just a suggestion:
typedef _Py_CODEUNIT *__attribute__((preserve_none)) (*jit_func)(_PyInterpreterFrame *, _PyStackRef *, PyThreadState *); | ||
jit_func jitted = (jit_func)exec->jit_code; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef _Py_CODEUNIT *__attribute__((preserve_none)) (*jit_func)(_PyInterpreterFrame *, _PyStackRef *, PyThreadState *); | |
jit_func jitted = (jit_func)exec->jit_code; | |
jit_func_preserve_none jitted = (jit_func_preserve_none)exec->jit_code; |
I suggest to use
Lines 1 to 4 in f937468
// To use preserve_none in JIT builds, we need to declare a separate function | |
// pointer with __attribute__((preserve_none)), since this attribute may not be | |
// supported by the compiler used to build the rest of the interpreter. | |
typedef jit_func __attribute__((preserve_none)) jit_func_preserve_none; |
which builds on top of
cpython/Include/internal/pycore_jit.h
Line 18 in d86ad87
typedef _Py_CODEUNIT *(*jit_func)(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate); |
and IMHO is better than duplicating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the other usage of jit_func_preserve_none
in
Lines 50 to 56 in f937468
#define TIER2_TO_TIER2(EXECUTOR) \ | |
do { \ | |
OPT_STAT_INC(traces_executed); \ | |
_PyExecutorObject *_executor = (EXECUTOR); \ | |
jit_func_preserve_none jitted = _executor->jit_code; \ | |
__attribute__((musttail)) return jitted(frame, stack_pointer, tstate); \ | |
} while (0) |
suggests that it is even possible to omit the cast in
jit_func_preserve_none jitted = (jit_func_preserve_none)exec->jit_code;
and indeed the same code is generated for emit_trampoline
in the stencils header 1.
Footnotes
-
Tested only for x86_64-pc-windows-msvc. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the back and forth, but having a closer look and playing on Godbolt suggests that the cast is better in case of -Wpedantic
, since strictly speaking void *jit_code
cpython/Include/internal/pycore_optimizer.h
Lines 52 to 61 in d86ad87
typedef struct _PyExecutorObject { | |
PyObject_VAR_HEAD | |
const _PyUOpInstruction *trace; | |
_PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */ | |
uint32_t exit_count; | |
uint32_t code_size; | |
size_t jit_size; | |
void *jit_code; | |
_PyExitData exits[1]; | |
} _PyExecutorObject; |
is a data pointer. So maybe change to a cast in
TIER2_TO_TIER2
, too?
Sorry for being such a pain, this is now merely for my understanding and I hope asking this question here is ok: When playing with the above Godbolt link, I more or less get the same nice output for
whereas on Windows x86_64 I get
which tells me, clang-cl is saving a ton more on the stack here.
|
Oh, I think I've found the answer myself: adding |
Maybe also restore the comment
that got lost in #137961? Because it is utterly important that we use |
This was introduced in #136528. The
DECLARE_TARGET
macro includesvisibility("hidden")
, which is valid for forward declarations but gets ignored when used in a typedef, so the compiler is yelling.