Skip to content

Commit ec317cd

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Remove kYieldInital instruction
Summary: This is now just a call + a yield value - it's straight forward to simplify now that 3.10 is gone. Reviewed By: mpage Differential Revision: D103313543 fbshipit-source-id: 9c187ad601d11c11db777b27b440aea8e443bd58
1 parent 1f2e103 commit ec317cd

10 files changed

Lines changed: 15 additions & 160 deletions

File tree

cinderx/Jit/codegen/autogen.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -735,82 +735,6 @@ void translateLoadThreadState(Environ* env, const Instruction* instr) {
735735
#endif
736736
}
737737

738-
void translateYieldInitial(Environ* env, const Instruction* instr) {
739-
#if defined(CINDER_X86_64)
740-
arch::Builder* as = env->as;
741-
742-
// Load tstate into RDI for call to
743-
// JITRT_UnlinkGenFrameAndReturnGenDataFooter.
744-
745-
// Consider avoiding reloading the tstate in from memory if it was already in
746-
// a register before spilling. Still needs to be in memory though so it can be
747-
// recovered after calling JITRT_MakeGenObject* which will trash it.
748-
PhyLocation tstate = instr->getInput(0)->getStackSlot();
749-
as->mov(x86::rdi, x86::ptr(x86::rbp, tstate.loc));
750-
751-
emitCall(
752-
*env,
753-
reinterpret_cast<uint64_t>(JITRT_UnlinkGenFrameAndReturnGenDataFooter),
754-
instr);
755-
// This will return pointers to a generator in RAX and JIT data in RDX.
756-
757-
// Arbitrary scratch register for use in emitStoreGenYieldPoint(). Any
758-
// caller-saved register not used in this scope will do because we're on the
759-
// exit path now.
760-
auto scratch_r = x86::r9;
761-
env->pending_yield_resume_label = as->newLabel();
762-
emitStoreGenYieldPoint(
763-
as,
764-
env,
765-
instr,
766-
env->pending_yield_resume_label,
767-
x86::rdx,
768-
scratch_r,
769-
false /* is_yield_from */);
770-
771-
// The jmp to exit and resume label binding are handled by separate
772-
// kBranchToYieldExit and kResumeGenYield instructions.
773-
#elif defined(CINDER_AARCH64)
774-
arch::Builder* as = env->as;
775-
776-
// Load tstate into X0 for call to
777-
// JITRT_UnlinkGenFrameAndReturnGenDataFooter.
778-
779-
// Consider avoiding reloading the tstate in from memory if it was already in
780-
// a register before spilling. Still needs to be in memory though so it can be
781-
// recovered after calling JITRT_MakeGenObject* which will trash it.
782-
PhyLocation tstate = instr->getInput(0)->getStackSlot();
783-
as->ldr(
784-
a64::x0,
785-
arch::ptr_resolve(as, arch::fp, tstate.loc, arch::reg_scratch_0));
786-
787-
emitCall(
788-
*env,
789-
reinterpret_cast<uint64_t>(JITRT_UnlinkGenFrameAndReturnGenDataFooter),
790-
instr);
791-
// This will return pointers to a generator in X0 and JIT data in X1.
792-
793-
// Arbitrary scratch register for use in emitStoreGenYieldPoint(). Any
794-
// caller-saved register not used in this scope will do because we're on the
795-
// exit path now.
796-
auto scratch_r = arch::reg_scratch_0;
797-
env->pending_yield_resume_label = as->newLabel();
798-
emitStoreGenYieldPoint(
799-
as,
800-
env,
801-
instr,
802-
env->pending_yield_resume_label,
803-
a64::x1,
804-
scratch_r,
805-
false /* is_yield_from */);
806-
807-
// The jmp to exit and resume label binding are handled by separate
808-
// kBranchToYieldExit and kResumeGenYield instructions.
809-
#else
810-
CINDER_UNSUPPORTED
811-
#endif
812-
}
813-
814738
void translateStoreGenYieldPoint(Environ* env, const Instruction* instr) {
815739
#if defined(CINDER_X86_64)
816740
arch::Builder* as = env->as;
@@ -2502,9 +2426,6 @@ void AutoTranslator::translateInstr(Environ* env, const Instruction* instr)
25022426
case Instruction::kLoadThreadState:
25032427
translateLoadThreadState(env, instr);
25042428
return;
2505-
case Instruction::kYieldInitial:
2506-
translateYieldInitial(env, instr);
2507-
return;
25082429
case Instruction::kStoreGenYieldPoint:
25092430
translateStoreGenYieldPoint(env, instr);
25102431
return;
@@ -2952,9 +2873,6 @@ void AutoTranslator::translateInstr(Environ* env, const Instruction* instr)
29522873
case Instruction::kLoadThreadState:
29532874
translateLoadThreadState(env, instr);
29542875
return;
2955-
case Instruction::kYieldInitial:
2956-
translateYieldInitial(env, instr);
2957-
return;
29582876
case Instruction::kStoreGenYieldPoint:
29592877
translateStoreGenYieldPoint(env, instr);
29602878
return;

cinderx/Jit/codegen/environ.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ struct Environ {
5252
std::vector<std::pair<int, jit::lir::BasicBlock*>>
5353
static_typecheck_jt_entries;
5454

55-
// Resume label shared between StoreGenYieldPoint/YieldInitial and
56-
// ResumeGenYield. Created by translateStoreGenYieldPoint or
57-
// translateYieldInitial (3.12+), bound by translateResumeGenYield.
55+
// Resume label shared between StoreGenYieldPoint and ResumeGenYield.
56+
// Created by translateStoreGenYieldPoint, bound by
57+
// translateResumeGenYield.
5858
asmjit::Label pending_yield_resume_label;
5959

6060
// Map from deopt metadata index to the stage 1 deopt exit LIR block.
@@ -148,7 +148,6 @@ struct Environ {
148148
inline_frame_map;
149149

150150
FrameMode frame_mode;
151-
int initial_yield_spill_size_{-1};
152151

153152
int max_arg_buffer_size{0};
154153

cinderx/Jit/codegen/gen_asm.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,6 @@ void* NativeGenerator::getVectorcallEntry() {
712712
env_.changed_regs = lsalloc.getChangedRegs();
713713
env_.exit_label = as_->newLabel();
714714
env_.frame_mode = GetFunction()->frameMode;
715-
if (GetFunction()->code->co_flags & kCoFlagsAnyGenerator) {
716-
env_.initial_yield_spill_size_ = lsalloc.initialYieldSpillSize();
717-
}
718-
719715
JIT_LOGIF(
720716
getConfig().log.dump_lir,
721717
"LIR for {} after register allocation:\n{}",

cinderx/Jit/lir/generator.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,10 +1203,9 @@ std::unique_ptr<jit::lir::Function> LIRGenerator::TranslateFunction() {
12031203
// dispatches to resume targets via indirect jump (populated post-regalloc
12041204
// by PopulateResumeEntryBlock). Its successors are the resume blocks,
12051205
// which keeps them reachable during sortBasicBlocks.
1206-
// We always create this for generators because translateYieldInitial
1207-
// references gen_resume_entry_label (the label bound to this block).
1208-
// On pre-3.12, kYieldInitial is monolithic and doesn't add to
1209-
// resume_blocks_, but still needs the resume entry block to exist.
1206+
// We always create this for generators because the codegen for
1207+
// kStoreGenYieldPoint references gen_resume_entry_label (the label
1208+
// bound to this block).
12101209
if (is_gen_) {
12111210
auto* resume_entry = lir_func_->allocateBasicBlock();
12121211
// Remove from basic_blocks_ immediately — this is a placeholder block
@@ -2318,18 +2317,16 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
23182317
}
23192318
case Opcode::kInitialYield: {
23202319
auto hir_instr = static_cast<const InitialYield*>(&i);
2321-
// 3.12+: decompose kYieldInitial into setup + branch + resume.
2322-
// kYieldInitial does the setup and store yield point but does NOT
2323-
// emit the jmp or bind the resume label.
2324-
Instruction* instr =
2325-
bbb.appendInstr(Instruction::kYieldInitial, env_->asm_tstate);
2326-
finishYield(bbb, instr, hir_instr);
2327-
2328-
// Capture the gen object from the return register into a vreg.
2329-
Instruction* gen_obj = bbb.appendInstr(
2320+
2321+
// Unlink the generator frame and get the gen object back.
2322+
Instruction* gen_obj = bbb.appendCallInstruction(
23302323
OutVReg{},
2331-
Instruction::kBind,
2332-
PhyReg{codegen::arch::reg_general_return_loc});
2324+
JITRT_UnlinkGenFrameAndReturnGenDataFooter,
2325+
env_->asm_tstate);
2326+
2327+
// Store yield point metadata (same as kYieldValue).
2328+
Instruction* store = bbb.appendInstr(Instruction::kStoreGenYieldPoint);
2329+
finishYield(bbb, store, hir_instr);
23332330

23342331
// kBranchToYieldExit: terminates this block.
23352332
auto* branch = bbb.appendInstr(Instruction::kBranchToYieldExit);

cinderx/Jit/lir/instruction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ bool Instruction::isTerminator() const {
292292

293293
bool Instruction::isAnyYield() const {
294294
switch (opcode_) {
295-
case kYieldInitial:
296295
case kStoreGenYieldPoint:
297296
case kStoreGenYieldFromPoint:
298297
return true;

cinderx/Jit/lir/instruction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ enum OperandSizeType {
171171
X(MovSXD) \
172172
X(IntToBool, false, FlagEffects::kSet, kDefault, 1, {1}) \
173173
X(LoadThreadState, false, FlagEffects::kInvalidate, kDefault, 0, {}, 0) \
174-
X(YieldInitial, false, FlagEffects::kInvalidate, kDefault, 0, {}, 1) \
175174
X(StoreGenYieldPoint, false, FlagEffects::kInvalidate, kDefault, 0, {}, 1) \
176175
X(StoreGenYieldFromPoint, \
177176
false, \

cinderx/Jit/lir/postalloc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ RewriteResult rewriteMemoryInputsToReg(instr_iter_t instr_iter) {
905905
case Instruction::kMovSX:
906906
case Instruction::kMovSXD:
907907
case Instruction::kLoadThreadState:
908-
case Instruction::kYieldInitial:
909908
case Instruction::kStoreGenYieldPoint:
910909
case Instruction::kStoreGenYieldFromPoint:
911910
case Instruction::kBranchToYieldExit:

cinderx/Jit/lir/regalloc.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,6 @@ int LinearScanAllocator::getFrameSize() const {
293293
return -max_stack_slot_;
294294
}
295295

296-
int LinearScanAllocator::initialYieldSpillSize() const {
297-
JIT_CHECK(
298-
initial_yield_spill_size_ != -1,
299-
"Don't have InitialYield spill size yet");
300-
301-
return initial_yield_spill_size_;
302-
}
303-
304296
bool LinearScanAllocator::isPredefinedUsed(const Operand* operand) const {
305297
auto& block = func_->basicblocks()[0];
306298

@@ -596,22 +588,6 @@ void LinearScanAllocator::spillRegistersForYield(int instr_id) {
596588
reserveRegisters(instr_id, INIT_REGISTERS);
597589
}
598590

599-
void LinearScanAllocator::computeInitialYieldSpillSize(
600-
const UnorderedMap<const Operand*, const LiveInterval*>& mapping) {
601-
JIT_CHECK(
602-
initial_yield_spill_size_ == -1,
603-
"Already computed InitialYield spill size");
604-
605-
for (auto& pair : mapping) {
606-
const LiveInterval* interval = pair.second;
607-
if (interval->allocated_loc.is_register()) {
608-
continue;
609-
}
610-
initial_yield_spill_size_ =
611-
std::max(initial_yield_spill_size_, -interval->allocated_loc.loc);
612-
}
613-
}
614-
615591
void LinearScanAllocator::reserveCallerSaveRegisters(int instr_id) {
616592
reserveRegisters(instr_id, CALLER_SAVE_REGS);
617593
}
@@ -1112,9 +1088,6 @@ void LinearScanAllocator::rewriteLIR() {
11121088
if (instr->output()->isInd()) {
11131089
rewriteInstrOutput(instr, mapping, &last_use_vregs);
11141090
}
1115-
if (instr->isYieldInitial()) {
1116-
computeInitialYieldSpillSize(mapping);
1117-
}
11181091
}
11191092
} else {
11201093
rewriteInstrOutput(instr, mapping, &last_use_vregs);

cinderx/Jit/lir/regalloc.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ class LinearScanAllocator {
109109
// Return the number of bytes that should be allocated below the base pointer.
110110
int getFrameSize() const;
111111

112-
int initialYieldSpillSize() const;
113-
114112
// returns true if the variables defined in the entry block is
115113
// used in the function.
116114
bool isPredefinedUsed(const Operand* operand) const;
@@ -142,8 +140,6 @@ class LinearScanAllocator {
142140
void calculateLiveIntervals();
143141

144142
void spillRegistersForYield(int instr_id);
145-
void computeInitialYieldSpillSize(
146-
const UnorderedMap<const Operand*, const LiveInterval*>& mapping);
147143

148144
// Reserve all caller-saved registers for a function call.
149145
void reserveCallerSaveRegisters(int instr_id);
@@ -273,7 +269,6 @@ class LinearScanAllocator {
273269
std::vector<PhyLocation> free_stack_slots_;
274270

275271
codegen::PhyRegisterSet changed_regs_;
276-
int initial_yield_spill_size_{-1};
277272

278273
// record vreg-to-physical-location mapping at the end of each basic block,
279274
// which is needed for resolve edges.

cinderx/RuntimeTests/lir_abi_test.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ class LIRABITest : public RuntimeTest {
8888
environ.block_label_map.emplace(deopt_bb, as.newLabel());
8989
break;
9090
}
91-
case Instruction::kYieldInitial:
92-
environ.code_rt->addDeoptMetadata(DeoptMetadata{});
93-
environ.initial_yield_spill_size_ = 16;
94-
break;
9591
default:
9692
break;
9793
}
@@ -1299,22 +1295,6 @@ TEST_F(LIRABITest, TestkBitTest_PhyReg_PhyReg) {
12991295
translateInstr(Instruction::kBitTest, makePhyReg(0), Imm{63});
13001296
}
13011297

1302-
// kYieldInitial ANY
1303-
TEST_F(LIRABITest, TestkYieldInitial) {
1304-
PyCodeObject code;
1305-
hir::FrameState frameState(BorrowedRef(&code), nullptr, nullptr, nullptr);
1306-
1307-
hir::Register out(0);
1308-
auto origin = std::unique_ptr<hir::InitialYield>(
1309-
hir::InitialYield::create(&out, frameState));
1310-
1311-
auto tstate = makeStk(-16);
1312-
auto live_regs = Imm{0};
1313-
auto deopt_idx = Imm{0};
1314-
1315-
translateInstrWithOrigin(
1316-
Instruction::kYieldInitial, origin.get(), tstate, live_regs, deopt_idx);
1317-
}
13181298
// kSelect R r r r
13191299
TEST_F(LIRABITest, TestkSelect_OutPhyReg_PhyReg_PhyReg_PhyReg) {
13201300
#if defined(CINDER_X86_64)

0 commit comments

Comments
 (0)