Skip to content

Commit 798ccd2

Browse files
[Support] Deprecate one form of support::endian::read (NFC) (llvm#160979)
This is a follow-up to llvm#156140, which deprecated one form of write. We have two forms of read: template <typename value_type, std::size_t alignment> [[nodiscard]] inline value_type read(const void *memory, endianness endian) template <typename value_type, endianness endian, std::size_t alignment> [[nodiscard]] inline value_type read(const void *memory) 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.
1 parent 3163fcf commit 798ccd2

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

llvm/include/llvm/Support/Endian.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ template <typename value_type, std::size_t alignment = unaligned>
6666
}
6767

6868
template <typename value_type, endianness endian, std::size_t alignment>
69-
[[nodiscard]] inline value_type read(const void *memory) {
69+
[[nodiscard]] LLVM_DEPRECATED("Pass endian as a function argument instead",
70+
"read") inline value_type
71+
read(const void *memory) {
7072
return read<value_type, alignment>(memory, endian);
7173
}
7274

@@ -127,7 +129,7 @@ template <typename value_type, endianness endian, std::size_t alignment>
127129
uint64_t startBit) {
128130
assert(startBit < 8);
129131
if (startBit == 0)
130-
return read<value_type, endian, alignment>(memory);
132+
return read<value_type, alignment>(memory, endian);
131133
else {
132134
// Read two values and compose the result from them.
133135
value_type val[2];
@@ -223,8 +225,8 @@ struct packed_endian_specific_integral {
223225
explicit packed_endian_specific_integral(value_type val) { *this = val; }
224226

225227
value_type value() const {
226-
return endian::read<value_type, endian, alignment>(
227-
(const void*)Value.buffer);
228+
return endian::read<value_type, alignment>((const void *)Value.buffer,
229+
endian);
228230
}
229231
operator value_type() const { return value(); }
230232

@@ -263,7 +265,7 @@ struct packed_endian_specific_integral {
263265
explicit ref(void *Ptr) : Ptr(Ptr) {}
264266

265267
operator value_type() const {
266-
return endian::read<value_type, endian, alignment>(Ptr);
268+
return endian::read<value_type, alignment>(Ptr, endian);
267269
}
268270

269271
void operator=(value_type NewValue) {

llvm/lib/CGData/CodeGenDataReader.cpp

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

172-
uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
173-
DataBuffer.getBufferStart());
172+
uint64_t Magic = endian::read<uint64_t, aligned>(DataBuffer.getBufferStart(),
173+
llvm::endianness::little);
174174
// Verify that it's magical.
175175
return Magic == IndexedCGData::Magic;
176176
}

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
11711171

11721172
if (DataBuffer.getBufferSize() < 8)
11731173
return false;
1174-
uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
1175-
DataBuffer.getBufferStart());
1174+
uint64_t Magic = endian::read<uint64_t, aligned>(DataBuffer.getBufferStart(),
1175+
llvm::endianness::little);
11761176
// Verify that it's magical.
11771177
return Magic == IndexedInstrProf::Magic;
11781178
}
@@ -1598,8 +1598,8 @@ Error IndexedInstrProfReader::getFunctionBitmap(StringRef FuncName,
15981598
std::memset(W, 0, sizeof(W));
15991599
std::memcpy(W, &BitmapBytes[I], N);
16001600
I += N;
1601-
return support::endian::read<XTy, llvm::endianness::little,
1602-
support::aligned>(W);
1601+
return support::endian::read<XTy, support::aligned>(
1602+
W, llvm::endianness::little);
16031603
},
16041604
Bitmap, Bitmap);
16051605
assert(I == E);

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,8 @@ SampleProfileReaderExtBinaryBase::readNameTableSec(bool IsMD5,
12901290
NameTable.reserve(*Size);
12911291
for (size_t I = 0; I < *Size; ++I) {
12921292
using namespace support;
1293-
uint64_t FID = endian::read<uint64_t, endianness::little, unaligned>(
1294-
Data + I * sizeof(uint64_t));
1293+
uint64_t FID = endian::read<uint64_t, unaligned>(
1294+
Data + I * sizeof(uint64_t), endianness::little);
12951295
NameTable.emplace_back(FunctionId(FID));
12961296
}
12971297
if (!ProfileIsCS)

llvm/unittests/Support/EndianTest.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ TEST(Endian, Read) {
2424
unsigned char littleval[] = {0x00, 0x04, 0x03, 0x02, 0x01};
2525
int32_t BigAsHost = 0x00010203;
2626
EXPECT_EQ(BigAsHost,
27-
(endian::read<int32_t, llvm::endianness::big, unaligned>(bigval)));
27+
(endian::read<int32_t, unaligned>(bigval, llvm::endianness::big)));
2828
int32_t LittleAsHost = 0x02030400;
29-
EXPECT_EQ(
30-
LittleAsHost,
31-
(endian::read<int32_t, llvm::endianness::little, unaligned>(littleval)));
29+
EXPECT_EQ(LittleAsHost, (endian::read<int32_t, unaligned>(
30+
littleval, llvm::endianness::little)));
3231

3332
EXPECT_EQ(
34-
(endian::read<int32_t, llvm::endianness::big, unaligned>(bigval + 1)),
35-
(endian::read<int32_t, llvm::endianness::little, unaligned>(littleval +
36-
1)));
33+
(endian::read<int32_t, unaligned>(bigval + 1, llvm::endianness::big)),
34+
(endian::read<int32_t, unaligned>(littleval + 1,
35+
llvm::endianness::little)));
3736
}
3837

3938
TEST(Endian, WriteNext) {

0 commit comments

Comments
 (0)