Skip to content

Commit 1e793f9

Browse files
more cleanup
1 parent cb15c9a commit 1e793f9

10 files changed

Lines changed: 30 additions & 113 deletions

File tree

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ PyAPI_FUNC(void) _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
323323
PyAPI_FUNC(void) _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
324324
PyAPI_FUNC(void) _Py_GatherStats_GetIter(_PyStackRef iterable);
325325
PyAPI_FUNC(void) _Py_Specialize_CallFunctionEx(_PyStackRef func_st, _Py_CODEUNIT *instr);
326+
PyAPI_FUNC(void) _Py_Specialize_Resume(_Py_CODEUNIT *instr, PyThreadState *tstate);
326327

327328
// Utility functions for reading/writing 32/64-bit values in the inline caches.
328329
// Great care should be taken to ensure that these functions remain correct and

Include/internal/pycore_magic_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ PC/launcher.c must also be updated.
305305
306306
*/
307307

308-
#define PYC_MAGIC_NUMBER 3662
308+
#define PYC_MAGIC_NUMBER 3663
309309
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
310310
(little-endian) and then appending b'\r\n'. */
311311
#define PYC_MAGIC_NUMBER_TOKEN \

Modules/_testinternalcapi/test_cases.c.h

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

Modules/_testinternalcapi/test_targets.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,7 @@ dummy_func(
173173
}
174174

175175
specializing op(_SPECIALIZE_RESUME, (counter/1 --)) {
176-
#if ENABLE_SPECIALIZATION_FT
177-
#if _Py_TIER2
178-
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
179-
next_instr = this_instr;
180-
_Py_Specialize_Resume(next_instr, tstate);
181-
DISPATCH_SAME_OPARG();
182-
}
183-
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
184-
#else
185176
_Py_Specialize_Resume(next_instr, tstate);
186-
#endif
187-
#endif /* ENABLE_SPECIALIZATION_FT */
188177
}
189178

190179
tier1 op(_MAYBE_INSTRUMENT, (--)) {
@@ -3131,15 +3120,16 @@ dummy_func(
31313120
_Py_BackoffCounter counter = this_instr[1].counter;
31323121
if (!IS_JIT_TRACING() &&
31333122
(backoff_counter_triggers(counter) &&
3134-
this_instr->op.code == JUMP_BACKWARD_JIT) &&
3123+
(this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) &&
31353124
next_instr->op.code != ENTER_EXECUTOR) {
31363125
/* Back up over EXTENDED_ARGs so executor is inserted at the correct place */
31373126
_Py_CODEUNIT *insert_exec_at = this_instr;
31383127
while (oparg > 255) {
31393128
oparg >>= 8;
31403129
insert_exec_at--;
31413130
}
3142-
int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at, next_instr, stack_pointer, 0, NULL, oparg, NULL);
3131+
int succ = _PyJit_TryInitializeTracing(tstate, frame, this_instr, insert_exec_at,
3132+
is_resume ? insert_exec_at : next_instr, stack_pointer, 0, NULL, oparg, NULL);
31433133
if (succ) {
31443134
ENTER_TRACING();
31453135
}
@@ -3192,7 +3182,7 @@ dummy_func(
31923182
#ifdef _Py_TIER2
31933183
if (IS_JIT_TRACING()) {
31943184
next_instr = this_instr;
3195-
goto consider_stop_tracing;
3185+
goto stop_tracing;
31963186
}
31973187
PyCodeObject *code = _PyFrame_GetCode(frame);
31983188
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
@@ -6029,25 +6019,10 @@ dummy_func(
60296019
#endif
60306020
}
60316021

6032-
label(consider_stop_tracing) {
6022+
label(stop_tracing) {
60336023
#if _Py_TIER2
60346024
assert(IS_JIT_TRACING());
60356025
int opcode = next_instr->op.code;
6036-
PyCodeObject *code = _PyFrame_GetCode(frame);
6037-
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
6038-
int orig_opcode = executor->vm_data.opcode;
6039-
// Not backwards jump, trace over it to form a longer trace.
6040-
if (orig_opcode == RESUME_CHECK_JIT || orig_opcode == RESUME) {
6041-
assert(executor->vm_data.index == INSTR_OFFSET());
6042-
assert(executor->vm_data.code == code);
6043-
assert(executor->vm_data.valid);
6044-
oparg = (oparg & ~255) | executor->vm_data.oparg;
6045-
opcode = orig_opcode;
6046-
if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]]) {
6047-
PAUSE_ADAPTIVE_COUNTER(next_instr[1].counter);
6048-
}
6049-
DISPATCH_GOTO_NON_TRACING();
6050-
}
60516026
_PyJit_translate_single_bytecode_to_trace(tstate, frame, NULL, _EXIT_TRACE);
60526027
LEAVE_TRACING();
60536028
int err = stop_tracing_and_jit(tstate, frame);

Python/generated_cases.c.h

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

Python/opcode_targets.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,9 @@ add_to_trace(
579579

580580

581581
static int
582-
opcode_is_terminator(int opcode)
582+
is_terminator(const _PyUOpInstruction *uop)
583583
{
584+
int opcode = _PyUop_Uncached[uop->opcode];
584585
return (
585586
opcode == _EXIT_TRACE ||
586587
opcode == _DEOPT ||
@@ -589,14 +590,6 @@ opcode_is_terminator(int opcode)
589590
);
590591
}
591592

592-
static int
593-
is_terminator(const _PyUOpInstruction *uop)
594-
{
595-
int opcode = uop->opcode;
596-
int base_opcode = _PyUop_Uncached[uop->opcode];
597-
return opcode_is_terminator(opcode) || opcode_is_terminator(base_opcode);
598-
}
599-
600593
/* Returns 1 on success (added to trace), 0 on trace end.
601594
*/
602595
// gh-142543: inlining this function causes stack overflows
@@ -633,7 +626,6 @@ _PyJit_translate_single_bytecode_to_trace(
633626
// We must point to the first EXTENDED_ARG when deopting.
634627
int oparg = tracer->prev_state.instr_oparg;
635628
int opcode = this_instr->op.code;
636-
637629
int rewind_oparg = oparg;
638630
while (rewind_oparg > 255) {
639631
rewind_oparg >>= 8;
@@ -1218,8 +1210,7 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
12181210
int exit_depth = get_cached_entries_for_side_exit(inst);
12191211
assert(_PyUop_Caching[base_exit_op].entries[exit_depth].opcode > 0);
12201212
int16_t exit_op = _PyUop_Caching[base_exit_op].entries[exit_depth].opcode;
1221-
bool is_control_flow = (base_opcode == _GUARD_IS_FALSE_POP || base_opcode == _GUARD_IS_TRUE_POP ||
1222-
base_opcode == _GUARD_IS_NONE_POP || base_opcode == _GUARD_IS_NOT_NONE_POP || is_for_iter_test[base_opcode]);
1213+
bool is_control_flow = (base_opcode == _GUARD_IS_FALSE_POP || base_opcode == _GUARD_IS_TRUE_POP || is_for_iter_test[base_opcode]);
12231214
if (jump_target != current_jump_target || current_exit_op != exit_op) {
12241215
make_exit(&buffer[next_spare], exit_op, jump_target, is_control_flow);
12251216
current_exit_op = exit_op;

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ init_interp_main(PyThreadState *tstate)
13661366
// This is also needed when the JIT is enabled
13671367
#ifdef _Py_TIER2
13681368
if (is_main_interp) {
1369-
int enabled = 1;
1369+
int enabled = 0;
13701370
#if _Py_TIER2 & 2
13711371
enabled = 0;
13721372
#endif

Python/specialize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,7 @@ _Py_Specialize_Resume(_Py_CODEUNIT *instr, PyThreadState *tstate)
27962796
if (tstate->tracing == 0 && instr->op.code == RESUME) {
27972797
if (tstate->interp->jit) {
27982798
specialize(instr, RESUME_CHECK_JIT);
2799-
set_counter((_Py_BackoffCounter *)instr + 1, trigger_backoff_counter());
2799+
set_counter((_Py_BackoffCounter *)instr + 1, initial_resume_backoff_counter());
28002800
return;
28012801
}
28022802
specialize(instr, RESUME_CHECK);

0 commit comments

Comments
 (0)