diff options
-rwxr-xr-x | tests/runner.py | 17 | ||||
-rw-r--r-- | tools/js-optimizer.js | 13 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-outline2-output.js | 2 |
3 files changed, 23 insertions, 9 deletions
diff --git a/tests/runner.py b/tests/runner.py index 9865dab8..b1a9e6b1 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10817,8 +10817,8 @@ f.close() args=['-I' + path_from_root('tests', 'bullet', 'src')]) - def zzztest_outline(self): - def test(name, src, libs, expected, args=[], suffix='cpp'): + def test_outline(self): + def test(name, src, libs, expected, expected_ranges, args=[], suffix='cpp'): print name def measure_funcs(filename): @@ -10836,20 +10836,23 @@ f.close() if size > 100: ret[curr] = size return ret - sizes = {} - for outlining_limit in [0, 500, 1000, 2500, 5000, 10000]: + for outlining_limit in [5000, 0]: Popen([PYTHON, EMCC, src] + libs + ['-o', 'test.js', '-O2', '-g3', '-s', 'OUTLINING_LIMIT=%d' % outlining_limit] + args).communicate() assert os.path.exists('test.js') for engine in JS_ENGINES: out = run_js('test.js', engine=engine, stderr=PIPE, full_output=True) self.assertContained(expected, out) - #if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) - sizes[outlining_limit] = max(measure_funcs('test.js').values()) - print sizes + if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) + low = expected_ranges[outlining_limit][0] + seen = max(measure_funcs('test.js').values()) + high = expected_ranges[outlining_limit][1] + print ' ', low, '<=', seen, '<=', high + assert low <= seen <= high test('zlib', path_from_root('tests', 'zlib', 'example.c'), self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']), open(path_from_root('tests', 'zlib', 'ref.txt'), 'r').read(), + { 5000: (800, 1100), 0: (1500, 1800) }, args=['-I' + path_from_root('tests', 'zlib')], suffix='c') def test_symlink(self): diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 91e2928e..5d883bc3 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -3127,7 +3127,7 @@ function outline(ast) { var allCodeInfo = analyzeCode(func, asmData, func); var owned = { sp: 1 }; // sp is always owned, each has its own keys(setUnion(codeInfo.reads, codeInfo.writes)).forEach(function(v) { - if (allCodeInfo.reads[v] === codeInfo.reads[v] && allCodeInfo.writes[v] === codeInfo.writes[v]) { + if (allCodeInfo.reads[v] === codeInfo.reads[v] && allCodeInfo.writes[v] === codeInfo.writes[v] && !(v in asmData.params)) { owned[v] = 1; } }); @@ -3286,8 +3286,19 @@ function outline(ast) { newAsmData.vars[v] = getAsmType(v, asmData); } denormalizeAsm(newFunc, newAsmData); + for (var v in owned) { + if (v != 'sp') delete asmData.vars[v]; // parent does not need these anymore + } // replace in stats stats.splice.apply(stats, [start, end-start+1].concat(reps)); + // if we just removed a final return from the original function, add one + var last = getStatements(func)[getStatements(func).length-1]; + if (last[0] === 'stat') last = last[1]; + if (last[0] !== 'return') { + if (allCodeInfo.hasReturnInt || allCodeInfo.hasReturnDouble) { + getStatements(func).push(['stat', ['return', makeAsmCoercion(['num', 0], allCodeInfo.hasReturnInt ? ASM_INT : ASM_DOUBLE)]]); + } + } return [newFunc]; } diff --git a/tools/test-js-optimizer-asm-outline2-output.js b/tools/test-js-optimizer-asm-outline2-output.js index 646c6517..5c46243a 100644 --- a/tools/test-js-optimizer-asm-outline2-output.js +++ b/tools/test-js-optimizer-asm-outline2-output.js @@ -21,7 +21,7 @@ function linear() { } function _free($mem) { $mem = $mem | 0; - var $5 = 0, $10 = 0, $16 = 0, $21 = 0, $25 = 0, $26 = 0, $37 = 0, $40 = 0, $_pre_phi307 = 0, $69 = 0, $72 = 0, $75 = 0, $80 = 0, $95 = 0, $100 = 0, $RP_0 = 0, $R_0 = 0, $102 = 0, $103 = 0, $106 = 0, $107 = 0, $R_1 = 0, $120 = 0, $151 = 0, $164 = 0, $psize_0 = 0, $p_0 = 0, $189 = 0, $194 = 0, $204 = 0, $220 = 0, $227 = 0, $233 = 0, $236 = 0, $_pre_phi305 = 0, $267 = 0, $270 = 0, $273 = 0, $278 = 0, $294 = 0, $299 = 0, $RP9_0 = 0, $R7_0 = 0, $301 = 0, $302 = 0, $305 = 0, $306 = 0, $R7_1 = 0, $320 = 0, $351 = 0, $364 = 0, $psize_1 = 0, $390 = 0, $396 = 0, $404 = 0, $_pre_phi = 0, $F16_0 = 0, $414 = 0, $415 = 0, $428 = 0, $436 = 0, $I18_0 = 0, $443 = 0, $447 = 0, $448 = 0, $463 = 0, $T_0 = 0, $K19_0 = 0, $472 = 0, $473 = 0, $486 = 0, $487 = 0, $489 = 0, $501 = 0, $sp_0_in_i = 0, $sp_0_i = 0, label = 0, sp = 0; + var $5 = 0, $10 = 0, $16 = 0, $21 = 0, $25 = 0, $26 = 0, $psize_0 = 0, $p_0 = 0, $189 = 0, $194 = 0, $204 = 0, $psize_1 = 0, $390 = 0, $396 = 0, $404 = 0, $_pre_phi = 0, $F16_0 = 0, $414 = 0, $415 = 0, $428 = 0, $436 = 0, $I18_0 = 0, $443 = 0, $447 = 0, $448 = 0, $463 = 0, $T_0 = 0, $K19_0 = 0, $472 = 0, $473 = 0, $486 = 0, $487 = 0, $489 = 0, $501 = 0, $sp_0_in_i = 0, $sp_0_i = 0, label = 0, sp = 0; sp = STACKTOP; if (($mem | 0) == 0) { STACKTOP = sp; |