@@ -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 LessPointerAddrSpace {
167
+ bool operator ()(const DataLayout::PointerSpec &LHS,
168
+ unsigned RHSAddrSpace) const {
169
+ return LHS.AddrSpace < RHSAddrSpace;
170
+ }
171
+ };
172
+ } // namespace
173
+
156
174
const char *DataLayout::getManglingComponent (const Triple &T) {
157
175
if (T.isOSBinFormatGOFF ())
158
176
return " -m:l" ;
@@ -581,15 +599,6 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
581
599
return Error::success ();
582
600
}
583
601
584
- static SmallVectorImpl<DataLayout::PrimitiveSpec>::const_iterator
585
- findPrimitiveSpecLowerBound (
586
- const SmallVectorImpl<DataLayout::PrimitiveSpec> &Specs,
587
- uint32_t BitWidth) {
588
- return partition_point (Specs, [BitWidth](const DataLayout::PrimitiveSpec &E) {
589
- return E.BitWidth < BitWidth;
590
- });
591
- }
592
-
593
602
Error DataLayout::setPrimitiveSpec (TypeSpecifier Specifier, uint32_t BitWidth,
594
603
Align ABIAlign, Align PrefAlign) {
595
604
// AlignmentsTy::ABIAlign and AlignmentsTy::PrefAlign were once stored as
@@ -620,9 +629,7 @@ Error DataLayout::setPrimitiveSpec(TypeSpecifier Specifier, uint32_t BitWidth,
620
629
break ;
621
630
}
622
631
623
- auto I = partition_point (*Specs, [BitWidth](const PrimitiveSpec &E) {
624
- return E.BitWidth < BitWidth;
625
- });
632
+ auto I = lower_bound (*Specs, BitWidth, LessPrimitiveBitWidth ());
626
633
if (I != Specs->end () && I->BitWidth == BitWidth) {
627
634
// Update the abi, preferred alignments.
628
635
I->ABIAlign = ABIAlign;
@@ -637,10 +644,7 @@ Error DataLayout::setPrimitiveSpec(TypeSpecifier Specifier, uint32_t BitWidth,
637
644
const DataLayout::PointerSpec &
638
645
DataLayout::getPointerSpec (uint32_t AddrSpace) const {
639
646
if (AddrSpace != 0 ) {
640
- auto I = lower_bound (PointerSpecs, AddrSpace,
641
- [](const PointerSpec &Spec, uint32_t AddrSpace) {
642
- return Spec.AddrSpace < AddrSpace;
643
- });
647
+ auto I = lower_bound (PointerSpecs, AddrSpace, LessPointerAddrSpace ());
644
648
if (I != PointerSpecs.end () && I->AddrSpace == AddrSpace)
645
649
return *I;
646
650
}
@@ -658,10 +662,7 @@ Error DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth,
658
662
if (IndexBitWidth > BitWidth)
659
663
return reportError (" Index width cannot be larger than pointer width" );
660
664
661
- auto I = lower_bound (PointerSpecs, AddrSpace,
662
- [](const PointerSpec &A, uint32_t AddrSpace) {
663
- return A.AddrSpace < AddrSpace;
664
- });
665
+ auto I = lower_bound (PointerSpecs, AddrSpace, LessPointerAddrSpace ());
665
666
if (I == PointerSpecs.end () || I->AddrSpace != AddrSpace) {
666
667
PointerSpecs.insert (I, PointerSpec{AddrSpace, BitWidth, ABIAlign, PrefAlign,
667
668
IndexBitWidth});
@@ -676,7 +677,7 @@ Error DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth,
676
677
677
678
Align DataLayout::getIntegerAlignment (uint32_t BitWidth,
678
679
bool abi_or_pref) const {
679
- auto I = findPrimitiveSpecLowerBound (IntSpecs, BitWidth);
680
+ auto I = lower_bound (IntSpecs, BitWidth, LessPrimitiveBitWidth () );
680
681
// If we don't have an exact match, use alignment of next larger integer
681
682
// type. If there is none, use alignment of largest integer type by going
682
683
// back one element.
@@ -792,7 +793,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
792
793
case Type::FP128TyID:
793
794
case Type::X86_FP80TyID: {
794
795
unsigned BitWidth = getTypeSizeInBits (Ty).getFixedValue ();
795
- auto I = findPrimitiveSpecLowerBound (FloatSpecs, BitWidth);
796
+ auto I = lower_bound (FloatSpecs, BitWidth, LessPrimitiveBitWidth () );
796
797
if (I != FloatSpecs.end () && I->BitWidth == BitWidth)
797
798
return abi_or_pref ? I->ABIAlign : I->PrefAlign ;
798
799
@@ -807,7 +808,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
807
808
case Type::FixedVectorTyID:
808
809
case Type::ScalableVectorTyID: {
809
810
unsigned BitWidth = getTypeSizeInBits (Ty).getKnownMinValue ();
810
- auto I = findPrimitiveSpecLowerBound (VectorSpecs, BitWidth);
811
+ auto I = lower_bound (VectorSpecs, BitWidth, LessPrimitiveBitWidth () );
811
812
if (I != VectorSpecs.end () && I->BitWidth == BitWidth)
812
813
return abi_or_pref ? I->ABIAlign : I->PrefAlign ;
813
814
0 commit comments