Skip to content

Commit be0bd54

Browse files
authored
gh-106529: Cleanups split off gh-112134 (#112214)
- Double max trace size to 256 - Add a dependency on executor_cases.c.h for ceval.o - Mark `_SPECIALIZE_UNPACK_SEQUENCE` as `TIER_ONE_ONLY` - Add debug output back showing the optimized trace - Bunch of cleanups to Tools/cases_generator/
1 parent b414497 commit be0bd54

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

Include/internal/pycore_uops.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010

1111
#include "pycore_frame.h" // _PyInterpreterFrame
1212

13-
#define _Py_UOP_MAX_TRACE_LENGTH 128
13+
#define _Py_UOP_MAX_TRACE_LENGTH 256
1414

1515
typedef struct {
1616
uint16_t opcode;

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ Python/ceval.o: \
16091609
$(srcdir)/Python/ceval_macros.h \
16101610
$(srcdir)/Python/condvar.h \
16111611
$(srcdir)/Python/generated_cases.c.h \
1612+
$(srcdir)/Python/executor_cases.c.h \
16121613
$(srcdir)/Python/opcode_targets.h
16131614

16141615
Python/flowgraph.o: \

Python/bytecodes.c

+1
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ dummy_func(
12101210
};
12111211

12121212
specializing op(_SPECIALIZE_UNPACK_SEQUENCE, (counter/1, seq -- seq)) {
1213+
TIER_ONE_ONLY
12131214
#if ENABLE_SPECIALIZATION
12141215
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
12151216
next_instr = this_instr;

Python/generated_cases.c.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ uop_dealloc(_PyUOpExecutorObject *self) {
325325
}
326326

327327
static const char *
328-
uop_name(int index) {
328+
uop_name(int index)
329+
{
329330
if (index <= MAX_REAL_OPCODE) {
330331
return _PyOpcode_OpName[index];
331332
}
@@ -832,6 +833,24 @@ make_executor_from_uops(_PyUOpInstruction *buffer, _PyBloomFilter *dependencies)
832833
assert(dest == -1);
833834
executor->base.execute = _PyUopExecute;
834835
_Py_ExecutorInit((_PyExecutorObject *)executor, dependencies);
836+
#ifdef Py_DEBUG
837+
char *python_lltrace = Py_GETENV("PYTHON_LLTRACE");
838+
int lltrace = 0;
839+
if (python_lltrace != NULL && *python_lltrace >= '0') {
840+
lltrace = *python_lltrace - '0'; // TODO: Parse an int and all that
841+
}
842+
if (lltrace >= 2) {
843+
printf("Optimized executor (length %d):\n", length);
844+
for (int i = 0; i < length; i++) {
845+
printf("%4d %s(%d, %d, %" PRIu64 ")\n",
846+
i,
847+
uop_name(executor->trace[i].opcode),
848+
executor->trace[i].oparg,
849+
executor->trace[i].target,
850+
executor->trace[i].operand);
851+
}
852+
}
853+
#endif
835854
return (_PyExecutorObject *)executor;
836855
}
837856

Tools/cases_generator/flags.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
def makes_escaping_api_call(instr: parsing.InstDef) -> bool:
5555
if "CALL_INTRINSIC" in instr.name:
56-
return True;
56+
return True
5757
tkns = iter(instr.tokens)
5858
for tkn in tkns:
5959
if tkn.kind != lx.IDENTIFIER:
@@ -79,6 +79,7 @@ def makes_escaping_api_call(instr: parsing.InstDef) -> bool:
7979
return True
8080
return False
8181

82+
8283
@dataclasses.dataclass
8384
class InstructionFlags:
8485
"""Construct and manipulate instruction flags"""
@@ -124,9 +125,7 @@ def fromInstruction(instr: parsing.InstDef) -> "InstructionFlags":
124125
or variable_used(instr, "exception_unwind")
125126
or variable_used(instr, "resume_with_error")
126127
),
127-
HAS_ESCAPES_FLAG=(
128-
makes_escaping_api_call(instr)
129-
),
128+
HAS_ESCAPES_FLAG=makes_escaping_api_call(instr),
130129
)
131130

132131
@staticmethod

Tools/cases_generator/parsing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class OpName(Node):
105105

106106
@dataclass
107107
class InstHeader(Node):
108-
annotations : list[str]
108+
annotations: list[str]
109109
kind: Literal["inst", "op"]
110110
name: str
111111
inputs: list[InputEffect]
@@ -114,7 +114,7 @@ class InstHeader(Node):
114114

115115
@dataclass
116116
class InstDef(Node):
117-
annotations : list[str]
117+
annotations: list[str]
118118
kind: Literal["inst", "op"]
119119
name: str
120120
inputs: list[InputEffect]

0 commit comments

Comments
 (0)