Skip to content

Commit 7196554

Browse files
[Support] Use list-initialization for returning pairs (#160447)
In C++17 and later, "return {A, B};" guarantees copy elision for a std::pair return type, ensuring the object is constructed directly in the return slot. This patch updates those instances under Support/.
1 parent d616013 commit 7196554

File tree

11 files changed

+30
-30
lines changed

11 files changed

+30
-30
lines changed

llvm/include/llvm/Support/BinaryStreamRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ struct BinarySubstreamRef {
209209
BinarySubstreamRef keep_front(uint64_t N) const { return slice(0, N); }
210210

211211
std::pair<BinarySubstreamRef, BinarySubstreamRef> split(uint64_t Off) const {
212-
return std::make_pair(keep_front(Off), drop_front(Off));
212+
return {keep_front(Off), drop_front(Off)};
213213
}
214214

215215
uint64_t size() const { return StreamData.getLength(); }

llvm/include/llvm/Support/DebugCounter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class DebugCounter {
136136

137137
// Return the name and description of the counter with the given ID.
138138
std::pair<std::string, std::string> getCounterInfo(unsigned ID) const {
139-
return std::make_pair(RegisteredCounters[ID], Counters.lookup(ID).Desc);
139+
return {RegisteredCounters[ID], Counters.lookup(ID).Desc};
140140
}
141141

142142
// Iterate through the registered counters

llvm/include/llvm/Support/FormatProviders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ template <typename IterT> class format_provider<llvm::iterator_range<IterT>> {
389389
StringRef Sep = consumeOneOption(Style, '$', ", ");
390390
StringRef Args = consumeOneOption(Style, '@', "");
391391
assert(Style.empty() && "Unexpected text in range option string!");
392-
return std::make_pair(Sep, Args);
392+
return {Sep, Args};
393393
}
394394

395395
public:

llvm/include/llvm/Support/MD5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MD5 {
5757
}
5858
std::pair<uint64_t, uint64_t> words() const {
5959
using namespace support;
60-
return std::make_pair(high(), low());
60+
return {high(), low()};
6161
}
6262
};
6363

llvm/include/llvm/Support/OnDiskHashTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ template <typename Info> class OnDiskChainedHashTable {
309309
offset_type NumEntries =
310310
endian::readNext<offset_type, llvm::endianness::little, aligned>(
311311
Buckets);
312-
return std::make_pair(NumBuckets, NumEntries);
312+
return {NumBuckets, NumEntries};
313313
}
314314

315315
offset_type getNumBuckets() const { return NumBuckets; }

llvm/include/llvm/Support/ScaledNumber.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ inline std::pair<DigitsT, int16_t> getRounded(DigitsT Digits, int16_t Scale,
5757
if (ShouldRound)
5858
if (!++Digits)
5959
// Overflow.
60-
return std::make_pair(DigitsT(1) << (getWidth<DigitsT>() - 1), Scale + 1);
61-
return std::make_pair(Digits, Scale);
60+
return {DigitsT(1) << (getWidth<DigitsT>() - 1), Scale + 1};
61+
return {Digits, Scale};
6262
}
6363

6464
/// Convenience helper for 32-bit rounding.
@@ -83,7 +83,7 @@ inline std::pair<DigitsT, int16_t> getAdjusted(uint64_t Digits,
8383

8484
const int Width = getWidth<DigitsT>();
8585
if (Width == 64 || Digits <= std::numeric_limits<DigitsT>::max())
86-
return std::make_pair(Digits, Scale);
86+
return {Digits, Scale};
8787

8888
// Shift right and round.
8989
int Shift = llvm::bit_width(Digits) - Width;
@@ -160,9 +160,9 @@ std::pair<DigitsT, int16_t> getQuotient(DigitsT Dividend, DigitsT Divisor) {
160160

161161
// Check for zero.
162162
if (!Dividend)
163-
return std::make_pair(0, 0);
163+
return {0, 0};
164164
if (!Divisor)
165-
return std::make_pair(std::numeric_limits<DigitsT>::max(), MaxScale);
165+
return {std::numeric_limits<DigitsT>::max(), MaxScale};
166166

167167
if (getWidth<DigitsT>() == 64)
168168
return divide64(Dividend, Divisor);
@@ -192,7 +192,7 @@ inline std::pair<int32_t, int> getLgImpl(DigitsT Digits, int16_t Scale) {
192192
static_assert(!std::numeric_limits<DigitsT>::is_signed, "expected unsigned");
193193

194194
if (!Digits)
195-
return std::make_pair(INT32_MIN, 0);
195+
return {INT32_MIN, 0};
196196

197197
// Get the floor of the lg of Digits.
198198
static_assert(sizeof(Digits) <= sizeof(uint64_t));
@@ -201,12 +201,12 @@ inline std::pair<int32_t, int> getLgImpl(DigitsT Digits, int16_t Scale) {
201201
// Get the actual floor.
202202
int32_t Floor = Scale + LocalFloor;
203203
if (Digits == UINT64_C(1) << LocalFloor)
204-
return std::make_pair(Floor, 0);
204+
return {Floor, 0};
205205

206206
// Round based on the next digit.
207207
assert(LocalFloor >= 1);
208208
bool Round = Digits & UINT64_C(1) << (LocalFloor - 1);
209-
return std::make_pair(Floor + Round, Round ? 1 : -1);
209+
return {Floor + Round, Round ? 1 : -1};
210210
}
211211

212212
/// Get the lg (rounded) of a scaled number.
@@ -348,11 +348,11 @@ std::pair<DigitsT, int16_t> getSum(DigitsT LDigits, int16_t LScale,
348348
// Compute sum.
349349
DigitsT Sum = LDigits + RDigits;
350350
if (Sum >= RDigits)
351-
return std::make_pair(Sum, Scale);
351+
return {Sum, Scale};
352352

353353
// Adjust sum after arithmetic overflow.
354354
DigitsT HighBit = DigitsT(1) << (getWidth<DigitsT>() - 1);
355-
return std::make_pair(HighBit | Sum >> 1, Scale + 1);
355+
return {HighBit | Sum >> 1, Scale + 1};
356356
}
357357

358358
/// Convenience helper for 32-bit sum.
@@ -384,18 +384,18 @@ std::pair<DigitsT, int16_t> getDifference(DigitsT LDigits, int16_t LScale,
384384

385385
// Compute difference.
386386
if (LDigits <= RDigits)
387-
return std::make_pair(0, 0);
387+
return {0, 0};
388388
if (RDigits || !SavedRDigits)
389-
return std::make_pair(LDigits - RDigits, LScale);
389+
return {LDigits - RDigits, LScale};
390390

391391
// Check if RDigits just barely lost its last bit. E.g., for 32-bit:
392392
//
393393
// 1*2^32 - 1*2^0 == 0xffffffff != 1*2^32
394394
const auto RLgFloor = getLgFloor(SavedRDigits, SavedRScale);
395395
if (!compare(LDigits, LScale, DigitsT(1), RLgFloor + getWidth<DigitsT>()))
396-
return std::make_pair(std::numeric_limits<DigitsT>::max(), RLgFloor);
396+
return {std::numeric_limits<DigitsT>::max(), RLgFloor};
397397

398-
return std::make_pair(LDigits, LScale);
398+
return {LDigits, LScale};
399399
}
400400

401401
/// Convenience helper for 32-bit difference.
@@ -435,9 +435,9 @@ class ScaledNumberBase {
435435

436436
static std::pair<uint64_t, bool> splitSigned(int64_t N) {
437437
if (N >= 0)
438-
return std::make_pair(N, false);
438+
return {N, false};
439439
uint64_t Unsigned = N == INT64_MIN ? UINT64_C(1) << 63 : uint64_t(-N);
440-
return std::make_pair(Unsigned, true);
440+
return {Unsigned, true};
441441
}
442442
static int64_t joinSigned(uint64_t U, bool IsNeg) {
443443
if (U > uint64_t(INT64_MAX))

llvm/lib/Support/OptimizedStructLayout.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
8282
#ifndef NDEBUG
8383
checkValidLayout(Fields, Size, MaxAlign);
8484
#endif
85-
return std::make_pair(Size, MaxAlign);
85+
return {Size, MaxAlign};
8686
}
8787

8888
// Walk over the flexible-offset fields, tracking MaxAlign and
@@ -164,7 +164,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
164164
#ifndef NDEBUG
165165
checkValidLayout(Fields, LastEnd, MaxAlign);
166166
#endif
167-
return std::make_pair(LastEnd, MaxAlign);
167+
return {LastEnd, MaxAlign};
168168
}
169169
}
170170

@@ -452,5 +452,5 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
452452
checkValidLayout(Fields, LastEnd, MaxAlign);
453453
#endif
454454

455-
return std::make_pair(LastEnd, MaxAlign);
455+
return {LastEnd, MaxAlign};
456456
}

llvm/lib/Support/ScaledNumber.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::pair<uint64_t, int16_t> ScaledNumbers::multiply64(uint64_t LHS,
4141

4242
// Check whether the upper digit is empty.
4343
if (!Upper)
44-
return std::make_pair(Lower, 0);
44+
return {Lower, 0};
4545

4646
// Shift as little as possible to maximize precision.
4747
unsigned LeadingZeros = llvm::countl_zero(Upper);
@@ -91,7 +91,7 @@ std::pair<uint64_t, int16_t> ScaledNumbers::divide64(uint64_t Dividend,
9191

9292
// Check for powers of two.
9393
if (Divisor == 1)
94-
return std::make_pair(Dividend, Shift);
94+
return {Dividend, Shift};
9595

9696
// Maximize size of dividend.
9797
if (int Zeros = llvm::countl_zero(Dividend)) {

llvm/lib/Support/SmallPtrSet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
5252
// Okay, we know we have space. Find a hash bucket.
5353
const void **Bucket = const_cast<const void**>(FindBucketFor(Ptr));
5454
if (*Bucket == Ptr)
55-
return std::make_pair(Bucket, false); // Already inserted, good.
55+
return {Bucket, false}; // Already inserted, good.
5656

5757
// Otherwise, insert it!
5858
if (*Bucket == getTombstoneMarker())
5959
--NumTombstones;
6060
++NumEntries;
6161
*Bucket = Ptr;
6262
incrementEpoch();
63-
return std::make_pair(Bucket, true);
63+
return {Bucket, true};
6464
}
6565

6666
const void *const *SmallPtrSetImplBase::doFind(const void *Ptr) const {

llvm/lib/Support/SourceMgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
202202
size_t NewlineOffs = StringRef(BufStart, Ptr - BufStart).find_last_of("\n\r");
203203
if (NewlineOffs == StringRef::npos)
204204
NewlineOffs = ~(size_t)0;
205-
return std::make_pair(LineNo, Ptr - BufStart - NewlineOffs);
205+
return {LineNo, Ptr - BufStart - NewlineOffs};
206206
}
207207

208208
// FIXME: Note that the formatting of source locations is spread between

0 commit comments

Comments
 (0)