Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
58 changes: 58 additions & 0 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,64 @@ def test_reassigning_dead_inputs(self):
"""
self.run_cases_test(input, output)

def test_recording_after_specializing_with_cache(self):
input = """
specializing op(SPEC, (counter/1 --)) {
spam;
}

tier2 op(REC, (--)) {
RECORD_VALUE(0);
}

op(BODY, (--)) {
ham;
}

macro(OP) = SPEC + unused/2 + REC + BODY;
"""
output = """
TARGET(OP) {
#if _Py_TAIL_CALL_INTERP
int opcode = OP;
(void)(opcode);
#endif
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;
next_instr += 4;
INSTRUCTION_STATS(OP);
// SPEC
{
uint16_t counter = read_u16(&this_instr[1].cache);
(void)counter;
spam;
}
/* Skip 2 cache entries */
// BODY
{
ham;
}
DISPATCH();
}
"""
self.run_cases_test(input, output)

def test_recording_after_non_specializing(self):
input = """
op(REGULAR, (--)) {
spam;
}

tier2 op(REC, (--)) {
RECORD_VALUE(0);
}

macro(OP) = REGULAR + REC;
"""
with self.assertRaisesRegex(SyntaxError, "Recording uop"):
self.run_cases_test(input, "")


class TestGeneratedAbstractCases(unittest.TestCase):
def setUp(self) -> None:
Expand Down
12 changes: 8 additions & 4 deletions Tools/cases_generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,9 @@ def add_macro(
macro: parser.Macro, instructions: dict[str, Instruction], uops: dict[str, Uop]
) -> None:
parts: list[Part] = []
first = True
# Track the last non-specializing uop seen, so that recording uops
# can follow specializing ones without triggering the position check.
prev_uop: Uop | None = None
for part in macro.uops:
match part:
case parser.OpName():
Expand All @@ -1144,12 +1146,14 @@ def add_macro(
f"No Uop named {part.name}", macro.tokens[0]
)
uop = uops[part.name]
if uop.properties.records_value and not first:
if uop.properties.records_value and prev_uop is not None:
raise analysis_error(
f"Recording uop {part.name} must be first in macro",
f"Recording uop {part.name} is not allowed "
f"after non-specializing uops in macro",
macro.tokens[0])
parts.append(uop)
first = False
if "specializing" not in uop.annotations:
prev_uop = uop
case parser.CacheEffect():
parts.append(Skip(part.size))
case _:
Expand Down
Loading