Skip to content

Commit fe6518c

Browse files
committed
refactor build checks for standalone and unsafe opts
1 parent 1204c42 commit fe6518c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

emcc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,13 @@ try:
568568
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts)
569569
if DEBUG: save_intermediate('opt', 'bc')
570570
# Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript)
571-
if not shared.Settings.BUILD_AS_SHARED_LIB and not shared.Settings.LINKABLE:
571+
if shared.Building.can_use_unsafe_opts() and shared.Building.can_build_standalone():
572572
if DEBUG: print >> sys.stderr, 'emcc: LLVM LTO'
573573
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), ['-disable-inlining', '-std-link-opts'])
574574
if DEBUG: save_intermediate('lto', 'bc')
575575
else:
576576
# If possible, remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
577-
if not LEAVE_INPUTS_RAW and not shared.Settings.BUILD_AS_SHARED_LIB and not shared.Settings.LINKABLE:
577+
if not LEAVE_INPUTS_RAW and shared.Building.can_build_standalone():
578578
if DEBUG: print >> sys.stderr, 'emcc: LLVM dead globals elimination'
579579
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), ['-internalize', '-globaldce'])
580580
if DEBUG: save_intermediate('dce', 'bc')

tools/shared.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,14 @@ def emscripten(filename, append_ext=True, extra_args=[]):
530530

531531
return filename + '.o.js'
532532

533+
@staticmethod
534+
def can_build_standalone():
535+
return not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE
536+
537+
@staticmethod
538+
def can_use_unsafe_opts():
539+
return Settings.USE_TYPED_ARRAYS == 2
540+
533541
@staticmethod
534542
def pick_llvm_opts(optimization_level):
535543
'''
@@ -543,28 +551,28 @@ def pick_llvm_opts(optimization_level):
543551
llvm-as < /dev/null | opt -std-compile-opts -disable-output -debug-pass=Arguments
544552
'''
545553
assert 0 <= optimization_level <= 3
546-
safe = Settings.USE_TYPED_ARRAYS != 2
554+
unsafe = Building.can_use_unsafe_opts()
547555
opts = []
548556
if optimization_level > 0:
549-
if not safe:
557+
if unsafe:
550558
opts.append('-disable-inlining') # we prefer to let closure compiler do our inlining, to avoid overly aggressive inlining
551559
# -Ox opts do -globaldce, which removes stuff that is needed for libraries and linkables
552-
if not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE:
560+
if Building.can_build_standalone():
553561
opts.append('-O%d' % optimization_level)
554562
else:
555563
opts.append('-std-compile-opts')
556564
#print '[unsafe: %s]' % ','.join(opts)
557565
else:
558-
allow_nonportable = not safe
566+
allow_nonportable = False
559567
optimize_size = True
560-
use_aa = not safe
568+
use_aa = False
561569

562570
# PassManagerBuilder::populateModulePassManager
563571
if allow_nonportable and use_aa: # ammo.js results indicate this can be nonportable
564572
opts.append('-tbaa')
565573
opts.append('-basicaa') # makes fannkuch slow but primes fast
566574

567-
if not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE:
575+
if Building.can_build_standalone():
568576
opts.append('-internalize')
569577

570578
opts.append('-globalopt')
@@ -624,7 +632,7 @@ def pick_llvm_opts(optimization_level):
624632

625633
opts.append('-strip-dead-prototypes')
626634

627-
if not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE:
635+
if Building.can_build_standalone():
628636
opts.append('-globaldce')
629637

630638
if optimization_level > 1: opts.append('-constmerge')

0 commit comments

Comments
 (0)