Author: Michael Kruse Date: 2026-02-18T13:52:41+01:00 New Revision: e07b9d15043271fb69177cdc5df9c504a21764ec
URL: https://github.com/llvm/llvm-project/commit/e07b9d15043271fb69177cdc5df9c504a21764ec DIFF: https://github.com/llvm/llvm-project/commit/e07b9d15043271fb69177cdc5df9c504a21764ec.diff LOG: Revert "[OpenMP] Remove standalone build mode (#149878)" Downstream builds are note sufficiently prepared. This reverts commit 176928cc1371c23d499b474fa95e076b61f776c4. Added: Modified: clang/cmake/caches/VectorEngine.cmake openmp/CMakeLists.txt openmp/cmake/OpenMPTesting.cmake openmp/docs/ReleaseNotes.rst openmp/runtime/CMakeLists.txt openmp/runtime/src/CMakeLists.txt openmp/runtime/test/CMakeLists.txt openmp/runtime/test/lit.cfg openmp/runtime/test/lit.site.cfg.in openmp/runtime/unittests/CMakeLists.txt Removed: ################################################################################ diff --git a/clang/cmake/caches/VectorEngine.cmake b/clang/cmake/caches/VectorEngine.cmake index b19e773a09049..b429fb0997d7a 100644 --- a/clang/cmake/caches/VectorEngine.cmake +++ b/clang/cmake/caches/VectorEngine.cmake @@ -66,6 +66,14 @@ set(RUNTIMES_ve-unknown-linux-gnu_LIBCXXABI_USE_COMPILER_RT TRUE CACHE BOOL "") # VE uses Compiler-RT from libcxx. set(RUNTIMES_ve-unknown-linux-gnu_LIBCXX_USE_COMPILER_RT TRUE CACHE BOOL "") +# Pretended standalone build for OpenMP since OpenMP doesn't support +# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR yet. +# - Use OPENMP_STANDALONE_BUILD +# - Define OPENMP_LIBDIR_SUFFIX to pretend per-target openmp directory +# - Define OPENMP_LLVM_TOOLS_DIR for test +set(RUNTIMES_x86_64-unknown-linux-gnu_OPENMP_STANDALONE_BUILD ON CACHE BOOL "") +set(RUNTIMES_ve-unknown-linux-gnu_OPENMP_STANDALONE_BUILD ON CACHE BOOL "") + # Specify LIBDIR_SUFFIX for OpenMP to install them at following directories. # install/lib/clang/${VERSION}/lib/x86_64-unknown-linux-gnu # install/lib/clang/${VERSION}/lib/ve-unknown-linux-gnu diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt index e7a26b13a67ff..355c64d28d296 100644 --- a/openmp/CMakeLists.txt +++ b/openmp/CMakeLists.txt @@ -10,57 +10,88 @@ list(INSERT CMAKE_MODULE_PATH 0 "${LLVM_COMMON_CMAKE_UTILS}/Modules" ) +# llvm/runtimes/ will set OPENMP_STANDALONE_BUILD. if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") - message(FATAL_ERROR [[The legacy standalone build mode has been removed. Please change - cmake <llvm-project>/openmp -to - cmake <llvm-project>/runtimes -DLLVM_ENABLE_RUNTIMES=openmp -For more details on building the LLVM OpenMP libraries, see https://openmp.llvm.org/Building.html]]) + set(OPENMP_STANDALONE_BUILD TRUE) + project(openmp C CXX ASM) +else() + set(OPENMP_STANDALONE_BUILD FALSE) endif() # Must go below project(..) include(GNUInstallDirs) -# Usually <llvm-project>/runtimes/CMakeLists.txt sets LLVM_TREE_AVAILABLE and -# we assume it is not available otherwise. The exception is that we are in an -# LLVM_ENABLE_PROJECTS=openmp build, the LLVM tree is actually available. -# Note that this build mode has been deprecated. -# See https://github.com/llvm/llvm-project/issues/124014 -if (NOT LLVM_RUNTIMES_BUILD AND "openmp" IN_LIST LLVM_ENABLE_PROJECTS) - set(LLVM_TREE_AVAILABLE True) -endif () +if (OPENMP_STANDALONE_BUILD) + set(LLVM_TREE_AVAILABLE False) -set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # CMAKE_BUILD_TYPE was not set, default to Release. + if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) + endif() -# When building in tree we install the runtime according to the LLVM settings. -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(OPENMP_INSTALL_LIBDIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING - "Path where built openmp libraries should be installed.") -else() - set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING + # Group common settings. + set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL + "Enable -Werror flags to turn warnings into errors for supporting compilers.") + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "Suffix of lib installation directory, e.g. 64 => lib64") + # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. + set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}" CACHE STRING "Path where built OpenMP libraries should be installed.") -endif() -if (NOT MSVC) - set(OPENMP_TEST_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang) - set(OPENMP_TEST_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++) + # Group test settings. + set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING + "C compiler to use for testing OpenMP runtime libraries.") + set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING + "C++ compiler to use for testing OpenMP runtime libraries.") + set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING + "FORTRAN compiler to use for testing OpenMP runtime libraries.") + set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.") + + set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") + set(CMAKE_CXX_STANDARD_REQUIRED NO) + set(CMAKE_CXX_EXTENSIONS NO) else() - set(OPENMP_TEST_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang.exe) - set(OPENMP_TEST_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++.exe) -endif() + # Usually <llvm-project>/runtimes/CMakeLists.txt sets LLVM_TREE_AVAILABLE and + # we assume it is not available otherwise. The exception is that we are in an + # LLVM_ENABLE_PROJECTS=openmp build, the LLVM tree is actually available. + # Note that this build mode has been deprecated. + # See https://github.com/llvm/llvm-project/issues/124014 + if (NOT LLVM_RUNTIMES_BUILD AND "openmp" IN_LIST LLVM_ENABLE_PROJECTS) + set(LLVM_TREE_AVAILABLE True) + endif () + + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + + # When building in tree we install the runtime according to the LLVM settings. + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(OPENMP_INSTALL_LIBDIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING + "Path where built openmp libraries should be installed.") + else() + set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING + "Path where built OpenMP libraries should be installed.") + endif() -# Set fortran test compiler if flang is found -if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}") - message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}") -else() - unset(OPENMP_TEST_Fortran_COMPILER) -endif() + if (NOT MSVC) + set(OPENMP_TEST_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang) + set(OPENMP_TEST_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++) + else() + set(OPENMP_TEST_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang.exe) + set(OPENMP_TEST_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++.exe) + endif() -# If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value, -# only set it locally for OpenMP. -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED NO) -set(CMAKE_CXX_EXTENSIONS NO) + # Set fortran test compiler if flang is found + if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}") + message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}") + else() + unset(OPENMP_TEST_Fortran_COMPILER) + endif() + + # If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value, + # only set it locally for OpenMP. + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED NO) + set(CMAKE_CXX_EXTENSIONS NO) +endif() # Check and set up common compiler flags. include(config-ix) @@ -150,8 +181,10 @@ else() endif() # Propagate OMPT support to offload - set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE) - set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE) + if(NOT ${OPENMP_STANDALONE_BUILD}) + set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE) + set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE) + endif() option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF) diff --git a/openmp/cmake/OpenMPTesting.cmake b/openmp/cmake/OpenMPTesting.cmake index b1ee5bb664e1d..262ea968c8351 100644 --- a/openmp/cmake/OpenMPTesting.cmake +++ b/openmp/cmake/OpenMPTesting.cmake @@ -1,14 +1,77 @@ # Keep track if we have all dependencies. set(ENABLE_CHECK_TARGETS TRUE) -if (TARGET FileCheck) - set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/FileCheck) +# Function to find required dependencies for testing. +function(find_standalone_test_dependencies) + find_package (Python3 COMPONENTS Interpreter) + + if (NOT Python3_Interpreter_FOUND) + message(STATUS "Could not find Python.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE) + return() + else() + set(Python3_EXECUTABLE ${Python3_EXECUTABLE} PARENT_SCOPE) + endif() + + # Find executables. + find_program(OPENMP_LLVM_LIT_EXECUTABLE + NAMES llvm-lit.py llvm-lit lit.py lit + PATHS ${OPENMP_LLVM_TOOLS_DIR}) + if (NOT OPENMP_LLVM_LIT_EXECUTABLE) + message(STATUS "Cannot find llvm-lit.") + message(STATUS "Please put llvm-lit in your PATH, set OPENMP_LLVM_LIT_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE) + return() + endif() + + find_program(OPENMP_FILECHECK_EXECUTABLE + NAMES FileCheck + PATHS ${OPENMP_LLVM_TOOLS_DIR}) + if (NOT OPENMP_FILECHECK_EXECUTABLE) + message(STATUS "Cannot find FileCheck.") + message(STATUS "Please put FileCheck in your PATH, set OPENMP_FILECHECK_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE) + return() + endif() + + find_program(OPENMP_NOT_EXECUTABLE + NAMES not + PATHS ${OPENMP_LLVM_TOOLS_DIR}) + if (NOT OPENMP_NOT_EXECUTABLE) + message(STATUS "Cannot find 'not'.") + message(STATUS "Please put 'not' in your PATH, set OPENMP_NOT_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE) + return() + endif() +endfunction() + +if (${OPENMP_STANDALONE_BUILD}) + find_standalone_test_dependencies() + + # Set lit arguments. + set(DEFAULT_LIT_ARGS "-sv --show-unsupported --show-xfail") + if (MSVC OR XCODE) + set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar") + endif() + if ("${CMAKE_SYSTEM_NAME}" MATCHES "AIX") + set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --time-tests --timeout=3000") + endif() + set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.") + separate_arguments(OPENMP_LIT_ARGS) else() - message(STATUS "Cannot find 'FileCheck'.") - message(WARNING "The check targets will not be available!") - set(ENABLE_CHECK_TARGETS FALSE) + if (NOT TARGET "FileCheck") + message(STATUS "Cannot find 'FileCheck'.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE) + else() + set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/FileCheck) + endif() + set(OPENMP_NOT_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/not) endif() -set(OPENMP_NOT_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/not) # Macro to extract information about compiler from file. (no own scope) macro(extract_test_compiler_information lang file) @@ -55,28 +118,50 @@ function(set_test_compiler_information dir) endif() endfunction() -# Set the information that we know. -set(OPENMP_TEST_COMPILER_ID "Clang") -# Cannot use CLANG_VERSION because we are not guaranteed that this is already set. -set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}") -set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_VERSION_MAJOR}") -set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") -# Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's -# CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work -# around that, until it is fixed there. -if("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "-lpthread") - set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread") -else() - set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}") -endif() -if(TARGET tsan) - set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 1) +if (${OPENMP_STANDALONE_BUILD}) + # Detect compiler that should be used for testing. + # We cannot use ExternalProject_Add() because its configuration runs when this + # project is built which is too late for detecting the compiler... + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler) + execute_process( + COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler + -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER} + -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler + OUTPUT_VARIABLE DETECT_COMPILER_OUT + ERROR_VARIABLE DETECT_COMPILER_ERR + RESULT_VARIABLE DETECT_COMPILER_RESULT) + if (DETECT_COMPILER_RESULT) + message(STATUS "Could not detect test compilers.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE) + else() + set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler) + endif() else() - set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0) + # Set the information that we know. + set(OPENMP_TEST_COMPILER_ID "Clang") + # Cannot use CLANG_VERSION because we are not guaranteed that this is already set. + set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}") + set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_VERSION_MAJOR}") + set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") + # Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's + # CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work + # around that, until it is fixed there. + if("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "-lpthread") + set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread") + else() + set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}") + endif() + if(TARGET tsan) + set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 1) + else() + set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0) + endif() + set(OPENMP_TEST_COMPILER_HAS_OMP_H 1) + set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS}") + set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1) endif() -set(OPENMP_TEST_COMPILER_HAS_OMP_H 1) -set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS}") -set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1) set(OPENMP_TEST_ENABLE_TSAN "${OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS}" CACHE BOOL "Whether to enable tests using tsan") @@ -127,21 +212,31 @@ function(add_openmp_testsuite target comment) set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_DEPENDS ${ARG_DEPENDS}) endif() - if (ARG_EXCLUDE_FROM_CHECK_ALL) - add_lit_testsuite(${target} - ${comment} - ${ARG_UNPARSED_ARGUMENTS} - EXCLUDE_FROM_CHECK_ALL - DEPENDS clang FileCheck not ${ARG_DEPENDS} - ARGS ${ARG_ARGS} + if (${OPENMP_STANDALONE_BUILD}) + set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS}) + add_custom_target(${target} + COMMAND ${Python3_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} + COMMENT ${comment} + DEPENDS ${ARG_DEPENDS} + USES_TERMINAL ) else() - add_lit_testsuite(${target} - ${comment} - ${ARG_UNPARSED_ARGUMENTS} - DEPENDS clang FileCheck not ${ARG_DEPENDS} - ARGS ${ARG_ARGS} - ) + if (ARG_EXCLUDE_FROM_CHECK_ALL) + add_lit_testsuite(${target} + ${comment} + ${ARG_UNPARSED_ARGUMENTS} + EXCLUDE_FROM_CHECK_ALL + DEPENDS clang FileCheck not ${ARG_DEPENDS} + ARGS ${ARG_ARGS} + ) + else() + add_lit_testsuite(${target} + ${comment} + ${ARG_UNPARSED_ARGUMENTS} + DEPENDS clang FileCheck not ${ARG_DEPENDS} + ARGS ${ARG_ARGS} + ) + endif() endif() if (TARGET flang-rt) diff --git a/openmp/docs/ReleaseNotes.rst b/openmp/docs/ReleaseNotes.rst index fcf216d183800..b99947540acd7 100644 --- a/openmp/docs/ReleaseNotes.rst +++ b/openmp/docs/ReleaseNotes.rst @@ -20,9 +20,6 @@ from the `LLVM releases web site <https://llvm.org/releases/>`_. Non-comprehensive list of changes in this release ================================================= -- Removed the standalone build mode. It is redundant with the runtimes default - build. - Device Runtime -------------- - Changed the OpenMP DeviceRTL to use 'generic' IR. The diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt index 43f75731bbd93..dc2f2be079bf3 100644 --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -19,52 +19,64 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) include(LibompGetArchitecture) include(LibompDefinitions) -# Determine the native architecture from LLVM. -string(TOLOWER "${LLVM_TARGET_ARCH}" LIBOMP_NATIVE_ARCH) -if( LIBOMP_NATIVE_ARCH STREQUAL "host" ) - string(REGEX MATCH "^[^-]*" LIBOMP_NATIVE_ARCH ${LLVM_HOST_TRIPLE}) -endif () -if(LIBOMP_NATIVE_ARCH MATCHES "i[2-6]86") - set(LIBOMP_ARCH i386) -elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86") - set(LIBOMP_ARCH i386) -elseif(LIBOMP_NATIVE_ARCH STREQUAL "amd64") - set(LIBOMP_ARCH x86_64) -elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86_64") - set(LIBOMP_ARCH x86_64) -elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc64le") - set(LIBOMP_ARCH ppc64le) -elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc64") - set(LIBOMP_ARCH ppc64) -elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc") - set(LIBOMP_ARCH ppc) -elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64_32") - set(LIBOMP_ARCH aarch64_32) -elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64") - set(LIBOMP_ARCH aarch64) -elseif(LIBOMP_NATIVE_ARCH MATCHES "arm64") - set(LIBOMP_ARCH aarch64) -elseif(LIBOMP_NATIVE_ARCH MATCHES "arm") - set(LIBOMP_ARCH arm) -elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64") - set(LIBOMP_ARCH riscv64) -elseif(LIBOMP_NATIVE_ARCH MATCHES "loongarch64") - set(LIBOMP_ARCH loongarch64) -elseif(LIBOMP_NATIVE_ARCH MATCHES "ve") - set(LIBOMP_ARCH ve) -elseif(LIBOMP_NATIVE_ARCH MATCHES "s390x") - set(LIBOMP_ARCH s390x) -elseif(LIBOMP_NATIVE_ARCH MATCHES "sparcv9") - set(LIBOMP_ARCH sparcv9) -elseif(LIBOMP_NATIVE_ARCH MATCHES "sparc") - set(LIBOMP_ARCH sparc) -elseif(LIBOMP_NATIVE_ARCH MATCHES "wasm") - set(LIBOMP_ARCH wasm32) -else() - # last ditch effort - libomp_get_architecture(LIBOMP_ARCH) -endif () -set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}) +# Determine the target architecture +if(${OPENMP_STANDALONE_BUILD}) + # If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake + libomp_get_architecture(LIBOMP_DETECTED_ARCH) + set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING + "The architecture to build for (x86_64/i386/arm/ppc/ppc64/ppc64le/aarch64/aarch64_32/mic/mips/mips64/riscv64/loongarch64/ve/s390x/sparc/sparcv9/wasm32).") + # Should assertions be enabled? They are on by default. + set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL + "enable assertions?") + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) +else() # Part of LLVM build + # Determine the native architecture from LLVM. + string(TOLOWER "${LLVM_TARGET_ARCH}" LIBOMP_NATIVE_ARCH) + if( LIBOMP_NATIVE_ARCH STREQUAL "host" ) + string(REGEX MATCH "^[^-]*" LIBOMP_NATIVE_ARCH ${LLVM_HOST_TRIPLE}) + endif () + if(LIBOMP_NATIVE_ARCH MATCHES "i[2-6]86") + set(LIBOMP_ARCH i386) + elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86") + set(LIBOMP_ARCH i386) + elseif(LIBOMP_NATIVE_ARCH STREQUAL "amd64") + set(LIBOMP_ARCH x86_64) + elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86_64") + set(LIBOMP_ARCH x86_64) + elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc64le") + set(LIBOMP_ARCH ppc64le) + elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc64") + set(LIBOMP_ARCH ppc64) + elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc") + set(LIBOMP_ARCH ppc) + elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64_32") + set(LIBOMP_ARCH aarch64_32) + elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64") + set(LIBOMP_ARCH aarch64) + elseif(LIBOMP_NATIVE_ARCH MATCHES "arm64") + set(LIBOMP_ARCH aarch64) + elseif(LIBOMP_NATIVE_ARCH MATCHES "arm") + set(LIBOMP_ARCH arm) + elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64") + set(LIBOMP_ARCH riscv64) + elseif(LIBOMP_NATIVE_ARCH MATCHES "loongarch64") + set(LIBOMP_ARCH loongarch64) + elseif(LIBOMP_NATIVE_ARCH MATCHES "ve") + set(LIBOMP_ARCH ve) + elseif(LIBOMP_NATIVE_ARCH MATCHES "s390x") + set(LIBOMP_ARCH s390x) + elseif(LIBOMP_NATIVE_ARCH MATCHES "sparcv9") + set(LIBOMP_ARCH sparcv9) + elseif(LIBOMP_NATIVE_ARCH MATCHES "sparc") + set(LIBOMP_ARCH sparc) + elseif(LIBOMP_NATIVE_ARCH MATCHES "wasm") + set(LIBOMP_ARCH wasm32) + else() + # last ditch effort + libomp_get_architecture(LIBOMP_ARCH) + endif () + set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}) +endif() # Time profiling support set(LIBOMP_PROFILING_SUPPORT ${OPENMP_ENABLE_LIBOMP_PROFILING}) @@ -417,6 +429,38 @@ set(LIBOMP_LIB_FILE ${LIBOMP_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX}) set(LIBOMP_INSTALL_ALIASES TRUE CACHE BOOL "Install libgomp and libiomp5 library aliases for backwards compatibility") +# Print configuration after all variables are set. +if(${OPENMP_STANDALONE_BUILD}) + libomp_say("Operating System -- ${CMAKE_SYSTEM_NAME}") + libomp_say("Target Architecture -- ${LIBOMP_ARCH}") + if(${MIC}) + libomp_say("Intel(R) MIC Architecture -- ${LIBOMP_MIC_ARCH}") + endif() + libomp_say("Build Type -- ${CMAKE_BUILD_TYPE}") + libomp_say("Library Kind -- ${LIBOMP_LIBRARY_KIND}") + libomp_say("Library Type -- ${LIBOMP_LIB_TYPE}") + libomp_say("Fortran Modules -- ${LIBOMP_FORTRAN_MODULES}") + # will say development if all zeros + if(${LIBOMP_VERSION_BUILD} STREQUAL 00000000) + set(LIBOMP_BUILD Development) + else() + set(LIBOMP_BUILD ${LIBOMP_VERSION_BUILD}) + endif() + libomp_say("Build -- ${LIBOMP_BUILD}") + libomp_say("Use Stats-gathering -- ${LIBOMP_STATS}") + libomp_say("Use Debugger-support -- ${LIBOMP_USE_DEBUGGER}") + libomp_say("Use ITT notify -- ${LIBOMP_USE_ITT_NOTIFY}") + libomp_say("Use OMPT-support -- ${LIBOMP_OMPT_SUPPORT}") + if(${LIBOMP_OMPT_SUPPORT}) + libomp_say("Use OMPT-optional -- ${LIBOMP_OMPT_OPTIONAL}") + endif() + libomp_say("Use OMPD-support -- ${LIBOMP_OMPD_SUPPORT}") + libomp_say("Use Adaptive locks -- ${LIBOMP_USE_ADAPTIVE_LOCKS}") + libomp_say("Use quad precision -- ${LIBOMP_USE_QUAD_PRECISION}") + libomp_say("Use Hwloc library -- ${LIBOMP_USE_HWLOC}") + libomp_say("Use OMPX-taskgraph -- ${LIBOMP_OMPX_TASKGRAPH}") +endif() + add_subdirectory(src) add_subdirectory(test) add_subdirectory(unittests) diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt index 26f472c6073ea..53f83c006b04f 100644 --- a/openmp/runtime/src/CMakeLists.txt +++ b/openmp/runtime/src/CMakeLists.txt @@ -174,7 +174,7 @@ libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS) # Build libomp library. Add LLVMSupport dependency if building in-tree with # libomptarget profiling enabled. -if(NOT OPENMP_ENABLE_LIBOMP_PROFILING) +if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING)) add_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:obj.omp>) set_property(TARGET omp PROPERTY FOLDER "OpenMP/Libraries") # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS @@ -395,8 +395,10 @@ add_dependencies(libomp-micro-tests libomp-test-deps) # `omp` needs to be exported if in-tree build. set(export_to_llvmexports) -get_target_export_arg(omp LLVM export_to_llvmexports) -set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS omp) +if (NOT OPENMP_STANDALONE_BUILD) + get_target_export_arg(omp LLVM export_to_llvmexports) + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS omp) +endif() # Install rules # We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR} diff --git a/openmp/runtime/test/CMakeLists.txt b/openmp/runtime/test/CMakeLists.txt index cbcd0c155f062..9ee3be6939811 100644 --- a/openmp/runtime/test/CMakeLists.txt +++ b/openmp/runtime/test/CMakeLists.txt @@ -33,6 +33,7 @@ pythonize_bool(LIBOMP_OMPT_OPTIONAL) pythonize_bool(LIBOMP_OMPX_TASKGRAPH) 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) diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg index 6d93789f2d44e..f35794f09f641 100644 --- a/openmp/runtime/test/lit.cfg +++ b/openmp/runtime/test/lit.cfg @@ -215,7 +215,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.test_compiler_has_omp_h: +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 7a51545b86fe1..cc8b3b252d7d1 100644 --- a/openmp/runtime/test/lit.site.cfg.in +++ b/openmp/runtime/test/lit.site.cfg.in @@ -20,6 +20,7 @@ config.has_ompt = @LIBOMP_OMPT_SUPPORT@ and @LIBOMP_OMPT_OPTIONAL@ config.has_ompx_taskgraph = @LIBOMP_OMPX_TASKGRAPH@ config.has_libm = @LIBOMP_HAVE_LIBM@ config.has_libatomic = @LIBOMP_HAVE_LIBATOMIC@ +config.is_standalone_build = @OPENMP_STANDALONE_BUILD@ config.has_omit_frame_pointer_flag = @OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS@ config.target_arch = "@LIBOMP_ARCH@" config.compiler_frontend_variant = "@CMAKE_C_COMPILER_FRONTEND_VARIANT@" diff --git a/openmp/runtime/unittests/CMakeLists.txt b/openmp/runtime/unittests/CMakeLists.txt index 6b85b70ea47b5..9e00456fd8fb4 100644 --- a/openmp/runtime/unittests/CMakeLists.txt +++ b/openmp/runtime/unittests/CMakeLists.txt @@ -6,8 +6,27 @@ if(WIN32 OR STUBS_LIBRARY) return() endif() +function(standalone_add_gtest success_var) + # LLVM_RUNTIMES_BUILD avoids gtest to link to LLVMSupport, which might be + # incompable with the platform libomp is compiled for. + set(LLVM_RUNTIMES_BUILD 1) + if (EXISTS "${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h") + set(${success_var} TRUE PARENT_SCOPE) + add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_BINARY_DIR}/third-party/runtimes_gtest") + else() + set(${success_var} FALSE PARENT_SCOPE) + message(WARNING "OpenMP unit tests will be skipped as LLVM third-party unittest directory is not available at: ${LLVM_THIRD_PARTY_DIR}/unittest") + return() + endif() +endfunction() + # Make the targets default_gtest and default_gtest_main available. -if ("openmp" IN_LIST LLVM_ENABLE_PROJECTS) +if (OPENMP_STANDALONE_BUILD) + standalone_add_gtest(STANDALONE_UNIT_TESTS) + if(NOT STANDALONE_UNIT_TESTS) + return() + endif() +elseif ("openmp" IN_LIST LLVM_ENABLE_PROJECTS) # llvm_gtest should already exist else () # LLVM_ENABLE_RUNTIMES build _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
