This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Improve logic for enabling LTO on LLVM itself
Needs ReviewPublic

Authored by zturner on Oct 11 2017, 10:55 AM.

Details

Summary

With this patch, if you specify LLVM_ENABLE_LTO=Full or LLVM_ENABLE_LTO=On and you are using cl + link, we enable the /GL and /LTCG flags for the compiler and linker, respectively.

Diff Detail

Event Timeline

zturner created this revision.Oct 11 2017, 10:55 AM
inglorion requested changes to this revision.Oct 11 2017, 11:34 AM
inglorion added inline comments.
llvm/cmake/modules/HandleLLVMOptions.cmake
780

Can you set ${style} to "OFF", "FULL", "MSVC", and "THIN" only? That way, dispatching on it won't have to worry about case and "ON" being an alias for "FULL". Also in the other passthrough case further down.

This revision now requires changes to proceed.Oct 11 2017, 11:34 AM
zturner updated this revision to Diff 118706.Oct 11 2017, 2:57 PM
zturner edited edge metadata.
zturner retitled this revision from [CMake] Allow LLVM_ENABLE_LTO to use MSVC LTCG to [CMake] Improve logic for enabling LTO on LLVM itself.
zturner added a reviewer: tejohnson.
  1. Updated with suggestions from inglorion. Specifically, decide_lto_style now either hard fails, or returns one of 4 values thin, full, msvc, none.
  2. Deletes the codepath for treating -flto separately from -flto=full. Since they are both the same, we just always use -flto=full
  3. Merge all the codepaths for the different styles into a single one. Instead of adding -flto=thin or -flto=full, we just add -flto=${LTO_STYLE}, collapsing some branches together.
  4. Enables the ThinLTO cache when using lld-link.
mehdi_amini added inline comments.Oct 11 2017, 8:37 PM
llvm/cmake/modules/HandleLLVMOptions.cmake
771

What is "msvc"? (pointer to another doc accepted :))

inglorion added inline comments.Oct 12 2017, 12:04 PM
llvm/cmake/modules/HandleLLVMOptions.cmake
781

nit: the case here doesn't match what you actually return (THIN vs thin)

838

I think the old code supports gcc + gold, which require -flto instead of -flto=full. We still need to translate style full to -flto here, which will do the same thing as -flto=full in clang.