Skip to content

[Support] Redefine endianness::native #67876

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 1 commit into from
Oct 4, 2023
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
8 changes: 6 additions & 2 deletions llvm/include/llvm/Support/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
namespace llvm {
namespace support {

enum endianness {big, little, native};
enum endianness {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to make it enum class at some point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed. I'm planning to do that. Thank you for the review!

big,
little,
native = llvm::sys::IsBigEndianHost ? big : little
};

// These are named values for common alignments.
enum {aligned = 0, unaligned = 1};
Expand All @@ -47,7 +51,7 @@ constexpr endianness system_endianness() {

template <typename value_type>
[[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) {
if ((endian != native) && (endian != system_endianness()))
if (endian != native)
sys::swapByteOrder(value);
return value;
}
Expand Down
12 changes: 1 addition & 11 deletions llvm/include/llvm/Support/HashBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@ template <typename HasherT> class HashBuilderBase {
};

/// Implementation of the `HashBuilder` interface.
///
/// `support::endianness::native` is not supported. `HashBuilder` is
/// expected to canonicalize `support::endianness::native` to one of
/// `support::endianness::big` or `support::endianness::little`.
template <typename HasherT, support::endianness Endianness>
class HashBuilderImpl : public HashBuilderBase<HasherT> {
static_assert(Endianness != support::endianness::native,
"HashBuilder should canonicalize endianness");

public:
explicit HashBuilderImpl(HasherT &Hasher)
: HashBuilderBase<HasherT>(Hasher) {}
Expand Down Expand Up @@ -395,10 +388,7 @@ class HashBuilderImpl : public HashBuilderBase<HasherT> {
/// Specifiying a non-`native` `Endianness` template parameter allows to compute
/// stable hash across platforms with different endianness.
template <class HasherT, support::endianness Endianness>
using HashBuilder =
HashBuilderImpl<HasherT, (Endianness == support::endianness::native
? support::endian::system_endianness()
: Endianness)>;
using HashBuilder = HashBuilderImpl<HasherT, Endianness>;

namespace hashbuilder_detail {
class HashCodeHasher {
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ void writeImmediate(WritableArmRelocation &R, uint32_t Imm) {

Expected<int64_t> readAddendData(LinkGraph &G, Block &B, const Edge &E) {
support::endianness Endian = G.getEndianness();
assert(Endian != support::native && "Declare as little or big explicitly");

Edge::Kind Kind = E.getKind();
const char *BlockWorkingMem = B.getContent().data();
Expand Down Expand Up @@ -404,7 +403,6 @@ Error applyFixupData(LinkGraph &G, Block &B, const Edge &E) {
char *FixupPtr = BlockWorkingMem + E.getOffset();

auto Write32 = [FixupPtr, Endian = G.getEndianness()](int64_t Value) {
assert(Endian != native && "Must be explicit: little or big");
assert(isInt<32>(Value) && "Must be in signed 32-bit range");
uint32_t Imm = static_cast<int32_t>(Value);
if (LLVM_LIKELY(Endian == little))
Expand Down