#include "frameobject.h" // PyFrameLocalsProxyObject
#include "opcode.h" // EXTENDED_ARG
-#include "../Include/pytypedefs.h"
#include "pycore_optimizer.h"
#include "clinic/frameobject.c.h"
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
RELOAD_STACK();
- #if TIER_ONE
LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
res = temp;
LLTRACE_RESUME_FRAME();
}
_PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
#endif
RELOAD_STACK();
- #if TIER_ONE
LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
value = PyStackRef_MakeHeapSafe(temp);
LLTRACE_RESUME_FRAME();
}
}
op(_FOR_ITER_TIER_TWO, (iter, null_or_index -- iter, null_or_index, next)) {
- TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_FOR_ITER);
_PyStackRef item = _PyForIter_VirtualIteratorNext(tstate, frame, iter, &null_or_index);
if (!PyStackRef_IsValid(item)) {
if (PyStackRef_IsError(item)) {
ERROR_NO_POP();
}
/* iterator ended normally */
- /* This just sets the IP to what it expects */
- TIER2_STORE_IP(oparg + 1);
+ /* This just sets the IP to what it expects (see normal _FOR_ITER */
+ frame->instr_ptr += (oparg + 2 + INLINE_CACHE_ENTRIES_FOR_ITER);
EXIT_IF(true);
}
next = item;
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
frame = tstate->current_frame = prev;
- #if TIER_ONE
LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
RELOAD_STACK();
res = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
LLTRACE_RESUME_FRAME();
for (;;) {
uopcode = next_uop->opcode;
#ifdef Py_DEBUG
- if (frame->lltrace >= 4) {
- if (next_uop->opcode != _START_EXECUTOR) {
- if (next_uop->format == UOP_FORMAT_TARGET) {
- _Py_CODEUNIT *aim = _PyFrame_GetBytecode(frame) + next_uop->target;
- printf(" aim=[%s]\n", _PyOpcode_OpName[aim->op.code]);
- }
- else if (next_uop->format == UOP_FORMAT_JUMP) {
- _PyUOpInstruction *aim_uop = current_executor->trace + next_uop->jump_target;
- if (aim_uop->format == UOP_FORMAT_TARGET) {
- _Py_CODEUNIT *aim = _PyFrame_GetBytecode(frame) + aim_uop->target;
- printf(" aim=[%s]\n", _PyOpcode_OpName[aim->op.code]);
- }
- }
- }
+ if (frame->lltrace >= 3) {
dump_stack(frame, stack_pointer);
if (next_uop->opcode == _START_EXECUTOR) {
printf("%4d uop: ", 0);
JUMP_TO_LABEL(start_frame); \
} while (0)
#else
+
#define DISPATCH_SAME_OPARG() \
{ \
opcode = next_instr->op.code; \
PRE_DISPATCH_GOTO(); \
DISPATCH_GOTO(); \
}
+
#define DISPATCH_INLINED(NEW_FRAME) \
do { \
assert(tstate->interp->eval_frame == NULL); \
* and skipped instructions.
*/
#define JUMPBY(x) (next_instr += (x))
-#define TIER2_STORE_IP(x) (frame->instr_ptr += (x))
#define SKIP_OVER(x) (next_instr += (x))
#define STACK_LEVEL() ((int)(stack_pointer - _PyFrame_Stackbase(frame)))
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
stack_pointer = _PyFrame_GetStackPointer(frame);
- #if TIER_ONE
- LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
+ frame->instr_ptr += (frame->return_offset);
res = temp;
LLTRACE_RESUME_FRAME();
stack_pointer[0] = res;
_PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
#endif
stack_pointer = _PyFrame_GetStackPointer(frame);
- #if TIER_ONE
- LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
+ frame->instr_ptr += (1 + INLINE_CACHE_ENTRIES_SEND);
value = PyStackRef_MakeHeapSafe(temp);
LLTRACE_RESUME_FRAME();
stack_pointer[0] = value;
oparg = CURRENT_OPARG();
null_or_index = stack_pointer[-1];
iter = stack_pointer[-2];
- TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_FOR_ITER);
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyStackRef item = _PyForIter_VirtualIteratorNext(tstate, frame, iter, &null_or_index);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (PyStackRef_IsError(item)) {
JUMP_TO_ERROR();
}
- TIER2_STORE_IP(oparg + 1);
+ frame->instr_ptr += (oparg + 2 + INLINE_CACHE_ENTRIES_FOR_ITER);
if (true) {
UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET();
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
LOAD_SP();
- LOAD_IP(0);
+ frame->instr_ptr += (0);
LLTRACE_RESUME_FRAME();
break;
}
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
frame = tstate->current_frame = prev;
- #if TIER_ONE
- LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
+ frame->instr_ptr += (frame->return_offset);
stack_pointer = _PyFrame_GetStackPointer(frame);
res = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
LLTRACE_RESUME_FRAME();
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
stack_pointer = _PyFrame_GetStackPointer(frame);
- #if TIER_ONE
LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
res = temp;
LLTRACE_RESUME_FRAME();
}
_PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
#endif
stack_pointer = _PyFrame_GetStackPointer(frame);
- #if TIER_ONE
LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
value = PyStackRef_MakeHeapSafe(temp);
LLTRACE_RESUME_FRAME();
}
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
frame = tstate->current_frame = prev;
- #if TIER_ONE
LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
stack_pointer = _PyFrame_GetStackPointer(frame);
res = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
LLTRACE_RESUME_FRAME();
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
stack_pointer = _PyFrame_GetStackPointer(frame);
- #if TIER_ONE
LOAD_IP(frame->return_offset);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(frame->return_offset);
- #endif
res = temp;
LLTRACE_RESUME_FRAME();
stack_pointer[0] = res;
_PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
#endif
stack_pointer = _PyFrame_GetStackPointer(frame);
- #if TIER_ONE
LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
- #if TIER_TWO
- TIER2_STORE_IP(1 + INLINE_CACHE_ENTRIES_SEND);
- #endif
value = PyStackRef_MakeHeapSafe(temp);
LLTRACE_RESUME_FRAME();
stack_pointer[0] = value;
self._replacers["oparg"] = self.oparg
self._replacers["JUMPBY"] = self.jumpby
self._replacers["DISPATCH"] = self.dispatch
+ self._replacers["LOAD_IP"] = self.load_ip
def goto_error(self, offset: int, storage: Storage) -> str:
# To do: Add jump targets for popping values.
next(tkn_iter)
return False
+ def load_ip(
+ self,
+ tkn: Token,
+ tkn_iter: TokenIterator,
+ uop: CodeSection,
+ storage: Storage,
+ inst: Instruction | None,
+ ) -> bool:
+ self.out.start_line()
+ self.emit("frame->instr_ptr += ")
+ emit_to(self.out, tkn_iter, "SEMI")
+ self.emit(";\n")
+ return True
+
def write_uop(uop: Uop, emitter: Emitter, stack: Stack) -> Stack:
locals: dict[str, Local] = {}
try: