mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
GH-121131: Clean up and fix some instrumented instructions. (GH-121132)
* Add support for 'prev_instr' to code generator and refactor some INSTRUMENTED instructions
This commit is contained in:
parent
d9efa45d74
commit
afb0aa6ed2
15 changed files with 277 additions and 215 deletions
|
@ -27,6 +27,7 @@ class Properties:
|
|||
tier: int | None = None
|
||||
oparg_and_1: bool = False
|
||||
const_oparg: int = -1
|
||||
needs_prev: bool = False
|
||||
|
||||
def dump(self, indent: str) -> None:
|
||||
print(indent, end="")
|
||||
|
@ -53,6 +54,7 @@ class Properties:
|
|||
has_free=any(p.has_free for p in properties),
|
||||
side_exit=any(p.side_exit for p in properties),
|
||||
pure=all(p.pure for p in properties),
|
||||
needs_prev=any(p.needs_prev for p in properties),
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -618,6 +620,7 @@ def compute_properties(op: parser.InstDef) -> Properties:
|
|||
has_free=has_free,
|
||||
pure="pure" in op.annotations,
|
||||
tier=tier_variable(op),
|
||||
needs_prev=variable_used(op, "prev_instr"),
|
||||
)
|
||||
|
||||
|
||||
|
@ -797,12 +800,6 @@ def assign_opcodes(
|
|||
|
||||
instrumented = [name for name in instructions if name.startswith("INSTRUMENTED")]
|
||||
|
||||
# Special case: this instruction is implemented in ceval.c
|
||||
# rather than bytecodes.c, so we need to add it explicitly
|
||||
# here (at least until we add something to bytecodes.c to
|
||||
# declare external instructions).
|
||||
instrumented.append("INSTRUMENTED_LINE")
|
||||
|
||||
specialized: set[str] = set()
|
||||
no_arg: list[str] = []
|
||||
has_arg: list[str] = []
|
||||
|
|
|
@ -151,7 +151,6 @@ def generate_deopt_table(analysis: Analysis, out: CWriter) -> None:
|
|||
if inst.family is not None:
|
||||
deopt = inst.family.name
|
||||
deopts.append((inst.name, deopt))
|
||||
deopts.append(("INSTRUMENTED_LINE", "INSTRUMENTED_LINE"))
|
||||
for name, deopt in sorted(deopts):
|
||||
out.emit(f"[{name}] = {deopt},\n")
|
||||
out.emit("};\n\n")
|
||||
|
@ -179,7 +178,6 @@ def generate_name_table(analysis: Analysis, out: CWriter) -> None:
|
|||
out.emit("#ifdef NEED_OPCODE_METADATA\n")
|
||||
out.emit(f"const char *_PyOpcode_OpName[{table_size}] = {{\n")
|
||||
names = list(analysis.instructions) + list(analysis.pseudos)
|
||||
names.append("INSTRUMENTED_LINE")
|
||||
for name in sorted(names):
|
||||
out.emit(f'[{name}] = "{name}",\n')
|
||||
out.emit("};\n")
|
||||
|
|
|
@ -148,6 +148,8 @@ def generate_tier1(
|
|||
out.emit("\n")
|
||||
out.emit(f"TARGET({name}) {{\n")
|
||||
unused_guard = "(void)this_instr;\n" if inst.family is None else ""
|
||||
if inst.properties.needs_prev:
|
||||
out.emit(f"_Py_CODEUNIT *prev_instr = frame->instr_ptr;\n")
|
||||
if needs_this and not inst.is_target:
|
||||
out.emit(f"_Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;\n")
|
||||
out.emit(unused_guard)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue