[llvm] [Offload] Do not link every target for JIT (PR #92013)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Mon May 13 12:17:10 PDT 2024


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/92013

Summary:
The offload library supports basic JIT functionality, however we
currently link against every single target even though only AMDGPU and
NVPTX are supported. This somewhat bloats the dynamic library list, so
we should constrain it to what's actually used.


>From bbcce811f96e96075622f5c7980e5b3329e28042 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 13 May 2024 14:15:48 -0500
Subject: [PATCH] [Offload] Do not link every target for JIT

Summary:
The offload library supports basic JIT functionality, however we
currently link against every single target even though only AMDGPU and
NVPTX are supported. This somewhat bloats the dynamic library list, so
we should constrain it to what's actually used.
---
 offload/plugins-nextgen/CMakeLists.txt        | 4 ++--
 offload/plugins-nextgen/amdgpu/CMakeLists.txt | 6 +++++-
 offload/plugins-nextgen/cuda/CMakeLists.txt   | 6 +++++-
 offload/plugins-nextgen/host/CMakeLists.txt   | 2 +-
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d1079f8a3e9cc..b8426b7816518 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -13,10 +13,10 @@
 # Common interface to handle creating a plugin library.
 set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
 add_subdirectory(common)
-function(add_target_library target_name lib_name)
+function(add_target_library target_name lib_name llvm_components)
   add_llvm_library(${target_name} STATIC
     LINK_COMPONENTS
-      ${LLVM_TARGETS_TO_BUILD}
+      ${llvm_components}
       AggressiveInstCombine
       Analysis
       BinaryFormat
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index 738183f8945ed..968532907b28c 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -28,7 +28,11 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE
 endif()
 
 # Create the library and add the default arguments.
-add_target_library(omptarget.rtl.amdgpu AMDGPU)
+if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
+  add_target_library(omptarget.rtl.amdgpu AMDGPU AMDGPU)
+else()
+  add_target_library(omptarget.rtl.amdgpu AMDGPU "")
+endif()
 
 target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
 target_include_directories(omptarget.rtl.amdgpu PRIVATE
diff --git a/offload/plugins-nextgen/cuda/CMakeLists.txt b/offload/plugins-nextgen/cuda/CMakeLists.txt
index dd684bb223431..d56eaa43c374d 100644
--- a/offload/plugins-nextgen/cuda/CMakeLists.txt
+++ b/offload/plugins-nextgen/cuda/CMakeLists.txt
@@ -24,7 +24,11 @@ endif()
 libomptarget_say("Building CUDA NextGen offloading plugin.")
 
 # Create the library and add the default arguments.
-add_target_library(omptarget.rtl.cuda CUDA)
+if("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
+  add_target_library(omptarget.rtl.cuda CUDA NVPTX)
+else()
+  add_target_library(omptarget.rtl.cuda CUDA "")
+endif()
 
 target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
 
diff --git a/offload/plugins-nextgen/host/CMakeLists.txt b/offload/plugins-nextgen/host/CMakeLists.txt
index 72b5681283fe2..92f2677e8a855 100644
--- a/offload/plugins-nextgen/host/CMakeLists.txt
+++ b/offload/plugins-nextgen/host/CMakeLists.txt
@@ -14,7 +14,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$")
 endif()
 
 # Create the library and add the default arguments.
-add_target_library(omptarget.rtl.host ${machine})
+add_target_library(omptarget.rtl.host ${machine} "")
 
 target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp)
 



More information about the llvm-commits mailing list