Skip to content

Commit 6e36000

Browse files
Merge pull request swiftlang#11903 from swiftlang/jepa-stable
[stable/21.x] Cherry-pick some upstream deprecations in `support::endian`
2 parents 535235b + d9712f6 commit 6e36000

File tree

15 files changed

+66
-64
lines changed

15 files changed

+66
-64
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: 16 additions & 12 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

@@ -66,7 +68,9 @@ template <typename value_type, std::size_t alignment = unaligned>
6668
}
6769

6870
template <typename value_type, endianness endian, std::size_t alignment>
69-
[[nodiscard]] inline value_type read(const void *memory) {
71+
[[nodiscard]] LLVM_DEPRECATED("Pass endian as a function argument instead",
72+
"read") inline value_type
73+
read(const void *memory) {
7074
return read<value_type, alignment>(memory, endian);
7175
}
7276

@@ -128,16 +132,16 @@ template <typename value_type, endianness endian, std::size_t alignment>
128132
uint64_t startBit) {
129133
assert(startBit < 8);
130134
if (startBit == 0)
131-
return read<value_type, endian, alignment>(memory);
135+
return read<value_type, alignment>(memory, endian);
132136
else {
133137
// Read two values and compose the result from them.
134138
value_type val[2];
135139
memcpy(&val[0],
136140
LLVM_ASSUME_ALIGNED(
137141
memory, (detail::PickAlignment<value_type, alignment>::value)),
138142
sizeof(value_type) * 2);
139-
val[0] = byte_swap<value_type, endian>(val[0]);
140-
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);
141145

142146
// Shift bits from the lower value into place.
143147
make_unsigned_t<value_type> lowerVal = val[0] >> startBit;
@@ -171,8 +175,8 @@ inline void writeAtBitAlignment(void *memory, value_type value,
171175
LLVM_ASSUME_ALIGNED(
172176
memory, (detail::PickAlignment<value_type, alignment>::value)),
173177
sizeof(value_type) * 2);
174-
val[0] = byte_swap<value_type, endian>(val[0]);
175-
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);
176180

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

202206
// Finally, rewrite values.
203-
val[0] = byte_swap<value_type, endian>(val[0]);
204-
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);
205209
memcpy(LLVM_ASSUME_ALIGNED(
206210
memory, (detail::PickAlignment<value_type, alignment>::value)),
207211
&val[0], sizeof(value_type) * 2);
@@ -224,8 +228,8 @@ struct packed_endian_specific_integral {
224228
explicit packed_endian_specific_integral(value_type val) { *this = val; }
225229

226230
value_type value() const {
227-
return endian::read<value_type, endian, alignment>(
228-
(const void*)Value.buffer);
231+
return endian::read<value_type, alignment>((const void *)Value.buffer,
232+
endian);
229233
}
230234
operator value_type() const { return value(); }
231235

@@ -264,7 +268,7 @@ struct packed_endian_specific_integral {
264268
explicit ref(void *Ptr) : Ptr(Ptr) {}
265269

266270
operator value_type() const {
267-
return endian::read<value_type, endian, alignment>(Ptr);
271+
return endian::read<value_type, alignment>(Ptr, endian);
268272
}
269273

270274
void operator=(value_type NewValue) {

llvm/lib/CGData/CodeGenDataReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ bool IndexedCodeGenDataReader::hasFormat(const MemoryBuffer &DataBuffer) {
154154
if (DataBuffer.getBufferSize() < sizeof(IndexedCGData::Magic))
155155
return false;
156156

157-
uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
158-
DataBuffer.getBufferStart());
157+
uint64_t Magic = endian::read<uint64_t, aligned>(DataBuffer.getBufferStart(),
158+
llvm::endianness::little);
159159
// Verify that it's magical.
160160
return Magic == IndexedCGData::Magic;
161161
}

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
}

0 commit comments

Comments
 (0)