Skip to content

Commit

Permalink
pythonGH-116422: Tier2 hot/cold splitting (pythonGH-116813)
Browse files Browse the repository at this point in the history
Splits the "cold" path, deopts and exits, from the "hot" path, reducing the size of most jitted instructions, at the cost of slower exits.
  • Loading branch information
markshannon authored Mar 26, 2024
1 parent 61599a4 commit bf82f77
Show file tree
Hide file tree
Showing 21 changed files with 1,660 additions and 1,001 deletions.
51 changes: 49 additions & 2 deletions Include/cpython/optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,63 @@ typedef struct {
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
} _PyVMData;

#define UOP_FORMAT_TARGET 0
#define UOP_FORMAT_EXIT 1
#define UOP_FORMAT_JUMP 2
#define UOP_FORMAT_UNUSED 3

/* Depending on the format,
* the 32 bits between the oparg and operand are:
* UOP_FORMAT_TARGET:
* uint32_t target;
* UOP_FORMAT_EXIT
* uint16_t exit_index;
* uint16_t error_target;
* UOP_FORMAT_JUMP
* uint16_t jump_target;
* uint16_t error_target;
*/
typedef struct {
uint16_t opcode;
uint16_t opcode:14;
uint16_t format:2;
uint16_t oparg;
union {
uint32_t target;
uint32_t exit_index;
struct {
union {
uint16_t exit_index;
uint16_t jump_target;
};
uint16_t error_target;
};
};
uint64_t operand; // A cache entry
} _PyUOpInstruction;

static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
{
assert(inst->format == UOP_FORMAT_TARGET);
return inst->target;
}

static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
{
assert(inst->format == UOP_FORMAT_EXIT);
return inst->exit_index;
}

static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
{
assert(inst->format == UOP_FORMAT_JUMP);
return inst->jump_target;
}

static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
{
assert(inst->format != UOP_FORMAT_TARGET);
return inst->error_target;
}

typedef struct _exit_data {
uint32_t target;
int16_t temperature;
Expand Down
116 changes: 57 additions & 59 deletions Include/internal/pycore_opcode_metadata.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {
#include <stdbool.h>

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

#define TRACE_STACK_SIZE 5

Expand Down
195 changes: 99 additions & 96 deletions Include/internal/pycore_uop_ids.h

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

Loading

0 comments on commit bf82f77

Please sign in to comment.