gh-128563: Move assignment of opcode into ifdef (GH-129803)

This commit is contained in:
Ken Jin 2025-02-07 21:11:57 +08:00 committed by GitHub
parent 3d3a4beefe
commit 175844713a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 566 additions and 825 deletions

View file

@ -305,10 +305,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -328,10 +327,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -354,10 +352,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -381,10 +378,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -409,10 +405,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -440,10 +435,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -473,10 +467,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP1) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP1;
int opcode = OP1;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
@ -489,10 +482,9 @@ class TestGeneratedCases(unittest.TestCase):
TARGET(OP3) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP3;
int opcode = OP3;
(void)(opcode);
#endif
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;
@ -528,10 +520,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(A) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = A;
int opcode = A;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(A);
@ -550,10 +541,9 @@ class TestGeneratedCases(unittest.TestCase):
TARGET(B) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = B;
int opcode = B;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(B);
@ -592,10 +582,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -616,10 +605,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -644,10 +632,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -680,10 +667,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -712,10 +698,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;
@ -744,10 +729,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -780,10 +764,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 6;
INSTRUCTION_STATS(OP);
@ -822,10 +805,9 @@ class TestGeneratedCases(unittest.TestCase):
TARGET(OP1) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP1;
int opcode = OP1;
(void)(opcode);
#endif
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;
@ -845,10 +827,9 @@ class TestGeneratedCases(unittest.TestCase):
TARGET(OP3) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP3;
int opcode = OP3;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 6;
INSTRUCTION_STATS(OP3);
@ -881,10 +862,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 4;
INSTRUCTION_STATS(OP);
@ -908,10 +888,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP1) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP1;
int opcode = OP1;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
@ -932,10 +911,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP1) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP1;
int opcode = OP1;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
@ -959,10 +937,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP1) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP1;
int opcode = OP1;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
@ -971,10 +948,9 @@ class TestGeneratedCases(unittest.TestCase):
TARGET(OP2) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP2;
int opcode = OP2;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP2);
@ -993,10 +969,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1021,10 +996,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1054,10 +1028,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1083,10 +1056,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1114,10 +1086,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1160,10 +1131,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(M) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = M;
int opcode = M;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(M);
@ -1209,10 +1179,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(M) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = M;
int opcode = M;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(M);
@ -1247,10 +1216,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1273,10 +1241,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(M) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = M;
int opcode = M;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(M);
@ -1295,10 +1262,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1318,10 +1284,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(M) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = M;
int opcode = M;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(M);
@ -1359,10 +1324,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1386,10 +1350,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1429,10 +1392,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(INST) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = INST;
int opcode = INST;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(INST);
@ -1460,10 +1422,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(TEST) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = TEST;
int opcode = TEST;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(TEST);
@ -1505,10 +1466,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(TEST) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = TEST;
int opcode = TEST;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(TEST);
@ -1549,10 +1509,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(TEST) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = TEST;
int opcode = TEST;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(TEST);
@ -1602,10 +1561,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(TEST) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = TEST;
int opcode = TEST;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(TEST);
@ -1655,10 +1613,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(TEST) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = TEST;
int opcode = TEST;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(TEST);
@ -1701,10 +1658,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP1) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP1;
int opcode = OP1;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
@ -1713,10 +1669,9 @@ class TestGeneratedCases(unittest.TestCase):
TARGET(OP2) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP2;
int opcode = OP2;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP2);
@ -1775,10 +1730,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(BALANCED) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = BALANCED;
int opcode = BALANCED;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(BALANCED);
@ -1800,10 +1754,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(BALANCED) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = BALANCED;
int opcode = BALANCED;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(BALANCED);
@ -1826,10 +1779,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(BALANCED) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = BALANCED;
int opcode = BALANCED;
(void)(opcode);
#endif
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;
@ -1853,10 +1805,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1893,10 +1844,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1932,10 +1882,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
@ -1968,10 +1917,9 @@ class TestGeneratedCases(unittest.TestCase):
output = """
TARGET(OP) {
#if defined(Py_TAIL_CALL_INTERP)
int opcode;
#endif
opcode = OP;
int opcode = OP;
(void)(opcode);
#endif
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);

File diff suppressed because it is too large Load diff

View file

@ -230,10 +230,9 @@ def generate_tier1_cases(
# We need to ifdef it because this breaks platforms
# without computed gotos/tail calling.
out.emit(f"#if defined(Py_TAIL_CALL_INTERP)\n")
out.emit(f"int opcode;\n")
out.emit(f"#endif\n")
out.emit(f"opcode = {name};\n")
out.emit(f"int opcode = {name};\n")
out.emit(f"(void)(opcode);\n")
out.emit(f"#endif\n")
needs_this = uses_this(inst)
unused_guard = "(void)this_instr;\n"
if inst.properties.needs_prev:
@ -252,6 +251,8 @@ def generate_tier1_cases(
if needs_this:
out.emit(f"_Py_CODEUNIT* const this_instr = next_instr - {inst.size};\n")
out.emit(unused_guard)
if inst.properties.uses_opcode:
out.emit(f"opcode = {name};\n")
if inst.family is not None:
out.emit(
f"static_assert({inst.family.size} == {inst.size-1}"