-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[flang][NFC] Use LLVM's endianness enum #86516
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
base: main
Are you sure you want to change the base?
Conversation
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.
✅ With the latest revision this PR passed the Python code formatter. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
std::uint64_t high_{0}, low_{0}; | ||
#else | ||
#error host endianness is not known | ||
std::uint64_t low_{0}, high_{0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're just defaulting to little-endianness here if BYTE_ORDER
is undefined. This can be worse than the current situation.
#else | ||
#error host endianness is not known | ||
#endif | ||
constexpr bool isHostLittleEndian = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This initialization should use braces and does not need parentheses.
@llvm/pr-subscribers-flang-semantics @llvm/pr-subscribers-flang-runtime Author: Tarun Prabhu (tarunprabhu) ChangesReplace 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:
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 };
|
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.