-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Support] Deprecate one form of support::endian::read (NFC) #160979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Support] Deprecate one form of support::endian::read (NFC) #160979
Conversation
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.
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesThis 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> template <typename value_type, endianness endian, std::size_t alignment> The difference is that endian is a function parameter in the former This patch streamlines the code by migrating the use of the latter to Full diff: https://github.com/llvm/llvm-project/pull/160979.diff 5 Files Affected:
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) {
|
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.
…1045) 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.
) 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.
…m#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.
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.