Skip to content

Support macos #1120

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 2 commits into from
Jan 12, 2022
Merged

Support macos #1120

merged 2 commits into from
Jan 12, 2022

Conversation

isuruf
Copy link
Collaborator

@isuruf isuruf commented Aug 11, 2021

Replaces #592

@d-parks
Copy link

d-parks commented Aug 11, 2021

Alternatively instead of removing the avx and sse versions of ceil/floor, you might want to update the dispatch tables in libpgmath/lib/x86_64/math_tables/mth*.h to use the SSE and AVX entry points so that SSE/AVX transition penalties can be avoided when running on AVX systems (although newer Intel processors do not suffer from large transition penalties).

@isuruf
Copy link
Collaborator Author

isuruf commented Aug 11, 2021

@d-parks, I've taken a stab in the dark. Please have a look.

@isuruf isuruf force-pushed the macos branch 2 times, most recently from 24b2134 to d699efa Compare August 13, 2021 05:56
@isuruf
Copy link
Collaborator Author

isuruf commented Aug 13, 2021

@d-parks, can you take a look at d699efa?

@kiranchandramohan
Copy link
Collaborator

@isuruf Can you share the build instructions on Mac?

@isuruf
Copy link
Collaborator Author

isuruf commented Aug 23, 2021

@kiranchandramohan, it's the same as https://github.com/flang-compiler/flang/wiki/Building-Flang, but with /usr/bin/gcc replaced with /usr/bin/clang. You also need flang-compiler/classic-flang-llvm-project#57

Copy link
Collaborator

@pawosm-arm pawosm-arm left a comment

Choose a reason for hiding this comment

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

mix of everything in one PR. I'm giving +1 to this, let's see what others think.

Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

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

LGTM.

@bryanpkc
Copy link
Collaborator

I would suggest rebasing the branch to get rid of the merge commit, and to organize the changes into two commits, one for the MacOS-related changes, and one for the libpgmath changes.

- Check for clock_settime before using it
- use __fenv_feenableexcept() from flt_env.c instead of feenableexcept() since it doesn't exist on macOS
- Use POSIX limits.h
- no rt for macos
- Enable macos support
- don't declare bzero() as it's likely a macro
- Remove bad strcpy declaration
@isuruf
Copy link
Collaborator Author

isuruf commented Oct 23, 2021

Done

@bryanpkc bryanpkc self-requested a review November 17, 2021 16:00
Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -50,7 +50,11 @@ __ktrap(void)
excepts |= FE_UNDERFLOW;
if (bv & 0x100)
excepts |= FE_INEXACT;
#ifdef TARGET_OSX
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tried this on my mac. Neither of __fenv_feenableexcept() or feenableexcept() could be found...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like the function was moved from flangrti to libpgmath. https://github.com/flang-compiler/flang/blob/master/runtime/libpgmath/lib/common/fltfenv.c

@pawosm-arm
Copy link
Collaborator

I've tried to build classic flang on my mac for the first time. Some changes were needed:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 93dd9578..dbe363f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,8 +50,8 @@ elseif (${TARGET_ARCHITECTURE} MATCHES "^(aarch64|arm64)$")
   set(TARGET_ARCHITECTURE aarch64)
   set(ARCHNAME aarch64)
   set(ARCH ARM)
-  add_definitions(-DTARGET_SUPPORTS_QUADFP)
-  set(TARGET_SUPPORTS_QUADFP True)
+#  add_definitions(-DTARGET_SUPPORTS_QUADFP)
+#  set(TARGET_SUPPORTS_QUADFP True)
 elseif( ${TARGET_ARCHITECTURE} STREQUAL "ppc64le" )
   set(ARCHNAME ppc64le)
   set(ARCH POWER)
@@ -292,7 +292,7 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
   option(WITH_WERROR "Compile with '-Werror' C/C++ compiler flag" ON)
   if (WITH_WERROR)
