Skip to content

Config: Move LLVM_HAS_*_TARGET definitions to a new header. #136388

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

Conversation

pcc
Copy link
Contributor

@pcc pcc commented Apr 18, 2025

When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS
_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1] https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2] https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code

Created using spr 1.3.6-beta.1
@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2025

@llvm/pr-subscribers-mlir-llvm

Author: Peter Collingbourne (pcc)

Changes

When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS
_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1] https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2] https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code


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

6 Files Affected:

  • (modified) llvm/CMakeLists.txt (+4-1)
  • (added) llvm/include/llvm/Config/Targets.h.cmake (+90)
  • (modified) llvm/include/llvm/Config/llvm-config.h.cmake (-75)
  • (modified) llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn (+10-1)
  • (modified) mlir/lib/Target/LLVM/NVVM/Target.cpp (+1-1)
  • (modified) mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp (+1-1)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index cfd1a086c0fc2..693cb085b8e2f 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1163,13 +1163,16 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
 
 endif()
 
-# Configure the three LLVM configuration header files.
+# Configure the LLVM configuration header files.
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
   ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
   ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
+configure_file(
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.h.cmake
+  ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.h)
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
   ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
diff --git a/llvm/include/llvm/Config/Targets.h.cmake b/llvm/include/llvm/Config/Targets.h.cmake
new file mode 100644
index 0000000000000..5bab635edc542
--- /dev/null
+++ b/llvm/include/llvm/Config/Targets.h.cmake
@@ -0,0 +1,90 @@
+/*===------- llvm/Config/Targets.h - LLVM target checks -----------*- C -*-===*/
+/*                                                                            */
+/* Part of the LLVM Project, under the Apache License v2.0 with LLVM          */
+/* Exceptions.                                                                */
+/* See https://llvm.org/LICENSE.txt for license information.                  */
+/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    */
+/*                                                                            */
+/*===----------------------------------------------------------------------===*/
+
+/* This file enables clients to know whether specific targets are enabled. */
+
+#ifndef LLVM_CONFIG_TARGETS_H
+#define LLVM_CONFIG_TARGETS_H
+
+/* Define if the AArch64 target is built in */
+#cmakedefine01 LLVM_HAS_AARCH64_TARGET
+
+/* Define if the AMDGPU target is built in */
+#cmakedefine01 LLVM_HAS_AMDGPU_TARGET
+
+/* Define if the ARC target is built in */
+#cmakedefine01 LLVM_HAS_ARC_TARGET
+
+/* Define if the ARM target is built in */
+#cmakedefine01 LLVM_HAS_ARM_TARGET
+
+/* Define if the AVR target is built in */
+#cmakedefine01 LLVM_HAS_AVR_TARGET
+
+/* Define if the BPF target is built in */
+#cmakedefine01 LLVM_HAS_BPF_TARGET
+
+/* Define if the CSKY target is built in */
+#cmakedefine01 LLVM_HAS_CSKY_TARGET
+
+/* Define if the DirectX target is built in */
+#cmakedefine01 LLVM_HAS_DIRECTX_TARGET
+
+/* Define if the Hexagon target is built in */
+#cmakedefine01 LLVM_HAS_HEXAGON_TARGET
+
+/* Define if the Lanai target is built in */
+#cmakedefine01 LLVM_HAS_LANAI_TARGET
+
+/* Define if the LoongArch target is built in */
+#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET
+
+/* Define if the M68k target is built in */
+#cmakedefine01 LLVM_HAS_M68K_TARGET
+
+/* Define if the Mips target is built in */
+#cmakedefine01 LLVM_HAS_MIPS_TARGET
+
+/* Define if the MSP430 target is built in */
+#cmakedefine01 LLVM_HAS_MSP430_TARGET
+
+/* Define if the NVPTX target is built in */
+#cmakedefine01 LLVM_HAS_NVPTX_TARGET
+
+/* Define if the PowerPC target is built in */
+#cmakedefine01 LLVM_HAS_POWERPC_TARGET
+
+/* Define if the RISCV target is built in */
+#cmakedefine01 LLVM_HAS_RISCV_TARGET
+
+/* Define if the Sparc target is built in */
+#cmakedefine01 LLVM_HAS_SPARC_TARGET
+
+/* Define if the SPIRV target is built in */
+#cmakedefine01 LLVM_HAS_SPIRV_TARGET
+
+/* Define if the SystemZ target is built in */
+#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET
+
+/* Define if the VE target is built in */
+#cmakedefine01 LLVM_HAS_VE_TARGET
+
+/* Define if the WebAssembly target is built in */
+#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET
+
+/* Define if the X86 target is built in */
+#cmakedefine01 LLVM_HAS_X86_TARGET
+
+/* Define if the XCore target is built in */
+#cmakedefine01 LLVM_HAS_XCORE_TARGET
+
+/* Define if the Xtensa target is built in */
+#cmakedefine01 LLVM_HAS_XTENSA_TARGET
+
+#endif
diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake
index 4230eb850fa4b..97f996338bc0c 100644
--- a/llvm/include/llvm/Config/llvm-config.h.cmake
+++ b/llvm/include/llvm/Config/llvm-config.h.cmake
@@ -54,81 +54,6 @@
 /* LLVM name for the native target MCA init function, if available */
 #cmakedefine LLVM_NATIVE_TARGETMCA LLVMInitialize${LLVM_NATIVE_ARCH}TargetMCA
 
-/* Define if the AArch64 target is built in */
-#cmakedefine01 LLVM_HAS_AARCH64_TARGET
-
-/* Define if the AMDGPU target is built in */
-#cmakedefine01 LLVM_HAS_AMDGPU_TARGET
-
-/* Define if the ARC target is built in */
-#cmakedefine01 LLVM_HAS_ARC_TARGET
-
-/* Define if the ARM target is built in */
-#cmakedefine01 LLVM_HAS_ARM_TARGET
-
-/* Define if the AVR target is built in */
-#cmakedefine01 LLVM_HAS_AVR_TARGET
-
-/* Define if the BPF target is built in */
-#cmakedefine01 LLVM_HAS_BPF_TARGET
-
-/* Define if the CSKY target is built in */
-#cmakedefine01 LLVM_HAS_CSKY_TARGET
-
-/* Define if the DirectX target is built in */
-#cmakedefine01 LLVM_HAS_DIRECTX_TARGET
-
-/* Define if the Hexagon target is built in */
-#cmakedefine01 LLVM_HAS_HEXAGON_TARGET
-
-/* Define if the Lanai target is built in */
-#cmakedefine01 LLVM_HAS_LANAI_TARGET
-
-/* Define if the LoongArch target is built in */
-#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET
-
-/* Define if the M68k target is built in */
-#cmakedefine01 LLVM_HAS_M68K_TARGET
-
-/* Define if the Mips target is built in */
-#cmakedefine01 LLVM_HAS_MIPS_TARGET
-
-/* Define if the MSP430 target is built in */
-#cmakedefine01 LLVM_HAS_MSP430_TARGET
-
-/* Define if the NVPTX target is built in */
-#cmakedefine01 LLVM_HAS_NVPTX_TARGET
-
-/* Define if the PowerPC target is built in */
-#cmakedefine01 LLVM_HAS_POWERPC_TARGET
-
-/* Define if the RISCV target is built in */
-#cmakedefine01 LLVM_HAS_RISCV_TARGET
-
-/* Define if the Sparc target is built in */
-#cmakedefine01 LLVM_HAS_SPARC_TARGET
-
-/* Define if the SPIRV target is built in */
-#cmakedefine01 LLVM_HAS_SPIRV_TARGET
-
-/* Define if the SystemZ target is built in */
-#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET
-
-/* Define if the VE target is built in */
-#cmakedefine01 LLVM_HAS_VE_TARGET
-
-/* Define if the WebAssembly target is built in */
-#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET
-
-/* Define if the X86 target is built in */
-#cmakedefine01 LLVM_HAS_X86_TARGET
-
-/* Define if the XCore target is built in */
-#cmakedefine01 LLVM_HAS_XCORE_TARGET
-
-/* Define if the Xtensa target is built in */
-#cmakedefine01 LLVM_HAS_XTENSA_TARGET
-
 /* Define if this is Unixish platform */
 #cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX}
 
diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
index 4a7cbe4af9e9b..36ec4a2c6faec 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -74,7 +74,10 @@ write_cmake_config("abi-breaking") {
 }
 
 write_cmake_config("config") {
-  public_deps = [ ":llvm-config" ]
+  public_deps = [
+    ":Targets",
+    ":llvm-config",
+  ]
 
   input = "config.h.cmake"
   output = "$target_gen_dir/config.h"
@@ -384,6 +387,12 @@ write_cmake_config("llvm-config") {
   } else {
     values += [ "LLVM_FORCE_ENABLE_STATS=" ]
   }
+}
+
+write_cmake_config("Targets") {
+  input = "Targets.h.cmake"
+  output = "$target_gen_dir/Targets.h"
+  values = []
 
   if (llvm_build_AArch64) {
     values += [ "LLVM_HAS_AARCH64_TARGET=1" ]
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index f8420385cbec4..914a349696617 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -27,7 +27,7 @@
 #include "mlir/Target/LLVMIR/Export.h"
 
 #include "llvm/ADT/ScopeExit.h"
-#include "llvm/Config/llvm-config.h"
+#include "llvm/Config/Targets.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/FormatVariadic.h"
diff --git a/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp b/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
index cae713a1ce1d2..af0af89c7d07e 100644
--- a/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
+++ b/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
@@ -19,7 +19,7 @@
 #include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h"
 
 #include "llvm/Bitcode/BitcodeWriter.h"
-#include "llvm/Config/llvm-config.h" // for LLVM_HAS_NVPTX_TARGET
+#include "llvm/Config/Targets.h" // for LLVM_HAS_NVPTX_TARGET
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Process.h"

@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2025

@llvm/pr-subscribers-mlir

Author: Peter Collingbourne (pcc)

Changes

When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS
_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1] https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2] https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code


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

6 Files Affected:

  • (modified) llvm/CMakeLists.txt (+4-1)
  • (added) llvm/include/llvm/Config/Targets.h.cmake (+90)
  • (modified) llvm/include/llvm/Config/llvm-config.h.cmake (-75)
  • (modified) llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn (+10-1)
  • (modified) mlir/lib/Target/LLVM/NVVM/Target.cpp (+1-1)
  • (modified) mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp (+1-1)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index cfd1a086c0fc2..693cb085b8e2f 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1163,13 +1163,16 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
 
 endif()
 
-# Configure the three LLVM configuration header files.
+# Configure the LLVM configuration header files.
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
   ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
   ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
+configure_file(
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.h.cmake
+  ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.h)
 configure_file(
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
   ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
diff --git a/llvm/include/llvm/Config/Targets.h.cmake b/llvm/include/llvm/Config/Targets.h.cmake
new file mode 100644
index 0000000000000..5bab635edc542
--- /dev/null
+++ b/llvm/include/llvm/Config/Targets.h.cmake
@@ -0,0 +1,90 @@
+/*===------- llvm/Config/Targets.h - LLVM target checks -----------*- C -*-===*/
+/*                                                                            */
+/* Part of the LLVM Project, under the Apache License v2.0 with LLVM          */
+/* Exceptions.                                                                */
+/* See https://llvm.org/LICENSE.txt for license information.                  */
+/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    */
+/*                                                                            */
+/*===----------------------------------------------------------------------===*/
+
+/* This file enables clients to know whether specific targets are enabled. */
+
+#ifndef LLVM_CONFIG_TARGETS_H
+#define LLVM_CONFIG_TARGETS_H
+
+/* Define if the AArch64 target is built in */
+#cmakedefine01 LLVM_HAS_AARCH64_TARGET
+
+/* Define if the AMDGPU target is built in */
+#cmakedefine01 LLVM_HAS_AMDGPU_TARGET
+
+/* Define if the ARC target is built in */
+#cmakedefine01 LLVM_HAS_ARC_TARGET
+
+/* Define if the ARM target is built in */
+#cmakedefine01 LLVM_HAS_ARM_TARGET
+
+/* Define if the AVR target is built in */
+#cmakedefine01 LLVM_HAS_AVR_TARGET
+
+/* Define if the BPF target is built in */
+#cmakedefine01 LLVM_HAS_BPF_TARGET
+
+/* Define if the CSKY target is built in */
+#cmakedefine01 LLVM_HAS_CSKY_TARGET
+
+/* Define if the DirectX target is built in */
+#cmakedefine01 LLVM_HAS_DIRECTX_TARGET
+
+/* Define if the Hexagon target is built in */
+#cmakedefine01 LLVM_HAS_HEXAGON_TARGET
+
+/* Define if the Lanai target is built in */
+#cmakedefine01 LLVM_HAS_LANAI_TARGET
+
+/* Define if the LoongArch target is built in */
+#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET
+
+/* Define if the M68k target is built in */
+#cmakedefine01 LLVM_HAS_M68K_TARGET
+
+/* Define if the Mips target is built in */
+#cmakedefine01 LLVM_HAS_MIPS_TARGET
+
+/* Define if the MSP430 target is built in */
+#cmakedefine01 LLVM_HAS_MSP430_TARGET
+
+/* Define if the NVPTX target is built in */
+#cmakedefine01 LLVM_HAS_NVPTX_TARGET
+
+/* Define if the PowerPC target is built in */
+#cmakedefine01 LLVM_HAS_POWERPC_TARGET
+
+/* Define if the RISCV target is built in */
+#cmakedefine01 LLVM_HAS_RISCV_TARGET
+
+/* Define if the Sparc target is built in */
+#cmakedefine01 LLVM_HAS_SPARC_TARGET
+
+/* Define if the SPIRV target is built in */
+#cmakedefine01 LLVM_HAS_SPIRV_TARGET
+
+/* Define if the SystemZ target is built in */
+#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET
+
+/* Define if the VE target is built in */
+#cmakedefine01 LLVM_HAS_VE_TARGET
+
+/* Define if the WebAssembly target is built in */
+#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET
+
+/* Define if the X86 target is built in */
+#cmakedefine01 LLVM_HAS_X86_TARGET
+
+/* Define if the XCore target is built in */
+#cmakedefine01 LLVM_HAS_XCORE_TARGET
+
+/* Define if the Xtensa target is built in */
+#cmakedefine01 LLVM_HAS_XTENSA_TARGET
+
+#endif
diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake
index 4230eb850fa4b..97f996338bc0c 100644
--- a/llvm/include/llvm/Config/llvm-config.h.cmake
+++ b/llvm/include/llvm/Config/llvm-config.h.cmake
@@ -54,81 +54,6 @@
 /* LLVM name for the native target MCA init function, if available */
 #cmakedefine LLVM_NATIVE_TARGETMCA LLVMInitialize${LLVM_NATIVE_ARCH}TargetMCA
 
-/* Define if the AArch64 target is built in */
-#cmakedefine01 LLVM_HAS_AARCH64_TARGET
-
-/* Define if the AMDGPU target is built in */
-#cmakedefine01 LLVM_HAS_AMDGPU_TARGET
-
-/* Define if the ARC target is built in */
-#cmakedefine01 LLVM_HAS_ARC_TARGET
-
-/* Define if the ARM target is built in */
-#cmakedefine01 LLVM_HAS_ARM_TARGET
-
-/* Define if the AVR target is built in */
-#cmakedefine01 LLVM_HAS_AVR_TARGET
-
-/* Define if the BPF target is built in */
-#cmakedefine01 LLVM_HAS_BPF_TARGET
-
-/* Define if the CSKY target is built in */
-#cmakedefine01 LLVM_HAS_CSKY_TARGET
-
-/* Define if the DirectX target is built in */
-#cmakedefine01 LLVM_HAS_DIRECTX_TARGET
-
-/* Define if the Hexagon target is built in */
-#cmakedefine01 LLVM_HAS_HEXAGON_TARGET
-
-/* Define if the Lanai target is built in */
-#cmakedefine01 LLVM_HAS_LANAI_TARGET
-
-/* Define if the LoongArch target is built in */
-#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET
-
-/* Define if the M68k target is built in */
-#cmakedefine01 LLVM_HAS_M68K_TARGET
-
-/* Define if the Mips target is built in */
-#cmakedefine01 LLVM_HAS_MIPS_TARGET
-
-/* Define if the MSP430 target is built in */
-#cmakedefine01 LLVM_HAS_MSP430_TARGET
-
-/* Define if the NVPTX target is built in */
-#cmakedefine01 LLVM_HAS_NVPTX_TARGET
-
-/* Define if the PowerPC target is built in */
-#cmakedefine01 LLVM_HAS_POWERPC_TARGET
-
-/* Define if the RISCV target is built in */
-#cmakedefine01 LLVM_HAS_RISCV_TARGET
-
-/* Define if the Sparc target is built in */
-#cmakedefine01 LLVM_HAS_SPARC_TARGET
-
-/* Define if the SPIRV target is built in */
-#cmakedefine01 LLVM_HAS_SPIRV_TARGET
-
-/* Define if the SystemZ target is built in */
-#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET
-
-/* Define if the VE target is built in */
-#cmakedefine01 LLVM_HAS_VE_TARGET
-
-/* Define if the WebAssembly target is built in */
-#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET
-
-/* Define if the X86 target is built in */
-#cmakedefine01 LLVM_HAS_X86_TARGET
-
-/* Define if the XCore target is built in */
-#cmakedefine01 LLVM_HAS_XCORE_TARGET
-
-/* Define if the Xtensa target is built in */
-#cmakedefine01 LLVM_HAS_XTENSA_TARGET
-
 /* Define if this is Unixish platform */
 #cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX}
 
diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
index 4a7cbe4af9e9b..36ec4a2c6faec 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -74,7 +74,10 @@ write_cmake_config("abi-breaking") {
 }
 
 write_cmake_config("config") {
-  public_deps = [ ":llvm-config" ]
+  public_deps = [
+    ":Targets",
+    ":llvm-config",
+  ]
 
   input = "config.h.cmake"
   output = "$target_gen_dir/config.h"
@@ -384,6 +387,12 @@ write_cmake_config("llvm-config") {
   } else {
     values += [ "LLVM_FORCE_ENABLE_STATS=" ]
   }
+}
+
+write_cmake_config("Targets") {
+  input = "Targets.h.cmake"
+  output = "$target_gen_dir/Targets.h"
+  values = []
 
   if (llvm_build_AArch64) {
     values += [ "LLVM_HAS_AARCH64_TARGET=1" ]
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index f8420385cbec4..914a349696617 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -27,7 +27,7 @@
 #include "mlir/Target/LLVMIR/Export.h"
 
 #include "llvm/ADT/ScopeExit.h"
-#include "llvm/Config/llvm-config.h"
+#include "llvm/Config/Targets.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/FormatVariadic.h"
diff --git a/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp b/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
index cae713a1ce1d2..af0af89c7d07e 100644
--- a/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
+++ b/mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
@@ -19,7 +19,7 @@
 #include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h"
 
 #include "llvm/Bitcode/BitcodeWriter.h"
-#include "llvm/Config/llvm-config.h" // for LLVM_HAS_NVPTX_TARGET
+#include "llvm/Config/Targets.h" // for LLVM_HAS_NVPTX_TARGET
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Process.h"

@pcc pcc requested review from nico, mstorsjo and MaskRay April 18, 2025 23:32
@s-barannikov
Copy link
Contributor

I'm strongly in favor of this change. I often enable/disable targets and it results in rebuilding everything.
ccache helps, but it still runs the preprocessing step (I think), which isn't quite fast. Also, any change in target list results in llvm-tblgen trying to rebuild all the generated files, which is even slower.

@@ -384,6 +387,12 @@ write_cmake_config("llvm-config") {
} else {
values += [ "LLVM_FORCE_ENABLE_STATS=" ]
}
}

write_cmake_config("Targets") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nico @aeubanks Alternatively we could just remove this build target; nothing that GN is currently capable of building needs it.

@MaskRay
Copy link
Member

MaskRay commented Apr 19, 2025

I'm strongly in favor of this change. I often enable/disable targets and it results in rebuilding everything. ccache helps, but it still runs the preprocessing step (I think), which isn't quite fast. Also, any change in target list results in llvm-tblgen trying to rebuild all the generated files, which is even slower.

+1.

The rebuild issue has been raised on the original change that added the macros: #71164
Thanks for taking care of it :)

@pcc pcc merged commit 667209e into main Apr 19, 2025
14 checks passed
@pcc pcc deleted the users/pcc/spr/config-move-llvm_has__target-definitions-to-a-new-header branch April 19, 2025 01:11
pratlucas added a commit to arm/arm-toolchain that referenced this pull request May 6, 2025
…ew header. (#313)

When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_*_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS_*_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1]
https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2]
https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code

Reviewers: nico, grypp, mstorsjo, MaskRay

Reviewed By: MaskRay

Pull Request: llvm/llvm-project#136388

Co-authored-by: Peter Collingbourne <[email protected]>
Co-authored-by: Lucas Duarte Prates <[email protected]>
pratlucas added a commit to arm/arm-toolchain that referenced this pull request May 6, 2025
…ew header. (#318)

When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_*_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS_*_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1]
https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2]
https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code

Reviewers: nico, grypp, mstorsjo, MaskRay

Reviewed By: MaskRay

Original Upstream Pull Request: llvm/llvm-project#136388

The conflict was introduced by the downstream changes from #124.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_*_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS_*_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1] https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2] https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code

Reviewers: nico, grypp, mstorsjo, MaskRay

Reviewed By: MaskRay

Pull Request: llvm#136388
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_*_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS_*_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1] https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2] https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code

Reviewers: nico, grypp, mstorsjo, MaskRay

Reviewed By: MaskRay

Pull Request: llvm#136388
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When enabling or disabling a target we typically need to rebuild most
of LLVM because of the change to the values of the LLVM_HAS_*_TARGET
macros in llvm-config.h, which is included by most of the code, but
are unused by LLVM itself. To avoid this, move the LLVM_HAS_*_TARGET
macros to a separate header, Targets.h.

Update the only in-tree user of the macros (MLIR) to refer to the new
header. I expect that out-of-tree users will detect the change either
at compile time if they build with -Wundef, or at runtime. As far as
I can tell, the usage of these macros is rare in out-of-tree projects,
I found no out-of-tree users in projects indexed by Debian code search
[1], and one user [2] in projects indexed by GitHub code search [3]
(excluding forks of LLVM).

[1] https://codesearch.debian.net/search?q=%23.*LLVM_HAS_.*_TARGET&literal=0
[2] https://github.com/AndreyPavlenko/graph-compiler/blob/238706b12b63945dc490f9f5f33a2d20b3c58944/lib/gc/Target/LLVM/XeVM/Target.cpp#L72
[3] https://github.com/search?q=%2F%23.*LLVM_HAS_.*_TARGET%2F&type=code

Reviewers: nico, grypp, mstorsjo, MaskRay

Reviewed By: MaskRay

Pull Request: llvm#136388
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants