[libcxx-commits] [libcxx] [llvm] [libcxx] Add cache file for the GPU build (PR #99348)

Joseph Huber via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 14 11:35:23 PDT 2024


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/99348

>From 1f2e33f08664409bc9649b1d64a95a8e8b74b9ef Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 16 Jul 2024 18:49:38 -0500
Subject: [PATCH 1/5] [libcxx] Make terminal check always false for `print` on
 GPU

Summary:
This check must be handled in order to compile. The GPU cannot easily
determine if a given `FILE *` is a terminal because the `stdio`
interface is actually a wrapper over the system's `FILE *`, so we can't
really detect it easily. An RPC call could be made to `isatty` if we
really need to support this in the future.
---
 libcxx/CMakeLists.txt           | 2 ++
 libcxx/include/__config_site.in | 1 +
 libcxx/include/print            | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 6168c76bff6d99..3699eca640772f 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -297,6 +297,7 @@ option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
    This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
+option(LIBCXX_HAS_TERMINAL_AVAILABLE "Build libc++ with terminal checking support" ON)
 
 if (LIBCXX_ENABLE_THREADS)
   set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
@@ -744,6 +745,7 @@ config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
+config_define_if_not(LIBCXX_HAS_TERMINAL_AVAILABLE _LIBCPP_HAS_NO_TERMINAL)
 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
   config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
 endif()
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index 67022146c9082b..bf2d31d8eeb1b9 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -15,6 +15,7 @@
 #cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT
 #cmakedefine _LIBCPP_HAS_NO_THREADS
 #cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+#cmakedefine _LIBCPP_HAS_NO_TERMINAL
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
diff --git a/libcxx/include/print b/libcxx/include/print
index 1a579daff270f7..2798a6bda26262 100644
--- a/libcxx/include/print
+++ b/libcxx/include/print
@@ -199,7 +199,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_terminal([[maybe_unused]] FILE* __stream)
   // the behavior in the test. This is not part of the public API.
 #  ifdef _LIBCPP_TESTING_PRINT_IS_TERMINAL
   return _LIBCPP_TESTING_PRINT_IS_TERMINAL(__stream);
-#  elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0
+#  elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0 || defined(_LIBCPP_HAS_NO_TERMINAL)
   return false;
 #  elif defined(_LIBCPP_WIN32API)
   return std::__is_windows_terminal(__stream);

>From 435dd41e07479633af2ceff0de12451b854fd35b Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 5 Aug 2024 15:35:10 -0500
Subject: [PATCH 2/5] Address comments

---
 libcxx/CMakeLists.txt                | 2 +-
 libcxx/utils/libcxx/test/features.py | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 3699eca640772f..434ca34321bdb2 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -97,6 +97,7 @@ option(LIBCXX_ENABLE_UNICODE
   "Whether to include support for Unicode in the library. Disabling Unicode can
    be useful when porting to platforms that don't support UTF-8 encoding (e.g.
    embedded)." ON)
+option(LIBCXX_HAS_TERMINAL_AVAILABLE "Build libc++ with terminal checking support" ON)
 option(LIBCXX_ENABLE_WIDE_CHARACTERS
   "Whether to include support for wide characters in the library. Disabling
    wide character support can be useful when porting to platforms that don't
@@ -297,7 +298,6 @@ option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
    This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
-option(LIBCXX_HAS_TERMINAL_AVAILABLE "Build libc++ with terminal checking support" ON)
 
 if (LIBCXX_ENABLE_THREADS)
   set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
index 97cdb0349885d6..6857a28eb32995 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -378,6 +378,7 @@ def _mingwSupportsModules(cfg):
     "_LIBCPP_HAS_NO_FILESYSTEM": "no-filesystem",
     "_LIBCPP_HAS_NO_RANDOM_DEVICE": "no-random-device",
     "_LIBCPP_HAS_NO_LOCALIZATION": "no-localization",
+    "_LIBCPP_HAS_NO_TERMINAL": "no-terminal",
     "_LIBCPP_HAS_NO_WIDE_CHARACTERS": "no-wide-characters",
     "_LIBCPP_HAS_NO_TIME_ZONE_DATABASE": "no-tzdb",
     "_LIBCPP_HAS_NO_UNICODE": "libcpp-has-no-unicode",

>From f32fc676438b3f6e0bdd6e9aea828e25a7022b72 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 14 Aug 2024 12:08:08 -0500
Subject: [PATCH 3/5] address comments

---
 .github/workflows/libcxx-build-and-test.yaml  | 1 +
 libcxx/CMakeLists.txt                         | 3 ++-
 libcxx/cmake/caches/Generic-no-terminal.cmake | 5 +++++
 libcxx/utils/ci/run-buildbot                  | 5 +++++
 4 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/cmake/caches/Generic-no-terminal.cmake

diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml
index 1456f245cf7c0c..8c6d7c6c3c4dec 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -146,6 +146,7 @@ jobs:
           'generic-no-experimental',
           'generic-no-filesystem',
           'generic-no-localization',
+          'generic-no-terminal',
           'generic-no-random_device',
           'generic-no-threads',
           'generic-no-tzdb',
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 434ca34321bdb2..273b2238f34851 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -97,7 +97,8 @@ option(LIBCXX_ENABLE_UNICODE
   "Whether to include support for Unicode in the library. Disabling Unicode can
    be useful when porting to platforms that don't support UTF-8 encoding (e.g.
    embedded)." ON)
-option(LIBCXX_HAS_TERMINAL_AVAILABLE "Build libc++ with terminal checking support" ON)
+option(LIBCXX_HAS_TERMINAL_AVAILABLE
+  "Build libc++ with support for checking whether a stream is a terminal." ON)
 option(LIBCXX_ENABLE_WIDE_CHARACTERS
   "Whether to include support for wide characters in the library. Disabling
    wide character support can be useful when porting to platforms that don't
diff --git a/libcxx/cmake/caches/Generic-no-terminal.cmake b/libcxx/cmake/caches/Generic-no-terminal.cmake
new file mode 100644
index 00000000000000..9f712ebce02dbf
--- /dev/null
+++ b/libcxx/cmake/caches/Generic-no-terminal.cmake
@@ -0,0 +1,5 @@
+set(LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
+
+# Speed up the CI
+set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
+set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index f1c20b9d721904..6353c87c3d865d 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -469,6 +469,11 @@ generic-no-localization)
     generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-localization.cmake"
     check-runtimes
 ;;
+generic-no-terminal)
+    clean
+    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-terminal.cmake"
+    check-runtimes
+;;
 generic-no-unicode)
     clean
     generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-unicode.cmake"

>From d98ea7bc15b6383a76507e21efdd2be4c3e5fb36 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 17 Jul 2024 11:12:57 -0500
Subject: [PATCH 4/5] [libcxx] Add cache file for the GPU build

Summary:
This patch adds a CMake cache config file for the GPU build. This cache
will set the default required options when used from the LLVM runtime
interface or directly. These options pretty much disable everything the
GPU can't handle.

With this and the fllowing patches: #99259, #99243, #99287, and #99333,
we will be able to build `libc++` targeting the GPU with an invocation
like this.

```
$ cmake ../llvm
-C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake                                \
-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \
-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx   \
-DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda                \
```

This will then install the libraries and headers into the appropriate
locations for use with `clang`.
---
 libcxx/cmake/caches/GPU.cmake | 94 +++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 libcxx/cmake/caches/GPU.cmake

diff --git a/libcxx/cmake/caches/GPU.cmake b/libcxx/cmake/caches/GPU.cmake
new file mode 100644
index 00000000000000..0d9fba64de7597
--- /dev/null
+++ b/libcxx/cmake/caches/GPU.cmake
@@ -0,0 +1,94 @@
+# Handle default arguments when done through the LLVM runtimes interface.
+foreach(target amdgcn-amd-amdhsa nvptx64-nvidia-cuda)
+  set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
+  set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_INSTALL_LIBRARY ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
+  set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
+
+  # Configuration options for libcxxabi.
+  set(RUNTIMES_${target}_LIBCXXABI_BAREMETAL ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
+
+  # Target specific compile flags.
+  if(${target} MATCHES "^amdgcn")
+    set(RUNTIMES_${target}_LIBCXX_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
+    set(RUNTIMES_${target}_LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
+    set(RUNTIMES_${target}_CMAKE_REQUIRED_FLAGS "-nogpulib -nodefaultlibs" CACHE STRING "")
+  else()
+    set(RUNTIMES_${target}_LIBCXX_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
+    set(RUNTIMES_${target}_LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
+    set(RUNTIMES_${target}_CMAKE_REQUIRED_FLAGS
+        "-flto -nodefaultlibs -c -Wno-unused-command-line-argument" CACHE STRING "")
+  endif()
+endforeach()
+
+# Handle default arguments when being built directly.
+if(${CMAKE_CXX_COMPILER_TARGET} MATCHES "^amdgcn|^nvptx")
+  set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
+  set(LIBCXX_CXX_ABI none CACHE STRING "")
+  set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+  set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+  set(LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+  set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE BOOL "")
+  set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
+  set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
+  set(LIBCXX_INSTALL_LIBRARY ON CACHE BOOL "")
+  set(LIBCXX_LIBC "llvm-libc" CACHE STRING "")
+  set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
+
+  # Configuration options for libcxxabi.
+  set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
+  set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+  set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+  set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
+  set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
+  set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
+
+  # Target specific compile flags.
+  if(${target} MATCHES "^amdgcn")
+    set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
+    set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
+    set(CMAKE_REQUIRED_FLAGS "-nogpulib" CACHE STRING "")
+  else()
+    set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
+    set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
+        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
+    set(CMAKE_REQUIRED_FLAGS "-flto;-c;-Wno-unused-command-line-argument" CACHE STRING "")
+  endif()
+endif()

>From ce7721735bf90e911725e8e4fa905ce4bf7de974 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 14 Aug 2024 13:00:17 -0500
Subject: [PATCH 5/5] Move to separate files

---
 libcxx/cmake/caches/AMDGPU.cmake | 36 ++++++++++++
 libcxx/cmake/caches/GPU.cmake    | 94 --------------------------------
 libcxx/cmake/caches/NVPTX.cmake  | 36 ++++++++++++
 3 files changed, 72 insertions(+), 94 deletions(-)
 create mode 100644 libcxx/cmake/caches/AMDGPU.cmake
 delete mode 100644 libcxx/cmake/caches/GPU.cmake
 create mode 100644 libcxx/cmake/caches/NVPTX.cmake

diff --git a/libcxx/cmake/caches/AMDGPU.cmake b/libcxx/cmake/caches/AMDGPU.cmake
new file mode 100644
index 00000000000000..127f880d2fb44c
--- /dev/null
+++ b/libcxx/cmake/caches/AMDGPU.cmake
@@ -0,0 +1,36 @@
+# Configuration options for libcxx.
+set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
+set(LIBCXX_CXX_ABI none CACHE STRING "")
+set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
+set(LIBCXX_INSTALL_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_LIBC "llvm-libc" CACHE STRING "")
+set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
+
+# Configuration options for libcxxabi.
+set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
+set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
+
+# Necessary compile flags for AMDGPU.
+set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
+    "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
+set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
+    "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
+set(CMAKE_REQUIRED_FLAGS "-nogpulib -nodefaultlibs" CACHE STRING "")
diff --git a/libcxx/cmake/caches/GPU.cmake b/libcxx/cmake/caches/GPU.cmake
deleted file mode 100644
index 0d9fba64de7597..00000000000000
--- a/libcxx/cmake/caches/GPU.cmake
+++ /dev/null
@@ -1,94 +0,0 @@
-# Handle default arguments when done through the LLVM runtimes interface.
-foreach(target amdgcn-amd-amdhsa nvptx64-nvidia-cuda)
-  set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_INSTALL_LIBRARY ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
-
-  # Configuration options for libcxxabi.
-  set(RUNTIMES_${target}_LIBCXXABI_BAREMETAL ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
-
-  # Target specific compile flags.
-  if(${target} MATCHES "^amdgcn")
-    set(RUNTIMES_${target}_LIBCXX_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
-    set(RUNTIMES_${target}_LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
-    set(RUNTIMES_${target}_CMAKE_REQUIRED_FLAGS "-nogpulib -nodefaultlibs" CACHE STRING "")
-  else()
-    set(RUNTIMES_${target}_LIBCXX_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
-    set(RUNTIMES_${target}_LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
-    set(RUNTIMES_${target}_CMAKE_REQUIRED_FLAGS
-        "-flto -nodefaultlibs -c -Wno-unused-command-line-argument" CACHE STRING "")
-  endif()
-endforeach()
-
-# Handle default arguments when being built directly.
-if(${CMAKE_CXX_COMPILER_TARGET} MATCHES "^amdgcn|^nvptx")
-  set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(LIBCXX_CXX_ABI none CACHE STRING "")
-  set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
-  set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-  set(LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
-  set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE BOOL "")
-  set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
-  set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
-  set(LIBCXX_INSTALL_LIBRARY ON CACHE BOOL "")
-  set(LIBCXX_LIBC "llvm-libc" CACHE STRING "")
-  set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
-  set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
-
-  # Configuration options for libcxxabi.
-  set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
-  set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
-  set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-  set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
-  set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
-  set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
-
-  # Target specific compile flags.
-  if(${target} MATCHES "^amdgcn")
-    set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
-    set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
-    set(CMAKE_REQUIRED_FLAGS "-nogpulib" CACHE STRING "")
-  else()
-    set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
-    set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
-        "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
-    set(CMAKE_REQUIRED_FLAGS "-flto;-c;-Wno-unused-command-line-argument" CACHE STRING "")
-  endif()
-endif()
diff --git a/libcxx/cmake/caches/NVPTX.cmake b/libcxx/cmake/caches/NVPTX.cmake
new file mode 100644
index 00000000000000..f921bb2741b498
--- /dev/null
+++ b/libcxx/cmake/caches/NVPTX.cmake
@@ -0,0 +1,36 @@
+# Configuration options for libcxx.
+set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
+set(LIBCXX_CXX_ABI none CACHE STRING "")
+set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(LIBCXX_HAS_TERMINAL_AVAILABLE OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
+set(LIBCXX_INSTALL_LIBRARY ON CACHE BOOL "")
+set(LIBCXX_LIBC "llvm-libc" CACHE STRING "")
+set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
+
+# Configuration options for libcxxabi.
+set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
+set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
+set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
+
+# Necessary compile flags for NVPTX.
+set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
+    "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
+set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
+    "-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
+set(CMAKE_REQUIRED_FLAGS "-nogpulib -nodefaultlibs -flto -c" CACHE STRING "")



More information about the libcxx-commits mailing list