diff options
-rwxr-xr-x | emcc | 7 | ||||
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | src/settings.js | 8 | ||||
-rwxr-xr-x | tests/runner.py | 4 | ||||
-rw-r--r-- | tools/shared.py | 9 |
5 files changed, 21 insertions, 9 deletions
@@ -569,8 +569,11 @@ try: if DEBUG: save_intermediate('opt', 'bc') # Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript) if shared.Building.can_use_unsafe_opts() and shared.Building.can_build_standalone(): - if DEBUG: print >> sys.stderr, 'emcc: LLVM LTO' - shared.Building.llvm_opt(in_temp(target_basename + '.bc'), ['-disable-inlining', '-std-link-opts']) + lto_opts = [] + if not shared.Building.can_inline(): lto_opts.append('-disable-inlining') + lto_opts.append('-std-link-opts') + if DEBUG: print >> sys.stderr, 'emcc: LLVM LTO:', lto_opts + shared.Building.llvm_opt(in_temp(target_basename + '.bc'), lto_opts) if DEBUG: save_intermediate('lto', 'bc') else: # If possible, remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it) diff --git a/src/jsifier.js b/src/jsifier.js index 97d04055..e66f7b69 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -628,7 +628,7 @@ function JSify(data, functionsOnly, givenFunctions) { func.JS += 'Module["' + func.ident + '"] = ' + func.ident + ';'; } - if (func.lines.length >= CLOSURE_INLINE_PREVENTION_LINES) { + if (INLINING_LIMIT && func.lines.length >= INLINING_LIMIT) { func.JS += func.ident + '["X"]=1;'; } diff --git a/src/settings.js b/src/settings.js index 16a7b665..6bca0174 100644 --- a/src/settings.js +++ b/src/settings.js @@ -85,10 +85,10 @@ var SKIP_STACK_IN_SMALL = 1; // When enabled, does not push/pop the stack at all // In particular, be careful with the autodebugger! (We do turn // this off automatically in that case, though.) var INLINE_LIBRARY_FUNCS = 1; // Will inline library functions that have __inline defined -var CLOSURE_INLINE_PREVENTION_LINES = 50; // Functions of this number of lines or larger will have - // code generated that tells the closure compiler not to - // inline them. This is useful to prevent the generation of - // overly large functions. +var INLINING_LIMIT = 50; // A limit on inlining. If 0, we will inline normally in LLVM and + // closure. If greater than 0, we will *not* inline in LLVM, and + // we will prevent inlining of functions of this size or larger + // in closure. var CATCH_EXIT_CODE = 0; // If set, causes exit() to throw an exception object which is caught // in a try..catch block and results in the exit status being // returned from run(). If zero (the default), the program is just diff --git a/tests/runner.py b/tests/runner.py index c082f855..93511589 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -5524,9 +5524,12 @@ Options that are modified or new in %s include: assert ('_puts(' in generated) == (opt_level >= 1), 'with opt >= 1, llvm opts are run and they should optimize printf to puts' assert ('function _malloc(bytes) {' in generated) == (not has_malloc), 'If malloc is needed, it should be there, if not not' assert 'function _main() {' in generated, 'Should be unminified, including whitespace' + assert 'function _dump' in generated, 'No inlining by default' # emcc -s RELOOP=1 src.cpp ==> should pass -s to emscripten.py. --typed-arrays is a convenient alias for -s USE_TYPED_ARRAYS for params, test, text in [ + (['-s', 'INLINING_LIMIT=0'], lambda generated: 'function _dump' in generated, 'no inlining without opts'), + (['-O1', '-s', 'INLINING_LIMIT=0'], lambda generated: 'function _dump' not in generated, 'inlining'), (['-s', 'USE_TYPED_ARRAYS=0'], lambda generated: 'new Int32Array' not in generated, 'disable typed arrays'), (['-s', 'USE_TYPED_ARRAYS=1'], lambda generated: 'IHEAPU = ' in generated, 'typed arrays 1 selected'), ([], lambda generated: 'Module["_dump"]' not in generated, 'dump is not exported by default'), @@ -5799,6 +5802,7 @@ elif 'benchmark' in str(sys.argv): try_delete(final_filename) output = Popen([EMCC, filename, '-O3', + '-s', 'INLINING_LIMIT=0', '-s', 'TOTAL_MEMORY=100*1024*1024', '-s', 'FAST_MEMORY=10*1024*1024', '-o', final_filename] + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate() assert os.path.exists(final_filename), 'Failed to compile file: ' + '\n'.join(output) diff --git a/tools/shared.py b/tools/shared.py index 366834ef..2304d817 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -540,6 +540,10 @@ class Building: return Settings.USE_TYPED_ARRAYS == 2 @staticmethod + def can_inline(): + return Settings.INLINING_LIMIT == 0 + + @staticmethod def pick_llvm_opts(optimization_level): ''' It may be safe to use nonportable optimizations (like -OX) if we remove the platform info from the .ll @@ -556,7 +560,8 @@ class Building: opts = [] if optimization_level > 0: if unsafe: - opts.append('-disable-inlining') # we prefer to let closure compiler do our inlining, to avoid overly aggressive inlining + if not Building.can_inline(): + opts.append('-disable-inlining') # -Ox opts do -globaldce, which removes stuff that is needed for libraries and linkables if Building.can_build_standalone(): opts.append('-O%d' % optimization_level) @@ -583,7 +588,7 @@ class Building: opts.append('-simplifycfg') opts.append('-prune-eh') - if not optimize_size: opts.append('-inline') # The condition here is a difference with LLVM's createStandardAliasAnalysisPasses + if Building.can_inline(): opts.append('-inline') opts.append('-functionattrs') if optimization_level > 2: opts.append('-argpromotion') |