Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uops support to instr_ptr branch #55

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 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: 4 additions & 0 deletions Python/abstract_interp_cases.c.h

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

8 changes: 7 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3961,12 +3961,18 @@ dummy_func(
}

op(_SAVE_CURRENT_IP, (--)) {
TIER_ONE_ONLY
#if TIER_ONE
assert(frame->next_instr_offset == 0);
frame->next_instr_offset = (uint16_t)(next_instr - frame->instr_ptr);
#endif
#if TIER_TWO
frame->next_instr_offset = oparg;
#endif
}

op(_EXIT_TRACE, (--)) {
TIER_TWO_ONLY
frame->next_instr_offset = 0; // Dispatch to frame->instr_ptr
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self);
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
Expand Down
2 changes: 2 additions & 0 deletions Python/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
// The caller recovers the frame from tstate->current_frame.
DPRINTF(2, "Error: [Opcode %d, operand %" PRIu64 "]\n", opcode, operand);
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
frame->next_instr_offset = 0; // Don't leave this random
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self);
return NULL;
Expand All @@ -140,6 +141,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
// This presumes nothing was popped from the stack (nor pushed).
DPRINTF(2, "DEOPT: [Opcode %d, operand %" PRIu64 "]\n", opcode, operand);
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
frame->next_instr_offset = 0; // Dispatch to frame->instr_ptr
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self);
return frame;
Expand Down
13 changes: 13 additions & 0 deletions Python/executor_cases.c.h

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

24 changes: 20 additions & 4 deletions Python/generated_cases.c.h

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

8 changes: 6 additions & 2 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,13 @@ translate_bytecode_to_trace(
case OPARG_BOTTOM: // Second half of super-instr
oparg = orig_oparg & 0xF;
break;
case OPARG_SET_IP: // op==_SET_IP; oparg=next instr
case OPARG_SET_IP: // op=_SET_IP; oparg=next instr
oparg = INSTR_IP(instr + offset, code);
uop = _SET_IP;
assert(uop == _SET_IP);
break;
case OPARG_SAVE_CURRENT_IP: // op=_SAVE_CURRENT_IP; oparg=next_instr_offset
oparg = offset;
assert(uop == _SAVE_CURRENT_IP);
break;

default:
Expand Down
4 changes: 2 additions & 2 deletions Tools/cases_generator/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ def analyze_macro(self, macro: parsing.Macro) -> MacroInstruction:
case Instruction() as instr:
part, offset = self.analyze_instruction(instr, offset)
parts.append(part)
if instr.name != "_SET_IP":
# _SET_IP in a macro is a no-op in Tier 1
if instr.name != "_SAVE_CURRENT_IP":
# _SAVE_CURRENT_IP's oparg does not transfer
flags.add(instr.instr_flags)
case _:
assert_never(component)
Expand Down
5 changes: 3 additions & 2 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"OPARG_TOP": 5,
"OPARG_BOTTOM": 6,
"OPARG_SET_IP": 7,
"OPARG_SAVE_CURRENT_IP": 8,
}

INSTR_FMT_PREFIX = "INSTR_FMT_"
Expand Down Expand Up @@ -658,7 +659,7 @@ def write_macro_expansions(
for part in parts:
if isinstance(part, Component):
# All component instructions must be viable uops
if not part.instr.is_viable_uop() and part.instr.name != "_SAVE_CURRENT_IP":
if not part.instr.is_viable_uop():
# This note just reminds us about macros that cannot
# be expanded to Tier 2 uops. It is not an error.
# It is sometimes emitted for macros that have a
Expand All @@ -672,7 +673,7 @@ def write_macro_expansions(
return
if not part.active_caches:
if part.instr.name == "_SAVE_CURRENT_IP":
size, offset = OPARG_SIZES["OPARG_SET_IP"], cache_offset - 1
size, offset = OPARG_SIZES["OPARG_SAVE_CURRENT_IP"], cache_offset
else:
size, offset = OPARG_SIZES["OPARG_FULL"], 0
else:
Expand Down