Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-146297: Rewind optimizer when out of space#146298

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Fidget-Spinner wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromFidget-Spinner:do_not_jit_unopt
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletionsInclude/internal/pycore_optimizer.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,6 +67,16 @@ uop_buffer_last(_PyJitUopBuffer *trace)
returntrace->next-1;
}

staticinlinebool
uop_buffer_rewind(_PyJitUopBuffer*trace)
{
if (trace->next <=trace->start) {
return false;
}
trace->next--;
return true;
}

staticinlineint
uop_buffer_length(_PyJitUopBuffer*trace)
{
Expand Down
45 changes: 31 additions & 14 deletionsPython/optimizer_analysis.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -488,17 +488,9 @@ optimize_uops(
_PyUOpInstruction *this_instr = NULL;
JitOptRef *stack_pointer = ctx->frame->stack_pointer;

for (int i = 0; i < trace_len; i++) {
int i = 0;
for (; i < trace_len && !ctx->done; i++) {
this_instr = &trace[i];
if (ctx->done) {
// Don't do any more optimization, but
// we still need to reach a terminator for corrctness.
*(ctx->out_buffer.next++) = *this_instr;
if (is_terminator_uop(this_instr)) {
break;
}
continue;
}

int oparg = this_instr->oparg;
opcode = this_instr->opcode;
Expand DownExpand Up@@ -531,10 +523,6 @@ optimize_uops(
assert(STACK_LEVEL() >= 0);
}
}
if (ctx->out_of_space) {
DPRINTF(3, "\n");
DPRINTF(1, "Out of space in abstract interpreter\n");
}
if (ctx->contradiction) {
// Attempted to push a "bottom" (contradiction) symbol onto the stack.
// This means that the abstract interpreter has optimized to trace
Expand All@@ -548,6 +536,35 @@ optimize_uops(
OPT_STAT_INC(optimizer_contradiction);
return 0;
}
if (ctx->out_of_space) {
DPRINTF(3, "\n");
DPRINTF(1, "Out of space in abstract interpreter at length %d\n",
uop_buffer_length(&ctx->out_buffer));
// Rewind to previous instruction and replace with _EXIT_TRACE.
_PyUOpInstruction *curr = uop_buffer_last(&ctx->out_buffer);
while (curr->opcode != _SET_IP) {
if (!uop_buffer_rewind(&ctx->out_buffer)) {
// Reached the start.
return 0;
}
curr = uop_buffer_last(&ctx->out_buffer);
}
assert(curr->opcode == _SET_IP);
int32_t old_target = (int32_t)uop_get_target(curr);
curr->opcode = _EXIT_TRACE;
curr->format = UOP_FORMAT_TARGET;
curr->target = old_target;
DPRINTF(1, "Rewound to length %d\n", uop_buffer_length(&ctx->out_buffer));
}
else {
// Don't do any more optimization, but
// we still need to reach a terminator for correctness.
while (!is_terminator_uop(uop_buffer_last(&ctx->out_buffer))) {
this_instr = &trace[i];
*(ctx->out_buffer.next++) = *this_instr;
i++;
}
}

/* Either reached the end or cannot optimize further, but there
* would be no benefit in retrying later */
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp