Bobby R. Bruce has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/44887 )

Change subject: scons: Add `--with-lto` flag to enabled LTO for all builds
......................................................................

scons: Add `--with-lto` flag to enabled LTO for all builds

Change-Id: I2eea7d447703491675c02730707cf9026cface5f
---
M SConstruct
M src/SConscript
2 files changed, 50 insertions(+), 25 deletions(-)



diff --git a/SConstruct b/SConstruct
index f3d65f0..d192b91 100755
--- a/SConstruct
+++ b/SConstruct
@@ -107,6 +107,8 @@
           help="Don't compress debug info in build files")
 AddOption('--no-lto', action='store_true',
           help='Disable Link-Time Optimization for fast')
+AddOption('--with-lto', action='store_true',
+          help='Enable Link-Time Optimization')
 AddOption('--verbose', action='store_true',
           help='Print full tool command lines')
 AddOption('--without-python', action='store_true',
@@ -262,9 +264,32 @@
 main.Prepend(CPPPATH=Dir('include'))

 # Initialize the Link-Time Optimization (LTO) flags
+
+if GetOption('no_lto') and GetOption('with_lto'):
+    error('\n'.join((
+          "`--no-lto` and `--with-lto` are both set. These are mutually ",
+          "exclusive flags. `--no-lto` disables LTO for .fast builds ",
+ "(enabled by default). `--with-lto` enables LTO for all builds.")))
+
+
 main['LTO_CCFLAGS'] = []
 main['LTO_LDFLAGS'] = []

+# THE LTO flags to set for the .fast builds only (the other builds use
+# 'LTO_CCFLAGS' and 'LTO_LDFLAGS')
+main['LTO_CCFLAGS_FAST'] = []
+main['LTO_LDFLAGS_FAST'] = []
+
+lto_flags_to_set = []
+
+if not GetOption('no_lto'):
+    lto_flags_to_set.append('LTO_CCFLAGS_FAST')
+    lto_flags_to_set.append('LTO_LDFLAGS_FAST')
+    if GetOption('with_lto'):
+        lto_flags_to_set.append('LTO_CCFLAGS')
+        lto_flags_to_set.append('LTO_LDFLAGS')
+
+
 # According to the readme, tcmalloc works best if the compiler doesn't
 # assume that we're using the builtin malloc and friends. These flags
 # are compiler-specific, so we need to set them after we detect which
@@ -329,22 +354,23 @@
               'Installed version:', main['CXXVERSION'])

     # 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'):
- # g++ uses "make" to parallelize LTO. The program can be overriden with - # the environment variable "MAKE", but we currently make no attempt to
-        # plumb that variable through.
-        parallelism = ''
-        if main.Detect('make'):
-            parallelism = '=%d' % GetOption('num_jobs')
-        else:
-            warning('"make" not found, link time optimization will be '
-                    'single threaded.')
+ # Note that these flags are only used by .fast by default. If `--no-lto` is
+    # set .fast will link without LTO. If `--with-lto` is set, all gem5
+    # variants (opt, debug, etc.) are linked with LTO.
+    #
+    # g++ uses "make" to parallelize LTO. The program can be overriden with
+    # the environment variable "MAKE", but we currently make no attempt to
+    # plumb that variable through.
+    parallelism = ''
+    if main.Detect('make'):
+        parallelism = '=%d' % GetOption('num_jobs')
+    else:
+        warning('"make" not found, link time optimization will be '
+                'single threaded.')

-        for var in 'LTO_CCFLAGS', 'LTO_LDFLAGS':
- # Use the same amount of jobs for LTO as we are running scons with.
-            main[var] = ['-flto%s' % parallelism]
+    for var in lto_flags_to_set:
+        # Use the same amount of jobs for LTO as we are running scons with.
+        main[var] = ['-flto%s' % parallelism]

main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc',
                                   '-fno-builtin-realloc', '-fno-builtin-free'])
@@ -354,10 +380,8 @@
         error('clang version 3.9 or newer required.\n'
               'Installed version:', main['CXXVERSION'])

-    # If not disabled, set the Link-Time Optimization (LTO) flags.
-    if not GetOption('no_lto'):
-        for var in 'LTO_CCFLAGS', 'LTO_LDFLAGS':
-            main[var] = ['-flto']
+    for var in lto_flags_to_set:
+        main[var] = ['-flto']

     # clang has a few additional warnings that we disable.
     with gem5_scons.Configure(main) as conf:
diff --git a/src/SConscript b/src/SConscript
index 47aa2ea..1daf3e6 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1431,15 +1431,16 @@
     else:
         ccflags['debug'] += ['-ggdb3']
     ldflags['debug'] += ['-O0']
-    # opt, fast, prof and perf all share the same cc flags, also add
+    # opt, 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']
+    for target in ['opt', 'prof', 'perf']:
+        ccflags[target] += ['-O3'] + env['LTO_CCFLAGS']
+        ldflags[target] += ['-O3'] + env['LTO_LDFLAGS']

-    ccflags['fast'] += env['LTO_CCFLAGS']
-    ldflags['fast'] += env['LTO_LDFLAGS']
+    ccflags['fast'] += ['-O3'] + env['LTO_CCFLAGS_FAST']
+    ldflags['fast'] += ['-O3'] + env['LTO_LDFLAGS_FAST']
+
 elif env['CLANG']:
     ccflags['debug'] += ['-g', '-O0']
     # opt, fast, prof and perf all share the same cc flags

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44887
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I2eea7d447703491675c02730707cf9026cface5f
Gerrit-Change-Number: 44887
Gerrit-PatchSet: 1
Gerrit-Owner: Bobby R. Bruce <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to