aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-14 21:58:52 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-14 21:58:52 -0800
commit149b9ea5747d610d2ebfb41bc87e8bb96f498359 (patch)
treea08fc9b33d9aac1baa436a0a4896a103b24702bb
parent757f28b777303a90fe2992d0e2f82ce0958f12f2 (diff)
emit ll from llvm opt directly, to skip writing and reading all the bitcode
-rwxr-xr-xemcc16
-rw-r--r--tools/shared.py10
2 files changed, 18 insertions, 8 deletions
diff --git a/emcc b/emcc
index 4c3aa009..c3f9d862 100755
--- a/emcc
+++ b/emcc
@@ -1638,18 +1638,26 @@ try:
else:
# At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
link_opts += shared.Building.get_safe_internalize() + ['-globaldce']
- shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
- if DEBUG: save_intermediate('linktime', 'bc')
+ if not save_bc:
+ # let llvm opt directly emit ll, to skip writing and reading all the bitcode
+ link_opts += ['-S']
+ shared.Building.llvm_opt(final, link_opts, final + '.link.ll')
+ final = final + '.link.ll'
+ if DEBUG: save_intermediate('linktime', 'll')
+ else:
+ shared.Building.llvm_opt(final, link_opts)
+ if DEBUG: save_intermediate('linktime', 'bc')
if save_bc:
shutil.copyfile(final, save_bc)
# Prepare .ll for Emscripten
if not LEAVE_INPUTS_RAW:
- final = shared.Building.llvm_dis(final, final + '.ll')
+ if save_bc:
+ final = shared.Building.llvm_dis(final, final + '.ll')
else:
assert len(input_files) == 1
- if DEBUG: save_intermediate('ll', 'll')
+ if DEBUG and save_bc: save_intermediate('ll', 'll')
if AUTODEBUG:
logging.debug('autodebug')
diff --git a/tools/shared.py b/tools/shared.py
index e2c6e89f..5b165b8b 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1110,14 +1110,16 @@ class Building:
# @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, opts):
+ def llvm_opt(filename, opts, out=None):
if type(opts) is int:
opts = Building.pick_llvm_opts(opts)
#opts += ['-debug-pass=Arguments']
logging.debug('emcc: LLVM opts: ' + str(opts))
- 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)
+ target = out or (filename + '.opt.bc')
+ output = Popen([LLVM_OPT, filename] + opts + ['-o', target], stdout=PIPE).communicate()[0]
+ assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output
+ if not out:
+ shutil.move(filename + '.opt.bc', filename)
@staticmethod
def llvm_opts(filename): # deprecated version, only for test runner. TODO: remove