summaryrefslogtreecommitdiffstats
path: root/Tools/cases_generator
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-10-31 10:09:54 (GMT)
committerGitHub <noreply@github.com>2023-10-31 10:09:54 (GMT)
commitd27acd4461ee603bcf6f4a81ca6afccc9fc87331 (patch)
treeb989f6c029b1350612cc9df07d0d027df2a745d8 /Tools/cases_generator
parente3353c498d79f0f3f108a9baf8807a12e77c2ebe (diff)
downloadcpython-d27acd4461ee603bcf6f4a81ca6afccc9fc87331.zip
cpython-d27acd4461ee603bcf6f4a81ca6afccc9fc87331.tar.gz
cpython-d27acd4461ee603bcf6f4a81ca6afccc9fc87331.tar.bz2
GH-111485: Increment `next_instr` consistently at the start of the instruction. (GH-111486)
Diffstat (limited to 'Tools/cases_generator')
-rw-r--r--Tools/cases_generator/analysis.py1
-rw-r--r--Tools/cases_generator/instructions.py5
-rw-r--r--Tools/cases_generator/stacking.py13
3 files changed, 13 insertions, 6 deletions
diff --git a/Tools/cases_generator/analysis.py b/Tools/cases_generator/analysis.py
index 53f715d..180bd01 100644
--- a/Tools/cases_generator/analysis.py
+++ b/Tools/cases_generator/analysis.py
@@ -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",
diff --git a/Tools/cases_generator/instructions.py b/Tools/cases_generator/instructions.py
index c6b5516..e9ed2a8 100644
--- a/Tools/cases_generator/instructions.py
+++ b/Tools/cases_generator/instructions.py
@@ -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;")
diff --git a/Tools/cases_generator/stacking.py b/Tools/cases_generator/stacking.py
index 69a6c10..123e38c 100644
--- a/Tools/cases_generator/stacking.py
+++ b/Tools/cases_generator/stacking.py
@@ -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)