Skip to content

Commit d484cdb

Browse files
committed
Add MAX_GENERATED_CACHED_REGISTER in analyzer
1 parent 9585f50 commit d484cdb

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

Tools/cases_generator/analyzer.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

10-
MAX_CACHED_REGISTER = 3
10+
MAX_GENERATED_CACHED_REGISTER = 5
1111

1212
@dataclass
1313
class EscapingCall:
@@ -1369,13 +1369,13 @@ def is_large(uop: Uop) -> bool:
13691369

13701370
def get_uop_cache_depths(uop: Uop) -> Iterator[tuple[int, int, int]]:
13711371
if uop.name == "_SPILL_OR_RELOAD":
1372-
for inputs in range(MAX_CACHED_REGISTER+1):
1373-
for outputs in range(MAX_CACHED_REGISTER+1):
1372+
for inputs in range(MAX_GENERATED_CACHED_REGISTER + 1):
1373+
for outputs in range(MAX_GENERATED_CACHED_REGISTER + 1):
13741374
if inputs != outputs:
13751375
yield inputs, outputs, inputs
13761376
return
13771377
if uop.name in ("_DEOPT", "_HANDLE_PENDING_AND_DEOPT", "_EXIT_TRACE", "_DYNAMIC_EXIT"):
1378-
for i in range(MAX_CACHED_REGISTER+1):
1378+
for i in range(MAX_GENERATED_CACHED_REGISTER + 1):
13791379
yield i, 0, 0
13801380
return
13811381
if uop.name in ("_START_EXECUTOR", "_JUMP_TO_TOP", "_COLD_EXIT"):
@@ -1397,20 +1397,20 @@ def get_uop_cache_depths(uop: Uop) -> Iterator[tuple[int, int, int]]:
13971397
has_array = True
13981398
break
13991399
ideal_outputs += 1
1400-
if ideal_inputs > MAX_CACHED_REGISTER:
1401-
ideal_inputs = MAX_CACHED_REGISTER
1402-
if ideal_outputs > MAX_CACHED_REGISTER:
1403-
ideal_outputs = MAX_CACHED_REGISTER
1400+
if ideal_inputs > MAX_GENERATED_CACHED_REGISTER:
1401+
ideal_inputs = MAX_GENERATED_CACHED_REGISTER
1402+
if ideal_outputs > MAX_GENERATED_CACHED_REGISTER:
1403+
ideal_outputs = MAX_GENERATED_CACHED_REGISTER
14041404
at_end = uop.properties.sync_sp or uop.properties.side_exit_at_end
14051405
exit_depth = ideal_outputs if at_end else ideal_inputs
14061406
if uop.properties.escapes or uop.properties.sync_sp or has_array or is_large(uop):
14071407
yield ideal_inputs, ideal_outputs, exit_depth
14081408
return
1409-
for inputs in range(MAX_CACHED_REGISTER + 1):
1409+
for inputs in range(MAX_GENERATED_CACHED_REGISTER + 1):
14101410
outputs = ideal_outputs - ideal_inputs + inputs
14111411
if outputs < ideal_outputs:
14121412
outputs = ideal_outputs
1413-
elif outputs > MAX_CACHED_REGISTER:
1413+
elif outputs > MAX_GENERATED_CACHED_REGISTER:
14141414
continue
14151415
yield inputs, outputs, outputs if at_end else inputs
14161416

Tools/cases_generator/tier2_generator.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
analysis_error,
1717
get_uop_cache_depths,
1818
is_large,
19-
MAX_CACHED_REGISTER,
19+
MAX_GENERATED_CACHED_REGISTER,
2020
)
2121

2222
from generators_common import (
@@ -202,8 +202,10 @@ def cache_items(self, stack: Stack, cached_items: int, zero_regs: bool) -> None:
202202
# replace this with a "clobber" to tell
203203
# the compiler that these values are unused
204204
# without having to emit any code.
205-
for i in range(cached_items, MAX_CACHED_REGISTER):
205+
for i in range(cached_items, MAX_GENERATED_CACHED_REGISTER):
206+
self.out.emit(f"#if MAX_CACHED_REGISTER >= {i + 1}\n")
206207
self.out.emit(f"_tos_cache{i} = PyStackRef_ZERO_BITS;\n")
208+
self.out.emit("#endif\n")
207209
self.emit(f"SET_CURRENT_CACHED_VALUES({cached_items});\n")
208210

209211

@@ -277,6 +279,9 @@ def generate_tier2(
277279
continue
278280
for inputs, outputs, exit_depth in get_uop_cache_depths(uop):
279281
emitter = Tier2Emitter(out, analysis.labels, exit_depth)
282+
needed_cached_registers = max(inputs, outputs)
283+
if needed_cached_registers:
284+
out.emit(f"#if MAX_CACHED_REGISTER >= {needed_cached_registers}\n")
280285
out.emit(f"case {uop.name}_r{inputs}{outputs}: {{\n")
281286
out.emit(f"CHECK_CURRENT_CACHED_VALUES({inputs});\n")
282287
out.emit("assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());\n")
@@ -293,6 +298,8 @@ def generate_tier2(
293298
out.start_line()
294299
out.emit("}")
295300
out.emit("\n\n")
301+
if needed_cached_registers:
302+
out.emit("#endif\n\n")
296303
out.emit("\n")
297304
outfile.write("#undef TIER_TWO\n")
298305

Tools/cases_generator/uop_metadata_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
analyze_files,
1111
get_uop_cache_depths,
1212
Uop,
13-
MAX_CACHED_REGISTER,
1413
)
1514
from generators_common import (
1615
DEFAULT_INPUT,
@@ -23,6 +22,7 @@
2322
from typing import TextIO
2423

2524
DEFAULT_OUTPUT = ROOT / "Include/internal/pycore_uop_metadata.h"
25+
MAX_CACHED_REGISTER = 3 # Specify this by different platform
2626

2727

2828
def uop_cache_info(uop: Uop) -> list[str] | None:
@@ -37,6 +37,8 @@ def uop_cache_info(uop: Uop) -> list[str] | None:
3737
high = -1
3838
defined = [ False ] * 4
3939
for inputs, outputs, exit_depth in get_uop_cache_depths(uop):
40+
if max(inputs, outputs) > MAX_CACHED_REGISTER:
41+
continue
4042
entries[inputs] = f"{{ {outputs}, {exit_depth}, {uop.name}_r{inputs}{outputs} }},\n"
4143
if inputs < low:
4244
low = inputs

0 commit comments

Comments
 (0)