summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xSConstruct24
-rwxr-xr-xsrc/SConscript13
2 files changed, 36 insertions, 1 deletions
diff --git a/SConstruct b/SConstruct
index ee53be196..d2e6b1233 100755
--- a/SConstruct
+++ b/SConstruct
@@ -165,6 +165,8 @@ AddLocalOption('--default', dest='default', type='string', action='store',
help='Override which build_opts file to use for defaults')
AddLocalOption('--ignore-style', dest='ignore_style', action='store_true',
help='Disable style checking hooks')
+AddLocalOption('--no-lto', dest='no_lto', action='store_true',
+ help='Disable Link-Time Optimization for fast')
AddLocalOption('--update-ref', dest='update_ref', action='store_true',
help='Update test reference outputs')
AddLocalOption('--verbose', dest='verbose', action='store_true',
@@ -477,6 +479,10 @@ else:
main['SHCXXCOMSTR'] = Transform("SHCXX")
Export('MakeAction')
+# Initialize the Link-Time Optimization (LTO) flags
+main['LTO_CCFLAGS'] = []
+main['LTO_LDFLAGS'] = []
+
CXX_version = readCommand([main['CXX'],'--version'], exception=False)
CXX_V = readCommand([main['CXX'],'-V'], exception=False)
@@ -506,6 +512,24 @@ if main['GCC']:
# http://gcc.gnu.org/projects/cxx0x.html for details
if compareVersions(gcc_version, '4.4') >= 0:
main.Append(CXXFLAGS=['-std=c++0x'])
+
+ # LTO support is only really working properly from 4.6 and beyond
+ if compareVersions(gcc_version, '4.6') >= 0:
+ # Add the appropriate Link-Time Optimization (LTO) flags
+ # unless LTO is explicitly turned off. Note that these flags
+ # are only used by the fast target.
+ if not GetOption('no_lto'):
+ # Pass the LTO flag when compiling to produce GIMPLE
+ # output, we merely create the flags here and only append
+ # them later/
+ main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
+
+ # Use the same amount of jobs for LTO as we are running
+ # scons with, we hardcode the use of the linker plugin
+ # which requires either gold or GNU ld >= 2.21
+ main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'),
+ '-fuse-linker-plugin']
+
elif main['ICC']:
pass #Fix me... add warning flags once we clean up icc warnings
elif main['SUNCC']:
diff --git a/src/SConscript b/src/SConscript
index 3e7c4c9e9..8c407f4c7 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -943,15 +943,26 @@ ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
ldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
+# For Link Time Optimization, the optimisation flags used to compile
+# individual files are decoupled from those used at link time
+# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
+# to also update the linker flags based on the target.
if env['GCC']:
if sys.platform == 'sunos5':
ccflags['debug'] += ['-gstabs+']
else:
ccflags['debug'] += ['-ggdb3']
ldflags['debug'] += ['-O0']
- # opt, fast, prof and perf all share the same cc flags
+ # opt, fast, prof and perf all share the same cc flags, also add
+ # the optimization to the ldflags as LTO defers the optimization
+ # to link time
for target in ['opt', 'fast', 'prof', 'perf']:
ccflags[target] += ['-O3']
+ ldflags[target] += ['-O3']
+
+ ccflags['fast'] += env['LTO_CCFLAGS']
+ ldflags['fast'] += env['LTO_LDFLAGS']
+
elif env['SUNCC']:
ccflags['debug'] += ['-g0']
ccflags['opt'] += ['-O']