-     set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Werror -Wno-error=sign-compare -Wno-error=pointer-sign -Wno-error=incompatible-pointer-types -Wno-error=string-conversion -Wno-error=c99-extensions -Wno-error=deprecated-register -Wno-error=format -Wno-error=format-pedantic -Wno-error=tautological-constant-out-of-range-compare -Wno-error=switch -Wno-error=covered-switch-default -Wno-error=enum-compare -Wno-error=char-subscripts -Wno-error=parentheses -Wno-error=array-bounds -Wno-error=fortify-source -Wno-error=comment")
+     set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Werror -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=pointer-sign -Wno-error=incompatible-pointer-types -Wno-error=string-conversion -Wno-error=c99-extensions -Wno-error=deprecated-register -Wno-error=format -Wno-error=format-pedantic -Wno-error=tautological-constant-out-of-range-compare -Wno-error=switch -Wno-error=covered-switch-default -Wno-error=enum-compare -Wno-error=char-subscripts -Wno-error=parentheses -Wno-error=array-bounds -Wno-error=fortify-source -Wno-error=comment")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=sign-compare -Wno-error=pointer-sign -Wno-error=incompatible-pointer-types -Wno-error=string-conversion -Wno-error=c99-extensions -Wno-error=deprecated-register -Wno-error=format -Wno-error=format-pedantic -Wno-error=tautological-constant-out-of-range-compare -Wno-error=switch -Wno-error=covered-switch-default -Wno-error=enum-compare -Wno-error=char-subscripts -Wno-error=parentheses -Wno-error=array-bounds -Wno-error=fortify-source -Wno-error=comment")
      if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 13)
        set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
diff --git a/runtime/flangrti/ktrap.c b/runtime/flangrti/ktrap.c
index 573152d6..308604cd 100644
--- a/runtime/flangrti/ktrap.c
+++ b/runtime/flangrti/ktrap.c
@@ -9,7 +9,7 @@
  *  \brief IEEE trap support
  */
 
-#ifndef TARGET_WIN
+#if !defined(TARGET_WIN) && !defined(TARGET_OSX)
 
 #include <fenv.h>
 
diff --git a/runtime/flangrti/tempnam.c b/runtime/flangrti/tempnam.c
index 7c6602f7..90541640 100644
--- a/runtime/flangrti/tempnam.c
+++ b/runtime/flangrti/tempnam.c
@@ -5,7 +5,7 @@
  *
  */
 
-#if !defined(WINNT) && !defined(USETEMPNAM) /* { */
+#if !defined(WINNT) && !defined(USETEMPNAM) && !defined(TARGET_OSX) /* { */
 #include <errno.h>
 #include <stdio.h>
 
diff --git a/runtime/libpgmath/CMakeLists.txt b/runtime/libpgmath/CMakeLists.txt
index dde2f682..f651ec9a 100644
--- a/runtime/libpgmath/CMakeLists.txt
+++ b/runtime/libpgmath/CMakeLists.txt
@@ -61,8 +61,8 @@ if(${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "aarch64" AND NOT ${LIBPGMATH_WITH_GENE
   else()
     message(STATUS "Libpgmath CPU target explicitly set to ${LLVM_FLANG_CPU_TARGET}")
   endif()
-  add_definitions(-DTARGET_SUPPORTS_QUADFP)
-  set(TARGET_SUPPORTS_QUADFP True)
+#  add_definitions(-DTARGET_SUPPORTS_QUADFP)
+#  set(TARGET_SUPPORTS_QUADFP True)
 endif()
 
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "x86_64|aarch64")
diff --git a/tools/flang2/flang2exe/expatomics.cpp b/tools/flang2/flang2exe/expatomics.cpp
index 995284d7..cbe94451 100644
--- a/tools/flang2/flang2exe/expatomics.cpp
+++ b/tools/flang2/flang2exe/expatomics.cpp
@@ -1778,7 +1778,7 @@ get_ops(MSZ msz, int is_openmp)
   }
 }
 
-#if TARGET_LLVM_ATOMICS
+#if TARGET_LLVM_ATOMICS && !defined(TARGET_OSX)
 /** Given a size operand, return corresponding MSZ if operand is a constant.
     Otherwise return MSZ_UNDEF. */
 static MSZ
diff --git a/tools/flang2/flang2exe/llassem.cpp b/tools/flang2/flang2exe/llassem.cpp
index ee85e464..0893dc9f 100644
--- a/tools/flang2/flang2exe/llassem.cpp
+++ b/tools/flang2/flang2exe/llassem.cpp
@@ -175,12 +175,6 @@ static SPTR bss_base;
 static char bss_name[MXIDLN];
 static LL_ObjToDbgList *bss_dbg_list;
 static int ag_ctors_cnt = 0;
-#if defined(TARGET_OSX)
-static int emitted_bss_name = 0;
-static int emitted_static_name = 0;
-static int emitted_outer_bss_name = 0;
-static int emitted_outer_static_name = 0;
-#endif
 static char outer_static_name[MXIDLN]; /* Fortran: name of STATIC area for outer
                                           function */
 static char contained_static_name[MXIDLN]; /* Fortran: name of STATIC area for

Also, just in case I've applied this: 8340731 and bunch of my PRs: #135 #546 and #1220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants