Skip to content

Commit 2bd04d4

Browse files
authored
gh-105481: combine regen-opcode-targets with regen-opcode to avoid calculating the specialized opcodes in two places (#107540)
1 parent 6ef8f8c commit 2bd04d4

File tree

5 files changed

+16
-68
lines changed

5 files changed

+16
-68
lines changed

Makefile.pre.in

+3-8
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ regen-limited-abi: all
13161316
# Regenerate all generated files
13171317

13181318
.PHONY: regen-all
1319-
regen-all: regen-cases regen-opcode regen-opcode-targets regen-typeslots \
1319+
regen-all: regen-cases regen-opcode regen-typeslots \
13201320
regen-token regen-ast regen-keyword regen-sre regen-frozen clinic \
13211321
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
13221322
regen-test-levenshtein regen-global-objects
@@ -1428,8 +1428,10 @@ regen-opcode:
14281428
$(srcdir)/Lib/opcode.py \
14291429
$(srcdir)/Lib/_opcode_metadata.py \
14301430
$(srcdir)/Include/opcode.h.new \
1431+
$(srcdir)/Python/opcode_targets.h.new \
14311432
$(srcdir)/Include/internal/pycore_opcode.h.new
14321433
$(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new
1434+
$(UPDATE_FILE) $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/opcode_targets.h.new
14331435
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode.h $(srcdir)/Include/internal/pycore_opcode.h.new
14341436

14351437
.PHONY: regen-token
@@ -1531,13 +1533,6 @@ Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c $(UNICODE_DEPS)
15311533
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h
15321534
Objects/setobject.o: $(srcdir)/Objects/stringlib/eq.h
15331535

1534-
.PHONY: regen-opcode-targets
1535-
regen-opcode-targets:
1536-
# Regenerate Python/opcode_targets.h from Lib/opcode.py
1537-
# using Python/makeopcodetargets.py
1538-
$(PYTHON_FOR_REGEN) $(srcdir)/Python/makeopcodetargets.py \
1539-
$(srcdir)/Python/opcode_targets.h.new
1540-
$(UPDATE_FILE) $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/opcode_targets.h.new
15411536

15421537
.PHONY: regen-cases
15431538
regen-cases:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the make target ``regen-opcode-targets``, merge its work into ``regen-opcode`` which repeats most of the calculation. This simplifies the code for the build and reduces code duplication.

PCbuild/regen.targets

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959
Inputs="@(_OpcodeSources)" Outputs="@(_OpcodeOutputs)"
6060
DependsOnTargets="FindPythonForBuild">
6161
<Message Text="Regenerate @(_OpcodeOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
62-
<Exec Command="$(PythonForBuild) Tools\build\generate_opcode_h.py Lib\opcode.py Lib\_opcode_metadata.py Include\opcode.h Include\internal\pycore_opcode.h Include\internal\pycore_intrinsics.h"
63-
WorkingDirectory="$(PySourcePath)" />
64-
<Exec Command="$(PythonForBuild) Python\makeopcodetargets.py Python\opcode_targets.h"
62+
<Exec Command="$(PythonForBuild) Tools\build\generate_opcode_h.py Lib\opcode.py Lib\_opcode_metadata.py Include\opcode.h Python/opcode_targets.h Include\internal\pycore_opcode.h Include\internal\pycore_intrinsics.h"
6563
WorkingDirectory="$(PySourcePath)" />
6664
</Target>
6765

Python/makeopcodetargets.py

-56
This file was deleted.

Tools/build/generate_opcode_h.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def get_python_module_dict(filename):
6464
def main(opcode_py,
6565
_opcode_metadata_py='Lib/_opcode_metadata.py',
6666
outfile='Include/opcode.h',
67+
opcode_targets_h='Python/opcode_targets.h',
6768
internaloutfile='Include/internal/pycore_opcode.h'):
6869

6970
_opcode_metadata = get_python_module_dict(_opcode_metadata_py)
@@ -161,9 +162,18 @@ def main(opcode_py,
161162
fobj.write(footer)
162163
iobj.write(internal_footer)
163164

165+
with open(opcode_targets_h, "w") as f:
166+
targets = ["_unknown_opcode"] * 256
167+
for op, name in enumerate(opname_including_specialized):
168+
if op < 256 and not name.startswith("<"):
169+
targets[op] = f"TARGET_{name}"
170+
171+
f.write("static void *opcode_targets[256] = {\n")
172+
f.write(",\n".join([f" &&{s}" for s in targets]))
173+
f.write("\n};\n")
164174

165175
print(f"{outfile} regenerated from {opcode_py}")
166176

167177

168178
if __name__ == '__main__':
169-
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
179+
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])

0 commit comments

Comments
 (0)