summaryrefslogtreecommitdiffstats
path: root/Tools/cases_generator/instructions.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-10-03 17:13:50 (GMT)
committerGitHub <noreply@github.com>2023-10-03 17:13:50 (GMT)
commitd67edcf0b361c9ee0d29ed719562c58a85304cd0 (patch)
tree06ce9512bc78d2759f55d3495cf3298b387649ea /Tools/cases_generator/instructions.py
parentd73501602f863a54c872ce103cd3fa119e38bac9 (diff)
downloadcpython-d67edcf0b361c9ee0d29ed719562c58a85304cd0.zip
cpython-d67edcf0b361c9ee0d29ed719562c58a85304cd0.tar.gz
cpython-d67edcf0b361c9ee0d29ed719562c58a85304cd0.tar.bz2
gh-109979: Auto-generate the target for DEOPT_IF() (#110193)
In Python/bytecodes.c, you now write ``` DEOPT_IF(condition); ``` The code generator expands this to ``` DEOPT_IF(condition, opcode); ``` where `opcode` is the name of the unspecialized instruction. This works inside macro expansions too. **CAVEAT:** The entire `DEOPT_IF(condition)` statement must be on a single line. If it isn't, the substitution will fail; an error will be printed by the code generator and the C compiler will report some errors.
Diffstat (limited to 'Tools/cases_generator/instructions.py')
-rw-r--r--Tools/cases_generator/instructions.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Tools/cases_generator/instructions.py b/Tools/cases_generator/instructions.py
index 6fbf7d9..5384bbe 100644
--- a/Tools/cases_generator/instructions.py
+++ b/Tools/cases_generator/instructions.py
@@ -144,7 +144,8 @@ class Instruction:
out: Formatter,
dedent: int,
active_caches: list[ActiveCacheEffect],
- tier: Tiers = TIER_ONE,
+ tier: Tiers,
+ family: parsing.Family | None,
) -> None:
"""Write the instruction body."""
# Write cache effect variable declarations and initializations
@@ -207,6 +208,14 @@ class Instruction:
)
else:
out.write_raw(f"{space}if ({cond}) goto {label};\n")
+ elif m := re.match(r"(\s*)DEOPT_IF\((.+)\);\s*(?://.*)?$", line):
+ space, cond = m.groups()
+ target = family.name if family else self.name
+ out.write_raw(f"{space}DEOPT_IF({cond}, {target});\n")
+ elif "DEOPT" in line:
+ filename = context.owner.filename
+ lineno = context.owner.tokens[context.begin].line
+ print(f"{filename}:{lineno}: ERROR: DEOPT_IF() must be all on one line")
elif m := re.match(r"(\s*)DECREF_INPUTS\(\);\s*(?://.*)?$", line):
out.reset_lineno()
space = extra + m.group(1)
@@ -244,7 +253,8 @@ class AbstractInstruction(Instruction):
out: Formatter,
dedent: int,
active_caches: list[ActiveCacheEffect],
- tier: Tiers = TIER_ONE,
+ tier: Tiers,
+ family: parsing.Family | None,
) -> None:
pass
@@ -268,7 +278,9 @@ class MacroInstruction:
macro: parsing.Macro
parts: MacroParts
cache_offset: int
+ # Set later
predicted: bool = False
+ family: parsing.Family | None = None
@dataclasses.dataclass