-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
GH-111848: Set the IP when de-optimizing #112065
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
317db3a
Replace jumps with deopts in tier 2
markshannon 2db61cc
Fewer special cases of uop names
markshannon f361328
Fix refleak
markshannon 2de3451
Merge branch 'main' into jumps-to-deopts
markshannon 69cee8d
Update test
markshannon bb9a1a2
Add target field to uop IR
markshannon 9cda14b
Remove redundant SET_IP and _CHECK_VALIDITY micro-ops
markshannon 6c61feb
Extend whitelist of non-escaping API functions.
markshannon 0a093fd
Add more functions to whitelist
markshannon 18a6511
Merge branch 'main' into deopts-with-ip
markshannon 222ee17
Tidy up
markshannon 4d1e295
Add another non-escaping function
markshannon b5737c8
Fix type annotation
markshannon 8e2f0f6
Address review comments
markshannon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,7 +446,8 @@ translate_bytecode_to_trace( | |
#define DPRINTF(level, ...) | ||
#endif | ||
|
||
#define ADD_TO_TRACE(OPCODE, OPARG, OPERAND) \ | ||
|
||
#define ADD_TO_TRACE(OPCODE, OPARG, OPERAND, TARGET) \ | ||
DPRINTF(2, \ | ||
" ADD_TO_TRACE(%s, %d, %" PRIu64 ")\n", \ | ||
uop_name(OPCODE), \ | ||
|
@@ -458,23 +459,12 @@ translate_bytecode_to_trace( | |
trace[trace_length].opcode = (OPCODE); \ | ||
trace[trace_length].oparg = (OPARG); \ | ||
trace[trace_length].operand = (OPERAND); \ | ||
trace[trace_length].target = (TARGET); \ | ||
trace_length++; | ||
|
||
#define INSTR_IP(INSTR, CODE) \ | ||
((uint32_t)((INSTR) - ((_Py_CODEUNIT *)(CODE)->co_code_adaptive))) | ||
|
||
#define ADD_TO_STUB(INDEX, OPCODE, OPARG, OPERAND) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no more stubs. Do you expect stubs to eventually make a comeback? If not, there are a few mentions of 'stub' that can be removed. Notably the |
||
DPRINTF(2, " ADD_TO_STUB(%d, %s, %d, %" PRIu64 ")\n", \ | ||
(INDEX), \ | ||
uop_name(OPCODE), \ | ||
(OPARG), \ | ||
(uint64_t)(OPERAND)); \ | ||
assert(reserved > 0); \ | ||
reserved--; \ | ||
trace[(INDEX)].opcode = (OPCODE); \ | ||
trace[(INDEX)].oparg = (OPARG); \ | ||
trace[(INDEX)].operand = (OPERAND); | ||
|
||
// Reserve space for n uops | ||
#define RESERVE_RAW(n, opname) \ | ||
if (trace_length + (n) > max_length) { \ | ||
|
@@ -483,7 +473,7 @@ translate_bytecode_to_trace( | |
OPT_STAT_INC(trace_too_long); \ | ||
goto done; \ | ||
} \ | ||
reserved = (n); // Keep ADD_TO_TRACE / ADD_TO_STUB honest | ||
reserved = (n); // Keep ADD_TO_TRACE honest | ||
|
||
// Reserve space for main+stub uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE | ||
#define RESERVE(main, stub) RESERVE_RAW((main) + (stub) + 3, uop_name(opcode)) | ||
|
@@ -493,7 +483,7 @@ translate_bytecode_to_trace( | |
if (trace_stack_depth >= TRACE_STACK_SIZE) { \ | ||
DPRINTF(2, "Trace stack overflow\n"); \ | ||
OPT_STAT_INC(trace_stack_overflow); \ | ||
ADD_TO_TRACE(_SET_IP, 0, 0); \ | ||
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, 0); \ | ||
goto done; \ | ||
} \ | ||
trace_stack[trace_stack_depth].code = code; \ | ||
|
@@ -513,22 +503,28 @@ translate_bytecode_to_trace( | |
PyUnicode_AsUTF8(code->co_filename), | ||
code->co_firstlineno, | ||
2 * INSTR_IP(initial_instr, code)); | ||
|
||
uint32_t target = 0; | ||
top: // Jump here after _PUSH_FRAME or likely branches | ||
for (;;) { | ||
target = INSTR_IP(instr, code); | ||
RESERVE_RAW(3, "epilogue"); // Always need space for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE | ||
ADD_TO_TRACE(_SET_IP, INSTR_IP(instr, code), 0); | ||
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0); | ||
ADD_TO_TRACE(_SET_IP, target, 0, target); | ||
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target); | ||
|
||
uint32_t opcode = instr->op. 8000 code; | ||
uint32_t oparg = instr->op.arg; | ||
uint32_t extras = 0; | ||
|
||
while (opcode == EXTENDED_ARG) { | ||
|
||
if (opcode == EXTENDED_ARG) { | ||
instr++; | ||
extras += 1; | ||
opcode = instr->op.code; | ||
oparg = (oparg << 8) | instr->op.arg; | ||
if (opcode == EXTENDED_ARG) { | ||
instr--; | ||
goto done; | ||
} | ||
} | ||
|
||
if (opcode == ENTER_EXECUTOR) { | ||
|
@@ -554,7 +550,7 @@ translate_bytecode_to_trace( | |
DPRINTF(4, "%s(%d): counter=%x, bitcount=%d, likely=%d, uopcode=%s\n", | ||
uop_name(opcode), oparg, | ||
counter, bitcount, jump_likely, uop_name(uopcode)); | ||
ADD_TO_TRACE(uopcode, max_length, 0); | ||
ADD_TO_TRACE(uopcode, max_length, 0, target); | ||
if (jump_likely) { | ||
_Py_CODEUNIT *target_instr = next_instr + oparg; | ||
DPRINTF(2, "Jump likely (%x = %d bits), continue at byte offset %d\n", | ||
|
@@ -569,7 +565,7 @@ translate_bytecode_to_trace( | |
{ | ||
if (instr + 2 - oparg == initial_instr && code == initial_code) { | ||
RESERVE(1, 0); | ||
ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0); | ||
ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0); | ||
markshannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else { | ||
OPT_STAT_INC(inner_loop); | ||
|
@@ -653,7 +649,7 @@ translate_bytecode_to_trace( | |
expansion->uops[i].offset); | ||
Py_FatalError("garbled expansion"); | ||
} | ||
ADD_TO_TRACE(uop, oparg, operand); | ||
ADD_TO_TRACE(uop, oparg, operand, target); | ||
if (uop == _POP_FRAME) { | ||
TRACE_STACK_POP(); | ||
DPRINTF(2, | ||
|
@@ -682,15 +678,15 @@ translate_bytecode_to_trace( | |
PyUnicode_AsUTF8(new_code->co_filename), | ||
new_code->co_firstlineno); | ||
OPT_STAT_INC(recursive_call); | ||
ADD_TO_TRACE(_SET_IP, 0, 0); | ||
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, 0); | ||
goto done; | ||
} | ||
if (new_code->co_version != func_version) { | ||
// func.__code__ was updated. | ||
// Perhaps it may happen again, so don't bother tracing. | ||
// TODO: Reason about this -- is it better to bail or not? | ||
DPRINTF(2, "Bailing because co_version != func_version\n"); | ||
ADD_TO_TRACE(_SET_IP, 0, 0); | ||
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, 0); | ||
goto done; | ||
} | ||
// Increment IP to the return address | ||
|
@@ -707,7 +703,7 @@ translate_bytecode_to_trace( | |
2 * INSTR_IP(instr, code)); | ||
goto top; | ||
} | ||
ADD_TO_TRACE(_SET_IP, 0, 0); | ||
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, 0); | ||
goto done; | ||
} | ||
} | ||
|
@@ -732,7 +728,7 @@ translate_bytecode_to_trace( | |
assert(code == initial_code); | ||
// Skip short traces like _SET_IP, LOAD_FAST, _SET_IP, _EXIT_TRACE | ||
if (trace_length > 4) { | ||
ADD_TO_TRACE(_EXIT_TRACE, 0, 0); | ||
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target); | ||
DPRINTF(1, | ||
"Created a trace for %s (%s:%d) at byte offset %d -- length %d+%d\n", | ||
PyUnicode_AsUTF8(code->co_qualname), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.