GeezerVison is showing github.com — GH-135379: Top of stack caching for the JIT. by markshannon · Pull Request #135465 · python/cpython
GH-135379: Top of stack caching for the JIT.
#135465
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.c
(8)
.h
(13)
.py
(8)
.rst
(1)
All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -29,7 +29,7 @@
# error "this header file must not be included directly"
#endif
#define PYSTATS_MAX_UOP_ID 1024
#define PYSTATS_MAX_UOP_ID 2000
#define SPECIALIZATION_FAILURE_KINDS 60
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -18,7 +18,10 @@ extern "C" {
#ifdef _Py_JIT
typedef _Py_CODEUNIT *(*jit_func)(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate);
typedef _Py_CODEUNIT *(*jit_func)(
_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate,
_PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2
);
int _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction *trace, size_t length);
void _PyJIT_Free(_PyExecutorObject *executor);
Expand Down
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Original file line number
Diff line number
Diff line change
Expand Up
@@ -24,19 +24,20 @@ typedef struct _PyExecutorLinkListNode {
typedef struct {
uint8_t opcode;
uint8_t oparg;
uint8_t valid:1 ;
uint8_t linked:1 ;
uint8_t chain_depth:6 ; // Must be big enough for MAX_CHAIN_DEPTH - 1.
uint8_t valid;
uint8_t linked;
uint8_t chain_depth; // Must be big enough for MAX_CHAIN_DEPTH - 1.
bool warm;
int index; // Index of ENTER_EXECUTOR (if code isn't NULL, below).
int32_t index; // Index of ENTER_EXECUTOR (if code isn't NULL, below).
_PyBloomFilter bloom;
_PyExecutorLinkListNode links;
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
} _PyVMData;
typedef struct _PyExitData {
uint32_t target;
uint16_t index:14;
uint16_t index:12;
uint16_t stack_cache:2;
uint16_t is_dynamic:1;
uint16_t is_control_flow:1;
_Py_BackoffCounter temperature;
Expand Down
Expand Up
@@ -344,17 +345,6 @@ extern _PyExecutorObject *_PyExecutor_GetColdDynamicExecutor(void);
PyAPI_FUNC(void) _PyExecutor_ClearExit(_PyExitData *exit);
static inline int is_terminator(const _PyUOpInstruction *uop)
{
int opcode = uop->opcode;
return (
opcode == _EXIT_TRACE ||
opcode == _DEOPT ||
opcode == _JUMP_TO_TOP ||
opcode == _DYNAMIC_EXIT
);
}
extern void _PyExecutor_Free(_PyExecutorObject *self);
PyAPI_FUNC(int) _PyDumpExecutors(FILE *out);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -76,6 +76,8 @@ static const _PyStackRef PyStackRef_ERROR = { .index = (1 << Py_TAGGED_SHIFT) };
#define INITIAL_STACKREF_INDEX (5 << Py_TAGGED_SHIFT)
#define PyStackRef_ZERO_BITS PyStackRef_NULL
static inline _PyStackRef
PyStackRef_Wrap(void *ptr)
{
Expand Down
Expand Up
@@ -369,6 +371,10 @@ PyStackRef_IsNullOrInt(_PyStackRef ref);
static const _PyStackRef PyStackRef_ERROR = { .bits = Py_TAG_INVALID };
/* For use in the JIT to clear an unused value.
* PyStackRef_ZERO_BITS has no meaning and should not be used other than by the JIT. */
static const _PyStackRef PyStackRef_ZERO_BITS = { .bits = 0 };
/* Wrap a pointer in a stack ref.
* The resulting stack reference is not safe and should only be used
* in the interpreter to pass values from one uop to another.
Expand Down
Expand Up
@@ -922,6 +928,17 @@ _PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
PyStackRef_XCLOSE(ref->ref);
}
static inline _PyStackRef
_PyThreadState_PopCStackRefSteal(PyThreadState *tstate, _PyCStackRef *ref)
{
#ifdef Py_GIL_DISABLED
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
assert(tstate_impl->c_stack_refs == ref);
tstate_impl->c_stack_refs = ref->next;
#endif
return ref->ref;
}
#ifdef Py_GIL_DISABLED
static inline int
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -38,9 +38,9 @@ typedef struct _PyUOpInstruction{
// This is the length of the trace we translate initially.
#ifdef Py_DEBUG
// With asserts, the stencils are a lot larger
#define UOP_MAX_TRACE_LENGTH 1000
#define UOP_MAX_TRACE_LENGTH 2000
#else
#define UOP_MAX_TRACE_LENGTH 3000
#define UOP_MAX_TRACE_LENGTH 5000
#endif
#define UOP_BUFFER_SIZE (UOP_MAX_TRACE_LENGTH * sizeof(_PyUOpInstruction))
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.