From cfb459a49ac55f14ef35b90f3c41d4ec34d08e73 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 4 Feb 2016 07:28:30 +0000 Subject: [PATCH 1/3] cmake: Add a flag to enable LTO This adds -DLLVM_ENABLE_LTO, rather than forcing people to manually add -flto to the various _FLAGS variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259766 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 125c5460fda0735a795012f1fa2ee711315bf03d) --- cmake/modules/HandleLLVMOptions.cmake | 7 +++++++ docs/CMake.rst | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 6db258ff66a..8af832c15bb 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -635,6 +635,13 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +option(LLVM_ENABLE_LTO "Enable link-time optimization" OFF) +append_if(LLVM_ENABLE_LTO "-flto" + CMAKE_CXX_FLAGS + CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS + CMAKE_SHARED_LINKER_FLAGS) + # Plugin support # FIXME: Make this configurable. if(WIN32 OR CYGWIN) diff --git a/docs/CMake.rst b/docs/CMake.rst index 4e5feae9993..6d61442ed97 100644 --- a/docs/CMake.rst +++ b/docs/CMake.rst @@ -347,6 +347,10 @@ LLVM-specific variables are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``, and ``Address;Undefined``. Defaults to empty string. +**LLVM_ENABLE_LTO**:BOOL + Add the ``-flto`` flag to the compile and link command lines, + enabling link-time optimization. Defaults to OFF. + **LLVM_PARALLEL_COMPILE_JOBS**:STRING Define the maximum number of concurrent compilation jobs. From 128319f56ea14d776c7c7b631f82b9b83a98e9d9 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Mon, 8 Feb 2016 21:01:24 +0000 Subject: [PATCH 2/3] 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 1d15d57f1e6bbea4eb80ed5eef4ce82412f5ee7c) --- cmake/modules/HandleLLVMOptions.cmake | 18 ++++++++++++------ docs/CMake.rst | 7 ++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 8af832c15bb..a6e2bad8bd6 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -635,12 +635,18 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) -option(LLVM_ENABLE_LTO "Enable link-time optimization" OFF) -append_if(LLVM_ENABLE_LTO "-flto" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) +option(LLVM_ENABLE_LTO "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO" OFF) +string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO) +if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") + append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL") + append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +elseif(LLVM_ENABLE_LTO) + append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) +endif() # Plugin support # FIXME: Make this configurable. diff --git a/docs/CMake.rst b/docs/CMake.rst index 6d61442ed97..56d6867f602 100644 --- a/docs/CMake.rst +++ b/docs/CMake.rst @@ -347,9 +347,10 @@ LLVM-specific variables are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``, and ``Address;Undefined``. Defaults to empty string. -**LLVM_ENABLE_LTO**:BOOL - Add the ``-flto`` flag to the compile and link command lines, - enabling link-time optimization. Defaults to OFF. +**LLVM_ENABLE_LTO**:STRING + Add ``-flto`` or ``-flto=`` flags to the compile and link command + lines, enabling link-time optimization. Possible values are ``Off``, + ``On``, ``Thin`` and ``Full``. Defaults to OFF. **LLVM_PARALLEL_COMPILE_JOBS**:STRING Define the maximum number of concurrent compilation jobs. From a4b7bbbf1848425c6c87da361b8641480f818fab Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Mon, 8 Feb 2016 21:55:19 +0000 Subject: [PATCH 3/3] cmake: Use "set" instead of "option" for LLVM_ENABLE_LTO Apparently option is for bools and cmake-gui will display this strangely with option. Pointed out by edward-san - thanks! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260154 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 5835d8e04475268c9a0b047a59c70194f29ddcd5) --- cmake/modules/HandleLLVMOptions.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index a6e2bad8bd6..4b211e28557 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -635,7 +635,7 @@ append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) -option(LLVM_ENABLE_LTO "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO" OFF) +set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO") string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO) if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS