diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index 00608236f7..aab176de62 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -752,124 +752,32 @@ impl Instruction { } /// Number of CACHE code units that follow this instruction. + /// + /// Instrumented and specialized opcodes have the same cache entries as their base. + /// /// _PyOpcode_Caches pub const fn cache_entries(self) -> usize { - match self { - // LOAD_ATTR: 9 cache entries - Self::LoadAttr { .. } - | Self::LoadAttrClass - | Self::LoadAttrClassWithMetaclassCheck - | Self::LoadAttrGetattributeOverridden - | Self::LoadAttrInstanceValue - | Self::LoadAttrMethodLazyDict - | Self::LoadAttrMethodNoDict - | Self::LoadAttrMethodWithValues - | Self::LoadAttrModule - | Self::LoadAttrNondescriptorNoDict - | Self::LoadAttrNondescriptorWithValues - | Self::LoadAttrProperty - | Self::LoadAttrSlot - | Self::LoadAttrWithHint => 9, - - // BINARY_OP: 5 cache entries - Self::BinaryOp { .. } - | Self::BinaryOpAddFloat - | Self::BinaryOpAddInt - | Self::BinaryOpAddUnicode - | Self::BinaryOpExtend - | Self::BinaryOpInplaceAddUnicode - | Self::BinaryOpMultiplyFloat - | Self::BinaryOpMultiplyInt - | Self::BinaryOpSubscrDict - | Self::BinaryOpSubscrGetitem - | Self::BinaryOpSubscrListInt - | Self::BinaryOpSubscrListSlice - | Self::BinaryOpSubscrStrInt - | Self::BinaryOpSubscrTupleInt - | Self::BinaryOpSubtractFloat - | Self::BinaryOpSubtractInt => 5, - - // LOAD_GLOBAL / STORE_ATTR: 4 cache entries - Self::LoadGlobal { .. } - | Self::LoadGlobalBuiltin - | Self::LoadGlobalModule - | Self::StoreAttr { .. } - | Self::StoreAttrInstanceValue - | Self::StoreAttrSlot - | Self::StoreAttrWithHint => 4, - - // CALL / CALL_KW / TO_BOOL: 3 cache entries - Self::Call { .. } - | Self::CallAllocAndEnterInit - | Self::CallBoundMethodExactArgs - | Self::CallBoundMethodGeneral - | Self::CallBuiltinClass - | Self::CallBuiltinFast - | Self::CallBuiltinFastWithKeywords - | Self::CallBuiltinO - | Self::CallIsinstance - | Self::CallLen - | Self::CallListAppend - | Self::CallMethodDescriptorFast - | Self::CallMethodDescriptorFastWithKeywords - | Self::CallMethodDescriptorNoargs - | Self::CallMethodDescriptorO - | Self::CallNonPyGeneral - | Self::CallPyExactArgs - | Self::CallPyGeneral - | Self::CallStr1 - | Self::CallTuple1 - | Self::CallType1 - | Self::CallKw { .. } - | Self::CallKwBoundMethod - | Self::CallKwNonPy - | Self::CallKwPy - | Self::ToBool - | Self::ToBoolAlwaysTrue - | Self::ToBoolBool - | Self::ToBoolInt - | Self::ToBoolList - | Self::ToBoolNone - | Self::ToBoolStr => 3, - - // 1 cache entry - Self::CompareOp { .. } - | Self::CompareOpFloat - | Self::CompareOpInt - | Self::CompareOpStr - | Self::ContainsOp { .. } - | Self::ContainsOpDict - | Self::ContainsOpSet - | Self::ForIter { .. } - | Self::ForIterGen - | Self::ForIterList - | Self::ForIterRange - | Self::ForIterTuple - | Self::JumpBackward { .. } - | Self::JumpBackwardJit - | Self::JumpBackwardNoJit - | Self::LoadSuperAttr { .. } - | Self::LoadSuperAttrAttr - | Self::LoadSuperAttrMethod - | Self::PopJumpIfTrue { .. } - | Self::PopJumpIfFalse { .. } - | Self::PopJumpIfNone { .. } - | Self::PopJumpIfNotNone { .. } - | Self::Send { .. } - | Self::SendGen - | Self::StoreSubscr - | Self::StoreSubscrDict - | Self::StoreSubscrListInt - | Self::UnpackSequence { .. } - | Self::UnpackSequenceList - | Self::UnpackSequenceTuple - | Self::UnpackSequenceTwoTuple => 1, - - // Instrumented opcodes have the same cache entries as their base - _ => match self.to_base() { - Some(base) => base.cache_entries(), - None => 0, - }, + match self.deoptimize().opcode() { + Opcode::LoadAttr => 9, + Opcode::BinaryOp => 5, + Opcode::LoadGlobal => 4, + Opcode::StoreAttr => 4, + Opcode::Call => 3, + Opcode::CallKw => 3, + Opcode::ToBool => 3, + Opcode::CompareOp => 1, + Opcode::ContainsOp => 1, + Opcode::ForIter => 1, + Opcode::JumpBackward => 1, + Opcode::LoadSuperAttr => 1, + Opcode::Send => 1, + Opcode::StoreSubscr => 1, + Opcode::UnpackSequence => 1, + Opcode::PopJumpIfTrue => 1, + Opcode::PopJumpIfFalse => 1, + Opcode::PopJumpIfNone => 1, + Opcode::PopJumpIfNotNone => 1, + _ => 0, } } }