[flang-commits] [flang] [flang][NFC] Use LLVM's endianness enum (PR #86516)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Mon Mar 25 08:44:48 PDT 2024
https://github.com/tarunprabhu created https://github.com/llvm/llvm-project/pull/86516
Replace the FLANG_LITTLE_ENDIAN and FLANG_BIG_ENDIAN preprocessor defines with equivalents from LLVM. This ensures that tools that use flang's headers are not required to provide these preorocessor defines themselves.
>From dc9f7641219e6bbc7e7b5ab0386d6ae40f84452c Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun at lanl.gov>
Date: Mon, 25 Mar 2024 09:40:27 -0600
Subject: [PATCH] [flang][NFC] Use LLVM's endianness enum
Replace the FLANG_LITTLE_ENDIAN and FLANG_BIG_ENDIAN preprocessor defines with
equivalents from LLVM. This ensures that tools that use flang's headers are
not required to provide these preorocessor defines themselves.
---
flang/include/flang/Common/uint128.h | 7 +++----
flang/include/flang/Evaluate/common.h | 10 +++-------
flang/runtime/environment.h | 11 ++++-------
3 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/flang/include/flang/Common/uint128.h b/flang/include/flang/Common/uint128.h
index 03e44eb6997d5b..4a9e5fb2e44c00 100644
--- a/flang/include/flang/Common/uint128.h
+++ b/flang/include/flang/Common/uint128.h
@@ -20,6 +20,7 @@
#endif
#include "leading-zero-bit-count.h"
+#include "llvm/ADT/bit.h"
#include <cstdint>
#include <type_traits>
@@ -261,12 +262,10 @@ template <bool IS_SIGNED = false> class Int128 {
}
}
static constexpr std::uint64_t topBit{std::uint64_t{1} << 63};
-#if FLANG_LITTLE_ENDIAN
- std::uint64_t low_{0}, high_{0};
-#elif FLANG_BIG_ENDIAN
+#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
std::uint64_t high_{0}, low_{0};
#else
-#error host endianness is not known
+ std::uint64_t low_{0}, high_{0};
#endif
};
diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h
index d04c901929e74b..39f63311e7944e 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -18,6 +18,7 @@
#include "flang/Common/restorer.h"
#include "flang/Parser/char-block.h"
#include "flang/Parser/message.h"
+#include "llvm/ADT/bit.h"
#include <cinttypes>
#include <map>
#include <set>
@@ -142,13 +143,8 @@ template <typename A> struct ValueWithRealFlags {
RealFlags flags{};
};
-#if FLANG_BIG_ENDIAN
-constexpr bool isHostLittleEndian{false};
-#elif FLANG_LITTLE_ENDIAN
-constexpr bool isHostLittleEndian{true};
-#else
-#error host endianness is not known
-#endif
+constexpr bool isHostLittleEndian =
+ (llvm::endianness::native == llvm::endianness::little);
// HostUnsignedInt<BITS> finds the smallest native unsigned integer type
// whose size is >= BITS.
diff --git a/flang/runtime/environment.h b/flang/runtime/environment.h
index 9bc1158509615f..f42312d73f439c 100644
--- a/flang/runtime/environment.h
+++ b/flang/runtime/environment.h
@@ -12,19 +12,16 @@
#include "flang/Common/optional.h"
#include "flang/Decimal/decimal.h"
+#include "llvm/ADT/bit.h"
+
struct EnvironmentDefaultList;
namespace Fortran::runtime {
class Terminator;
-#if FLANG_BIG_ENDIAN
-constexpr bool isHostLittleEndian{false};
-#elif FLANG_LITTLE_ENDIAN
-constexpr bool isHostLittleEndian{true};
-#else
-#error host endianness is not known
-#endif
+constexpr bool isHostLittleEndian =
+ (llvm::endianness::native == llvm::endianness::little);
// External unformatted I/O data conversions
enum class Convert { Unknown, Native, LittleEndian, BigEndian, Swap };
More information about the flang-commits
mailing list