[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.
This commit is contained in:
parent
3163fcfa45
commit
798ccd2e47
@ -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 @@ public:
|
||||
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) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user