diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/js-optimizer.js | 24 | ||||
-rw-r--r-- | tools/shared.py | 27 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre-output.js | 8 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre.js | 4 |
4 files changed, 49 insertions, 14 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 57ce0071..57585663 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -585,12 +585,24 @@ function simplifyExpressions(ast) { } } else if (type === 'assign') { // optimizations for assigning into HEAP32 specifically - if (node[1] === true && node[2][0] === 'sub' && node[2][1][0] === 'name' && node[2][1][1] === 'HEAP32') { - // HEAP32[..] = x | 0 does not need the | 0 (unless it is a mandatory |0 of a call) - if (node[3][0] === 'binary' && node[3][1] === '|') { - if (node[3][2][0] === 'num' && node[3][2][1] === 0 && node[3][3][0] != 'call') { - node[3] = node[3][3]; - } else if (node[3][3][0] === 'num' && node[3][3][1] === 0 && node[3][2][0] != 'call') { + if (node[1] === true && node[2][0] === 'sub' && node[2][1][0] === 'name') { + if (node[2][1][1] === 'HEAP32') { + // HEAP32[..] = x | 0 does not need the | 0 (unless it is a mandatory |0 of a call) + if (node[3][0] === 'binary' && node[3][1] === '|') { + if (node[3][2][0] === 'num' && node[3][2][1] === 0 && node[3][3][0] != 'call') { + node[3] = node[3][3]; + } else if (node[3][3][0] === 'num' && node[3][3][1] === 0 && node[3][2][0] != 'call') { + node[3] = node[3][2]; + } + } + } else if (node[2][1][1] === 'HEAP8') { + // HEAP8[..] = x & 0xff does not need the & 0xff + if (node[3][0] === 'binary' && node[3][1] === '&' && node[3][3][0] == 'num' && node[3][3][1] == 0xff) { + node[3] = node[3][2]; + } + } else if (node[2][1][1] === 'HEAP16') { + // HEAP16[..] = x & 0xffff does not need the & 0xffff + if (node[3][0] === 'binary' && node[3][1] === '&' && node[3][3][0] == 'num' && node[3][3][1] == 0xffff) { node[3] = node[3][2]; } } diff --git a/tools/shared.py b/tools/shared.py index 3456ab18..443ff4c7 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -176,13 +176,28 @@ if WINDOWS: else: logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit) -# Emscripten configuration is done through the EM_CONFIG environment variable. -# If the string value contained in this environment variable contains newline -# separated definitions, then these definitions will be used to configure +# Emscripten configuration is done through the --em-config command line option or +# the EM_CONFIG environment variable. If the specified string value contains newline +# or semicolon-separated definitions, then these definitions will be used to configure # Emscripten. Otherwise, the string is understood to be a path to a settings # file that contains the required definitions. -EM_CONFIG = os.environ.get('EM_CONFIG') +try: + EM_CONFIG = sys.argv[sys.argv.index('--em-config')+1] + # Emscripten compiler spawns other processes, which can reimport shared.py, so make sure that + # those child processes get the same configuration file by setting it to the currently active environment. + os.environ['EM_CONFIG'] = EM_CONFIG +except: + EM_CONFIG = os.environ.get('EM_CONFIG') + +if EM_CONFIG and not os.path.isfile(EM_CONFIG): + if EM_CONFIG.startswith('-'): + raise Exception('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config EMSCRIPTEN_ROOT=/path/;LLVM_ROOT=/path;...') + if not '=' in EM_CONFIG: + raise Exception('File ' + EM_CONFIG + ' passed to --em-config does not exist!') + else: + EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n' + if not EM_CONFIG: EM_CONFIG = '~/.emscripten' if '\n' in EM_CONFIG: @@ -926,7 +941,7 @@ class Building: @staticmethod - def build_library(name, build_dir, output_dir, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None, native=False): + def build_library(name, build_dir, output_dir, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args='help', cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None, native=False): ''' Build a library into a .bc file. We build the .bc file once and cache it for all our tests. (We cache in memory since the test directory is destroyed and recreated for each test. Note that we cache separately for different compilers). @@ -934,6 +949,8 @@ class Building: if type(generated_libs) is not list: generated_libs = [generated_libs] if source_dir is None: source_dir = path_from_root('tests', name.replace('_native', '')) + if make_args == 'help': + make_args = ['-j', str(multiprocessing.cpu_count())] temp_dir = build_dir if copy_project: diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js index 2e3db000..0fa81050 100644 --- a/tools/test-js-optimizer-asm-pre-output.js +++ b/tools/test-js-optimizer-asm-pre-output.js @@ -58,12 +58,14 @@ function b($this, $__n) { _memset($38 + $23 | 0, 0, $__n | 0, 1, 1213141516); $40 = $23 + $__n | 0; if ((HEAP8[$4 & 16777215] & 1) == 0) { - HEAP8[$4 & 16777215] = $40 << 1 & 255; + HEAP8[$4 & 16777215] = $40 << 1; } else { HEAP32[($this + 4 & 16777215) >> 2] = $40; } HEAP8[$38 + $40 & 16777215] = 0; HEAP32[$4] = ~HEAP32[$5]; + HEAP8[$4] = HEAP32[$5]; + HEAP16[$4] = HEAP32[$5]; HEAP32[$4] = ~HEAP32[$5]; HEAP32[$4] = ~HEAP32[$5]; h(~~g ^ -1); @@ -240,10 +242,10 @@ function _main($argc, $argv) { } if (($i_09_i_i | 0) > (HEAP32[9600 + ($j_08_i_i << 2) >> 2] | 0)) { $34 = $j_08_i_i + 1 | 0; - HEAP8[$i_09_i_i + 8952 | 0] = $34 & 255; + HEAP8[$i_09_i_i + 8952 | 0] = $34; $j_1_i_i = $34; } else { - HEAP8[$i_09_i_i + 8952 | 0] = $j_08_i_i & 255; + HEAP8[$i_09_i_i + 8952 | 0] = $j_08_i_i; $j_1_i_i = $j_08_i_i; } $38 = $i_09_i_i + 1 | 0; diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js index 9e6edf0f..dadeef53 100644 --- a/tools/test-js-optimizer-asm-pre.js +++ b/tools/test-js-optimizer-asm-pre.js @@ -66,6 +66,10 @@ function b($this, $__n) { HEAP8[($38 + $40 | 0) & 16777215] = 0; // Eliminate the |0. HEAP32[$4] = ((~(HEAP32[$5]|0))|0); + // Eliminate the &255 + HEAP8[$4] = HEAP32[$5]&255; + // Eliminate the &65535 + HEAP16[$4] = HEAP32[$5]&65535; // Rewrite to ~. HEAP32[$4] = HEAP32[$5]^-1; // Rewrite to ~ and eliminate the |0. |