diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-02-02 22:17:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 22:17:13 +0000 |
commit | cd94cf8995bcddc40e627e94037e549b7a18b20e (patch) | |
tree | 309dea74fed132ce63058abf99e81a7e44ed1c43 /mesonbuild/compilers/mixins/clang.py | |
parent | 65b3d67c7e55ef4ccee496f53d18af859711b29e (diff) | |
parent | 6f532b72c85e38880cf7953098bb91e8f3feb696 (diff) | |
download | meson-cd94cf8995bcddc40e627e94037e549b7a18b20e.zip meson-cd94cf8995bcddc40e627e94037e549b7a18b20e.tar.gz meson-cd94cf8995bcddc40e627e94037e549b7a18b20e.tar.bz2 |
Merge pull request #8087 from dcbaker/submit/lto-extensions
Add option for thinLTO
Diffstat (limited to 'mesonbuild/compilers/mixins/clang.py')
-rw-r--r-- | mesonbuild/compilers/mixins/clang.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index fcb2225..1778c31 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -19,7 +19,7 @@ import shutil import typing as T from ... import mesonlib -from ...linkers import AppleDynamicLinker +from ...linkers import AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker from ...mesonlib import OptionKey from ..compilers import CompileCheckMode from .gnu import GnuLikeCompiler @@ -49,7 +49,9 @@ class ClangCompiler(GnuLikeCompiler): super().__init__() self.id = 'clang' self.defines = defines or {} - self.base_options.add(OptionKey('b_colorout')) + self.base_options.update( + {OptionKey('b_colorout'), OptionKey('b_lto_threads'), OptionKey('b_lto_mode')}) + # TODO: this really should be part of the linker base_options, but # linkers don't have base_options. if isinstance(self.linker, AppleDynamicLinker): @@ -135,3 +137,18 @@ class ClangCompiler(GnuLikeCompiler): def get_coverage_link_args(self) -> T.List[str]: return ['--coverage'] + + def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]: + args: T.List[str] = [] + if mode == 'thin': + # Thin LTO requires the use of gold, lld, ld64, or lld-link + if not isinstance(self.linker, (AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker)): + raise mesonlib.MesonException(f"LLVM's thinLTO only works with gnu gold, lld, lld-link, and ld64, not {self.linker.id}") + args.append(f'-flto={mode}') + else: + assert mode == 'default', 'someone forgot to wire something up' + args.extend(super().get_lto_compile_args(threads=threads)) + # In clang -flto=0 means auto + if threads >= 0: + args.append(f'-flto-jobs={threads}') + return args |