summaryrefslogtreecommitdiff
path: root/src/SConscript
diff options
context:
space:
mode:
authorCurtis Dunham <Curtis.Dunham@arm.com>2014-05-09 18:58:47 -0400
committerCurtis Dunham <Curtis.Dunham@arm.com>2014-05-09 18:58:47 -0400
commitfe27f937aa833a2d25e0462fd0cac301a45df8cb (patch)
treef3e6d4a35c883af82e66ae6837722c7579db146e /src/SConscript
parent0c1913336af42b6d789fa7738690e64b7784d9df (diff)
downloadgem5-fe27f937aa833a2d25e0462fd0cac301a45df8cb.tar.xz
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes to the ISA generation step. The end goal is to reduce the size of the generated compilation units for instruction execution and decoding so that batch compilation can proceed with all CPUs active without exhausting physical memory. The ISA parser (src/arch/isa_parser.py) has been improved so that it can accept 'split [output_type];' directives at the top level of the grammar and 'split(output_type)' python calls within 'exec {{ ... }}' blocks. This has the effect of "splitting" the files into smaller compilation units. I use air-quotes around "splitting" because the files themselves are not split, but preprocessing directives are inserted to have the same effect. Architecturally, the ISA parser has had some changes in how it works. In general, it emits code sooner. It doesn't generate per-CPU files, and instead defers to the C preprocessor to create the duplicate copies for each CPU type. Likewise there are more files emitted and the C preprocessor does more substitution that used to be done by the ISA parser. Finally, the build system (SCons) needs to be able to cope with a dynamic list of source files coming out of the ISA parser. The changes to the SCons{cript,truct} files support this. In broad strokes, the targets requested on the command line are hidden from SCons until all the build dependencies are determined, otherwise it would try, realize it can't reach the goal, and terminate in failure. Since build steps (i.e. running the ISA parser) must be taken to determine the file list, several new build stages have been inserted at the very start of the build. First, the build dependencies from the ISA parser will be emitted to arch/$ISA/generated/inc.d, which is then read by a new SCons builder to finalize the dependencies. (Once inc.d exists, the ISA parser will not need to be run to complete this step.) Once the dependencies are known, the 'Environments' are made by the makeEnv() function. This function used to be called before the build began but now happens during the build. It is easy to see that this step is quite slow; this is a known issue and it's important to realize that it was already slow, but there was no obvious cause to attribute it to since nothing was displayed to the terminal. Since new steps that used to be performed serially are now in a potentially-parallel build phase, the pathname handling in the SCons scripts has been tightened up to deal with chdir() race conditions. In general, pathnames are computed earlier and more likely to be stored, passed around, and processed as absolute paths rather than relative paths. In the end, some of these issues had to be fixed by inserting serializing dependencies in the build. Minor note: For the null ISA, we just provide a dummy inc.d so SCons is never compelled to try to generate it. While it seems slightly wrong to have anything in src/arch/*/generated (i.e. a non-generated 'generated' file), it's by far the simplest solution.
Diffstat (limited to 'src/SConscript')
-rwxr-xr-xsrc/SConscript142
1 files changed, 97 insertions, 45 deletions
diff --git a/src/SConscript b/src/SConscript
index 398c342ec..287c388ba 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -149,6 +149,14 @@ class SourceFile(object):
def __eq__(self, other): return self.filename == other.filename
def __ne__(self, other): return self.filename != other.filename
+ @staticmethod
+ def done():
+ def disabled(cls, name, *ignored):
+ raise RuntimeError("Additional SourceFile '%s'" % name,\
+ "declared, but targets deps are already fixed.")
+ SourceFile.__init__ = disabled
+
+
class Source(SourceFile):
'''Add a c/c++ source file to the build'''
def __init__(self, source, Werror=True, swig=False, **guards):
@@ -877,20 +885,26 @@ for source in PySource.all:
#
# List of constructed environments to pass back to SConstruct
-envList = []
-
date_source = Source('base/date.cc', skip_lib=True)
+# Capture this directory for the closure makeEnv, otherwise when it is
+# called, it won't know what directory it should use.
+variant_dir = Dir('.').path
+def variant(*path):
+ return os.path.join(variant_dir, *path)
+def variantd(*path):
+ return variant(*path)+'/'
+
# Function to create a new build environment as clone of current
# environment 'env' with modified object suffix and optional stripped
# binary. Additional keyword arguments are appended to corresponding
# build environment vars.
-def makeEnv(label, objsfx, strip = False, **kwargs):
+def makeEnv(env, label, objsfx, strip = False, **kwargs):
# SCons doesn't know to append a library suffix when there is a '.' in the
# name. Use '_' instead.
- libname = 'gem5_' + label
- exename = 'gem5.' + label
- secondary_exename = 'm5.' + label
+ libname = variant('gem5_' + label)
+ exename = variant('gem5.' + label)
+ secondary_exename = variant('m5.' + label)
new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
new_env.Label = label
@@ -978,8 +992,8 @@ def makeEnv(label, objsfx, strip = False, **kwargs):
test_objs = [ make_obj(s, static=True) for s in test_sources ]
if test.main:
test_objs += main_objs
- testname = "unittest/%s.%s" % (test.target, label)
- new_env.Program(testname, test_objs + static_objs)
+ path = variant('unittest/%s.%s' % (test.target, label))
+ new_env.Program(path, test_objs + static_objs)
progname = exename
if strip:
@@ -999,7 +1013,7 @@ def makeEnv(label, objsfx, strip = False, **kwargs):
MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
new_env.M5Binary = targets[0]
- envList.append(new_env)
+ return new_env
# Start out with the compiler flags common to all compilers,
# i.e. they all use -g for opt and -g -pg for prof
@@ -1065,39 +1079,77 @@ needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
if 'all' in needed_envs:
needed_envs += target_types
-# Debug binary
-if 'debug' in needed_envs:
- makeEnv('debug', '.do',
- CCFLAGS = Split(ccflags['debug']),
- CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
- LINKFLAGS = Split(ldflags['debug']))
-
-# Optimized binary
-if 'opt' in needed_envs:
- makeEnv('opt', '.o',
- CCFLAGS = Split(ccflags['opt']),
- CPPDEFINES = ['TRACING_ON=1'],
- LINKFLAGS = Split(ldflags['opt']))
-
-# "Fast" binary
-if 'fast' in needed_envs:
- makeEnv('fast', '.fo', strip = True,
- CCFLAGS = Split(ccflags['fast']),
- CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
- LINKFLAGS = Split(ldflags['fast']))
-
-# Profiled binary using gprof
-if 'prof' in needed_envs:
- makeEnv('prof', '.po',
- CCFLAGS = Split(ccflags['prof']),
- CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
- LINKFLAGS = Split(ldflags['prof']))
-
-# Profiled binary using google-pprof
-if 'perf' in needed_envs:
- makeEnv('perf', '.gpo',
- CCFLAGS = Split(ccflags['perf']),
- CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
- LINKFLAGS = Split(ldflags['perf']))
-
-Return('envList')
+gem5_root = Dir('.').up().up().abspath
+def makeEnvirons(target, source, env):
+ # cause any later Source() calls to be fatal, as a diagnostic.
+ Source.done()
+
+ envList = []
+
+ # Debug binary
+ if 'debug' in needed_envs:
+ envList.append(
+ makeEnv(env, 'debug', '.do',
+ CCFLAGS = Split(ccflags['debug']),
+ CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
+ LINKFLAGS = Split(ldflags['debug'])))
+
+ # Optimized binary
+ if 'opt' in needed_envs:
+ envList.append(
+ makeEnv(env, 'opt', '.o',
+ CCFLAGS = Split(ccflags['opt']),
+ CPPDEFINES = ['TRACING_ON=1'],
+ LINKFLAGS = Split(ldflags['opt'])))
+
+ # "Fast" binary
+ if 'fast' in needed_envs:
+ envList.append(
+ makeEnv(env, 'fast', '.fo', strip = True,
+ CCFLAGS = Split(ccflags['fast']),
+ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
+ LINKFLAGS = Split(ldflags['fast'])))
+
+ # Profiled binary using gprof
+ if 'prof' in needed_envs:
+ envList.append(
+ makeEnv(env, 'prof', '.po',
+ CCFLAGS = Split(ccflags['prof']),
+ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
+ LINKFLAGS = Split(ldflags['prof'])))
+
+ # Profiled binary using google-pprof
+ if 'perf' in needed_envs:
+ envList.append(
+ makeEnv(env, 'perf', '.gpo',
+ CCFLAGS = Split(ccflags['perf']),
+ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
+ LINKFLAGS = Split(ldflags['perf'])))
+
+ # Set up the regression tests for each build.
+ for e in envList:
+ SConscript(os.path.join(gem5_root, 'tests', 'SConscript'),
+ variant_dir = variantd('tests', e.Label),
+ exports = { 'env' : e }, duplicate = False)
+
+# The MakeEnvirons Builder defers the full dependency collection until
+# after processing the ISA definition (due to dynamically generated
+# source files). Add this dependency to all targets so they will wait
+# until the environments are completely set up. Otherwise, a second
+# process (e.g. -j2 or higher) will try to compile the requested target,
+# not know how, and fail.
+env.Append(BUILDERS = {'MakeEnvirons' :
+ Builder(action=MakeAction(makeEnvirons,
+ Transform("ENVIRONS", 1)))})
+
+isa_target = env['PHONY_BASE'] + '-deps'
+environs = env['PHONY_BASE'] + '-environs'
+env.Depends('#all-deps', isa_target)
+env.Depends('#all-environs', environs)
+env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA']))
+envSetup = env.MakeEnvirons(environs, isa_target)
+
+# make sure no -deps targets occur before all ISAs are complete
+env.Depends(isa_target, '#all-isas')
+# likewise for -environs targets and all the -deps targets
+env.Depends(environs, '#all-deps')