[llvm] 798ccd2 - [Support] Deprecate one form of support::endian::read (NFC) (#160979)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 27 09:05:20 PDT 2025
Author: Kazu Hirata
Date: 2025-09-27T09:05:16-07:00
New Revision: 798ccd2e4722b228317e8a30dd3624a0308a927e
URL: https://github.com/llvm/llvm-project/commit/798ccd2e4722b228317e8a30dd3624a0308a927e
DIFF: https://github.com/llvm/llvm-project/commit/798ccd2e4722b228317e8a30dd3624a0308a927e.diff
LOG: [Support] Deprecate one form of support::endian::read (NFC) (#160979)
This is a follow-up to #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.
Added:
Modified:
llvm/include/llvm/Support/Endian.h
llvm/lib/CGData/CodeGenDataReader.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/lib/ProfileData/SampleProfReader.cpp
llvm/unittests/Support/EndianTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h
index 7eb1d7e8dfe7f..6c86feb78053c 100644
--- a/llvm/include/llvm/Support/Endian.h
+++ b/llvm/include/llvm/Support/Endian.h
@@ -66,7 +66,9 @@ template <typename value_type, std::size_t alignment = unaligned>
}
template <typename value_type, endianness endian, std::size_t alignment>
-[[nodiscard]] inline value_type read(const void *memory) {
+[[nodiscard]] LLVM_DEPRECATED("Pass endian as a function argument instead",
+ "read") inline value_type
+ read(const void *memory) {
return read<value_type, alignment>(memory, endian);
}
@@ -127,7 +129,7 @@ template <typename value_type, endianness endian, std::size_t alignment>
uint64_t startBit) {
assert(startBit < 8);
if (startBit == 0)
- return read<value_type, endian, alignment>(memory);
+ return read<value_type, alignment>(memory, endian);
else {
// Read two values and compose the result from them.
value_type val[2];
@@ -223,8 +225,8 @@ struct packed_endian_specific_integral {
explicit packed_endian_specific_integral(value_type val) { *this = val; }
value_type value() const {
- return endian::read<value_type, endian, alignment>(
- (const void*)Value.buffer);
+ return endian::read<value_type, alignment>((const void *)Value.buffer,
+ endian);
}
operator value_type() const { return value(); }
@@ -263,7 +265,7 @@ struct packed_endian_specific_integral {
explicit ref(void *Ptr) : Ptr(Ptr) {}
operator value_type() const {
- return endian::read<value_type, endian, alignment>(Ptr);
+ return endian::read<value_type, alignment>(Ptr, endian);
}
void operator=(value_type NewValue) {
diff --git a/llvm/lib/CGData/CodeGenDataReader.cpp b/llvm/lib/CGData/CodeGenDataReader.cpp
index fc59be8df525a..3fd8cfe1a8762 100644
--- a/llvm/lib/CGData/CodeGenDataReader.cpp
+++ b/llvm/lib/CGData/CodeGenDataReader.cpp
@@ -169,8 +169,8 @@ bool IndexedCodeGenDataReader::hasFormat(const MemoryBuffer &DataBuffer) {
if (DataBuffer.getBufferSize() < sizeof(IndexedCGData::Magic))
return false;
- uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
- DataBuffer.getBufferStart());
+ uint64_t Magic = endian::read<uint64_t, aligned>(DataBuffer.getBufferStart(),
+ llvm::endianness::little);
// Verify that it's magical.
return Magic == IndexedCGData::Magic;
}
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 886add7131da2..1da92eafa4b4a 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -1171,8 +1171,8 @@ bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
if (DataBuffer.getBufferSize() < 8)
return false;
- uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
- DataBuffer.getBufferStart());
+ uint64_t Magic = endian::read<uint64_t, aligned>(DataBuffer.getBufferStart(),
+ llvm::endianness::little);
// Verify that it's magical.
return Magic == IndexedInstrProf::Magic;
}
@@ -1598,8 +1598,8 @@ Error IndexedInstrProfReader::getFunctionBitmap(StringRef FuncName,
std::memset(W, 0, sizeof(W));
std::memcpy(W, &BitmapBytes[I], N);
I += N;
- return support::endian::read<XTy, llvm::endianness::little,
- support::aligned>(W);
+ return support::endian::read<XTy, support::aligned>(
+ W, llvm::endianness::little);
},
Bitmap, Bitmap);
assert(I == E);
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 81ae792e70b99..766c0814ca067 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -1290,8 +1290,8 @@ SampleProfileReaderExtBinaryBase::readNameTableSec(bool IsMD5,
NameTable.reserve(*Size);
for (size_t I = 0; I < *Size; ++I) {
using namespace support;
- uint64_t FID = endian::read<uint64_t, endianness::little, unaligned>(
- Data + I * sizeof(uint64_t));
+ uint64_t FID = endian::read<uint64_t, unaligned>(
+ Data + I * sizeof(uint64_t), endianness::little);
NameTable.emplace_back(FunctionId(FID));
}
if (!ProfileIsCS)
diff --git a/llvm/unittests/Support/EndianTest.cpp b/llvm/unittests/Support/EndianTest.cpp
index c48b7707b7751..0ee631db74ac1 100644
--- a/llvm/unittests/Support/EndianTest.cpp
+++ b/llvm/unittests/Support/EndianTest.cpp
@@ -24,16 +24,15 @@ TEST(Endian, Read) {
unsigned char littleval[] = {0x00, 0x04, 0x03, 0x02, 0x01};
int32_t BigAsHost = 0x00010203;
EXPECT_EQ(BigAsHost,
- (endian::read<int32_t, llvm::endianness::big, unaligned>(bigval)));
+ (endian::read<int32_t, unaligned>(bigval, llvm::endianness::big)));
int32_t LittleAsHost = 0x02030400;
- EXPECT_EQ(
- LittleAsHost,
- (endian::read<int32_t, llvm::endianness::little, unaligned>(littleval)));
+ EXPECT_EQ(LittleAsHost, (endian::read<int32_t, unaligned>(
+ littleval, llvm::endianness::little)));
EXPECT_EQ(
- (endian::read<int32_t, llvm::endianness::big, unaligned>(bigval + 1)),
- (endian::read<int32_t, llvm::endianness::little, unaligned>(littleval +
- 1)));
+ (endian::read<int32_t, unaligned>(bigval + 1, llvm::endianness::big)),
+ (endian::read<int32_t, unaligned>(littleval + 1,
+ llvm::endianness::little)));
}
TEST(Endian, WriteNext) {
More information about the llvm-commits
mailing list