Index: openmp/CMakeLists.txt =================================================================== --- openmp/CMakeLists.txt +++ openmp/CMakeLists.txt @@ -39,8 +39,6 @@ set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe) set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe) endif() - - list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include) endif() # Check and set up common compiler flags. @@ -63,20 +61,6 @@ set(ENABLE_LIBOMPTARGET OFF) endif() -# Attempt to locate LLVM source, required by libomptarget -if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS) - if (LLVM_MAIN_INCLUDE_DIR) - list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR}) - elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include) - list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include) - endif() -endif() - -if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS) - message(STATUS "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS, disabling libomptarget") - set(ENABLE_LIBOMPTARGET OFF) -endif() - option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading." ${ENABLE_LIBOMPTARGET}) option(OPENMP_ENABLE_LIBOMPTARGET_PROFILING "Enable time profiling for libomptarget." Index: openmp/README.rst =================================================================== --- openmp/README.rst +++ openmp/README.rst @@ -243,6 +243,15 @@ Options for ``libomptarget`` ---------------------------- +An installed LLVM package is a prerequisite for building ``libomptarget`` +library. So ``libomptarget`` may only be built in two cases: + +- As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS** or + **LLVM_EXTERNAL_PROJECTS**, or +- as a standalone project build that uses a pre-installed LLVM package. + In this mode one has to make sure that the default CMake + ``find_package(LLVM)`` call `succeeds `_. + **LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""`` Path of the folder that contains ``omp.h``. This is required for testing out-of-tree builds. Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake =================================================================== --- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake +++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake @@ -19,6 +19,25 @@ include (FindPackageHandleStandardArgs) +################################################################################ +# Looking for LLVM... +################################################################################ + +if (OPENMP_STANDALONE_BUILD) + # Complete LLVM package is required for building libomptarget + # in an out-of-tree mode. + find_package(LLVM REQUIRED) + message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") + message(STATUS "Using LLVM in: ${LLVM_DIR}") + list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR}) + include(AddLLVM) +else() + list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS + ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include + ) +endif() + ################################################################################ # Looking for libelf... ################################################################################ @@ -250,27 +269,4 @@ endif() endif() -if (OPENMP_STANDALONE_BUILD) - # This duplicates code from llvm/cmake/config-ix.cmake - if( WIN32 AND NOT CYGWIN ) - # We consider Cygwin as another Unix - set(PURE_WINDOWS 1) - endif() - - # library checks - if( NOT PURE_WINDOWS ) - check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) - endif() - - if(HAVE_LIBPTHREAD) - # We want to find pthreads library and at the moment we do want to - # have it reported as '-l' instead of '-pthread'. - # TODO: switch to -pthread once the rest of the build system can deal with it. - set(CMAKE_THREAD_PREFER_PTHREAD TRUE) - set(THREADS_HAVE_PTHREAD_ARG Off) - find_package(Threads REQUIRED) - set(OPENMP_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) - endif() -else() - set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB}) -endif() +set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB}) Index: openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt =================================================================== --- openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt +++ openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt @@ -10,32 +10,6 @@ # ##===----------------------------------------------------------------------===## -find_package(LLVM QUIET CONFIG - PATHS - $ENV{AOMP} - $ENV{HOME}/rocm/aomp - /opt/rocm/aomp - /usr/lib/rocm/aomp - ${LIBOMPTARGET_NVPTX_CUDA_COMPILER_DIR} - ${LIBOMPTARGET_NVPTX_CUDA_LINKER_DIR} - ${CMAKE_CXX_COMPILER_DIR} - NO_DEFAULT_PATH) - -if (LLVM_DIR) - libomptarget_say("Found LLVM ${LLVM_PACKAGE_VERSION}. Configure: ${LLVM_DIR}/LLVMConfig.cmake") -else() - libomptarget_say("Not building AMDGCN device RTL: AOMP not found") - return() -endif() - -set(AOMP_INSTALL_PREFIX ${LLVM_INSTALL_PREFIX}) - -if (AOMP_INSTALL_PREFIX) - set(AOMP_BINDIR ${AOMP_INSTALL_PREFIX}/bin) -else() - set(AOMP_BINDIR ${LLVM_BUILD_BINARY_DIR}/bin) -endif() - # Copied from nvptx CMakeLists if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") set(aux_triple x86_64-unknown-linux-gnu) @@ -48,7 +22,20 @@ return() endif() -libomptarget_say("Building AMDGCN device RTL. LLVM_COMPILER_PATH=${AOMP_BINDIR}") +if (LLVM_DIR) + # Builds that use pre-installed LLVM have LLVM_DIR set. + find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) + find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} + NO_DEFAULT_PATH) + find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) + libomptarget_say("Building AMDGCN device RTL. Using clang: ${CLANG_TOOL}") +else() + # LLVM in-tree builds may use CMake target names to discover the tools. + set(CLANG_TOOL $) + set(LINK_TOOL $) + set(OPT_TOOL $) + libomptarget_say("Building AMDGCN device RTL. Using clang from in-tree build") +endif() project(omptarget-amdgcn) @@ -109,7 +96,7 @@ endif() macro(add_cuda_bc_library) - set(cu_cmd ${AOMP_BINDIR}/clang++ + set(cu_cmd ${CLANG_TOOL} -xc++ -c -std=c++14 @@ -145,7 +132,7 @@ add_custom_command( OUTPUT linkout.cuda.${mcpu}.bc - COMMAND ${AOMP_BINDIR}/llvm-link ${bc1_files} -o linkout.cuda.${mcpu}.bc + COMMAND ${LINK_TOOL} ${bc1_files} -o linkout.cuda.${mcpu}.bc DEPENDS ${bc1_files}) list(APPEND bc_files linkout.cuda.${mcpu}.bc) @@ -160,7 +147,7 @@ set(bc_libname lib${libname}-${mcpu}.bc) add_custom_command( OUTPUT ${bc_libname} - COMMAND ${AOMP_BINDIR}/llvm-link ${bc_files} | ${AOMP_BINDIR}/opt --always-inline -o ${OUTPUTDIR}/${bc_libname} + COMMAND ${LINK_TOOL} ${bc_files} | ${OPT_TOOL} --always-inline -o ${OUTPUTDIR}/${bc_libname} DEPENDS ${bc_files}) add_custom_target(lib${libname}-${mcpu} ALL DEPENDS ${bc_libname}) Index: openmp/libomptarget/src/CMakeLists.txt =================================================================== --- openmp/libomptarget/src/CMakeLists.txt +++ openmp/libomptarget/src/CMakeLists.txt @@ -24,29 +24,19 @@ include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS}) -# Build libomptarget library with libdl dependency. Add LLVMSupport -# dependency if building in-tree with profiling enabled. -if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING)) - add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}) - target_link_libraries(omptarget - ${CMAKE_DL_LIBS} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") -else() - set(LLVM_LINK_COMPONENTS - Support - ) - add_llvm_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES} - LINK_LIBS ${CMAKE_DL_LIBS} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports" - ) +# Build libomptarget library with libdl dependency. +add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}) +if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING) + # Add LLVMSupport dependency if profiling is enabled. + # Linking with LLVM component libraries also requires + # aligning the compile flags. + llvm_update_compile_flags(omptarget) target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED) + target_link_libraries(omptarget PRIVATE LLVMSupport) endif() - -# libomptarget needs to be set separately because add_llvm_library doesn't -# conform with location configuration of its parent scope. -set_target_properties(omptarget - PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR}) +target_link_libraries(omptarget PRIVATE + ${CMAKE_DL_LIBS} + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") # Install libomptarget under the lib destination folder. install(TARGETS omptarget LIBRARY COMPONENT omptarget