Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions clang/cmake/caches/llvm-toolchain/stage1.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Stage 1:
# * Build the prerequisites for stage 2.
# * We will be building an LTO optimized libcxx in stage 2, so we need to
# build clang and lld.


set(CMAKE_BUILD_TYPE Release CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")

set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
set(CLANG_BOOTSTRAP_CMAKE_ARGS -C ${CMAKE_CURRENT_LIST_DIR}/stage2.cmake CACHE BOOL "")
set(CLANG_BOOTSTRAP_TARGETS stage3-check-all stage3-distribution stage3-install-distribution stage3-clang stage3-clang-bolt CACHE BOOL "")
20 changes: 20 additions & 0 deletions clang/cmake/caches/llvm-toolchain/stage2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Stage 2:
# * Build an LTO optimized libcxx, so we can staticially link it into stage 3
# clang.
# * Stage 3 will be PGO optimized, so we need to build clang, lld, and
# compiler-rt in stage 2.


set(CMAKE_BUILD_TYPE Release CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "" FORCE)
set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "" FORCE)

set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
set(CLANG_BOOTSTRAP_CMAKE_ARGS -C ${CMAKE_CURRENT_LIST_DIR}/stage3-instrumented.cmake CACHE BOOL "")
set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE BOOL "")
set(CLANG_BOOTSTRAP_TARGETS stage3-check-all stage3-distribution stage3-install-distribution stage3-clang stage3-clang-bolt CACHE BOOL "")
set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "")
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE STRING "")
set(LLVM_ENABLE_LLD ON CACHE STRING "")
#set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
10 changes: 10 additions & 0 deletions clang/cmake/caches/llvm-toolchain/stage3-instrumented.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Stage 3 instrumented:
# * Build an instrumented clang, so we can generate profile data for stage 3.


set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
set(CLANG_BOOTSTRAP_CMAKE_ARGS -C ${CMAKE_CURRENT_LIST_DIR}/stage3.cmake CACHE BOOL "")
set(CLANG_BOOTSTRAP_TARGETS clang check-all distribution install-distribution clang-bolt CACHE BOOL "")
set(CLANG_BOLT OFF CACHE STRING "")

include(${CMAKE_CURRENT_LIST_DIR}/stage3.cmake)
16 changes: 16 additions & 0 deletions clang/cmake/caches/llvm-toolchain/stage3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Stage 3:
# * This is the final stage.
# * The goals is to have a clang that is LTO, PGO, and bolt optimized and also
# statically linked to libcxx and compiler-rt.

set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "" FORCE)
set(LLVM_ENABLE_PROJECTS "clang;lld;bolt;" CACHE STRING "" FORCE)
set(LLVM_ENABLE_LLD ON CACHE STRING "")
set(LLVM_ENABLE_LTO THIN CACHE STRING "")
set(LLVM_ENABLE_LIBCXX ON CACHE STRING "")
set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE STRING "")
set(CLANG_BOLT "INSTRUMENT" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow -rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" CACHE STRING "")
set(LLVM_DISTRIBUTION_COMPONENTS "clang;lld;runtimes;clang-resource-headers" CACHE STRING "")
21 changes: 21 additions & 0 deletions clang/cmake/caches/llvm-toolchain/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# LLVM Toolchain Build

This directory contains cache files for building a complete LLVM-based toolchain.
The resulting clang build will be LTO, PGO, and BOLT optimized and statically
linked against libc++ and compiler-rt.

The build is done in 4 stages:

* Stage 1: Build clang/lld.
* Stage 2: Build an LTO optimized libc++ with Stage 1 clang/lld.
* Stage 3 Instrumented: Build clang with instrumentation in order to generate
profile data for PGO.
* Stage 3: Build clang with LTO, PGO, and BOLT optimizations and statically link
with stage2 libc++ and compiler-rt.

## Usage

::

$ cmake -S llvm -B build -C clang/cmake/caches/llvm-toolchain/stage1.cmake
$ ninja stage3-install-distribution