Skip to content

Commit df1e636

Browse files
committed
Address PR comments
1 parent f77395f commit df1e636

3 files changed

Lines changed: 17 additions & 36 deletions

File tree

Python/optimizer_analysis.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ watch_type(PyTypeObject *type, _PyBloomFilter *filter)
178178
_Py_BloomFilter_Add(filter, type);
179179
}
180180

181-
/* Look up the value INST would load from OBJ, without modifying INST. */
182181
static PyObject *
183-
lookup_global_const(_PyUOpInstruction *inst, PyObject *obj)
182+
convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj)
184183
{
185184
assert(inst->opcode == _LOAD_GLOBAL_MODULE || inst->opcode == _LOAD_GLOBAL_BUILTINS || inst->opcode == _LOAD_ATTR_MODULE);
186185
assert(PyDict_CheckExact(obj));
@@ -200,17 +199,6 @@ lookup_global_const(_PyUOpInstruction *inst, PyObject *obj)
200199
if (res == NULL) {
201200
return NULL;
202201
}
203-
return res;
204-
}
205-
206-
/* Rewrite INST in place into a load of the constant it fetches from OBJ. */
207-
static PyObject *
208-
convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj)
209-
{
210-
PyObject *res = lookup_global_const(inst, obj);
211-
if (res == NULL) {
212-
return NULL;
213-
}
214202
if (_Py_IsImmortal(res)) {
215203
inst->opcode = _LOAD_CONST_INLINE_BORROW;
216204
} else {

Python/optimizer_bytecodes.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,19 +2527,16 @@ dummy_func(void) {
25272527
PyDict_Watch(BUILTINS_WATCHER_ID, builtins);
25282528
ctx->builtins_watched = true;
25292529
}
2530-
if (ctx->frame->globals_checked_version != 0 && ctx->frame->globals_watched) {
2531-
cnst = lookup_global_const(this_instr, builtins);
2530+
if (ctx->frame->globals_checked_version != 0 &&
2531+
ctx->frame->globals_watched &&
2532+
uop_buffer_remaining_space(&ctx->out_buffer) >= 2)
2533+
{
2534+
cnst = convert_global_to_const(this_instr, builtins);
25322535
if (cnst != NULL) {
2533-
/* Emitting two uops in place of one: make sure they fit. */
2534-
if (uop_buffer_remaining_space(&ctx->out_buffer) < 2) {
2535-
cnst = NULL;
2536-
}
2537-
else {
2538-
ADD_OP(_GUARD_BUILTINS_IS_CANONICAL, 0, 0);
2539-
ADD_OP(_Py_IsImmortal(cnst) ? _LOAD_CONST_INLINE_BORROW
2540-
: _LOAD_CONST_INLINE,
2541-
0, (uintptr_t)cnst);
2542-
}
2536+
/* convert_global_to_const already chose the right
2537+
* _LOAD_CONST_INLINE[_BORROW] opcode; reuse it. */
2538+
ADD_OP(_GUARD_BUILTINS_IS_CANONICAL, 0, 0);
2539+
ADD_OP(this_instr->opcode, 0, (uintptr_t)cnst);
25432540
}
25442541
}
25452542
}

Python/optimizer_cases.c.h

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)