Skip to content

Commit 4348ec6

Browse files
committed
move to legalization in the JS backend
1 parent 15d592f commit 4348ec6

3 files changed

Lines changed: 17 additions & 31 deletions

File tree

emcc

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ try:
870870
# Set ASM_JS default here so that we can override it from the command line.
871871
shared.Settings.ASM_JS = 1 if opt_level > 0 else 2
872872

873-
pre_fastcomp_opts = []
874-
875873
# Apply -s settings in newargs here (after optimization levels, so they can override them)
876874
for change in settings_changes:
877875
key, value = change.split('=')
@@ -902,20 +900,6 @@ try:
902900
logging.error('Compiler settings are incompatible with fastcomp. You can fall back to the older compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html')
903901
raise e
904902

905-
fastcomp_opts = []
906-
if shared.Settings.NO_EXIT_RUNTIME:
907-
pre_fastcomp_opts += ['-emscripten-no-exit-runtime']
908-
if not llvm_lto: fastcomp_opts += ['-globalopt', '-globaldce']
909-
fastcomp_opts += ['-pnacl-abi-simplify-preopt', '-pnacl-abi-simplify-postopt']
910-
if shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
911-
fastcomp_opts += ['-enable-emscripten-cxx-exceptions']
912-
if shared.Settings.DISABLE_EXCEPTION_CATCHING == 2:
913-
fastcomp_opts += ['-emscripten-cxx-exceptions-whitelist=' + ','.join(shared.Settings.EXCEPTION_CATCHING_WHITELIST or ['fake'])]
914-
if shared.Settings.ASYNCIFY:
915-
fastcomp_opts += ['-emscripten-asyncify']
916-
fastcomp_opts += ['-emscripten-asyncify-functions=' + ','.join(shared.Settings.ASYNCIFY_FUNCTIONS)]
917-
fastcomp_opts += ['-emscripten-asyncify-whitelist=' + ','.join(shared.Settings.ASYNCIFY_WHITELIST)]
918-
919903
assert not shared.Settings.PGO, 'cannot run PGO in ASM_JS mode'
920904

921905
if shared.Settings.SAFE_HEAP and not js_opts:
@@ -1278,7 +1262,7 @@ try:
12781262
if not shared.Settings.ASSERTIONS:
12791263
link_opts += ['-disable-verify']
12801264

1281-
if llvm_lto >= 2:
1265+
if llvm_lto >= 2 and llvm_opts > 0:
12821266
logging.debug('running LLVM opts as pre-LTO')
12831267
final = shared.Building.llvm_opt(final, llvm_opts, DEFAULT_FINAL)
12841268
if DEBUG: save_intermediate('opt', 'bc')
@@ -1289,9 +1273,8 @@ try:
12891273
# add a manual internalize with the proper things we need to be kept alive during lto
12901274
link_opts += shared.Building.get_safe_internalize() + ['-std-link-opts']
12911275
# execute it now, so it is done entirely before we get to the stage of legalization etc.
1292-
final = shared.Building.llvm_opt(final, pre_fastcomp_opts + link_opts, DEFAULT_FINAL)
1276+
final = shared.Building.llvm_opt(final, link_opts, DEFAULT_FINAL)
12931277
if DEBUG: save_intermediate('lto', 'bc')
1294-
pre_fastcomp_opts = []
12951278
link_opts = []
12961279
else:
12971280
# At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
@@ -1303,15 +1286,11 @@ try:
13031286
final = shared.Building.llvm_opt(final, link_opts, get_final() + '.link.ll')
13041287
if DEBUG: save_intermediate('linktime', 'll')
13051288
else:
1306-
if not save_bc:
1307-
# Simplify LLVM bitcode for fastcomp
1308-
link_opts = pre_fastcomp_opts + link_opts + fastcomp_opts
1309-
final = shared.Building.llvm_opt(final, link_opts, DEFAULT_FINAL)
1310-
if DEBUG: save_intermediate('linktime', 'bc')
1289+
if len(link_opts) > 0:
1290+
final = shared.Building.llvm_opt(final, link_opts, DEFAULT_FINAL)
1291+
if DEBUG: save_intermediate('linktime', 'bc')
13111292
if save_bc:
13121293
shutil.copyfile(final, save_bc)
1313-
final = shared.Building.llvm_opt(final, fastcomp_opts, get_final() + '.adsimp.bc')
1314-
if DEBUG: save_intermediate('adsimp', 'bc')
13151294

13161295
# Prepare .ll for Emscripten
13171296
if LEAVE_INPUTS_RAW:
@@ -1325,11 +1304,6 @@ try:
13251304
final = next
13261305
if DEBUG: save_intermediate('autodebug', 'll')
13271306

1328-
# Simplify bitcode after autodebug
1329-
if AUTODEBUG or LEAVE_INPUTS_RAW:
1330-
final = shared.Building.llvm_opt(final, fastcomp_opts, get_final() + '.adsimp.bc')
1331-
if DEBUG: save_intermediate('adsimp', 'bc')
1332-
13331307
assert type(final) == str, 'we must have linked the final files, if linking was deferred, by this point'
13341308

13351309
log_time('post-link')

emscripten.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
8383
elif settings['GLOBAL_BASE'] >= 0:
8484
backend_args += ['-emscripten-global-base=%d' % settings['GLOBAL_BASE']]
8585
backend_args += ['-O' + str(settings['OPT_LEVEL'])]
86+
if settings['DISABLE_EXCEPTION_CATCHING'] != 1:
87+
backend_args += ['-enable-emscripten-cxx-exceptions']
88+
if settings['DISABLE_EXCEPTION_CATCHING'] == 2:
89+
backend_args += ['-emscripten-cxx-exceptions-whitelist=' + ','.join(settings['EXCEPTION_CATCHING_WHITELIST'] or ['fake'])]
90+
if settings['ASYNCIFY']:
91+
backend_args += ['-emscripten-asyncify']
92+
backend_args += ['-emscripten-asyncify-functions=' + ','.join(settings['ASYNCIFY_FUNCTIONS'])]
93+
backend_args += ['-emscripten-asyncify-whitelist=' + ','.join(settings['ASYNCIFY_WHITELIST'])]
94+
if settings['NO_EXIT_RUNTIME']:
95+
backend_args += ['-emscripten-no-exit-runtime']
96+
8697
if DEBUG:
8798
logging.debug('emscript: llvm backend: ' + ' '.join(backend_args))
8899
t = time.time()

tools/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,7 @@ def llvm_opt(filename, opts, out=None):
14721472
assert out, 'must provide out if llvm_opt on a list of inputs'
14731473
if type(opts) is int:
14741474
opts = Building.pick_llvm_opts(opts)
1475+
assert len(opts) > 0, 'should not call opt with nothing to do'
14751476
opts = opts[:]
14761477
#opts += ['-debug-pass=Arguments']
14771478
if get_clang_version() >= '3.4':

0 commit comments

Comments
 (0)