@@ -153,6 +153,24 @@ bool DataLayout::PointerSpec::operator==(const PointerSpec &Other) const {
153153 IndexBitWidth == Other.IndexBitWidth ;
154154}
155155
156+ namespace {
157+ // Predicate to sort primitive specs by bit width.
158+ struct LessPrimitiveBitWidth {
159+ bool operator ()(const DataLayout::PrimitiveSpec &LHS,
160+ unsigned RHSBitWidth) const {
161+ return LHS.BitWidth < RHSBitWidth;
162+ }
163+ };
164+
165+ // Predicate to sort pointer specs by address space number.
166+ struct LessPointerAddressSpace {
167+ bool operator ()(const DataLayout::PointerSpec &LHS,
168+ unsigned RHSAddressSpace) const {
169+ return LHS.AddressSpace < RHSAddressSpace;
170+ }
171+ };
172+ } // namespace
173+
156174const char *DataLayout::getManglingComponent (const Triple &T) {
157175 if (T.isOSBinFormatGOFF ())
158176 return " -m:l" ;
@@ -583,15 +601,6 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
583601 return Error::success ();
584602}
585603
586- static SmallVectorImpl<DataLayout::PrimitiveSpec>::const_iterator
587- findPrimitiveSpecLowerBound (
588- const SmallVectorImpl<DataLayout::PrimitiveSpec> &Specs,
589- uint32_t BitWidth) {
590- return partition_point (Specs, [BitWidth](const DataLayout::PrimitiveSpec &E) {
591- return E.BitWidth < BitWidth;
592- });
593- }
594-
595604Error DataLayout::setPrimitiveSpec (PrimitiveSpecifier Specifier,
596605 uint32_t BitWidth, Align ABIAlign,
597606 Align PrefAlign) {
@@ -623,9 +632,7 @@ Error DataLayout::setPrimitiveSpec(PrimitiveSpecifier Specifier,
623632 break ;
624633 }
625634
626- auto I = partition_point (*Specs, [BitWidth](const PrimitiveSpec &E) {
627- return E.BitWidth < BitWidth;
628- });
635+ auto I = lower_bound (*Specs, BitWidth, LessPrimitiveBitWidth ());
629636 if (I != Specs->end () && I->BitWidth == BitWidth) {
630637 // Update the abi, preferred alignments.
631638 I->ABIAlign = ABIAlign;
@@ -640,10 +647,7 @@ Error DataLayout::setPrimitiveSpec(PrimitiveSpecifier Specifier,
640647const DataLayout::PointerSpec &
641648DataLayout::getPointerSpec (uint32_t AddressSpace) const {
642649 if (AddressSpace != 0 ) {
643- auto I = lower_bound (PointerSpecs, AddressSpace,
644- [](const PointerSpec &Spec, uint32_t AddressSpace) {
645- return Spec.AddressSpace < AddressSpace;
646- });
650+ auto I = lower_bound (PointerSpecs, AddressSpace, LessPointerAddressSpace ());
647651 if (I != PointerSpecs.end () && I->AddressSpace == AddressSpace)
648652 return *I;
649653 }
@@ -661,10 +665,7 @@ Error DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t TypeBitWidth,
661665 if (IndexBitWidth > TypeBitWidth)
662666 return reportError (" Index width cannot be larger than pointer width" );
663667
664- auto I = lower_bound (PointerSpecs, AddrSpace,
665- [](const PointerSpec &A, uint32_t AddressSpace) {
666- return A.AddressSpace < AddressSpace;
667- });
668+ auto I = lower_bound (PointerSpecs, AddrSpace, LessPointerAddressSpace ());
668669 if (I == PointerSpecs.end () || I->AddressSpace != AddrSpace) {
669670 PointerSpecs.insert (I, PointerSpec{AddrSpace, TypeBitWidth, ABIAlign,
670671 PrefAlign, IndexBitWidth});
@@ -679,7 +680,7 @@ Error DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t TypeBitWidth,
679680
680681Align DataLayout::getIntegerAlignment (uint32_t BitWidth,
681682 bool abi_or_pref) const {
682- auto I = findPrimitiveSpecLowerBound (IntSpecs, BitWidth);
683+ auto I = lower_bound (IntSpecs, BitWidth, LessPrimitiveBitWidth () );
683684 // If we don't have an exact match, use alignment of next larger integer
684685 // type. If there is none, use alignment of largest integer type by going
685686 // back one element.
@@ -795,7 +796,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
795796 case Type::FP128TyID:
796797 case Type::X86_FP80TyID: {
797798 unsigned BitWidth = getTypeSizeInBits (Ty).getFixedValue ();
798- auto I = findPrimitiveSpecLowerBound (FloatSpecs, BitWidth);
799+ auto I = lower_bound (FloatSpecs, BitWidth, LessPrimitiveBitWidth () );
799800 if (I != FloatSpecs.end () && I->BitWidth == BitWidth)
800801 return abi_or_pref ? I->ABIAlign : I->PrefAlign ;
801802
@@ -810,7 +811,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
810811 case Type::FixedVectorTyID:
811812 case Type::ScalableVectorTyID: {
812813 unsigned BitWidth = getTypeSizeInBits (Ty).getKnownMinValue ();
813- auto I = findPrimitiveSpecLowerBound (VectorSpecs, BitWidth);
814+ auto I = lower_bound (VectorSpecs, BitWidth, LessPrimitiveBitWidth () );
814815 if (I != VectorSpecs.end () && I->BitWidth == BitWidth)
815816 return abi_or_pref ? I->ABIAlign : I->PrefAlign ;
816817
0 commit comments