Skip to content

Commit 0ff2b02

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Inline frame deallocation on OSS builds
Summary: We can easily inline frame deallocation on OSS builds now too - we just need to test if the frameobj has been materialized. Reviewed By: yoney Differential Revision: D106881389 fbshipit-source-id: 1a229fe34ec9f016b606968cb4c550f8a8a2d51b
1 parent 8e2529b commit 0ff2b02

3 files changed

Lines changed: 11 additions & 35 deletions

File tree

cinderx/Jit/jit_rt.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -832,30 +832,6 @@ void JITRT_UnlinkFrame(PyThreadState* tstate) {
832832
cleanupFrameExecutable(frame);
833833
}
834834

835-
void JITRT_UnlinkLightweightFrameFast(PyThreadState* tstate) {
836-
_PyInterpreterFrame* frame = currentFrame(tstate);
837-
setCurrentFrame(tstate, frame->previous);
838-
839-
JIT_DCHECK(
840-
frameCode(frame) != nullptr && frameCode(frame)->co_nfreevars == 0,
841-
"assumes no freevars");
842-
843-
JIT_DCHECK(
844-
frameCode(frame) != nullptr &&
845-
!(frameCode(frame)->co_flags & jit::kCoFlagsAnyGenerator),
846-
"doesn't work with generators");
847-
848-
// Fast path for non-generator frames with no freevars.
849-
// The frame header is directly before the frame for non-generators.
850-
if (frame->frame_obj != nullptr) {
851-
// Frame was materialized by the runtime, use the slow path.
852-
increfFuncObjForNonGenerator(frame);
853-
854-
jit::jitFrameClearExceptCode(frame);
855-
}
856-
cleanupFrameExecutable(frame);
857-
}
858-
859835
PyObject*
860836
JITRT_LoadGlobal(PyObject* globals, PyObject* builtins, PyObject* name) {
861837
PyObject* result =

cinderx/Jit/jit_rt.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ void JITRT_DecrefFrame(PyFrameObject* frame);
6666
*/
6767
void JITRT_UnlinkFrame(PyThreadState* tstate);
6868

69-
// Specialized version of JITRT_UnlinkFrame for non-generator functions with no
70-
// free variables that use lightweight frames. Avoids the expensive
71-
// jitFrameClearExceptCode path.
72-
void JITRT_UnlinkLightweightFrameFast(PyThreadState* tstate);
73-
7469
/*
7570
* Handles a call that includes kw arguments where the target function has
7671
* *args, **kwargs, or keyword only args.

cinderx/Jit/lir/generator.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5191,15 +5191,9 @@ void LIRGenerator::emitUnlinkFrame(
51915191
} else if (!env_->can_deopt) {
51925192
emitInlineUnlinkLeafFrame(
51935193
bbb, is_generator, func_reg, executable, exec_dtor, callee_frame);
5194-
#ifdef ENABLE_LIGHTWEIGHT_FRAMES
51955194
} else {
51965195
emitInlineUnlinkFastFrame(
51975196
bbb, is_generator, func_reg, executable, exec_dtor, callee_frame);
5198-
#else
5199-
} else {
5200-
bbb.appendInvokeInstruction(
5201-
JITRT_UnlinkLightweightFrameFast, env_->asm_tstate);
5202-
#endif
52035197
}
52045198
}
52055199

@@ -5249,6 +5243,7 @@ void LIRGenerator::emitInlineUnlinkFastFrame(
52495243
auto done_block = bbb.allocateBlock();
52505244
auto not_materialized = bbb.allocateBlock();
52515245

5246+
#ifdef ENABLE_LIGHTWEIGHT_FRAMES
52525247
Instruction* frame_status = bbb.appendInstr(
52535248
OutVReg{},
52545249
Instruction::kMove,
@@ -5259,6 +5254,16 @@ void LIRGenerator::emitInlineUnlinkFastFrame(
52595254
static_assert(JIT_FRAME_INITIALIZED == 2);
52605255
bbb.appendBranch(
52615256
Instruction::kBranchBitNotSet, not_materialized, frame_status, Imm{1});
5257+
#else
5258+
Instruction* frame_obj_reg = bbb.appendInstr(
5259+
OutVReg{},
5260+
Instruction::kMove,
5261+
Ind{frame,
5262+
static_cast<int32_t>(offsetof(_PyInterpreterFrame, frame_obj))});
5263+
5264+
bbb.appendInstr(Instruction::kTest, frame_obj_reg, frame_obj_reg);
5265+
bbb.appendBranch(Instruction::kBranchZ, not_materialized);
5266+
#endif
52625267

52635268
{
52645269
BasicBlock* materialized_block = bbb.allocateBlock();

0 commit comments

Comments
 (0)