Skip to content
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
579b758
Tier 2 TOS caching. Work in progress
markshannon Jun 11, 2025
489e510
Tier 2 TOS caching, working for interpreter.
markshannon Jun 13, 2025
f603929
Get JIT working
markshannon Jun 13, 2025
cf1d7ab
Fix tool to support 3.11
markshannon Jun 13, 2025
efd7a0a
Add news
markshannon Jun 13, 2025
bb4e6b9
int arithmetic doesn't escape
markshannon Jun 13, 2025
e976b9b
Repair stats
markshannon Jun 13, 2025
11de93e
Add missing type annotation
markshannon Jun 13, 2025
4698695
Pacify mypy
markshannon Jun 13, 2025
33837a7
Add type annotation
markshannon Jun 13, 2025
8bb12ef
Avoid overflow gathering stats
markshannon Jun 13, 2025
920e6de
Reduce spilling
markshannon Jun 13, 2025
45e1abd
Merge branch 'main' into tier-2-tos-caching
markshannon Jun 16, 2025
3d72871
Merge branch 'main' into tier-2-tos-caching
markshannon Jun 17, 2025
0240115
Merge branch 'main' into tier-2-tos-caching
markshannon Jun 19, 2025
2850d72
Improve heuristics for stack caching
markshannon Jun 19, 2025
1c291f1
Merge branch 'main' into tier-2-tos-caching
markshannon Jun 20, 2025
ba2331a
Add news
markshannon Jun 20, 2025
cbee8d2
Fix uop execution stats
markshannon Jun 23, 2025
40988a0
Address review comments
markshannon Jun 23, 2025
76030e9
Address code review
markshannon Jun 26, 2025
991bbea
Merge branch 'main' into tier-2-tos-caching
markshannon Jun 26, 2025
51d4342
Remove blank line
markshannon Jun 26, 2025
9438c19
Zero out unused registers to reduce register pressure
markshannon Jul 21, 2025
53a50eb
Merge branch 'main' into tier-2-tos-caching
markshannon Jul 21, 2025
a4de1bf
Avoid spilling around DEOPT_IF
markshannon Jul 22, 2025
9a8a5eb
Merge branch 'main' into tier-2-tos-caching
markshannon Aug 9, 2025
3852c28
Get tos caching working with exit-at-end. Add some more tracing info
markshannon Aug 11, 2025
259218a
Make sure code compiles for no-debug build
markshannon Aug 11, 2025
7fd861c
Add #ifdefs for debug-jit as well
markshannon Aug 11, 2025
6041480
So many conditional compilation macros
markshannon Aug 11, 2025
aad6741
Clarify and simplify tos caching lookup tables
markshannon Aug 13, 2025
7888aa1
Use ideal inputs for escaping uops
markshannon Aug 13, 2025
722f51a
Fix type annotation
markshannon Aug 13, 2025
531d3c8
Use C stackrefs to make use of _PyObject_GetMethodStackRef safe.
markshannon Aug 13, 2025
0922ee1
Missing edits
markshannon Aug 13, 2025
6a85f95
More missing edits
markshannon Aug 13, 2025
0327b8b
Add _PyThreadState_PopCStackRefSteal as suggested by Sam
markshannon Aug 13, 2025
0995ea9
Allow 'peek' variables to be cached in registers even if uop escapes
markshannon Aug 14, 2025
0b1ed44
Merge branch 'main' into tier-2-tos-caching
markshannon Aug 21, 2025
e350669
Cache TOS across side exits: Work in progress
markshannon Aug 18, 2025
7830f69
Post merge fixups
markshannon Aug 19, 2025
efe4628
Add missing type annotation
markshannon Aug 22, 2025
492ecda
Revert TOS caching through side exits
markshannon Aug 22, 2025
dc660a2
Merge branch 'main' into tier-2-tos-caching
markshannon Aug 22, 2025
a1b36b3
Merge branch 'main' into tier-2-tos-caching
markshannon Sep 22, 2025
7d47f13
Merge branch 'main' into tier-2-tos-caching
markshannon Oct 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/cpython/pystats.h
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 1500

#define SPECIALIZATION_FAILURE_KINDS 60

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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
48 changes: 25 additions & 23 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
#define JIT_CLEANUP_THRESHOLD 100000

// This is the length of the trace we project initially.
#define UOP_MAX_TRACE_LENGTH 800
#define UOP_MAX_TRACE_LENGTH 1600

#define TRACE_STACK_SIZE 5

Expand Down
17 changes: 17 additions & 0 deletions Include/internal/pycore_stackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ static const _PyStackRef PyStackRef_ERROR = { .index = 2 };
#define PyStackRef_False ((_PyStackRef){ .index = 6 })
#define PyStackRef_True ((_PyStackRef){ .index = 8 })

#define PyStackRef_ZERO_BITS PyStackRef_NULL


#define INITIAL_STACKREF_INDEX 10

static inline int
Expand Down Expand Up @@ -264,6 +267,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 @@ -303,6 +310,16 @@ PyStackRef_IsValid(_PyStackRef ref)
return ref.bits >= Py_INT_TAG;
}

static inline bool
PyStackRef_IsWrapped(_PyStackRef ref)
{
#ifdef Py_DEBUG
return (ref.bits & Py_TAG_INVALID) != 0 && !PyStackRef_IsError(ref);
#else
Py_FatalError("Cannot determine if value is wrapped if Py_DEBUG is not set");
#endif
}

static inline bool
PyStackRef_IsTaggedInt(_PyStackRef i)
{
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#define GC_STAT_ADD(gen, name, n) do { if (_Py_stats) _Py_stats->gc_stats[(gen)].name += (n); } while (0)
#define OPT_STAT_INC(name) do { if (_Py_stats) _Py_stats->optimization_stats.name++; } while (0)
#define OPT_STAT_ADD(name, n) do { if (_Py_stats) _Py_stats->optimization_stats.name += (n); } while (0)
#define UOP_STAT_INC(opname, name) do { if (_Py_stats) { assert(opname < 512); _Py_stats->optimization_stats.opcode[opname].name++; } } while (0)
#define UOP_STAT_INC(opname, name) do { if (_Py_stats) { _Py_stats->optimization_stats.opcode[opname].name++; } } while (0)
#define UOP_PAIR_INC(uopcode, lastuop) \
do { \
if (lastuop && _Py_stats) { \
Expand Down
Loading
Loading