Skip to content

Commit 8c6ab93

Browse files
authored
Remove the asmjs native optimizer (#12131)
This is no longer in use since fastcomp removal. See: #11860
1 parent 1eb50fb commit 8c6ab93

19 files changed

+7
-7600
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ See docs/process.md for how version tagging works.
1717

1818
Current Trunk
1919
-------------
20+
- The native optimizer and the corresponding config setting
21+
(`EMSCRIPTEN_NATIVE_OPTIMIZER`) have been removed (it was only relevant to
22+
asmjs/fastcomp backend).
2023
- Remove `ALLOC_DYNAMIC` and deprecate `dynamicAlloc`. (#12057, which also
2124
removes the internal `DYNAMICTOP_PTR` API.)
2225
- Add `ABORT_ON_EXCEPTIONS` which will abort when an unhandled WASM exception

embuilder.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# University of Illinois/NCSA Open Source License. Both these licenses can be
55
# found in the LICENSE file.
66

7-
"""Tool to manage building of system libraries and other components.
8-
such as ports and the native optimizer.
7+
"""Tool to manage building of system libraries and ports.
98
109
In general emcc will build them automatically on demand, so you do not
1110
strictly need to use this tool, but it gives you more control over the
@@ -20,7 +19,6 @@
2019

2120
from tools import shared
2221
from tools import system_libs
23-
from tools import js_optimizer
2422
import emscripten
2523

2624

@@ -97,15 +95,6 @@ def get_help():
9795
build %s
9896
9997
Issuing 'embuilder.py build ALL' causes each task to be built.
100-
101-
It is also possible to build native_optimizer manually by using CMake. To
102-
do that, run
103-
104-
1. cd $EMSCRIPTEN/tools/optimizer
105-
2. cmake . -DCMAKE_BUILD_TYPE=Release
106-
3. make (or mingw32-make/vcbuild/msbuild on Windows)
107-
108-
and set up the location to the native optimizer in .emscripten
10998
''' % '\n '.join(all_tasks)
11099

111100

@@ -196,10 +185,6 @@ def main():
196185
if force:
197186
shared.Cache.erase_file('generated_struct_info.json')
198187
emscripten.generate_struct_info()
199-
elif what == 'native_optimizer':
200-
if force:
201-
shared.Cache.erase_file('optimizer.2.exe')
202-
js_optimizer.get_native_optimizer()
203188
elif what == 'icu':
204189
build_port('icu', libname('libicuuc'))
205190
elif what == 'zlib':

tests/test_core.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8449,9 +8449,6 @@ def setUp(self):
84498449
simd2 = make_run('simd2', emcc_args=['-O2', '-msimd128'])
84508450
bulkmem2 = make_run('bulkmem2', emcc_args=['-O2', '-mbulk-memory'])
84518451

8452-
# asm.js
8453-
asm2nn = make_run('asm2nn', emcc_args=['-O2'], settings={'WASM': 0}, env={'EMCC_NATIVE_OPTIMIZER': '0'})
8454-
84558452
# wasm
84568453
wasm2s = make_run('wasm2s', emcc_args=['-O2'], settings={'SAFE_HEAP': 1})
84578454
wasm2ss = make_run('wasm2ss', emcc_args=['-O2'], settings={'STACK_OVERFLOW_CHECK': 2})

tests/test_sanity.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def restore():
3333
def restore_and_set_up():
3434
restore()
3535
with open(CONFIG_FILE, 'a') as f:
36-
# don't use the native optimizer from the emsdk - we want to test how it builds
37-
f.write('\nEMSCRIPTEN_NATIVE_OPTIMIZER = ""\n')
3836
# make LLVM_ROOT sensitive to the LLVM env var, as we test that
3937
f.write('LLVM_ROOT = "%s"\n' % LLVM_ROOT)
4038
# unfreeze the cache, so we can test that

tools/js_optimizer.py

Lines changed: 2 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import re
1212
import json
1313
import shutil
14-
import logging
1514

1615
__rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
1716
sys.path.insert(1, __rootpath__)
@@ -35,9 +34,6 @@ def path_from_root(*pathelems):
3534
return os.path.join(__rootpath__, *pathelems)
3635

3736

38-
# Passes supported by the native optimizer
39-
NATIVE_PASSES = set(['asm', 'asmPreciseF32', 'receiveJSON', 'emitJSON', 'eliminate', 'eliminateMemSafe', 'simplifyExpressions', 'simplifyIfs', 'optimizeFrounds', 'registerize', 'registerizeHarder', 'minifyNames', 'minifyLocals', 'minifyWhitespace', 'cleanup', 'asmLastOpts', 'last', 'noop', 'closure'])
40-
4137
JS_OPTIMIZER = path_from_root('tools', 'js-optimizer.js')
4238

4339
NUM_CHUNKS_PER_CORE = 3
@@ -52,8 +48,6 @@ def path_from_root(*pathelems):
5248
func_sig_json = re.compile(r'\["defun", ?"([_\w$]+)",')
5349
import_sig = re.compile(r'(var|const) ([_\w$]+ *=[^;]+);')
5450

55-
NATIVE_OPTIMIZER = os.environ.get('EMCC_NATIVE_OPTIMIZER') or '2' # use optimized native optimizer by default (can also be '1' or 'g')
56-
5751

5852
def split_funcs(js, just_split=False):
5953
if just_split:
@@ -74,137 +68,6 @@ def split_funcs(js, just_split=False):
7468
return funcs
7569

7670

77-
def get_native_optimizer():
78-
# Allow users to override the location of the optimizer executable by setting
79-
# an environment variable EMSCRIPTEN_NATIVE_OPTIMIZER=/path/to/optimizer(.exe)
80-
opt = os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER')
81-
if opt:
82-
logging.debug('env forcing native optimizer at ' + opt)
83-
return opt
84-
# Also, allow specifying the location of the optimizer in .emscripten
85-
# configuration file under EMSCRIPTEN_NATIVE_OPTIMIZER='/path/to/optimizer'
86-
opt = shared.EMSCRIPTEN_NATIVE_OPTIMIZER
87-
if opt:
88-
logging.debug('config forcing native optimizer at ' + opt)
89-
return opt
90-
91-
log_output = None if DEBUG else subprocess.PIPE
92-
93-
def get_optimizer(name, args):
94-
def create_optimizer_cmake():
95-
shared.logging.debug('building native optimizer via CMake: ' + name)
96-
output = shared.Cache.get_path(name)
97-
shared.try_delete(output)
98-
99-
if NATIVE_OPTIMIZER == '1':
100-
cmake_build_type = 'RelWithDebInfo'
101-
elif NATIVE_OPTIMIZER == '2':
102-
cmake_build_type = 'Release'
103-
elif NATIVE_OPTIMIZER == 'g':
104-
cmake_build_type = 'Debug'
105-
106-
build_path = shared.Cache.get_path('optimizer_build_' + cmake_build_type)
107-
shared.try_delete(os.path.join(build_path, 'CMakeCache.txt'))
108-
109-
if not os.path.exists(build_path):
110-
os.mkdir(build_path)
111-
112-
if WINDOWS:
113-
# Poor man's check for whether or not we should attempt 64 bit build
114-
if os.environ.get('ProgramFiles(x86)'):
115-
cmake_generators = [
116-
'Visual Studio 15 2017 Win64',
117-
'Visual Studio 15 2017',
118-
'Visual Studio 14 2015 Win64',
119-
'Visual Studio 14 2015',
120-
'Visual Studio 12 Win64', # The year component is omitted for compatibility with older CMake.
121-
'Visual Studio 12',
122-
'Visual Studio 11 Win64',
123-
'Visual Studio 11',
124-
'MinGW Makefiles',
125-
'Unix Makefiles',
126-
]
127-
else:
128-
cmake_generators = [
129-
'Visual Studio 15 2017',
130-
'Visual Studio 14 2015',
131-
'Visual Studio 12',
132-
'Visual Studio 11',
133-
'MinGW Makefiles',
134-
'Unix Makefiles',
135-
]
136-
else:
137-
cmake_generators = ['Unix Makefiles']
138-
139-
for cmake_generator in cmake_generators:
140-
# Delete CMakeCache.txt so that we can switch to a new CMake generator.
141-
shared.try_delete(os.path.join(build_path, 'CMakeCache.txt'))
142-
proc = subprocess.Popen(['cmake', '-G', cmake_generator, '-DCMAKE_BUILD_TYPE=' + cmake_build_type, shared.path_from_root('tools', 'optimizer')], cwd=build_path, stdin=log_output, stdout=log_output, stderr=log_output)
143-
proc.communicate()
144-
if proc.returncode == 0:
145-
make = ['cmake', '--build', build_path]
146-
if 'Visual Studio' in cmake_generator:
147-
make += ['--config', cmake_build_type, '--', '/nologo', '/verbosity:minimal']
148-
149-
proc = subprocess.Popen(make, cwd=build_path, stdin=log_output, stdout=log_output, stderr=log_output)
150-
proc.communicate()
151-
if proc.returncode == 0:
152-
if WINDOWS and 'Visual Studio' in cmake_generator:
153-
shutil.copyfile(os.path.join(build_path, cmake_build_type, 'optimizer.exe'), output)
154-
else:
155-
shutil.copyfile(os.path.join(build_path, 'optimizer'), output)
156-
return output
157-
158-
assert False
159-
160-
def create_optimizer():
161-
shared.logging.debug('building native optimizer: ' + name)
162-
output = shared.Cache.get_path(name)
163-
shared.try_delete(output)
164-
for compiler in [shared.CLANG_CXX, 'g++', 'clang++']: # try our clang first, otherwise hope for a system compiler in the path
165-
shared.logging.debug(' using ' + compiler)
166-
try:
167-
shared.run_process([compiler,
168-
shared.path_from_root('tools', 'optimizer', 'parser.cpp'),
169-
shared.path_from_root('tools', 'optimizer', 'simple_ast.cpp'),
170-
shared.path_from_root('tools', 'optimizer', 'optimizer.cpp'),
171-
shared.path_from_root('tools', 'optimizer', 'optimizer-shared.cpp'),
172-
shared.path_from_root('tools', 'optimizer', 'optimizer-main.cpp'),
173-
'-O3', '-std=c++11', '-fno-exceptions', '-fno-rtti', '-o', output] + args,
174-
stdout=log_output, stderr=log_output)
175-
except Exception as e:
176-
logging.debug(str(e))
177-
continue # perhaps the later compilers will succeed
178-
# success
179-
return output
180-
shared.exit_with_error('Failed to build native optimizer')
181-
182-
use_cmake_to_configure = WINDOWS # Currently only Windows uses CMake to drive the optimizer build, but set this to True to use on other platforms as well.
183-
if use_cmake_to_configure:
184-
return shared.Cache.get(name, create_optimizer_cmake)
185-
else:
186-
return shared.Cache.get(name, create_optimizer)
187-
188-
if NATIVE_OPTIMIZER == '1':
189-
return get_optimizer('optimizer.exe', [])
190-
elif NATIVE_OPTIMIZER == '2':
191-
return get_optimizer('optimizer.2.exe', ['-DNDEBUG'])
192-
elif NATIVE_OPTIMIZER == 'g':
193-
return get_optimizer('optimizer.g.exe', ['-O0', '-g', '-fno-omit-frame-pointer'])
194-
195-
196-
# Check if we should run a pass or set of passes natively. if a set of passes,
197-
# they must all be valid to run in the native optimizer at once.
198-
def use_native(x, source_map=False):
199-
if source_map:
200-
return False
201-
if not NATIVE_OPTIMIZER or NATIVE_OPTIMIZER == '0':
202-
return False
203-
if isinstance(x, list):
204-
return len(NATIVE_PASSES.intersection(x)) == len(x) and 'asm' in x
205-
return x in NATIVE_PASSES
206-
207-
20871
class Minifier(object):
20972
"""asm.js minification support. We calculate minification of
21073
globals here, then pass that into the parallel js-optimizer.js runners which
@@ -445,15 +308,8 @@ def write_chunk(chunk, i):
445308

446309
with ToolchainProfiler.profile_block('run_optimizer'):
447310
if len(filenames):
448-
if not use_native(passes, source_map):
449-
commands = [shared.NODE_JS + [JS_OPTIMIZER, f, 'noPrintMetadata'] +
450-
(['--debug'] if source_map else []) + passes for f in filenames]
451-
else:
452-
# use the native optimizer
453-
shared.logging.debug('js optimizer using native')
454-
assert not source_map # XXX need to use js optimizer
455-
commands = [[get_native_optimizer(), f] + passes for f in filenames]
456-
# print [' '.join(command) for command in commands]
311+
commands = [shared.NODE_JS + [JS_OPTIMIZER, f, 'noPrintMetadata'] +
312+
(['--debug'] if source_map else []) + passes for f in filenames]
457313

458314
cores = min(cores, len(filenames))
459315
if len(chunks) > 1 and cores >= 2:

tools/optimizer/CMakeLists.txt

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)