[llvm-branch-commits] [openmp] 63be0bc - [OpenMP][libomp] Detect if test compiler has omp.h

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 9 04:32:46 PDT 2022


Author: Jonathan Peyton
Date: 2022-08-09T13:30:31+02:00
New Revision: 63be0bcb6d302910e11df2c305ed707ca6ee7421

URL: https://github.com/llvm/llvm-project/commit/63be0bcb6d302910e11df2c305ed707ca6ee7421
DIFF: https://github.com/llvm/llvm-project/commit/63be0bcb6d302910e11df2c305ed707ca6ee7421.diff

LOG: [OpenMP][libomp] Detect if test compiler has omp.h

omp50_taskdep_depobj.c relies on the test compiler's omp.h file.
If the test compiler does not have an omp.h file, then use the one
within the build tree.

Fixes: https://github.com/llvm/llvm-project/issues/56820
Differential Revision: https://reviews.llvm.org/D131000

(cherry picked from commit 9cf6511bff97007401238f6cff6bf80cb9af04a5)

Added: 
    

Modified: 
    openmp/cmake/DetectTestCompiler/CMakeLists.txt
    openmp/cmake/OpenMPTesting.cmake
    openmp/runtime/test/CMakeLists.txt
    openmp/runtime/test/lit.cfg
    openmp/runtime/test/lit.site.cfg.in

Removed: 
    


################################################################################
diff  --git a/openmp/cmake/DetectTestCompiler/CMakeLists.txt b/openmp/cmake/DetectTestCompiler/CMakeLists.txt
index c8afd47a2b3bf..dc709f59684a8 100644
--- a/openmp/cmake/DetectTestCompiler/CMakeLists.txt
+++ b/openmp/cmake/DetectTestCompiler/CMakeLists.txt
@@ -3,6 +3,8 @@ project(DetectTestCompiler C CXX)
 
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
+include(CheckIncludeFile)
+include(CheckIncludeFileCXX)
 
 function(write_compiler_information lang)
   set(information "${CMAKE_${lang}_COMPILER}")
@@ -11,6 +13,7 @@ function(write_compiler_information lang)
   set(information "${information}\\;${${lang}_FLAGS}")
   set(information "${information}\\;${${lang}_HAS_TSAN_FLAG}")
   set(information "${information}\\;${${lang}_HAS_OMIT_FRAME_POINTER}")
+  set(information "${information}\\;${${lang}_HAS_OMP_H}")
   file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information})
 endfunction(write_compiler_information)
 
@@ -44,9 +47,15 @@ endif()
 check_c_compiler_flag("-fno-omit-frame-pointer" C_HAS_OMIT_FRAME_POINTER)
 check_cxx_compiler_flag("-fno-omit-frame-pointer" CXX_HAS_OMIT_FRAME_POINTER)
 
-SET(CMAKE_REQUIRED_FLAGS "-fsanitize=thread")
+set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+set(CMAKE_REQUIRED_FLAGS "-fsanitize=thread")
 check_c_compiler_flag("" C_HAS_TSAN_FLAG)
 check_cxx_compiler_flag("" CXX_HAS_TSAN_FLAG)
+set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+
+# Check if omp.h header exists for the test compiler
+check_include_file_cxx(omp.h CXX_HAS_OMP_H)
+check_include_file(omp.h C_HAS_OMP_H)
 
 write_compiler_information(C)
 write_compiler_information(CXX)

diff  --git a/openmp/cmake/OpenMPTesting.cmake b/openmp/cmake/OpenMPTesting.cmake
index 0370b5feaccd7..1a9e0ded01aa2 100644
--- a/openmp/cmake/OpenMPTesting.cmake
+++ b/openmp/cmake/OpenMPTesting.cmake
@@ -77,6 +77,7 @@ macro(extract_test_compiler_information lang file)
   list(GET information 3 openmp_flags)
   list(GET information 4 has_tsan_flags)
   list(GET information 5 has_omit_frame_pointer_flags)
+  list(GET information 6 has_omp_h)
 
   set(OPENMP_TEST_${lang}_COMPILER_PATH ${path})
   set(OPENMP_TEST_${lang}_COMPILER_ID ${id})
@@ -84,6 +85,7 @@ macro(extract_test_compiler_information lang file)
   set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags})
   set(OPENMP_TEST_${lang}_COMPILER_HAS_TSAN_FLAGS ${has_tsan_flags})
   set(OPENMP_TEST_${lang}_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS ${has_omit_frame_pointer_flags})
+  set(OPENMP_TEST_${lang}_COMPILER_HAS_OMP_H ${has_omp_h})
 endmacro()
 
 # Function to set variables with information about the test compiler.
@@ -101,6 +103,7 @@ function(set_test_compiler_information dir)
     set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE)
     set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_TSAN_FLAGS}" PARENT_SCOPE)
     set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS}" PARENT_SCOPE)
+    set(OPENMP_TEST_COMPILER_HAS_OMP_H "${OPENMP_TEST_C_COMPILER_HAS_OMP_H}" PARENT_SCOPE)
 
     # Determine major version.
     string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}")
@@ -150,6 +153,7 @@ else()
   else()
     set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0)
   endif()
+  set(OPENMP_TEST_COMPILER_HAS_OMP_H 1)
   # TODO: Implement blockaddress in GlobalISel and remove this flag!
   set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS} -fno-experimental-isel")
   set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1)

diff  --git a/openmp/runtime/test/CMakeLists.txt b/openmp/runtime/test/CMakeLists.txt
index aa9a3732d8aa0..71680a31ae256 100644
--- a/openmp/runtime/test/CMakeLists.txt
+++ b/openmp/runtime/test/CMakeLists.txt
@@ -31,6 +31,7 @@ pythonize_bool(LIBOMP_HAVE_LIBM)
 pythonize_bool(LIBOMP_HAVE_LIBATOMIC)
 pythonize_bool(OPENMP_STANDALONE_BUILD)
 pythonize_bool(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS)
+pythonize_bool(OPENMP_TEST_COMPILER_HAS_OMP_H)
 
 add_library(ompt-print-callback INTERFACE)
 target_include_directories(ompt-print-callback INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/ompt)

diff  --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index b000787409ef6..fe1886b711c86 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -140,7 +140,7 @@ config.substitutions.append(("%clang", config.test_c_compiler))
 config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
 # %flags-use-compiler-omp-h allows us to use the test compiler's omp.h file which
 # may have 
diff erent definitions of structures than our omp.h file.
-if config.is_standalone_build:
+if config.is_standalone_build and config.test_compiler_has_omp_h:
     config.substitutions.append(("%flags-use-compiler-omp-h",
         config.test_flags_use_compiler_omp_h))
 else:

diff  --git a/openmp/runtime/test/lit.site.cfg.in b/openmp/runtime/test/lit.site.cfg.in
index 4d8235d5bad0d..e84a2d31a1f68 100644
--- a/openmp/runtime/test/lit.site.cfg.in
+++ b/openmp/runtime/test/lit.site.cfg.in
@@ -3,6 +3,7 @@
 config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
 config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
 config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
+config.test_compiler_has_omp_h = @OPENMP_TEST_COMPILER_HAS_OMP_H@
 config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
 config.test_not = "@OPENMP_NOT_EXECUTABLE@"
 config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"


        


More information about the llvm-branch-commits mailing list