Skip to content

[ProfileData] Remove swapToHostOrder #94665

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/Support/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ template <typename value_type, endianness endian, std::size_t alignment>

/// Read a value of a particular endianness from a buffer, and increment the
/// buffer past that value.
template <typename value_type, std::size_t alignment, typename CharT>
template <typename value_type, std::size_t alignment = unaligned,
typename CharT>
[[nodiscard]] inline value_type readNext(const CharT *&memory,
endianness endian) {
value_type ret = read<value_type, alignment>(memory, endian);
Expand Down
13 changes: 2 additions & 11 deletions llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,16 +1176,6 @@ void ValueProfData::deserializeTo(InstrProfRecord &Record,
}
}

template <class T>
static T swapToHostOrder(const unsigned char *&D, llvm::endianness Orig) {
using namespace support;

if (Orig == llvm::endianness::little)
return endian::readNext<T, llvm::endianness::little>(D);
else
return endian::readNext<T, llvm::endianness::big>(D);
}

static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
ValueProfData());
Expand Down Expand Up @@ -1224,7 +1214,8 @@ ValueProfData::getValueProfData(const unsigned char *D,
return make_error<InstrProfError>(instrprof_error::truncated);

const unsigned char *Header = D;
uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
uint32_t TotalSize = endian::readNext<uint32_t>(Header, Endianness);

if (D + TotalSize > BufferEnd)
return make_error<InstrProfError>(instrprof_error::too_large);

Expand Down
Loading