Skip to content

Commit ce88e86

Browse files
committed
[CMake][Release] Refactor cache file and use two stages for non-PGO builds (#89812)
Completely refactor the cache file to simplify it and remove unnecessary variables. The main functional change here is that the non-PGO builds now use two stages, so `ninja -C build stage2-package` can be used with both PGO and non-PGO builds. (cherry picked from commit 6473fbf)
1 parent f2c5a10 commit ce88e86

File tree

1 file changed

+66
-68
lines changed

1 file changed

+66
-68
lines changed

clang/cmake/caches/Release.cmake

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,93 @@
11
# Plain options configure the first build.
22
# BOOTSTRAP_* options configure the second build.
33
# BOOTSTRAP_BOOTSTRAP_* options configure the third build.
4+
# PGO Builds have 3 stages (stage1, stage2-instrumented, stage2)
5+
# non-PGO Builds have 2 stages (stage1, stage2)
46

5-
# General Options
7+
8+
function (set_final_stage_var name value type)
9+
if (LLVM_RELEASE_ENABLE_PGO)
10+
set(BOOTSTRAP_BOOTSTRAP_${name} ${value} CACHE ${type} "")
11+
else()
12+
set(BOOTSTRAP_${name} ${value} CACHE ${type} "")
13+
endif()
14+
endfunction()
15+
16+
function (set_instrument_and_final_stage_var name value type)
17+
# This sets the varaible for the final stage in non-PGO builds and in
18+
# the stage2-instrumented stage for PGO builds.
19+
set(BOOTSTRAP_${name} ${value} CACHE ${type} "")
20+
if (LLVM_RELEASE_ENABLE_PGO)
21+
# Set the variable in the final stage for PGO builds.
22+
set(BOOTSTRAP_BOOTSTRAP_${name} ${value} CACHE ${type} "")
23+
endif()
24+
endfunction()
25+
26+
# General Options:
27+
# If you want to override any of the LLVM_RELEASE_* variables you can set them
28+
# on the command line via -D, but you need to do this before you pass this
29+
# cache file to CMake via -C. e.g.
30+
#
31+
# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake
632
set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
733
set(LLVM_RELEASE_ENABLE_PGO OFF CACHE BOOL "")
8-
34+
set(LLVM_RELEASE_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
35+
set(LLVM_RELEASE_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
36+
# Note we don't need to add install here, since it is one of the pre-defined
37+
# steps.
38+
set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
939
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
1040

11-
# Stage 1 Bootstrap Setup
41+
# Stage 1 Options
42+
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
1243
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
44+
45+
set(STAGE1_PROJECTS "clang")
46+
set(STAGE1_RUNTIMES "")
47+
1348
if (LLVM_RELEASE_ENABLE_PGO)
49+
list(APPEND STAGE1_PROJECTS "lld")
50+
list(APPEND STAGE1_RUNTIMES "compiler-rt")
1451
set(CLANG_BOOTSTRAP_TARGETS
1552
generate-profdata
16-
stage2
1753
stage2-package
1854
stage2-clang
19-
stage2-distribution
2055
stage2-install
21-
stage2-install-distribution
22-
stage2-install-distribution-toolchain
2356
stage2-check-all
2457
stage2-check-llvm
25-
stage2-check-clang
26-
stage2-test-suite CACHE STRING "")
27-
else()
28-
set(CLANG_BOOTSTRAP_TARGETS
29-
clang
30-
check-all
31-
check-llvm
32-
check-clang
33-
test-suite
34-
stage3
35-
stage3-clang
36-
stage3-check-all
37-
stage3-check-llvm
38-
stage3-check-clang
39-
stage3-install
40-
stage3-test-suite CACHE STRING "")
41-
endif()
58+
stage2-check-clang CACHE STRING "")
4259

43-
# Stage 1 Options
44-
set(STAGE1_PROJECTS "clang")
45-
set(STAGE1_RUNTIMES "")
60+
# Configuration for stage2-instrumented
61+
set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")
62+
# This enables the build targets for the final stage which is called stage2.
63+
set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")
64+
set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE STRING "")
65+
set(BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt" CACHE STRING "")
66+
set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
4667

47-
if (LLVM_RELEASE_ENABLE_PGO)
48-
list(APPEND STAGE1_PROJECTS "lld")
49-
list(APPEND STAGE1_RUNTIMES "compiler-rt")
68+
else()
69+
if (LLVM_RELEASE_ENABLE_LTO)
70+
list(APPEND STAGE1_PROJECTS "lld")
71+
endif()
72+
# Any targets added here will be given the target name stage2-${target}, so
73+
# if you want to run them you can just use:
74+
# ninja -C $BUILDDIR stage2-${target}
75+
set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")
5076
endif()
5177

78+
# Stage 1 Common Config
5279
set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "")
5380
set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")
5481

55-
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
56-
57-
# Stage 2 Bootstrap Setup
58-
set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")
59-
set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
60-
clang
61-
package
62-
check-all
63-
check-llvm
64-
check-clang CACHE STRING "")
65-
66-
# Stage 2 Options
67-
set(STAGE2_PROJECTS "clang")
68-
set(STAGE2_RUNTIMES "")
69-
70-
if (LLVM_RELEASE_ENABLE_LTO OR LLVM_RELEASE_ENABLE_PGO)
71-
list(APPEND STAGE2_PROJECTS "lld")
72-
endif()
73-
74-
if (LLVM_RELEASE_ENABLE_PGO)
75-
set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE STRING "")
76-
list(APPEND STAGE2_RUNTIMES "compiler-rt")
77-
set(BOOTSTRAP_LLVM_ENABLE_LTO ${LLVM_RELEASE_ENABLE_LTO})
78-
if (LLVM_RELEASE_ENABLE_LTO)
79-
set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
80-
endif()
82+
# stage2-instrumented and Final Stage Config:
83+
# Options that need to be set in both the instrumented stage (if we are doing
84+
# a pgo build) and the final stage.
85+
set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}" STRING)
86+
if (LLVM_RELEASE_ENABLE_LTO)
87+
set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)
8188
endif()
8289

83-
set(BOOTSTRAP_LLVM_ENABLE_PROJECTS ${STAGE2_PROJECTS} CACHE STRING "")
84-
set(BOOTSTRAP_LLVM_ENABLE_RUNTIMES ${STAGE2_RUNTIMES} CACHE STRING "")
85-
if (NOT LLVM_RELEASE_ENABLE_PGO)
86-
set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
87-
endif()
90+
# Final Stage Config (stage2)
91+
set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)
92+
set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS}" STRING)
8893

89-
# Stage 3 Options
90-
set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
91-
set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
92-
set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LTO ${LLVM_RELEASE_ENABLE_LTO} CACHE STRING "")
93-
if (LLVM_RELEASE_ENABLE_LTO)
94-
set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
95-
endif()

0 commit comments

Comments
 (0)