Skip to content
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

[OpenMP] Add extra flags to libomptarget and plugin builds #74520

Merged
merged 3 commits into from
Dec 11, 2023

Conversation

jdoerfert
Copy link
Member

No description provided.

@jdoerfert jdoerfert added openmp openmp:libomptarget OpenMP offload runtime labels Dec 5, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-openmp

Author: Johannes Doerfert (jdoerfert)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/74520.diff

2 Files Affected:

  • (modified) openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt (+16)
  • (modified) openmp/libomptarget/src/CMakeLists.txt (+16)
diff --git a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
index 5b332ed3d2f41..7c349ffd2026f 100644
--- a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
@@ -88,6 +88,22 @@ target_compile_definitions(PluginCommon PRIVATE
   DEBUG_PREFIX="PluginInterface"
 )
 
+target_compile_options(PluginCommon PUBLIC -fno-exceptions)
+
+if(NOT LLVM_ENABLE_RTTI)
+	target_compile_options(PluginCommon PUBLIC -fno-rtti)
+endif()
+
+include(CheckIPOSupported)
+check_ipo_supported(RESULT use_lto OUTPUT output)
+if(use_lto)
+	target_compile_options(PluginCommon PUBLIC -flto)
+	target_link_options(PluginCommon PUBLIC -flto)
+else()
+       message(WARNING "LTO is not supported: ${output}")
+endif()
+
+
 target_include_directories(PluginCommon
   PRIVATE
   ${LIBOMPTARGET_INCLUDE_DIR}
diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
index 7c311f738ac8e..e907a1b25566b 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -55,6 +55,22 @@ target_compile_definitions(omptarget PRIVATE
   DEBUG_PREFIX="omptarget"
 )
 
+target_compile_options(omptarget PRIVATE -fno-exceptions)
+
+if(NOT LLVM_ENABLE_RTTI)
+  target_compile_options(omptarget PRIVATE -fno-rtti)
+endif()
+
+include(CheckIPOSupported)
+check_ipo_supported(RESULT use_lto OUTPUT output)
+if(use_lto)
+	target_compile_options(omptarget PUBLIC -flto)
+	target_link_options(omptarget PUBLIC -flto)
+else()
+       message(WARNING "LTO is not supported: ${output}")
+endif()
+
+
 # libomptarget.so needs to be aware of where the plugins live as they
 # are now separated in the build directory.
 set_target_properties(omptarget PROPERTIES

openmp/libomptarget/CMakeLists.txt Outdated Show resolved Hide resolved
@jdoerfert jdoerfert merged commit 12cbccc into llvm:main Dec 11, 2023
4 checks passed
@jdoerfert jdoerfert deleted the offload_prep10 branch December 11, 2023 18:41
Meinersbur added a commit that referenced this pull request Jan 26, 2024
…79387)

CheckIPOSupported is used to test for working LTO since #74520. However, before CMake 3.24 this will test the default linker and ignore options such as LLVM_ENABLE_LLD. As a result, CMake would test whether LTO works with the default linker but builds with another one. In a typical scenario, libomptarget is compiled with the in-tree Clang, but linked with ld.gold, which requires the LLVMgold plugin, when it actually would work with the lld linker (or also fail because the system lld is too old to understand opaque pointers). Using gcc as the compiler would pass the test, but fail when linking with lld since does not understand gcc's LTO format.

Disable LTO by default for now since automatic detection causes too many problems. It causes the openmp-offload-cuda-project buildbot (https://lab.llvm.org/staging/#/builders/151) to fail and LLVM_ENABLE_RUNTIMES=openmp builds will have it implicitly disabled in the vast majority of system configurations anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomptarget OpenMP offload runtime openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants