Skip to content

Commit

Permalink
add no_save_ip & no_advance_ip to RETURN_VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
WolframAlph committed Jan 19, 2025
1 parent 5aaf416 commit df73fb4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 23 deletions.
10 changes: 6 additions & 4 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Programs/test_frozenmain.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#define replicate(TIMES)
#define tier1
#define no_save_ip
#define no_advance_ip

// Dummy variables for stack effects.
static PyObject *value, *value1, *value2, *left, *right, *res, *sum, *prod, *sub;
Expand Down Expand Up @@ -1104,7 +1105,7 @@ dummy_func(
// The stack effect here is a bit misleading.
// retval is popped from the stack, but res
// is pushed to a different frame, the callers' frame.
inst(RETURN_VALUE, (retval -- res)) {
no_advance_ip no_save_ip inst(RETURN_VALUE, (retval -- res)) {
#if TIER_ONE
assert(frame != &entry_frame);
#endif
Expand Down
2 changes: 0 additions & 2 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Tools/cases_generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Properties:
const_oparg: int = -1
needs_prev: bool = False
no_save_ip: bool = False
no_advance_ip: bool = False

def dump(self, indent: str) -> None:
simple_properties = self.__dict__.copy()
Expand Down Expand Up @@ -64,6 +65,7 @@ def from_list(properties: list["Properties"]) -> "Properties":
pure=all(p.pure for p in properties),
needs_prev=any(p.needs_prev for p in properties),
no_save_ip=all(p.no_save_ip for p in properties),
no_advance_ip=all(p.no_advance_ip for p in properties),
)

@property
Expand All @@ -89,6 +91,7 @@ def infallible(self) -> bool:
side_exit=False,
pure=True,
no_save_ip=False,
no_advance_ip=False,
)


Expand Down Expand Up @@ -841,6 +844,7 @@ def compute_properties(op: parser.InstDef) -> Properties:
has_free=has_free,
pure="pure" in op.annotations,
no_save_ip="no_save_ip" in op.annotations,
no_advance_ip="no_advance_ip" in op.annotations,
tier=tier_variable(op),
needs_prev=variable_used(op, "prev_instr"),
)
Expand Down
2 changes: 2 additions & 0 deletions Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ def cflags(p: Properties) -> str:
flags.append("HAS_PURE_FLAG")
if p.no_save_ip:
flags.append("HAS_NO_SAVE_IP_FLAG")
if p.no_save_ip:
flags.append("HAS_NO_ADVANCE_IP_FLAG")
if p.oparg_and_1:
flags.append("HAS_OPARG_AND_1_FLAG")
if flags:
Expand Down
1 change: 1 addition & 0 deletions Tools/cases_generator/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def choice(*opts: str) -> str:
"tier1",
"tier2",
"no_save_ip",
"no_advance_ip",
}

__all__ = []
Expand Down
3 changes: 2 additions & 1 deletion Tools/cases_generator/opcode_metadata_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"OPARG_AND_1",
"ERROR_NO_POP",
"NO_SAVE_IP",
"NO_ADVANCE_IP"
]


Expand Down Expand Up @@ -287,7 +288,7 @@ def generate_metadata_table(analysis: Analysis, out: CWriter) -> None:
out.emit("struct opcode_metadata {\n")
out.emit("uint8_t valid_entry;\n")
out.emit("uint8_t instr_format;\n")
out.emit("uint16_t flags;\n")
out.emit("uint32_t flags;\n")
out.emit("};\n\n")
out.emit(
f"extern const struct opcode_metadata _PyOpcode_opcode_metadata[{table_size}];\n"
Expand Down
3 changes: 2 additions & 1 deletion Tools/cases_generator/tier1_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def generate_tier1(
out.emit(unused_guard)
elif not inst.properties.no_save_ip:
out.emit(f"frame->instr_ptr = next_instr;\n")
out.emit(f"next_instr += {inst.size};\n")
if not inst.properties.no_advance_ip:
out.emit(f"next_instr += {inst.size};\n")
out.emit(f"INSTRUCTION_STATS({name});\n")
if inst.is_target:
out.emit(f"PREDICTED({name});\n")
Expand Down

0 comments on commit df73fb4

Please sign in to comment.