Skip to content
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
40 changes: 13 additions & 27 deletions flang/cmake/modules/FlangCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,16 @@ if (FLANG_RUNTIME_F128_MATH_LIB)
add_compile_definitions(FLANG_RUNTIME_F128_MATH_LIB="${FLANG_RUNTIME_F128_MATH_LIB}")
endif()

# The NVPTX target can't emit a binary due to the PTXAS dependency, just
# hard-code this.
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
else ()
# Check if 128-bit float computations can be done via long double
# Note that '-nostdinc++' might be implied when this code kicks in
# (see 'runtimes/CMakeLists.txt'), so we cannot use 'cfloat' C++ header
# file in the test below.
# Compile it as C.
check_c_source_compiles(
"#include <float.h>
#if LDBL_MANT_DIG != 113
#error LDBL_MANT_DIG != 113
#endif
int main() { return 0; }
"
HAVE_LDBL_MANT_DIG_113)

include(TestBigEndian)
test_big_endian(IS_BIGENDIAN)
if (IS_BIGENDIAN)
add_compile_definitions(FLANG_BIG_ENDIAN=1)
else ()
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
endif ()
endif ()
# Check if 128-bit float computations can be done via long double
# Note that '-nostdinc++' might be implied when this code kicks in
# (see 'runtimes/CMakeLists.txt'), so we cannot use 'cfloat' C++ header
# file in the test below.
# Compile it as C.
check_c_source_compiles(
"#include <float.h>
#if LDBL_MANT_DIG != 113
#error LDBL_MANT_DIG != 113
#endif
int main() { return 0; }
"
HAVE_LDBL_MANT_DIG_113)
17 changes: 17 additions & 0 deletions flang/include/flang/Common/api-attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,21 @@
#define RT_OPTNONE_ATTR
#endif

/* Detect system endianness if it was not explicitly set. */
#if !defined(FLANG_LITTLE_ENDIAN) && !defined(FLANG_BIG_ENDIAN)

/* We always assume Windows is little endian, otherwise use the GCC compatible
* flags. */
#if defined(_MSC_VER) || defined(_WIN32)
#define FLANG_LITTLE_ENDIAN 1
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define FLANG_LITTLE_ENDIAN 1
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define FLANG_BIG_ENDIAN 1
#else
#error "Unknown or unsupported endianness."
#endif

#endif /* !defined(FLANG_LITTLE_ENDIAN) && !defined(FLANG_BIG_ENDIAN) */

#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */
1 change: 1 addition & 0 deletions flang/include/flang/Evaluate/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef FORTRAN_EVALUATE_COMMON_H_
#define FORTRAN_EVALUATE_COMMON_H_

#include "flang/Common/api-attrs.h"
#include "flang/Common/enum-set.h"
#include "flang/Common/idioms.h"
#include "flang/Common/indirection.h"
Expand Down