aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/compilers.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-12-10 13:50:31 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-02-02 12:42:48 -0800
commitbffc94b08f713cc9916009575664b132aee76bcf (patch)
tree416e0f7e8686cb3f5c17093664e0691edec7904f /mesonbuild/compilers/compilers.py
parentf31ffaaf1754e4578127049844c14eba6bdda477 (diff)
downloadmeson-bffc94b08f713cc9916009575664b132aee76bcf.zip
meson-bffc94b08f713cc9916009575664b132aee76bcf.tar.gz
meson-bffc94b08f713cc9916009575664b132aee76bcf.tar.bz2
compilers: Add support for using multiple threads with lto
Both Clang and GCC support using multiple threads for preforming link time optimizaions, and they can now be configured using the `-Db_lto_threads` option. Fixes #7820
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
-rw-r--r--mesonbuild/compilers/compilers.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 0f83f4c..07569a7 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -268,6 +268,8 @@ clike_debug_args = {False: [],
base_options: 'KeyedOptionDictType' = {
OptionKey('b_pch'): coredata.UserBooleanOption('Use precompiled headers', True),
OptionKey('b_lto'): coredata.UserBooleanOption('Use link time optimization', False),
+ OptionKey('b_lto'): coredata.UserBooleanOption('Use link time optimization', False),
+ OptionKey('b_lto_threads'): coredata.UserIntegerOption('Use multiple threads for Link Time Optimization', (None, None,0)),
OptionKey('b_sanitize'): coredata.UserComboOption('Code sanitizer to use',
['none', 'address', 'thread', 'undefined', 'memory', 'address,undefined'],
'none'),
@@ -300,11 +302,25 @@ def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType',
except KeyError:
return False
+
+def get_option_value(options: 'KeyedOptionDictType', opt: OptionKey, fallback: '_T') -> '_T':
+ """Get the value of an option, or the fallback value."""
+ try:
+ v: '_T' = options[opt].value
+ except KeyError:
+ return fallback
+
+ assert isinstance(v, type(fallback)), f'Should have {type(fallback)!r} but was {type(v)!r}'
+ # Mypy doesn't understand that the above assert ensures that v is type _T
+ return v
+
+
def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler') -> T.List[str]:
args = [] # type T.List[str]
try:
if options[OptionKey('b_lto')].value:
- args.extend(compiler.get_lto_compile_args())
+ args.extend(compiler.get_lto_compile_args(
+ threads=get_option_value(options, OptionKey('b_lto_threads'), 0)))
except KeyError:
pass
try:
@@ -926,7 +942,7 @@ class Compiler(metaclass=abc.ABCMeta):
ret.append(arg)
return ret
- def get_lto_compile_args(self) -> T.List[str]:
+ def get_lto_compile_args(self, *, threads: int = 0) -> T.List[str]:
return []
def get_lto_link_args(self) -> T.List[str]: