Skip to content

Commit 9a5671e

Browse files
[Support] Deprecate one form of support::endian::byte_swap (NFC) (#161045)
This is a follow-up to #156140 and #160979, which deprecated one form of write and read, respectively. We have two forms of byte_swap: template <typename value_type> [[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) template <typename value_type, endianness endian> [[nodiscard]] inline value_type byte_swap(value_type value) The difference is that endian is a function parameter in the former but a template parameter in the latter. This patch streamlines the code by migrating the use of the latter to the former while deprecating the latter because the latter is just forwarded to the former.
1 parent 372f786 commit 9a5671e

File tree

12 files changed

+45
-44
lines changed

12 files changed

+45
-44
lines changed

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ void PGOHash::combine(HashType Type) {
972972
if (Count && Count % NumTypesPerWord == 0) {
973973
using namespace llvm::support;
974974
uint64_t Swapped =
975-
endian::byte_swap<uint64_t, llvm::endianness::little>(Working);
975+
endian::byte_swap<uint64_t>(Working, llvm::endianness::little);
976976
MD5.update(llvm::ArrayRef((uint8_t *)&Swapped, sizeof(Swapped)));
977977
Working = 0;
978978
}
@@ -999,7 +999,7 @@ uint64_t PGOHash::finalize() {
999999
} else {
10001000
using namespace llvm::support;
10011001
uint64_t Swapped =
1002-
endian::byte_swap<uint64_t, llvm::endianness::little>(Working);
1002+
endian::byte_swap<uint64_t>(Working, llvm::endianness::little);
10031003
MD5.update(llvm::ArrayRef((uint8_t *)&Swapped, sizeof(Swapped)));
10041004
}
10051005
}

llvm/include/llvm/Bitstream/BitstreamWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class BitstreamWriter {
8787

8888
void WriteWord(unsigned Value) {
8989
Value =
90-
support::endian::byte_swap<uint32_t, llvm::endianness::little>(Value);
90+
support::endian::byte_swap<uint32_t>(Value, llvm::endianness::little);
9191
Buffer.append(reinterpret_cast<const char *>(&Value),
9292
reinterpret_cast<const char *>(&Value + 1));
9393
}

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,19 +1215,19 @@ namespace accessors {
12151215
/// Return the structural hash associated with the function.
12161216
template <class FuncRecordTy, llvm::endianness Endian>
12171217
uint64_t getFuncHash(const FuncRecordTy *Record) {
1218-
return support::endian::byte_swap<uint64_t, Endian>(Record->FuncHash);
1218+
return support::endian::byte_swap<uint64_t>(Record->FuncHash, Endian);
12191219
}
12201220

12211221
/// Return the coverage map data size for the function.
12221222
template <class FuncRecordTy, llvm::endianness Endian>
12231223
uint64_t getDataSize(const FuncRecordTy *Record) {
1224-
return support::endian::byte_swap<uint32_t, Endian>(Record->DataSize);
1224+
return support::endian::byte_swap<uint32_t>(Record->DataSize, Endian);
12251225
}
12261226

12271227
/// Return the function lookup key. The value is considered opaque.
12281228
template <class FuncRecordTy, llvm::endianness Endian>
12291229
uint64_t getFuncNameRef(const FuncRecordTy *Record) {
1230-
return support::endian::byte_swap<uint64_t, Endian>(Record->NameRef);
1230+
return support::endian::byte_swap<uint64_t>(Record->NameRef, Endian);
12311231
}
12321232

12331233
/// Return the PGO name of the function. Used for formats in which the name is
@@ -1280,14 +1280,14 @@ struct CovMapFunctionRecordV1 {
12801280

12811281
/// Return function lookup key. The value is consider opaque.
12821282
template <llvm::endianness Endian> IntPtrT getFuncNameRef() const {
1283-
return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
1283+
return support::endian::byte_swap<IntPtrT>(NamePtr, Endian);
12841284
}
12851285

12861286
/// Return the PGO name of the function.
12871287
template <llvm::endianness Endian>
12881288
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
12891289
IntPtrT NameRef = getFuncNameRef<Endian>();
1290-
uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);
1290+
uint32_t NameS = support::endian::byte_swap<uint32_t>(NameSize, Endian);
12911291
FuncName = ProfileNames.getFuncName(NameRef, NameS);
12921292
if (NameS && FuncName.empty())
12931293
return make_error<CoverageMapError>(coveragemap_error::malformed,
@@ -1385,7 +1385,7 @@ struct CovMapFunctionRecordV3 {
13851385

13861386
/// Get the filename set reference.
13871387
template <llvm::endianness Endian> uint64_t getFilenamesRef() const {
1388-
return support::endian::byte_swap<uint64_t, Endian>(FilenamesRef);
1388+
return support::endian::byte_swap<uint64_t>(FilenamesRef, Endian);
13891389
}
13901390

13911391
/// Read the inline coverage mapping. Ignore the buffer parameter, it is for
@@ -1416,19 +1416,19 @@ struct CovMapHeader {
14161416
#define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;
14171417
#include "llvm/ProfileData/InstrProfData.inc"
14181418
template <llvm::endianness Endian> uint32_t getNRecords() const {
1419-
return support::endian::byte_swap<uint32_t, Endian>(NRecords);
1419+
return support::endian::byte_swap<uint32_t>(NRecords, Endian);
14201420
}
14211421

14221422
template <llvm::endianness Endian> uint32_t getFilenamesSize() const {
1423-
return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
1423+
return support::endian::byte_swap<uint32_t>(FilenamesSize, Endian);
14241424
}
14251425

14261426
template <llvm::endianness Endian> uint32_t getCoverageSize() const {
1427-
return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
1427+
return support::endian::byte_swap<uint32_t>(CoverageSize, Endian);
14281428
}
14291429

14301430
template <llvm::endianness Endian> uint32_t getVersion() const {
1431-
return support::endian::byte_swap<uint32_t, Endian>(Version);
1431+
return support::endian::byte_swap<uint32_t>(Version, Endian);
14321432
}
14331433
};
14341434

llvm/include/llvm/Support/Endian.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ template <typename value_type>
4949

5050
/// Swap the bytes of value to match the given endianness.
5151
template <typename value_type, endianness endian>
52-
[[nodiscard]] inline value_type byte_swap(value_type value) {
52+
[[nodiscard]]
53+
LLVM_DEPRECATED("Pass endian as a function argument instead",
54+
"byte_swap") inline value_type byte_swap(value_type value) {
5355
return byte_swap(value, endian);
5456
}
5557

@@ -137,8 +139,8 @@ template <typename value_type, endianness endian, std::size_t alignment>
137139
LLVM_ASSUME_ALIGNED(
138140
memory, (detail::PickAlignment<value_type, alignment>::value)),
139141
sizeof(value_type) * 2);
140-
val[0] = byte_swap<value_type, endian>(val[0]);
141-
val[1] = byte_swap<value_type, endian>(val[1]);
142+
val[0] = byte_swap<value_type>(val[0], endian);
143+
val[1] = byte_swap<value_type>(val[1], endian);
142144

143145
// Shift bits from the lower value into place.
144146
make_unsigned_t<value_type> lowerVal = val[0] >> startBit;
@@ -172,8 +174,8 @@ inline void writeAtBitAlignment(void *memory, value_type value,
172174
LLVM_ASSUME_ALIGNED(
173175
memory, (detail::PickAlignment<value_type, alignment>::value)),
174176
sizeof(value_type) * 2);
175-
val[0] = byte_swap<value_type, endian>(val[0]);
176-
val[1] = byte_swap<value_type, endian>(val[1]);
177+
val[0] = byte_swap<value_type>(val[0], endian);
178+
val[1] = byte_swap<value_type>(val[1], endian);
177179

178180
// Mask off any existing bits in the upper part of the lower value that
179181
// we want to replace.
@@ -201,8 +203,8 @@ inline void writeAtBitAlignment(void *memory, value_type value,
201203
val[1] |= upperVal;
202204

203205
// Finally, rewrite values.
204-
val[0] = byte_swap<value_type, endian>(val[0]);
205-
val[1] = byte_swap<value_type, endian>(val[1]);
206+
val[0] = byte_swap<value_type>(val[0], endian);
207+
val[1] = byte_swap<value_type>(val[1], endian);
206208
memcpy(LLVM_ASSUME_ALIGNED(
207209
memory, (detail::PickAlignment<value_type, alignment>::value)),
208210
&val[0], sizeof(value_type) * 2);

llvm/lib/CGData/CodeGenDataWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void CGDataOStream::patch(ArrayRef<CGDataPatchItem> P) {
4040
for (const auto &K : P) {
4141
for (size_t I = 0; I < K.D.size(); ++I) {
4242
uint64_t Bytes =
43-
endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
43+
endian::byte_swap<uint64_t>(K.D[I], llvm::endianness::little);
4444
Data.replace(K.Pos + I * sizeof(uint64_t), sizeof(uint64_t),
4545
reinterpret_cast<const char *>(&Bytes), sizeof(uint64_t));
4646
}
@@ -52,7 +52,7 @@ void CGDataOStream::patch(ArrayRef<CGDataPatchItem> P) {
5252
for (const auto &K : P) {
5353
for (size_t I = 0; I < K.D.size(); ++I) {
5454
uint64_t Bytes =
55-
endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
55+
endian::byte_swap<uint64_t>(K.D[I], llvm::endianness::little);
5656
VOStream.pwrite(reinterpret_cast<const char *>(&Bytes),
5757
sizeof(uint64_t), K.Pos + I * sizeof(uint64_t));
5858
}

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ static uint32_t writePlaceholder(raw_svector_ostream &Stream) {
2323
static uint32_t rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
2424
uint32_t Offset) {
2525
uint32_t ByteOffset = Stream.tell();
26-
uint32_t Value =
27-
support::endian::byte_swap<uint32_t, llvm::endianness::little>(
28-
ByteOffset);
26+
uint32_t Value = support::endian::byte_swap<uint32_t>(
27+
ByteOffset, llvm::endianness::little);
2928
Stream.pwrite(reinterpret_cast<const char *>(&Value), sizeof(Value), Offset);
3029
return ByteOffset;
3130
}

llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,9 @@ loadTestingFormat(StringRef Data, StringRef CompilationDir) {
949949
if (Data.size() < sizeof(uint64_t))
950950
return make_error<CoverageMapError>(coveragemap_error::malformed,
951951
"the size of data is too small");
952-
auto TestingVersion =
953-
support::endian::byte_swap<uint64_t, llvm::endianness::little>(
954-
*reinterpret_cast<const uint64_t *>(Data.data()));
952+
auto TestingVersion = support::endian::byte_swap<uint64_t>(
953+
*reinterpret_cast<const uint64_t *>(Data.data()),
954+
llvm::endianness::little);
955955
Data = Data.substr(sizeof(uint64_t));
956956

957957
// Read the ProfileNames data.
@@ -1274,9 +1274,9 @@ BinaryCoverageReader::create(
12741274
std::vector<std::unique_ptr<BinaryCoverageReader>> Readers;
12751275

12761276
if (ObjectBuffer.getBuffer().size() > sizeof(TestingFormatMagic)) {
1277-
uint64_t Magic =
1278-
support::endian::byte_swap<uint64_t, llvm::endianness::little>(
1279-
*reinterpret_cast<const uint64_t *>(ObjectBuffer.getBufferStart()));
1277+
uint64_t Magic = support::endian::byte_swap<uint64_t>(
1278+
*reinterpret_cast<const uint64_t *>(ObjectBuffer.getBufferStart()),
1279+
llvm::endianness::little);
12801280
if (Magic == TestingFormatMagic) {
12811281
// This is a special format used for testing.
12821282
auto ReaderOrErr =

llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
292292

293293
void TestingFormatWriter::write(raw_ostream &OS, TestingFormatVersion Version) {
294294
auto ByteSwap = [](uint64_t N) {
295-
return support::endian::byte_swap<uint64_t, llvm::endianness::little>(N);
295+
return support::endian::byte_swap<uint64_t>(N, llvm::endianness::little);
296296
};
297297

298298
// Output a 64bit magic number.

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void ProfOStream::patch(ArrayRef<PatchItem> P) {
292292
for (const auto &K : P) {
293293
for (int I = 0, E = K.D.size(); I != E; I++) {
294294
uint64_t Bytes =
295-
endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
295+
endian::byte_swap<uint64_t>(K.D[I], llvm::endianness::little);
296296
Data.replace(K.Pos + I * sizeof(uint64_t), sizeof(uint64_t),
297297
(const char *)&Bytes, sizeof(uint64_t));
298298
}

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,10 +1186,10 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
11861186
if (Version >= IndexedInstrProf::Version4) {
11871187
const IndexedInstrProf::Summary *SummaryInLE =
11881188
reinterpret_cast<const IndexedInstrProf::Summary *>(Cur);
1189-
uint64_t NFields = endian::byte_swap<uint64_t, llvm::endianness::little>(
1190-
SummaryInLE->NumSummaryFields);
1191-
uint64_t NEntries = endian::byte_swap<uint64_t, llvm::endianness::little>(
1192-
SummaryInLE->NumCutoffEntries);
1189+
uint64_t NFields = endian::byte_swap<uint64_t>(
1190+
SummaryInLE->NumSummaryFields, llvm::endianness::little);
1191+
uint64_t NEntries = endian::byte_swap<uint64_t>(
1192+
SummaryInLE->NumCutoffEntries, llvm::endianness::little);
11931193
uint32_t SummarySize =
11941194
IndexedInstrProf::Summary::getSize(NFields, NEntries);
11951195
std::unique_ptr<IndexedInstrProf::Summary> SummaryData =
@@ -1198,7 +1198,7 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
11981198
const uint64_t *Src = reinterpret_cast<const uint64_t *>(SummaryInLE);
11991199
uint64_t *Dst = reinterpret_cast<uint64_t *>(SummaryData.get());
12001200
for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
1201-
Dst[I] = endian::byte_swap<uint64_t, llvm::endianness::little>(Src[I]);
1201+
Dst[I] = endian::byte_swap<uint64_t>(Src[I], llvm::endianness::little);
12021202

12031203
SummaryEntryVector DetailedSummary;
12041204
for (unsigned I = 0; I < SummaryData->NumCutoffEntries; I++) {

0 commit comments

Comments
 (0)