8000 GH-118093: Handle some polymorphism before requiring progress in tier two by brandtbucher · Pull Request #122843 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-118093: Handle some polymorphism before requiring progress in tier two #122843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 12, 2024
Prev Previous commit
Next Next commit
Clean up the diff
  • Loading branch information
brandtbucher committed Aug 8, 2024
commit 133aa69f6dc8433b9387f7b426ae8924e36f7afd
8 changes: 4 additions & 4 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
#define MAX_ABSTRACT_FRAME_DEPTH (TRACE_STACK_SIZE + 2)

// The number of traces that will be stitched together via side exits for a
// single instruction before requiring progress. In practice, this is the number
// of different classes/functions/etc. that tier two can handle for a single
// tier one instruction.
// The maximum number of side exits that we can take before requiring forward
// progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this
// is the "maximum amount of polymorphism" that an isolated trace tree can
// handle before rejoining the rest of the program.
#define MAX_CHAIN_DEPTH 4

typedef struct _Py_UopsSymbol _Py_UopsSymbol;
Expand Down
13 changes: 7 additions & 6 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ _PyOptimizer_Optimize(
int index = get_index_for_executor(code, start);
if (index < 0) {
/* Out of memory. Don't raise and assume that the
* error will show up elsewhere.
*
* If an optimizer has already produced an executor,
* it might get confused by the executor disappearing,
* but there is not much we can do about that here. */
* error will show up elsewhere.
*
* If an optimizer has already produced an executor,
* it might get confused by the executor disappearing,
* but there is not much we can do about that here. */
Py_DECREF(*executor_ptr);
return 0;
}
Expand Down Expand Up @@ -588,6 +588,8 @@ translate_bytecode_to_trace(
uint32_t opcode = instr->op.code;
uint32_t oparg = instr->op.arg;

/* Special case the first instruction,
* so that we can guarantee forward progress */
if (!first && instr == initial_instr) {
// We have looped around to the start:
RESERVE(1);
Expand All @@ -606,7 +608,6 @@ translate_bytecode_to_trace(
goto done;
}
}

if (opcode == ENTER_EXECUTOR) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we are done?
If we are wanting specialized traces, they may overlap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment justifying the decision.

goto done;
}
Expand Down
0