Lines Matching +full:check +full:- +full:docs +full:- +full:build
2 How To Build Clang and LLVM with Profile-Guided Optimizations
8 PGO (Profile-Guided Optimization) allows your compiler to better optimize code
12 This guide walks you through how to build Clang with PGO, though it also applies
15 If you want to build other software with PGO, see the `end-user documentation
16 for PGO <https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization>`_.
22 See https://llvm.org/docs/AdvancedBuilds.html#multi-stage-pgo
29 compiler-rt. Despite the name, it performs four clean builds of Clang, so it
30 can take a while to run to completion. Please see the script's ``--help`` for
32 If you want to get the most out of PGO for a particular use-case (e.g. compiling
39 This script also supports a ``--dry-run`` option, which causes it to print
52 - runs all of Clang and LLVM's lit tests, and
53 - uses the instrumented Clang to build Clang, LLVM, and all of the other
58 - solid coverage of building C++,
59 - good coverage of building C,
60 - great coverage of running optimizations,
61 - great coverage of the backend for your host's architecture, and
62 - some coverage of other architectures (if other arches are supported backends).
74 how to build Clang/LLVM with PGO.
76 First, you should have at least LLVM, Clang, and compiler-rt checked out
81 1. Build a standard Release Clang and the relevant libclang_rt.profile library
82 2. Build Clang using the Clang you built above, but with instrumentation
85 - Running the instrumented Clang/LLVM/lld/etc. on tasks that represent how
87 - Using a tool to convert the "raw" profiles generated above into a single,
90 4. Build a final release Clang (along with whatever other binaries you need)
95 1. Configure a Clang build as you normally would. It's highly recommended that
96 you use the Release configuration for this, since it will be used to build
98 to build the ``all`` target (e.g. ``ninja all`` or ``make -j4 all``).
100 2. Configure a Clang build as above, but add the following CMake args:
102 - ``-DLLVM_BUILD_INSTRUMENTED=IR`` -- This causes us to build everything
104 - ``-DLLVM_BUILD_RUNTIME=No`` -- A few projects have bad interactions when
105 built with profiling, and aren't necessary to build. This flag turns them
107 - ``-DCMAKE_C_COMPILER=/path/to/stage1/clang`` - Use the Clang we built in
109 - ``-DCMAKE_CXX_COMPILER=/path/to/stage1/clang++`` - Same as above.
111 In this build directory, you simply need to build the ``clang`` target (and
117 a. Build your benchmark using the Clang generated in step 2. The 'standard'
118 benchmark recommended is to run ``check-clang`` and ``check-llvm`` in your
119 instrumented Clang's build directory, and to do a full build of Clang/LLVM
120 using your instrumented Clang. So, create yet another build directory,
123 - ``-DCMAKE_C_COMPILER=/path/to/stage2/clang`` - Use the Clang we built in
125 - ``-DCMAKE_CXX_COMPILER=/path/to/stage2/clang++`` - Same as above.
128 ``-DCMAKE_BUILD_TYPE=RelWithDebInfo`` instead of
129 ``-DCMAKE_BUILD_TYPE=Release``. This will grant better coverage of
131 result in a much larger build directory.
133 It's recommended to build the ``all`` target with your instrumented Clang,
138 ``llvm-profdata`` (even if you only have one! The profile merge transforms
140 ``/path/to/stage1/llvm-profdata merge
141 -output=/path/to/output/profdata.prof path/to/stage2/profiles/*.profraw``.
143 4. Now, build your final, PGO-optimized Clang. To do this, you'll want to pass
146 - ``-DLLVM_PROFDATA_FILE=/path/to/output/profdata.prof`` - Use the PGO
148 - ``-DCMAKE_C_COMPILER=/path/to/stage1/clang`` - Use the Clang we built in
150 - ``-DCMAKE_CXX_COMPILER=/path/to/stage1/clang++`` - Same as above.
152 From here, you can build whatever targets you need.
155 You may see warnings about a mismatched profile in the build output. These
157 ``-DCMAKE_C_FLAGS='-Wno-backend-plugin'
158 -DCMAKE_CXX_FLAGS='-Wno-backend-plugin'`` to your CMake invocation.
161 Congrats! You now have a Clang built with profile-guided optimizations, and you
162 can delete all but the final build directory if you'd like.
166 built and run during the build process. While it's potentially nice to build
169 ``-DLLVM_NATIVE_TOOL_DIR=/path/to/stage1/bin``