[libc-commits] [libc] [libc] Refactor _build_gpu_objects cmake function. (PR #80631)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Sun Feb 4 21:40:15 PST 2024


================
@@ -145,21 +145,78 @@ function(get_nvptx_compile_options output_var gpu_arch)
   set(${output_var} ${nvptx_options} PARENT_SCOPE)
 endfunction()
 
-# Builds the object target for the GPU.
+# Build the object target for a single GPU arch.
+# Usage:
+#     _build_gpu_object_for_single_arch(
+#       <target_name>
+#       <gpu_arch>
+#       SRCS <list of .cpp files>
+#       HDRS <list of .h files>
+#       DEPENDS <list of dependencies>
+#       COMPILE_OPTIONS <optional list of special compile options for this target>
+#       FLAGS <optional list of flags>
+#     )
+function(_build_gpu_object_for_single_arch fq_target_name gpu_arch)
+  cmake_parse_arguments(
+    "ADD_GPU_OBJ"
+    "" # No optional arguments
+    "NAME;CXX_STANDARD" # Single value arguments
+    "SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;FLAGS"  # Multi value arguments
+    ${ARGN}
+  )
+
+  if(NOT ADD_GPU_OBJ_CXX_STANDARD)
+    set(ADD_GPU_OBJ_CXX_STANDARD ${CMAKE_CXX_STANDARD})
+  endif()
+
+  set(compile_options ${ADD_GPU_OBJ_COMPILE_OPTIONS})
+  # Derive the triple from the specified architecture.
+  if("${gpu_arch}" IN_LIST all_amdgpu_architectures)
+    set(gpu_target_triple ${AMDGPU_TARGET_TRIPLE})
+    list(APPEND compile_options "-mcpu=${gpu_arch}")
+    list(APPEND compile_options "SHELL:-Xclang -mcode-object-version=none")
----------------
SchrodingerZhu wrote:

Out of curiosity, what does `SHELL:` prefix do here

https://github.com/llvm/llvm-project/pull/80631


More information about the libc-commits mailing list