mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
GH-111485: Increment next_instr consistently at the start of the instruction. (GH-111486)
This commit is contained in:
parent
e3353c498d
commit
d27acd4461
11 changed files with 1079 additions and 521 deletions
|
|
@ -432,7 +432,6 @@ class Analyzer:
|
|||
"LOAD_FAST_LOAD_FAST",
|
||||
"LOAD_CONST_LOAD_FAST",
|
||||
"STORE_FAST_STORE_FAST",
|
||||
"_BINARY_OP_INPLACE_ADD_UNICODE",
|
||||
"POP_JUMP_IF_TRUE",
|
||||
"POP_JUMP_IF_FALSE",
|
||||
"_ITER_JUMP_LIST",
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class Instruction:
|
|||
# Computed by constructor
|
||||
always_exits: str # If the block always exits, its last line; else ""
|
||||
has_deopt: bool
|
||||
needs_this_instr: bool
|
||||
cache_offset: int
|
||||
cache_effects: list[parsing.CacheEffect]
|
||||
input_effects: list[StackEffect]
|
||||
|
|
@ -87,6 +88,7 @@ class Instruction:
|
|||
effect for effect in inst.inputs if isinstance(effect, parsing.CacheEffect)
|
||||
]
|
||||
self.cache_offset = sum(c.size for c in self.cache_effects)
|
||||
self.needs_this_instr = variable_used(self.inst, "this_instr") or any(c.name != UNUSED for c in self.cache_effects)
|
||||
self.input_effects = [
|
||||
effect for effect in inst.inputs if isinstance(effect, StackEffect)
|
||||
]
|
||||
|
|
@ -164,7 +166,8 @@ class Instruction:
|
|||
func = f"read_u{bits}"
|
||||
if tier == TIER_ONE:
|
||||
out.emit(
|
||||
f"{typ}{ceffect.name} = {func}(&next_instr[{active.offset}].cache);"
|
||||
f"{typ}{ceffect.name} = "
|
||||
f"{func}(&this_instr[{active.offset + 1}].cache);"
|
||||
)
|
||||
else:
|
||||
out.emit(f"{typ}{ceffect.name} = ({typ.strip()})operand;")
|
||||
|
|
|
|||
|
|
@ -365,8 +365,17 @@ def write_macro_instr(mac: MacroInstruction, out: Formatter) -> None:
|
|||
]
|
||||
out.emit("")
|
||||
with out.block(f"TARGET({mac.name})"):
|
||||
needs_this = any(part.instr.needs_this_instr for part in parts)
|
||||
if needs_this and not mac.predicted:
|
||||
out.emit(f"_Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;")
|
||||
else:
|
||||
out.emit(f"frame->instr_ptr = next_instr;")
|
||||
out.emit(f"next_instr += {mac.cache_offset+1};")
|
||||
out.emit(f"INSTRUCTION_STATS({mac.name});")
|
||||
if mac.predicted:
|
||||
out.emit(f"PREDICTED({mac.name});")
|
||||
if needs_this:
|
||||
out.emit(f"_Py_CODEUNIT *this_instr = next_instr - {mac.cache_offset+1};")
|
||||
out.static_assert_family_size(mac.name, mac.family, mac.cache_offset)
|
||||
try:
|
||||
next_instr_is_set = write_components(
|
||||
|
|
@ -375,8 +384,6 @@ def write_macro_instr(mac: MacroInstruction, out: Formatter) -> None:
|
|||
except AssertionError as err:
|
||||
raise AssertionError(f"Error writing macro {mac.name}") from err
|
||||
if not parts[-1].instr.always_exits:
|
||||
if not next_instr_is_set and mac.cache_offset:
|
||||
out.emit(f"next_instr += {mac.cache_offset};")
|
||||
if parts[-1].instr.check_eval_breaker:
|
||||
out.emit("CHECK_EVAL_BREAKER();")
|
||||
out.emit("DISPATCH();")
|
||||
|
|
@ -450,8 +457,6 @@ def write_components(
|
|||
|
||||
if mgr.instr.name == "_SAVE_RETURN_OFFSET":
|
||||
next_instr_is_set = True
|
||||
if cache_offset:
|
||||
out.emit(f"next_instr += {cache_offset};")
|
||||
if tier == TIER_ONE:
|
||||
assert_no_pokes(managers)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue