Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 128319f

Browse files
bognergottesmm
authored andcommitted
cmake: Accept "thin" or "full" as arguments to -DLLVM_ENABLE_LTO
Mehdi suggested in a review of r259766 that it's also useful to easily set the type of LTO. Augment the cmake variable to support that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260143 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 1d15d57)
1 parent cfb459a commit 128319f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,18 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate"
635635
CMAKE_EXE_LINKER_FLAGS
636636
CMAKE_SHARED_LINKER_FLAGS)
637637

638-
option(LLVM_ENABLE_LTO "Enable link-time optimization" OFF)
639-
append_if(LLVM_ENABLE_LTO "-flto"
640-
CMAKE_CXX_FLAGS
641-
CMAKE_C_FLAGS
642-
CMAKE_EXE_LINKER_FLAGS
643-
CMAKE_SHARED_LINKER_FLAGS)
638+
option(LLVM_ENABLE_LTO "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO" OFF)
639+
string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
640+
if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
641+
append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
642+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
643+
elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
644+
append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
645+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
646+
elseif(LLVM_ENABLE_LTO)
647+
append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
648+
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
649+
endif()
644650

645651
# Plugin support
646652
# FIXME: Make this configurable.

docs/CMake.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,10 @@ LLVM-specific variables
347347
are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
348348
and ``Address;Undefined``. Defaults to empty string.
349349

350-
**LLVM_ENABLE_LTO**:BOOL
351-
Add the ``-flto`` flag to the compile and link command lines,
352-
enabling link-time optimization. Defaults to OFF.
350+
**LLVM_ENABLE_LTO**:STRING
351+
Add ``-flto`` or ``-flto=`` flags to the compile and link command
352+
lines, enabling link-time optimization. Possible values are ``Off``,
353+
``On``, ``Thin`` and ``Full``. Defaults to OFF.
353354

354355
**LLVM_PARALLEL_COMPILE_JOBS**:STRING
355356
Define the maximum number of concurrent compilation jobs.

0 commit comments

Comments
 (0)