[Openmp-commits] [openmp] [OpenMP] Add extra flags to libomptarget and plugin builds (PR #74520)

Johannes Doerfert via Openmp-commits openmp-commits at lists.llvm.org
Mon Dec 11 10:34:35 PST 2023


https://github.com/jdoerfert updated https://github.com/llvm/llvm-project/pull/74520

>From f505868953d07125f67bcbb79be426a6deee1a13 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert <johannes at jdoerfert.de>
Date: Tue, 5 Dec 2023 12:35:04 -0800
Subject: [PATCH 1/2] [OpenMP] Add extra flags to libomptarget and plugin
 builds

---
 openmp/libomptarget/CMakeLists.txt            | 19 +++++++++++++++++++
 .../plugins-nextgen/common/CMakeLists.txt     |  3 +++
 openmp/libomptarget/src/CMakeLists.txt        |  3 +++
 3 files changed, 25 insertions(+)

diff --git a/openmp/libomptarget/CMakeLists.txt b/openmp/libomptarget/CMakeLists.txt
index 972b887c7c9520..fe895d5bc32547 100644
--- a/openmp/libomptarget/CMakeLists.txt
+++ b/openmp/libomptarget/CMakeLists.txt
@@ -75,6 +75,25 @@ if(LIBOMPTARGET_ENABLE_DEBUG)
   add_definitions(-DOMPTARGET_DEBUG)
 endif()
 
+# No exceptions and no RTTI, except if requested.
+set(offload_compile_flags -fno-exceptions)
+if(NOT LLVM_ENABLE_RTTI)
+	set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
+endif()
+
+# If LTO is not explicitly disabled we check if we can enable it and do so.
+set(LIBOMPTARGET_USE_LTO TRUE CACHE BOOL "Use LTO for the offload runtimes if available")
+if (LIBOMPTARGET_USE_LTO)
+	include(CheckIPOSupported)
+	check_ipo_supported(RESULT use_lto OUTPUT output)
+	if(use_lto)
+		set(offload_compile_flags ${offload_compile_flags} -flto)
+		set(offload_link_flags ${offload_link_flags} -flto)
+	else()
+	       message(WARNING "LTO is not supported: ${output}")
+	endif()
+endif()
+
 # OMPT support for libomptarget
 # Follow host OMPT support and check if host support has been requested.
 # LIBOMP_HAVE_OMPT_SUPPORT indicates whether host OMPT support has been implemented.
diff --git a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
index 5b332ed3d2f417..8ae3ff2a6d2916 100644
--- a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
@@ -88,6 +88,9 @@ target_compile_definitions(PluginCommon PRIVATE
   DEBUG_PREFIX="PluginInterface"
 )
 
+target_compile_options(PluginCommon PUBLIC ${offload_compile_flags})
+target_link_options(PluginCommon PUBLIC ${offload_link_flags})
+
 target_include_directories(PluginCommon
   PRIVATE
   ${LIBOMPTARGET_INCLUDE_DIR}
diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
index 7c311f738ac8eb..253e9f0aa176f6 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -55,6 +55,9 @@ target_compile_definitions(omptarget PRIVATE
   DEBUG_PREFIX="omptarget"
 )
 
+target_compile_options(omptarget PUBLIC ${offload_compile_flags})
+target_link_options(omptarget PUBLIC ${offload_link_flags})
+
 # 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

>From f96dc0a43075dcf9700b7813550ed687136b0d0a Mon Sep 17 00:00:00 2001
From: Johannes Doerfert <johannesdoerfert at gmail.com>
Date: Mon, 11 Dec 2023 10:34:28 -0800
Subject: [PATCH 2/2] Update CMakeLists.txt

---
 openmp/libomptarget/CMakeLists.txt | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/openmp/libomptarget/CMakeLists.txt b/openmp/libomptarget/CMakeLists.txt
index fe895d5bc32547..21ecb6ddba3dc9 100644
--- a/openmp/libomptarget/CMakeLists.txt
+++ b/openmp/libomptarget/CMakeLists.txt
@@ -78,20 +78,20 @@ endif()
 # No exceptions and no RTTI, except if requested.
 set(offload_compile_flags -fno-exceptions)
 if(NOT LLVM_ENABLE_RTTI)
-	set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
+  set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
 endif()
 
 # If LTO is not explicitly disabled we check if we can enable it and do so.
 set(LIBOMPTARGET_USE_LTO TRUE CACHE BOOL "Use LTO for the offload runtimes if available")
 if (LIBOMPTARGET_USE_LTO)
-	include(CheckIPOSupported)
-	check_ipo_supported(RESULT use_lto OUTPUT output)
-	if(use_lto)
-		set(offload_compile_flags ${offload_compile_flags} -flto)
-		set(offload_link_flags ${offload_link_flags} -flto)
-	else()
-	       message(WARNING "LTO is not supported: ${output}")
-	endif()
+  include(CheckIPOSupported)
+  check_ipo_supported(RESULT use_lto OUTPUT output)
+  if(use_lto)
+    set(offload_compile_flags ${offload_compile_flags} -flto)
+    set(offload_link_flags ${offload_link_flags} -flto)
+  else()
+    message(WARNING "LTO is not supported: ${output}")
+  endif()
 endif()
 
 # OMPT support for libomptarget



More information about the Openmp-commits mailing list