Skip to content

Instantly share code, notes, and snippets.

@kripken
Created November 24, 2017 22:38
Show Gist options
  • Save kripken/0197b7146a37b4604b09d5fa2ec3f909 to your computer and use it in GitHub Desktop.
Save kripken/0197b7146a37b4604b09d5fa2ec3f909 to your computer and use it in GitHub Desktop.
diff --git a/tools/shared.py b/tools/shared.py
index a591325..60a1853 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1854,49 +1854,50 @@ class Building(object):
# LLVM optimizations
# @param opt A list of LLVM optimization parameters
@staticmethod
def llvm_opt(filename, opts, out=None):
inputs = filename
if not isinstance(inputs, list):
inputs = [inputs]
else:
assert out, 'must provide out if llvm_opt on a list of inputs'
assert len(opts) > 0, 'should not call opt with nothing to do'
- opts = opts[:]
- # TODO: disable inlining when needed
- # if not Building.can_inline():
- # opts.append('-disable-inlining')
- #opts += ['-debug-pass=Arguments']
- if not Settings.SIMD:
- opts += ['-disable-loop-vectorization', '-disable-slp-vectorization', '-vectorize-loops=false', '-vectorize-slp=false']
- if not Settings.WASM_BACKEND:
- # This option have been removed in llvm ToT
- opts += ['-vectorize-slp-aggressive=false']
- else:
- opts += ['-bb-vectorize-vector-bits=128']
-
+ opts = opts + Building.get_opt_opts()
logging.debug('emcc: LLVM opts: ' + ' '.join(opts) + ' [num inputs: ' + str(len(inputs)) + ']')
target = out or (filename + '.opt.bc')
proc = Popen([LLVM_OPT] + inputs + opts + ['-o', target], stdout=PIPE)
output = proc.communicate()[0]
if proc.returncode != 0 or not os.path.exists(target):
logging.error('Failed to run llvm optimizations: ' + output)
for i in inputs:
if not os.path.exists(i):
logging.warning('Note: Input file "' + i + '" did not exist.')
elif not Building.is_bitcode(i):
logging.warning('Note: Input file "' + i + '" exists but was not an LLVM bitcode file suitable for Emscripten. Perhaps accidentally mixing native built object files with Emscripten?')
sys.exit(1)
if not out:
shutil.move(filename + '.opt.bc', filename)
return target
+ # gets the options we should pass to the llvm-opt optimizer
+ @staticmethod
+ def get_opt_opts():
+ opts = []
+ if not Settings.SIMD:
+ opts += ['-disable-loop-vectorization', '-disable-slp-vectorization', '-vectorize-loops=false', '-vectorize-slp=false']
+ if not Settings.WASM_BACKEND:
+ # This option have been removed in llvm ToT
+ opts += ['-vectorize-slp-aggressive=false']
+ else:
+ opts += ['-bb-vectorize-vector-bits=128']
+ return opts
+
@staticmethod
def llvm_opts(filename): # deprecated version, only for test runner. TODO: remove
if Building.LLVM_OPTS:
shutil.move(filename + '.o', filename + '.o.pre')
output = Popen([LLVM_OPT, filename + '.o.pre'] + Building.LLVM_OPT_OPTS + ['-o', filename + '.o'], stdout=PIPE).communicate()[0]
assert os.path.exists(filename + '.o'), 'Failed to run llvm optimizations: ' + output
@staticmethod
def llvm_dis(input_filename, output_filename=None):
# LLVM binary ==> LLVM assembly
diff --git a/tools/system_libs.py b/tools/system_libs.py
index dcca8af..170e895 100755
--- a/tools/system_libs.py
+++ b/tools/system_libs.py
@@ -3,29 +3,30 @@ import os, json, logging, zipfile, glob, shutil
from . import shared
from subprocess import Popen, CalledProcessError
import subprocess, multiprocessing, re
from tools.shared import check_call
stdout = None
stderr = None
def call_process(cmd):
# call clang directly, instead of emcc, when we can (we can't if a special emcc
- # -s flag is issued)
- if cmd[0] == shared.PYTHON and cmd[1] in (shared.EMCC, shared.EMXX) and '-s' not in cmd:
+ # -s flag is issued, or js is emitted)
+ if cmd[0] == shared.PYTHON and cmd[1] in (shared.EMCC, shared.EMXX) and \
+ not any([x.endswith('.js') for x in cmd]):
if cmd[1] == shared.EMCC:
cmd[1] = shared.CLANG_CC
else:
cmd[1] = shared.CLANG_CPP
cmd = cmd[1:]
# add compiler opts emcc would have
- cmd += shared.COMPILER_OPTS + ['-emit-llvm', '-c']
+ cmd += shared.COMPILER_OPTS + ['-emit-llvm', '-c'] + shared.Building.get_opt_opts()
# call the process
proc = Popen(cmd, stdout=stdout, stderr=stderr)
proc.communicate()
if proc.returncode != 0:
# Deliberately do not use CalledProcessError, see issue #2944
raise Exception('Command \'%s\' returned non-zero exit status %s' % (' '.join(cmd), proc.returncode))
CORES = int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
def run_commands(commands):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment