Skip to content

Commit 667209e

Browse files
authored
Config: Move LLVM_HAS_*_TARGET definitions to a new header.
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: #136388
1 parent 5c37898 commit 667209e

File tree

6 files changed

+106
-79
lines changed

6 files changed

+106
-79
lines changed

llvm/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,16 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
11631163

11641164
endif()
11651165

1166-
# Configure the three LLVM configuration header files.
1166+
# Configure the LLVM configuration header files.
11671167
configure_file(
11681168
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
11691169
${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
11701170
configure_file(
11711171
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
11721172
${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
1173+
configure_file(
1174+
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.h.cmake
1175+
${LLVM_INCLUDE_DIR}/llvm/Config/Targets.h)
11731176
configure_file(
11741177
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
11751178
${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*===------- llvm/Config/Targets.h - LLVM target checks -----------*- C -*-===*/
2+
/* */
3+
/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */
4+
/* Exceptions. */
5+
/* See https://llvm.org/LICENSE.txt for license information. */
6+
/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
7+
/* */
8+
/*===----------------------------------------------------------------------===*/
9+
10+
/* This file enables clients to know whether specific targets are enabled. */
11+
12+
#ifndef LLVM_CONFIG_TARGETS_H
13+
#define LLVM_CONFIG_TARGETS_H
14+
15+
/* Define if the AArch64 target is built in */
16+
#cmakedefine01 LLVM_HAS_AARCH64_TARGET
17+
18+
/* Define if the AMDGPU target is built in */
19+
#cmakedefine01 LLVM_HAS_AMDGPU_TARGET
20+
21+
/* Define if the ARC target is built in */
22+
#cmakedefine01 LLVM_HAS_ARC_TARGET
23+
24+
/* Define if the ARM target is built in */
25+
#cmakedefine01 LLVM_HAS_ARM_TARGET
26+
27+
/* Define if the AVR target is built in */
28+
#cmakedefine01 LLVM_HAS_AVR_TARGET
29+
30+
/* Define if the BPF target is built in */
31+
#cmakedefine01 LLVM_HAS_BPF_TARGET
32+
33+
/* Define if the CSKY target is built in */
34+
#cmakedefine01 LLVM_HAS_CSKY_TARGET
35+
36+
/* Define if the DirectX target is built in */
37+
#cmakedefine01 LLVM_HAS_DIRECTX_TARGET
38+
39+
/* Define if the Hexagon target is built in */
40+
#cmakedefine01 LLVM_HAS_HEXAGON_TARGET
41+
42+
/* Define if the Lanai target is built in */
43+
#cmakedefine01 LLVM_HAS_LANAI_TARGET
44+
45+
/* Define if the LoongArch target is built in */
46+
#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET
47+
48+
/* Define if the M68k target is built in */
49+
#cmakedefine01 LLVM_HAS_M68K_TARGET
50+
51+
/* Define if the Mips target is built in */
52+
#cmakedefine01 LLVM_HAS_MIPS_TARGET
53+
54+
/* Define if the MSP430 target is built in */
55+
#cmakedefine01 LLVM_HAS_MSP430_TARGET
56+
57+
/* Define if the NVPTX target is built in */
58+
#cmakedefine01 LLVM_HAS_NVPTX_TARGET
59+
60+
/* Define if the PowerPC target is built in */
61+
#cmakedefine01 LLVM_HAS_POWERPC_TARGET
62+
63+
/* Define if the RISCV target is built in */
64+
#cmakedefine01 LLVM_HAS_RISCV_TARGET
65+
66+
/* Define if the Sparc target is built in */
67+
#cmakedefine01 LLVM_HAS_SPARC_TARGET
68+
69+
/* Define if the SPIRV target is built in */
70+
#cmakedefine01 LLVM_HAS_SPIRV_TARGET
71+
72+
/* Define if the SystemZ target is built in */
73+
#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET
74+
75+
/* Define if the VE target is built in */
76+
#cmakedefine01 LLVM_HAS_VE_TARGET
77+
78+
/* Define if the WebAssembly target is built in */
79+
#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET
80+
81+
/* Define if the X86 target is built in */
82+
#cmakedefine01 LLVM_HAS_X86_TARGET
83+
84+
/* Define if the XCore target is built in */
85+
#cmakedefine01 LLVM_HAS_XCORE_TARGET
86+
87+
/* Define if the Xtensa target is built in */
88+
#cmakedefine01 LLVM_HAS_XTENSA_TARGET
89+
90+
#endif

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,81 +54,6 @@
5454
/* LLVM name for the native target MCA init function, if available */
5555
#cmakedefine LLVM_NATIVE_TARGETMCA LLVMInitialize${LLVM_NATIVE_ARCH}TargetMCA
5656

57-
/* Define if the AArch64 target is built in */
58-
#cmakedefine01 LLVM_HAS_AARCH64_TARGET
59-
60-
/* Define if the AMDGPU target is built in */
61-
#cmakedefine01 LLVM_HAS_AMDGPU_TARGET
62-
63-
/* Define if the ARC target is built in */
64-
#cmakedefine01 LLVM_HAS_ARC_TARGET
65-
66-
/* Define if the ARM target is built in */
67-
#cmakedefine01 LLVM_HAS_ARM_TARGET
68-
69-
/* Define if the AVR target is built in */
70-
#cmakedefine01 LLVM_HAS_AVR_TARGET
71-
72-
/* Define if the BPF target is built in */
73-
#cmakedefine01 LLVM_HAS_BPF_TARGET
74-
75-
/* Define if the CSKY target is built in */
76-
#cmakedefine01 LLVM_HAS_CSKY_TARGET
77-
78-
/* Define if the DirectX target is built in */
79-
#cmakedefine01 LLVM_HAS_DIRECTX_TARGET
80-
81-
/* Define if the Hexagon target is built in */
82-
#cmakedefine01 LLVM_HAS_HEXAGON_TARGET
83-
84-
/* Define if the Lanai target is built in */
85-
#cmakedefine01 LLVM_HAS_LANAI_TARGET
86-
87-
/* Define if the LoongArch target is built in */
88-
#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET
89-
90-
/* Define if the M68k target is built in */
91-
#cmakedefine01 LLVM_HAS_M68K_TARGET
92-
93-
/* Define if the Mips target is built in */
94-
#cmakedefine01 LLVM_HAS_MIPS_TARGET
95-
96-
/* Define if the MSP430 target is built in */
97-
#cmakedefine01 LLVM_HAS_MSP430_TARGET
98-
99-
/* Define if the NVPTX target is built in */
100-
#cmakedefine01 LLVM_HAS_NVPTX_TARGET
101-
102-
/* Define if the PowerPC target is built in */
103-
#cmakedefine01 LLVM_HAS_POWERPC_TARGET
104-
105-
/* Define if the RISCV target is built in */
106-
#cmakedefine01 LLVM_HAS_RISCV_TARGET
107-
108-
/* Define if the Sparc target is built in */
109-
#cmakedefine01 LLVM_HAS_SPARC_TARGET
110-
111-
/* Define if the SPIRV target is built in */
112-
#cmakedefine01 LLVM_HAS_SPIRV_TARGET
113-
114-
/* Define if the SystemZ target is built in */
115-
#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET
116-
117-
/* Define if the VE target is built in */
118-
#cmakedefine01 LLVM_HAS_VE_TARGET
119-
120-
/* Define if the WebAssembly target is built in */
121-
#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET
122-
123-
/* Define if the X86 target is built in */
124-
#cmakedefine01 LLVM_HAS_X86_TARGET
125-
126-
/* Define if the XCore target is built in */
127-
#cmakedefine01 LLVM_HAS_XCORE_TARGET
128-
129-
/* Define if the Xtensa target is built in */
130-
#cmakedefine01 LLVM_HAS_XTENSA_TARGET
131-
13257
/* Define if this is Unixish platform */
13358
#cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX}
13459

llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ write_cmake_config("abi-breaking") {
7474
}
7575

7676
write_cmake_config("config") {
77-
public_deps = [ ":llvm-config" ]
77+
public_deps = [
78+
":Targets",
79+
":llvm-config",
80+
]
7881

7982
input = "config.h.cmake"
8083
output = "$target_gen_dir/config.h"
@@ -384,6 +387,12 @@ write_cmake_config("llvm-config") {
384387
} else {
385388
values += [ "LLVM_FORCE_ENABLE_STATS=" ]
386389
}
390+
}
391+
392+
write_cmake_config("Targets") {
393+
input = "Targets.h.cmake"
394+
output = "$target_gen_dir/Targets.h"
395+
values = []
387396

388397
if (llvm_build_AArch64) {
389398
values += [ "LLVM_HAS_AARCH64_TARGET=1" ]

mlir/lib/Target/LLVM/NVVM/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "mlir/Target/LLVMIR/Export.h"
2828

2929
#include "llvm/ADT/ScopeExit.h"
30-
#include "llvm/Config/llvm-config.h"
30+
#include "llvm/Config/Targets.h"
3131
#include "llvm/Support/FileSystem.h"
3232
#include "llvm/Support/FileUtilities.h"
3333
#include "llvm/Support/FormatVariadic.h"

mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h"
2020

2121
#include "llvm/Bitcode/BitcodeWriter.h"
22-
#include "llvm/Config/llvm-config.h" // for LLVM_HAS_NVPTX_TARGET
22+
#include "llvm/Config/Targets.h" // for LLVM_HAS_NVPTX_TARGET
2323
#include "llvm/IRReader/IRReader.h"
2424
#include "llvm/Support/MemoryBufferRef.h"
2525
#include "llvm/Support/Process.h"

0 commit comments

Comments
 (0)