Skip to content

Commit 7476c20

Browse files
[ProfileData] Remove swapToHostOrder (#94665)
This patch removes swapToHostOrder in favor of llvm::support::endian::readNext as swapToHostOrder is too thin a wrapper around readNext. Note that there are two variants of readNext: - readNext<type, endian, align>(ptr) - readNext<type, align>(ptr, endian) swapToHostOrder uses the former, but this patch switches to the latter. While we are at it, this patch teaches readNext to default to unaligned just as I did in: commit 568368a Author: Kazu Hirata <[email protected]> Date: Mon Apr 15 19:05:30 2024 -0700
1 parent fbcb92c commit 7476c20

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

llvm/include/llvm/Support/Endian.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ template <typename value_type, endianness endian, std::size_t alignment>
7272

7373
/// Read a value of a particular endianness from a buffer, and increment the
7474
/// buffer past that value.
75-
template <typename value_type, std::size_t alignment, typename CharT>
75+
template <typename value_type, std::size_t alignment = unaligned,
76+
typename CharT>
7677
[[nodiscard]] inline value_type readNext(const CharT *&memory,
7778
endianness endian) {
7879
value_type ret = read<value_type, alignment>(memory, endian);

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,16 +1176,6 @@ void ValueProfData::deserializeTo(InstrProfRecord &Record,
11761176
}
11771177
}
11781178

1179-
template <class T>
1180-
static T swapToHostOrder(const unsigned char *&D, llvm::endianness Orig) {
1181-
using namespace support;
1182-
1183-
if (Orig == llvm::endianness::little)
1184-
return endian::readNext<T, llvm::endianness::little>(D);
1185-
else
1186-
return endian::readNext<T, llvm::endianness::big>(D);
1187-
}
1188-
11891179
static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
11901180
return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
11911181
ValueProfData());
@@ -1224,7 +1214,8 @@ ValueProfData::getValueProfData(const unsigned char *D,
12241214
return make_error<InstrProfError>(instrprof_error::truncated);
12251215

12261216
const unsigned char *Header = D;
1227-
uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
1217+
uint32_t TotalSize = endian::readNext<uint32_t>(Header, Endianness);
1218+
12281219
if (D + TotalSize > BufferEnd)
12291220
return make_error<InstrProfError>(instrprof_error::too_large);
12301221

0 commit comments

Comments
 (0)