Skip to content

Commit bf82f77

Browse files
authored
GH-116422: Tier2 hot/cold splitting (GH-116813)
Splits the "cold" path, deopts and exits, from the "hot" path, reducing the size of most jitted instructions, at the cost of slower exits.
1 parent 61599a4 commit bf82f77

21 files changed

+1660
-1001
lines changed

Include/cpython/optimizer.h

+49-2
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,63 @@ typedef struct {
3030
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
3131
} _PyVMData;
3232

33+
#define UOP_FORMAT_TARGET 0
34+
#define UOP_FORMAT_EXIT 1
35+
#define UOP_FORMAT_JUMP 2
36+
#define UOP_FORMAT_UNUSED 3
37+
38+
/* Depending on the format,
39+
* the 32 bits between the oparg and operand are:
40+
* UOP_FORMAT_TARGET:
41+
* uint32_t target;
42+
* UOP_FORMAT_EXIT
43+
* uint16_t exit_index;
44+
* uint16_t error_target;
45+
* UOP_FORMAT_JUMP
46+
* uint16_t jump_target;
47+
* uint16_t error_target;
48+
*/
3349
typedef struct {
34-
uint16_t opcode;
50+
uint16_t opcode:14;
51+
uint16_t format:2;
3552
uint16_t oparg;
3653
union {
3754
uint32_t target;
38-
uint32_t exit_index;
55+
struct {
56+
union {
57+
uint16_t exit_index;
58+
uint16_t jump_target;
59+
};
60+
uint16_t error_target;
61+
};
3962
};
4063
uint64_t operand; // A cache entry
4164
} _PyUOpInstruction;
4265

66+
static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
67+
{
68+
assert(inst->format == UOP_FORMAT_TARGET);
69+
return inst->target;
70+
}
71+
72+
static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
73+
{
74+
assert(inst->format == UOP_FORMAT_EXIT);
75+
return inst->exit_index;
76+
}
77+
78+
static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
79+
{
80+
assert(inst->format == UOP_FORMAT_JUMP);
81+
return inst->jump_target;
82+
}
83+
84+
static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
85+
{
86+
assert(inst->format != UOP_FORMAT_TARGET);
87+
return inst->error_target;
88+
}
89+
4390
typedef struct _exit_data {
4491
uint32_t target;
4592
int16_t temperature;

Include/internal/pycore_opcode_metadata.h

+57-59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_optimizer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
#include <stdbool.h>
1313

1414
// This is the length of the trace we project initially.
15-
#define UOP_MAX_TRACE_LENGTH 512
15+
#define UOP_MAX_TRACE_LENGTH 800
1616

1717
#define TRACE_STACK_SIZE 5
1818

Include/internal/pycore_uop_ids.h

+99-96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)