Skip to content

Commit 69c4998

Browse files
committed
de-couple the MAX_CACHED_REGISTER and MIN_GENERATED_CACHE_REGISTER
1 parent fbf7580 commit 69c4998

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

Include/internal/pycore_uop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#define MAX_CACHED_REGISTER 3
12+
1113
#include <stdint.h>
1214
/* Depending on the format,
1315
* the 32 bits between the oparg and operand are:

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/analyzer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
from parser import Stmt, SimpleStmt, BlockStmt, IfStmt, WhileStmt, ForStmt, MacroIfStmt
99

10+
MIN_GENERATED_CACHED_REGISTER = 3
1011
MAX_GENERATED_CACHED_REGISTER = 5
11-
MAX_CACHED_REGISTER = 3 # Platform-specific; controls compile-time case pruning
12+
MAX_CACHED_REGISTER = (
13+
MIN_GENERATED_CACHED_REGISTER # Platform-specific; controls compile-time case pruning
14+
)
1215

1316
@dataclass
1417
class EscapingCall:

Tools/cases_generator/tier2_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
get_uop_cache_depths,
1818
is_large,
1919
MAX_CACHED_REGISTER,
20+
MIN_GENERATED_CACHED_REGISTER,
2021
MAX_GENERATED_CACHED_REGISTER,
2122
)
2223

@@ -267,7 +268,7 @@ def generate_tier2(
267268

268269
first = True
269270
for target_depth in range(
270-
MAX_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
271+
MIN_GENERATED_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
271272
):
272273
directive = "#if" if first else "#elif"
273274
out.start_line()

Tools/cases_generator/uop_id_generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Analysis,
1111
analyze_files,
1212
get_uop_cache_depths,
13-
MAX_CACHED_REGISTER,
13+
MIN_GENERATED_CACHED_REGISTER,
1414
MAX_GENERATED_CACHED_REGISTER,
1515
)
1616
from generators_common import (
@@ -31,6 +31,7 @@ def generate_uop_ids(
3131
write_header(__file__, filenames, outfile)
3232
out = CWriter(outfile, 0, False)
3333
with out.header_guard("Py_CORE_UOP_IDS_H"):
34+
out.emit('#include "pycore_uop.h"\n')
3435
next_id = 1 if distinct_namespace else 300
3536
# These two are first by convention
3637
out.emit(f"#define _EXIT_TRACE {next_id}\n")
@@ -52,10 +53,9 @@ def generate_uop_ids(
5253

5354
base_max_uop_id = next_id - 1
5455
out.emit(f"#define MAX_UOP_ID {base_max_uop_id}\n")
55-
out.emit(f"#define MAX_CACHED_REGISTER {MAX_CACHED_REGISTER}\n")
5656
first = True
5757
for target_depth in range(
58-
MAX_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
58+
MIN_GENERATED_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
5959
):
6060
directive = "#if" if first else "#elif"
6161
out.emit(f"{directive} MAX_CACHED_REGISTER == {target_depth}\n")

Tools/cases_generator/uop_metadata_generator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_uop_cache_depths,
1212
Uop,
1313
MAX_CACHED_REGISTER,
14+
MIN_GENERATED_CACHED_REGISTER,
1415
MAX_GENERATED_CACHED_REGISTER,
1516
)
1617
from generators_common import (
@@ -82,7 +83,7 @@ def emit_runtime_tables(out: CWriter, max_cached_register: int) -> None:
8283
def emit_runtime_table_selector(out: CWriter) -> None:
8384
first = True
8485
for max_cached_register in range(
85-
MAX_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
86+
MIN_GENERATED_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
8687
):
8788
directive = "#if" if first else "#elif"
8889
out.emit(f"{directive} MAX_CACHED_REGISTER == {max_cached_register}\n")
@@ -135,7 +136,7 @@ def emit_exact_match_dispatch(
135136
) -> None:
136137
first = True
137138
for max_cached_register in range(
138-
MAX_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
139+
MIN_GENERATED_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
139140
):
140141
directive = "#if" if first else "#elif"
141142
out.emit(f"{directive} MAX_CACHED_REGISTER == {max_cached_register}\n")
@@ -154,7 +155,7 @@ def generate_names_and_flags(analysis: Analysis, out: CWriter) -> None:
154155
out.emit("extern int _PyUop_num_popped(int opcode, int oparg);\n")
155156
out.emit(CACHING_INFO_DECL)
156157
for max_cached_register in range(
157-
MAX_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
158+
MIN_GENERATED_CACHED_REGISTER, MAX_GENERATED_CACHED_REGISTER + 1
158159
):
159160
emit_runtime_tables(out, max_cached_register)
160161
emit_runtime_table_selector(out)

Tools/jit/_targets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
ASYNCIO_RUNNER = asyncio.Runner()
3333

34-
# TODO: Read this from Tools/cases_generator/analyzer.py instead of hardcoding.
3534
_MAX_CACHED_REGISTER = 3
3635

3736
_S = typing.TypeVar("_S", _schema.COFFSection, _schema.ELFSection, _schema.MachOSection)

0 commit comments

Comments
 (0)