@@ -30,14 +30,14 @@ Bootstrap Builds
30
30
================
31
31
32
32
The Clang CMake build system supports bootstrap (aka multi-stage) builds. At a
33
- high level a multi-stage build is a chain of builds that pass data from one
33
+ high level, a multi-stage build is a chain of builds that pass data from one
34
34
stage into the next. The most common and simple version of this is a traditional
35
35
bootstrap build.
36
36
37
37
In a simple two-stage bootstrap build, we build clang using the system compiler,
38
38
then use that just-built clang to build clang again. In CMake this simplest form
39
39
of a bootstrap build can be configured with a single option,
40
- CLANG_ENABLE_BOOTSTRAP.
40
+ `` CLANG_ENABLE_BOOTSTRAP `` .
41
41
42
42
.. code-block :: console
43
43
@@ -52,9 +52,9 @@ configurations for each stage. The next series of examples utilize CMake cache
52
52
scripts to provide more complex options.
53
53
54
54
By default, only a few CMake options will be passed between stages.
55
- The list, called _BOOTSTRAP_DEFAULT_PASSTHROUGH, is defined in clang/CMakeLists.txt.
56
- To force the passing of the variables between stages, use the -DCLANG_BOOTSTRAP_PASSTHROUGH
57
- CMake option, each variable separated by a ";". As example:
55
+ The list, called _BOOTSTRAP_DEFAULT_PASSTHROUGH, is defined in `` clang/CMakeLists.txt `` .
56
+ To force the passing of the variables between stages, use the `` -DCLANG_BOOTSTRAP_PASSTHROUGH ``
57
+ CMake option, each variable separated by a ";". For example:
58
58
59
59
.. code-block :: console
60
60
@@ -65,9 +65,9 @@ CMake option, each variable separated by a ";". As example:
65
65
<path to source>/llvm
66
66
$ ninja stage2
67
67
68
- CMake options starting by ``BOOTSTRAP_ `` will be passed only to the stage2 build.
68
+ CMake options starting with ``BOOTSTRAP_ `` will be passed only to the stage2 build.
69
69
This gives the opportunity to use Clang specific build flags.
70
- For example, the following CMake call will enabled ' -fno-addrsig' only during
70
+ For example, the following CMake call will enable `` -fno-addrsig `` only during
71
71
the stage2 build for C and C++.
72
72
73
73
.. code-block :: console
@@ -77,7 +77,7 @@ the stage2 build for C and C++.
77
77
The clang build system refers to builds as stages. A stage1 build is a standard
78
78
build using the compiler installed on the host, and a stage2 build is built
79
79
using the stage1 compiler. This nomenclature holds up to more stages too. In
80
- general a stage*n* build is built using the output from stage*n-1*.
80
+ general, a stage*n* build is built using the output from stage*n-1*.
81
81
82
82
Apple Clang Builds (A More Complex Bootstrap)
83
83
=============================================
@@ -90,7 +90,7 @@ compiler is a balance of optimization vs build time because it is a throwaway.
90
90
The stage2 compiler is the fully optimized compiler intended to ship to users.
91
91
92
92
Setting up these compilers requires a lot of options. To simplify the
93
- configuration the Apple Clang build settings are contained in CMake Cache files.
93
+ configuration, the Apple Clang build settings are contained in CMake Cache files.
94
94
You can build an Apple Clang compiler using the following commands:
95
95
96
96
.. code-block :: console
@@ -99,7 +99,7 @@ You can build an Apple Clang compiler using the following commands:
99
99
$ ninja stage2-distribution
100
100
101
101
This CMake invocation configures the stage1 host compiler, and sets
102
- CLANG_BOOTSTRAP_CMAKE_ARGS to pass the Apple-stage2.cmake cache script to the
102
+ `` CLANG_BOOTSTRAP_CMAKE_ARGS `` to pass the Apple-stage2.cmake cache script to the
103
103
stage2 configuration step.
104
104
105
105
When you build the stage2-distribution target it builds the minimal stage1
@@ -113,16 +113,16 @@ build configurations.
113
113
Multi-stage PGO
114
114
===============
115
115
116
- Profile-Guided Optimizations (PGO) is a really great way to optimize the code
116
+ Profile-Guided Optimization (PGO) is a really great way to optimize the code
117
117
clang generates. Our multi-stage PGO builds are a workflow for generating PGO
118
118
profiles that can be used to optimize clang.
119
119
120
120
At a high level, the way PGO works is that you build an instrumented compiler,
121
121
then you run the instrumented compiler against sample source files. While the
122
122
instrumented compiler runs it will output a bunch of files containing
123
- performance counters (.profraw files). After generating all the profraw files
123
+ performance counters (`` .profraw `` files). After generating all the profraw files
124
124
you use llvm-profdata to merge the files into a single profdata file that you
125
- can feed into the LLVM_PROFDATA_FILE option.
125
+ can feed into the `` LLVM_PROFDATA_FILE `` option.
126
126
127
127
Our PGO.cmake cache automates that whole process. You can use it for
128
128
configuration with CMake with the following command:
@@ -133,11 +133,11 @@ configuration with CMake with the following command:
133
133
<path to source>/llvm
134
134
135
135
There are several additional options that the cache file also accepts to modify
136
- the build, particularly the PGO_INSTRUMENT_LTO option. Setting this option to
136
+ the build, particularly the `` PGO_INSTRUMENT_LTO `` option. Setting this option to
137
137
Thin or Full will enable ThinLTO or full LTO respectively, further enhancing
138
138
the performance gains from a PGO build by enabling interprocedural
139
139
optimizations. For example, to run a CMake configuration for a PGO build
140
- that also enables ThinTLO , use the following command:
140
+ that also enables ThinLTO , use the following command:
141
141
142
142
.. code-block :: console
143
143
@@ -149,10 +149,10 @@ By default, clang will generate profile data by compiling a simple
149
149
hello world program. You can also tell clang use an external
150
150
project for generating profile data that may be a better fit for your
151
151
use case. The project you specify must either be a lit test suite
152
- (use the CLANG_PGO_TRAINING_DATA option) or a CMake project (use the
153
- CLANG_PERF_TRAINING_DATA_SOURCE_DIR option).
152
+ (use the `` CLANG_PGO_TRAINING_DATA `` option) or a CMake project (use the
153
+ `` CLANG_PERF_TRAINING_DATA_SOURCE_DIR `` option).
154
154
155
- For example, If you wanted to use the
155
+ For example, if you wanted to use the
156
156
`LLVM Test Suite <https://github.com/llvm/llvm-test-suite/ >`_ to generate
157
157
profile data you would use the following command:
158
158
@@ -162,8 +162,8 @@ profile data you would use the following command:
162
162
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR=<path to llvm-test-suite> \
163
163
-DBOOTSTRAP_CLANG_PGO_TRAINING_DEPS=runtimes
164
164
165
- The BOOTSTRAP\_ prefixes tells CMake to pass the variables on to the instrumented
166
- stage two build. And the CLANG_PGO_TRAINING_DEPS option let's you specify
165
+ The `` BOOTSTRAP\_ `` prefix tells CMake to pass the variables on to the instrumented
166
+ stage two build. And the `` CLANG_PGO_TRAINING_DEPS `` option let's you specify
167
167
additional build targets to build before building the external project. The
168
168
LLVM Test Suite requires compiler-rt to build, so we need to add the
169
169
`runtimes ` target as a dependency.
@@ -182,7 +182,7 @@ build directory. This takes a really long time because it builds clang twice,
182
182
and you *must * have compiler-rt in your build tree.
183
183
184
184
This process uses any source files under the perf-training directory as training
185
- data as long as the source files are marked up with LIT-style RUN lines.
185
+ data as long as the source files are marked up with LIT-style `` RUN `` lines.
186
186
187
187
After it finishes you can use :code: `find . -name clang.profdata ` to find it, but it
188
188
should be at a path something like:
@@ -191,7 +191,7 @@ should be at a path something like:
191
191
192
192
<build dir>/tools/clang/stage2-instrumented-bins/utils/perf-training/clang.profdata
193
193
194
- You can feed that file into the LLVM_PROFDATA_FILE option when you build your
194
+ You can feed that file into the `` LLVM_PROFDATA_FILE `` option when you build your
195
195
optimized compiler.
196
196
197
197
It may be necessary to build additional targets before running perf training, such as
@@ -214,7 +214,7 @@ The PGO cache generates the following additional targets:
214
214
215
215
**stage2-instrumented-generate-profdata **
216
216
Depends on stage2-instrumented and will use the instrumented compiler to
217
- generate profdata based on the training files in clang/utils/perf-training
217
+ generate profdata based on the training files in `` clang/utils/perf-training ``
218
218
219
219
**stage2 **
220
220
Depends on stage2-instrumented-generate-profdata and will use the stage1
@@ -257,11 +257,11 @@ Then, build the BOLT-optimized binary by running the following ninja command:
257
257
$ ninja clang-bolt
258
258
259
259
If you're seeing errors in the build process, try building with a recent
260
- version of Clang/LLVM by setting the CMAKE_C_COMPILER and
261
- CMAKE_CXX_COMPILER flags to the appropriate values.
260
+ version of Clang/LLVM by setting the `` CMAKE_C_COMPILER `` and
261
+ `` CMAKE_CXX_COMPILER `` flags to the appropriate values.
262
262
263
263
It is also possible to use BOLT on top of PGO and (Thin)LTO for an even more
264
- significant runtime speedup. To configure a three stage PGO build with ThinLTO
264
+ significant runtime speedup. To configure a three- stage PGO build with ThinLTO
265
265
that optimizes the resulting binary with BOLT, use the following CMake
266
266
configuration command:
267
267
@@ -282,14 +282,14 @@ Then, to build the final optimized binary, build the stage2-clang-bolt target:
282
282
3-Stage Non-Determinism
283
283
=======================
284
284
285
- In the ancient lore of compilers non-determinism is like the multi-headed hydra.
285
+ In the ancient lore of compilers, non-determinism is like the multi-headed hydra.
286
286
Whenever its head pops up, terror and chaos ensue.
287
287
288
- Historically one of the tests to verify that a compiler was deterministic would
289
- be a three stage build. The idea of a three stage build is you take your sources
288
+ Historically, one of the tests to verify that a compiler was deterministic would
289
+ be a three- stage build. The idea of a three- stage build is that you take your sources
290
290
and build a compiler (stage1), then use that compiler to rebuild the sources
291
291
(stage2), then you use that compiler to rebuild the sources a third time
292
- (stage3) with an identical configuration to the stage2 build. At the end of
292
+ (stage3) with a configuration identical to the stage2 build. At the end of
293
293
this, you have a stage2 and stage3 compiler that should be bit-for-bit
294
294
identical.
295
295
@@ -301,4 +301,4 @@ following commands:
301
301
$ cmake -G Ninja -C <path to source>/clang/cmake/caches/3-stage.cmake <path to source>/llvm
302
302
$ ninja stage3
303
303
304
- After the build you can compare the stage2 and stage3 compilers.
304
+ After the build, you can compare the stage2 and stage3 compilers.
0 commit comments