use llvm internalive and globaldce to remove unneeded code before compiling to js
This commit is contained in:
Родитель
9aa0797ea0
Коммит
e7c773654d
6
emcc
6
emcc
|
@ -512,6 +512,11 @@ try:
|
|||
if llvm_opt_level > 0 and not LEAVE_INPUTS_RAW:
|
||||
if DEBUG: print >> sys.stderr, 'emcc: LLVM opts'
|
||||
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), LLVM_INTERNAL_OPT_LEVEL, safe=llvm_opt_level < 2)
|
||||
else:
|
||||
# If possible, remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
|
||||
if not shared.Settings.BUILD_AS_SHARED_LIB:
|
||||
if DEBUG: print >> sys.stderr, 'emcc: LLVM dead globals elimination'
|
||||
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), ['-internalize', '-globaldce'])
|
||||
|
||||
# Emscripten
|
||||
try:
|
||||
|
@ -531,6 +536,7 @@ try:
|
|||
|
||||
if not LEAVE_INPUTS_RAW:
|
||||
final = in_temp(target_basename + '.bc')
|
||||
if DEBUG: save_intermediate('bc', 'bc')
|
||||
final = shared.Building.llvm_dis(final, final + '.ll')
|
||||
if DEBUG: save_intermediate('ll', 'll')
|
||||
else:
|
||||
|
|
|
@ -439,10 +439,14 @@ class Building:
|
|||
output = Popen(['python', DFE, filename + '.o.ll.orig', filename + '.o.ll'], stdout=PIPE).communicate()[0]
|
||||
assert os.path.exists(filename + '.o.ll'), 'Failed to run ll optimizations'
|
||||
|
||||
# Optional LLVM optimizations
|
||||
# LLVM optimizations
|
||||
# @param opt Either an integer, in which case it is the optimization level (-O1, -O2, etc.), or a list of raw
|
||||
# optimization passes passed to llvm opt
|
||||
@staticmethod
|
||||
def llvm_opt(filename, level, safe=True):
|
||||
output = Popen([LLVM_OPT, filename] + Building.pick_llvm_opts(level, safe) + ['-o=' + filename + '.opt.bc'], stdout=PIPE).communicate()[0]
|
||||
def llvm_opt(filename, opts, safe=True):
|
||||
if type(opts) is int:
|
||||
opts = Building.pick_llvm_opts(opts, safe)
|
||||
output = Popen([LLVM_OPT, filename] + opts + ['-o=' + filename + '.opt.bc'], stdout=PIPE).communicate()[0]
|
||||
assert os.path.exists(filename + '.opt.bc'), 'Failed to run llvm optimizations: ' + output
|
||||
shutil.move(filename + '.opt.bc', filename)
|
||||
|
||||
|
@ -533,6 +537,10 @@ class Building:
|
|||
(which we do in do_ll_opts) - but even there we have issues (even in TA2) with instruction combining
|
||||
into i64s. In any case, the handpicked ones here should be safe and portable. They are also tuned for
|
||||
things that look useful.
|
||||
|
||||
An easy way to see LLVM's standard list of passes is
|
||||
|
||||
llvm-as < /dev/null | opt -std-compile-opts -disable-output -debug-pass=Arguments
|
||||
'''
|
||||
opts = []
|
||||
if optimization_level > 0:
|
||||
|
@ -552,6 +560,9 @@ class Building:
|
|||
opts.append('-tbaa')
|
||||
opts.append('-basicaa') # makes fannkuch slow but primes fast
|
||||
|
||||
if not Settings.BUILD_AS_SHARED_LIB:
|
||||
opts.append('-internalize')
|
||||
|
||||
opts.append('-globalopt')
|
||||
opts.append('-ipsccp')
|
||||
opts.append('-deadargelim')
|
||||
|
@ -609,7 +620,8 @@ class Building:
|
|||
|
||||
opts.append('-strip-dead-prototypes')
|
||||
|
||||
if optimization_level > 2: opts.append('-globaldce')
|
||||
if not Settings.BUILD_AS_SHARED_LIB:
|
||||
opts.append('-globaldce')
|
||||
|
||||
if optimization_level > 1: opts.append('-constmerge')
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче