bpo-45923: Add `RESUME_QUICK` (GH-31244)

This commit is contained in:
Brandt Bucher 2022-02-10 09:50:02 -08:00 committed by GitHub
parent 1a6411f573
commit d7a5aca982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 22 deletions

19
Include/opcode.h generated
View File

@ -164,15 +164,16 @@ extern "C" {
#define LOAD_METHOD_CLASS 76
#define LOAD_METHOD_MODULE 77
#define LOAD_METHOD_NO_DICT 78
#define STORE_ATTR_ADAPTIVE 79
#define STORE_ATTR_INSTANCE_VALUE 80
#define STORE_ATTR_SLOT 81
#define STORE_ATTR_WITH_HINT 131
#define LOAD_FAST__LOAD_FAST 140
#define STORE_FAST__LOAD_FAST 141
#define LOAD_FAST__LOAD_CONST 143
#define LOAD_CONST__LOAD_FAST 150
#define STORE_FAST__STORE_FAST 153
#define RESUME_QUICK 79
#define STORE_ATTR_ADAPTIVE 80
#define STORE_ATTR_INSTANCE_VALUE 81
#define STORE_ATTR_SLOT 131
#define STORE_ATTR_WITH_HINT 140
#define LOAD_FAST__LOAD_FAST 141
#define STORE_FAST__LOAD_FAST 143
#define LOAD_FAST__LOAD_CONST 150
#define LOAD_CONST__LOAD_FAST 153
#define STORE_FAST__STORE_FAST 154
#define DO_TRACING 255
#ifdef NEED_OPCODE_JUMP_TABLES
static uint32_t _PyOpcode_RelativeJump[8] = {

View File

@ -278,6 +278,7 @@ _specialized_instructions = [
"LOAD_METHOD_CLASS",
"LOAD_METHOD_MODULE",
"LOAD_METHOD_NO_DICT",
"RESUME_QUICK",
"STORE_ATTR_ADAPTIVE",
"STORE_ATTR_INSTANCE_VALUE",
"STORE_ATTR_SLOT",

View File

@ -0,0 +1 @@
Add a quickened form of :opcode:`RESUME` that skips quickening checks.

View File

@ -1734,9 +1734,6 @@ handle_eval_breaker:
}
TARGET(RESUME) {
assert(tstate->cframe == &cframe);
assert(frame == cframe.current_frame);
int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code);
if (err) {
if (err < 0) {
@ -1747,6 +1744,13 @@ handle_eval_breaker:
first_instr = frame->f_code->co_firstinstr;
next_instr = first_instr + nexti;
}
JUMP_TO_INSTRUCTION(RESUME_QUICK);
}
TARGET(RESUME_QUICK) {
PREDICTED(RESUME_QUICK);
assert(tstate->cframe == &cframe);
assert(frame == cframe.current_frame);
frame->f_state = FRAME_EXECUTING;
if (_Py_atomic_load_relaxed(eval_breaker) && oparg < 2) {
goto handle_eval_breaker;
@ -4004,7 +4008,6 @@ handle_eval_breaker:
TARGET(JUMP_ABSOLUTE) {
PREDICTED(JUMP_ABSOLUTE);
assert(oparg < INSTR_OFFSET());
int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code);
if (err) {
if (err < 0) {
@ -4015,9 +4018,7 @@ handle_eval_breaker:
first_instr = frame->f_code->co_firstinstr;
next_instr = first_instr + nexti;
}
JUMPTO(oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
JUMP_TO_INSTRUCTION(JUMP_ABSOLUTE_QUICK);
}
TARGET(JUMP_NO_INTERRUPT) {
@ -4032,6 +4033,7 @@ handle_eval_breaker:
}
TARGET(JUMP_ABSOLUTE_QUICK) {
PREDICTED(JUMP_ABSOLUTE_QUICK);
assert(oparg < INSTR_OFFSET());
JUMPTO(oparg);
CHECK_EVAL_BREAKER();

View File

@ -78,9 +78,9 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_METHOD_CLASS,
&&TARGET_LOAD_METHOD_MODULE,
&&TARGET_LOAD_METHOD_NO_DICT,
&&TARGET_RESUME_QUICK,
&&TARGET_STORE_ATTR_ADAPTIVE,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_STORE_ATTR_SLOT,
&&TARGET_LIST_TO_TUPLE,
&&TARGET_RETURN_VALUE,
&&TARGET_IMPORT_STAR,
@ -130,7 +130,7 @@ static void *opcode_targets[256] = {
&&TARGET_POP_JUMP_IF_NOT_NONE,
&&TARGET_POP_JUMP_IF_NONE,
&&TARGET_RAISE_VARARGS,
&&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_STORE_ATTR_SLOT,
&&TARGET_MAKE_FUNCTION,
&&TARGET_BUILD_SLICE,
&&TARGET_JUMP_NO_INTERRUPT,
@ -139,21 +139,21 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_DEREF,
&&TARGET_STORE_DEREF,
&&TARGET_DELETE_DEREF,
&&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_LOAD_FAST__LOAD_FAST,
&&TARGET_STORE_FAST__LOAD_FAST,
&&TARGET_CALL_FUNCTION_EX,
&&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_STORE_FAST__LOAD_FAST,
&&TARGET_EXTENDED_ARG,
&&TARGET_LIST_APPEND,
&&TARGET_SET_ADD,
&&TARGET_MAP_ADD,
&&TARGET_LOAD_CLASSDEREF,
&&TARGET_COPY_FREE_VARS,
&&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_RESUME,
&&TARGET_MATCH_CLASS,
&&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_STORE_FAST__STORE_FAST,
&&_unknown_opcode,
&&TARGET_FORMAT_VALUE,
&&TARGET_BUILD_CONST_KEY_MAP,
&&TARGET_BUILD_STRING,

View File

@ -407,6 +407,9 @@ optimize(SpecializedCacheOrInstruction *quickened, int len)
case JUMP_ABSOLUTE:
instructions[i] = _Py_MAKECODEUNIT(JUMP_ABSOLUTE_QUICK, oparg);
break;
case RESUME:
instructions[i] = _Py_MAKECODEUNIT(RESUME_QUICK, oparg);
break;
case LOAD_FAST:
switch(previous_opcode) {
case LOAD_FAST: