diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-18 12:31:45 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-18 12:31:45 -0800 |
commit | e7c773654dcf02af4ac8d80f9ea29683b911b668 (patch) | |
tree | 716564b8ce1ec572321883a7fed8213860e0f681 /tools | |
parent | 9aa0797ea013ccd0a91c78c9e6c83d1f42cba3c3 (diff) |
use llvm internalive and globaldce to remove unneeded code before compiling to js
Diffstat (limited to 'tools')
-rw-r--r-- | tools/shared.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tools/shared.py b/tools/shared.py index f33e2cbd..718edc75 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -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') |