Skip to content

Commit d9712f6

Browse files
kazutakahirataAnthonyLatsis
authored andcommitted
[Support] Deprecate one form of support::endian::byte_swap (NFC) (llvm#161045)
This is a follow-up to llvm#156140 and llvm#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. (cherry picked from commit 9a5671e)
1 parent 1695406 commit d9712f6

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
@@ -1216,19 +1216,19 @@ namespace accessors {
12161216
/// Return the structural hash associated with the function.
12171217
template <class FuncRecordTy, llvm::endianness Endian>
12181218
uint64_t getFuncHash(const FuncRecordTy *Record) {
1219-
return support::endian::byte_swap<uint64_t, Endian>(Record->FuncHash);
1219+
return support::endian::byte_swap<uint64_t>(Record->FuncHash, Endian);
12201220
}
12211221

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

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

12341234
/// Return the PGO name of the function. Used for formats in which the name is
@@ -1281,14 +1281,14 @@ struct CovMapFunctionRecordV1 {
12811281

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

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

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

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

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

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

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

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

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

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

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

204206
// Finally, rewrite values.
205-
val[0] = byte_swap<value_type, endian>(val[0]);
206-
val[1] = byte_swap<value_type, endian>(val[1]);
207+
val[0] = byte_swap<value_type>(val[0], endian);
208+
val[1] = byte_swap<value_type>(val[1], endian);
207209
memcpy(LLVM_ASSUME_ALIGNED(
208210
memory, (detail::PickAlignment<value_type, alignment>::value)),
209211
&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
@@ -22,9 +22,8 @@ static uint32_t writePlaceholder(raw_svector_ostream &Stream) {
2222

2323
static void rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
2424
uint32_t Offset) {
25-
uint32_t Value =
26-
support::endian::byte_swap<uint32_t, llvm::endianness::little>(
27-
Stream.tell());
25+
uint32_t Value = support::endian::byte_swap<uint32_t>(
26+
Stream.tell(), llvm::endianness::little);
2827
Stream.pwrite(reinterpret_cast<const char *>(&Value), sizeof(Value), Offset);
2928
}
3029

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)