Skip to content

Commit 7ee1faf

Browse files
committed
Simplify cache_entries
1 parent a2c3e65 commit 7ee1faf

File tree

1 file changed

+24
-110
lines changed

1 file changed

+24
-110
lines changed

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 24 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -699,117 +699,31 @@ impl Instruction {
699699
/// Number of CACHE code units that follow this instruction.
700700
/// _PyOpcode_Caches
701701
pub const fn cache_entries(self) -> usize {
702-
match self {
703-
// LOAD_ATTR: 9 cache entries
704-
Self::LoadAttr { .. }
705-
| Self::LoadAttrClass
706-
| Self::LoadAttrClassWithMetaclassCheck
707-
| Self::LoadAttrGetattributeOverridden
708-
| Self::LoadAttrInstanceValue
709-
| Self::LoadAttrMethodLazyDict
710-
| Self::LoadAttrMethodNoDict
711-
| Self::LoadAttrMethodWithValues
712-
| Self::LoadAttrModule
713-
| Self::LoadAttrNondescriptorNoDict
714-
| Self::LoadAttrNondescriptorWithValues
715-
| Self::LoadAttrProperty
716-
| Self::LoadAttrSlot
717-
| Self::LoadAttrWithHint => 9,
718-
719-
// BINARY_OP: 5 cache entries
720-
Self::BinaryOp { .. }
721-
| Self::BinaryOpAddFloat
722-
| Self::BinaryOpAddInt
723-
| Self::BinaryOpAddUnicode
724-
| Self::BinaryOpExtend
725-
| Self::BinaryOpInplaceAddUnicode
726-
| Self::BinaryOpMultiplyFloat
727-
| Self::BinaryOpMultiplyInt
728-
| Self::BinaryOpSubscrDict
729-
| Self::BinaryOpSubscrGetitem
730-
| Self::BinaryOpSubscrListInt
731-
| Self::BinaryOpSubscrListSlice
732-
| Self::BinaryOpSubscrStrInt
733-
| Self::BinaryOpSubscrTupleInt
734-
| Self::BinaryOpSubtractFloat
735-
| Self::BinaryOpSubtractInt => 5,
736-
737-
// LOAD_GLOBAL / STORE_ATTR: 4 cache entries
738-
Self::LoadGlobal { .. }
739-
| Self::LoadGlobalBuiltin
740-
| Self::LoadGlobalModule
741-
| Self::StoreAttr { .. }
742-
| Self::StoreAttrInstanceValue
743-
| Self::StoreAttrSlot
744-
| Self::StoreAttrWithHint => 4,
745-
746-
// CALL / CALL_KW / TO_BOOL: 3 cache entries
747-
Self::Call { .. }
748-
| Self::CallAllocAndEnterInit
749-
| Self::CallBoundMethodExactArgs
750-
| Self::CallBoundMethodGeneral
751-
| Self::CallBuiltinClass
752-
| Self::CallBuiltinFast
753-
| Self::CallBuiltinFastWithKeywords
754-
| Self::CallBuiltinO
755-
| Self::CallIsinstance
756-
| Self::CallLen
757-
| Self::CallListAppend
758-
| Self::CallMethodDescriptorFast
759-
| Self::CallMethodDescriptorFastWithKeywords
760-
| Self::CallMethodDescriptorNoargs
761-
| Self::CallMethodDescriptorO
762-
| Self::CallNonPyGeneral
763-
| Self::CallPyExactArgs
764-
| Self::CallPyGeneral
765-
| Self::CallStr1
766-
| Self::CallTuple1
767-
| Self::CallType1
768-
| Self::CallKw { .. }
769-
| Self::CallKwBoundMethod
770-
| Self::CallKwNonPy
771-
| Self::CallKwPy
772-
| Self::ToBool
773-
| Self::ToBoolAlwaysTrue
774-
| Self::ToBoolBool
775-
| Self::ToBoolInt
776-
| Self::ToBoolList
777-
| Self::ToBoolNone
778-
| Self::ToBoolStr => 3,
779-
780-
// 1 cache entry
781-
Self::CompareOp { .. }
782-
| Self::CompareOpFloat
783-
| Self::CompareOpInt
784-
| Self::CompareOpStr
785-
| Self::ContainsOp { .. }
786-
| Self::ContainsOpDict
787-
| Self::ContainsOpSet
788-
| Self::ForIter { .. }
789-
| Self::ForIterGen
790-
| Self::ForIterList
791-
| Self::ForIterRange
792-
| Self::ForIterTuple
793-
| Self::JumpBackward { .. }
794-
| Self::JumpBackwardJit
795-
| Self::JumpBackwardNoJit
796-
| Self::LoadSuperAttr { .. }
797-
| Self::LoadSuperAttrAttr
798-
| Self::LoadSuperAttrMethod
799-
| Self::PopJumpIfTrue { .. }
800-
| Self::PopJumpIfFalse { .. }
801-
| Self::PopJumpIfNone { .. }
802-
| Self::PopJumpIfNotNone { .. }
803-
| Self::Send { .. }
804-
| Self::SendGen
805-
| Self::StoreSubscr
806-
| Self::StoreSubscrDict
807-
| Self::StoreSubscrListInt
808-
| Self::UnpackSequence { .. }
809-
| Self::UnpackSequenceList
810-
| Self::UnpackSequenceTuple
811-
| Self::UnpackSequenceTwoTuple => 1,
702+
let instr = match self.deopt() {
703+
Some(v) => v,
704+
None => self,
705+
};
812706

707+
match instr {
708+
Self::LoadAttr { .. } => 9,
709+
Self::BinaryOp { .. } => 5,
710+
Self::LoadGlobal { .. } => 4,
711+
Self::StoreAttr { .. } => 4,
712+
Self::Call { .. } => 3,
713+
Self::CallKw { .. } => 3,
714+
Self::ToBool => 3,
715+
Self::CompareOp { .. } => 1,
716+
Self::ContainsOp { .. } => 1,
717+
Self::ForIter { .. } => 1,
718+
Self::JumpBackward { .. } => 1,
719+
Self::LoadSuperAttr { .. } => 1,
720+
Self::Send { .. } => 1,
721+
Self::StoreSubscr => 1,
722+
Self::UnpackSequence { .. } => 1,
723+
Self::PopJumpIfTrue { .. } => 1,
724+
Self::PopJumpIfFalse { .. } => 1,
725+
Self::PopJumpIfNone { .. } => 1,
726+
Self::PopJumpIfNotNone { .. } => 1,
813727
// Instrumented opcodes have the same cache entries as their base
814728
_ => match self.to_base() {
815729
Some(base) => base.cache_entries(),

0 commit comments

Comments
 (0)