[flang-commits] [flang] [flang][NFC] Use LLVM's endianness enum (PR #86516)

via flang-commits flang-commits at lists.llvm.org
Tue Mar 26 14:31:22 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-runtime

Author: Tarun Prabhu (tarunprabhu)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/86516.diff


3 Files Affected:

- (modified) flang/include/flang/Common/uint128.h (+3-4) 
- (modified) flang/include/flang/Evaluate/common.h (+3-7) 
- (modified) flang/runtime/environment.h (+4-7) 


``````````diff
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 };

``````````

</details>


https://github.com/llvm/llvm-project/pull/86516


More information about the flang-commits mailing list