@@ -153,6 +153,24 @@ bool DataLayout::PointerSpec::operator==(const PointerSpec &Other) const {
153
153
IndexBitWidth == Other.IndexBitWidth ;
154
154
}
155
155
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
+
156
174
const char *DataLayout::getManglingComponent (const Triple &T) {
157
175
if (T.isOSBinFormatGOFF ())
158
176
return " -m:l" ;
@@ -583,15 +601,6 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
583
601
return Error::success ();
584
602
}
585
603
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
-
595
604
Error DataLayout::setPrimitiveSpec (PrimitiveSpecifier Specifier,
596
605
uint32_t BitWidth, Align ABIAlign,
597
606
Align PrefAlign) {
@@ -623,9 +632,7 @@ Error DataLayout::setPrimitiveSpec(PrimitiveSpecifier Specifier,
623
632
break ;
624
633
}
625
634
626
- auto I = partition_point (*Specs, [BitWidth](const PrimitiveSpec &E) {
627
- return E.BitWidth < BitWidth;
628
- });
635
+ auto I = lower_bound (*Specs, BitWidth, LessPrimitiveBitWidth ());
629
636
if (I != Specs->end () && I->BitWidth == BitWidth) {
630
637
// Update the abi, preferred alignments.
631
638
I->ABIAlign = ABIAlign;
@@ -640,10 +647,7 @@ Error DataLayout::setPrimitiveSpec(PrimitiveSpecifier Specifier,
640
647
const DataLayout::PointerSpec &
641
648
DataLayout::getPointerSpec (uint32_t AddressSpace) const {
642
649
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 ());
647
651
if (I != PointerSpecs.end () && I->AddressSpace == AddressSpace)
648
652
return *I;
649
653
}
@@ -661,10 +665,7 @@ Error DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t TypeBitWidth,
661
665
if (IndexBitWidth > TypeBitWidth)
662
666
return reportError (" Index width cannot be larger than pointer width" );
663
667
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 ());
668
669
if (I == PointerSpecs.end () || I->AddressSpace != AddrSpace) {
669
670
PointerSpecs.insert (I, PointerSpec{AddrSpace, TypeBitWidth, ABIAlign,
670
671
PrefAlign, IndexBitWidth});
@@ -679,7 +680,7 @@ Error DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t TypeBitWidth,
679
680
680
681
Align DataLayout::getIntegerAlignment (uint32_t BitWidth,
681
682
bool abi_or_pref) const {
682
- auto I = findPrimitiveSpecLowerBound (IntSpecs, BitWidth);
683
+ auto I = lower_bound (IntSpecs, BitWidth, LessPrimitiveBitWidth () );
683
684
// If we don't have an exact match, use alignment of next larger integer
684
685
// type. If there is none, use alignment of largest integer type by going
685
686
// back one element.
@@ -795,7 +796,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
795
796
case Type::FP128TyID:
796
797
case Type::X86_FP80TyID: {
797
798
unsigned BitWidth = getTypeSizeInBits (Ty).getFixedValue ();
798
- auto I = findPrimitiveSpecLowerBound (FloatSpecs, BitWidth);
799
+ auto I = lower_bound (FloatSpecs, BitWidth, LessPrimitiveBitWidth () );
799
800
if (I != FloatSpecs.end () && I->BitWidth == BitWidth)
800
801
return abi_or_pref ? I->ABIAlign : I->PrefAlign ;
801
802
@@ -810,7 +811,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
810
811
case Type::FixedVectorTyID:
811
812
case Type::ScalableVectorTyID: {
812
813
unsigned BitWidth = getTypeSizeInBits (Ty).getKnownMinValue ();
813
- auto I = findPrimitiveSpecLowerBound (VectorSpecs, BitWidth);
814
+ auto I = lower_bound (VectorSpecs, BitWidth, LessPrimitiveBitWidth () );
814
815
if (I != VectorSpecs.end () && I->BitWidth == BitWidth)
815
816
return abi_or_pref ? I->ABIAlign : I->PrefAlign ;
816
817
0 commit comments