aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/file_packager.py2
-rw-r--r--tools/js-optimizer.js2
-rw-r--r--tools/js_optimizer.py3
-rw-r--r--tools/shared.py61
-rw-r--r--tools/test-js-optimizer-regs-output.js4
-rw-r--r--tools/test-js-optimizer-regs.js6
6 files changed, 46 insertions, 32 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 7e196efd..bfa8e2f0 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -228,7 +228,7 @@ if has_preloaded:
curr = open(file_['localname'], 'rb').read()
file_['data_end'] = start + len(curr)
if AV_WORKAROUND: curr += '\x00'
- print >> sys.stderr, 'bundling', file_['name'], file_['localname'], file_['data_start'], file_['data_end']
+ #print >> sys.stderr, 'bundling', file_['name'], file_['localname'], file_['data_start'], file_['data_end']
start += len(curr)
data.write(curr)
data.close()
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index efbfa8aa..f2dc516a 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1598,7 +1598,7 @@ function registerize(ast) {
fun[2].push(reg);
}
}
- getStatements(fun).unshift(['var', vars]);
+ if (vars.length > 0) getStatements(fun).unshift(['var', vars]);
}
} else {
//printErr('unfake params: \n\n' + astToSrc(fun) + '\n\n');
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index f2e610d0..cbf64486 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -88,10 +88,11 @@ def run_on_js(filename, passes, js_engine, jcache):
if i < len(parts)-1: func += '\n}\n' # last part needs no }
m = func_sig.search(func)
if m:
- ident = m.group(1)
+ ident = m.group(2)
else:
if suffix: continue # ignore whitespace
ident = 'anon_%d' % i
+ assert ident
funcs.append((ident, func))
parts = None
total_size = len(js)
diff --git a/tools/shared.py b/tools/shared.py
index c283c1f5..ce9001fb 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -566,12 +566,10 @@ class Settings:
if opt_level >= 2:
Settings.RELOOP = 1
if opt_level >= 3:
+ # Aside from these, -O3 also runs closure compiler
Settings.INLINING_LIMIT = 0
Settings.DOUBLE_MODE = 0
Settings.PRECISE_I64_MATH = 0
- Settings.CORRECT_SIGNS = 0
- Settings.CORRECT_OVERFLOWS = 0
- Settings.CORRECT_ROUNDINGS = 0
if noisy: print >> sys.stderr, 'Warning: Applying some potentially unsafe optimizations! (Use -O2 if this fails.)'
global Settings
@@ -665,6 +663,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
def make(args, stdout=None, stderr=None, env=None):
if env is None:
env = Building.get_building_env()
+ if not args:
+ print >> sys.stderr, 'Error: Executable to run not specified.'
+ sys.exit(1)
#args += ['VERBOSE=1']
try:
Popen(args, stdout=stdout, stderr=stderr, env=env).communicate()
@@ -748,12 +749,16 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
resolved_symbols = set()
temp_dirs = []
files = map(os.path.abspath, files)
+ has_ar = False
+ for f in files:
+ has_ar = has_ar or Building.is_ar(f)
for f in files:
if not Building.is_ar(f):
if Building.is_bitcode(f):
- new_symbols = Building.llvm_nm(f)
- resolved_symbols = resolved_symbols.union(new_symbols.defs)
- unresolved_symbols = unresolved_symbols.union(new_symbols.undefs.difference(resolved_symbols)).difference(new_symbols.defs)
+ if has_ar:
+ new_symbols = Building.llvm_nm(f)
+ resolved_symbols = resolved_symbols.union(new_symbols.defs)
+ unresolved_symbols = unresolved_symbols.union(new_symbols.undefs.difference(resolved_symbols)).difference(new_symbols.defs)
actual_files.append(f)
else:
# Extract object files from ar archives, and link according to gnu ld semantics
@@ -828,6 +833,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
def llvm_opt(filename, opts):
if type(opts) is int:
opts = Building.pick_llvm_opts(opts)
+ #opts += ['-debug-pass=Arguments']
if DEBUG: print >> sys.stderr, 'emcc: LLVM opts:', 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
@@ -864,8 +870,14 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
assert os.path.exists(output_filename), 'Could not create bc file: ' + output
return output_filename
+ nm_cache = {} # cache results of nm - it can be slow to run
+
@staticmethod
def llvm_nm(filename, stdout=PIPE, stderr=None):
+ if filename in Building.nm_cache:
+ #if DEBUG: print >> sys.stderr, 'loading nm results for %s from cache' % filename
+ return Building.nm_cache[filename]
+
# LLVM binary ==> list of symbols
output = Popen([LLVM_NM, filename], stdout=stdout, stderr=stderr).communicate()[0]
class ret:
@@ -886,6 +898,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
ret.defs = set(ret.defs)
ret.undefs = set(ret.undefs)
ret.commons = set(ret.commons)
+ Building.nm_cache[filename] = ret
return ret
@staticmethod
@@ -1086,24 +1099,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
@staticmethod
def is_bitcode(filename):
- # checks if a file contains LLVM bitcode
- # if the file doesn't exist or doesn't have valid symbols, it isn't bitcode
- try:
- defs = Building.llvm_nm(filename, stderr=PIPE)
- # If no symbols found, it might just be an empty bitcode file, try to dis it
- if len(defs.defs) + len(defs.undefs) + len(defs.commons) == 0:
- # llvm-nm 3.0 has a bug when reading symbols from ar files
- # so try to see if we're dealing with an ar file, in which
- # case we should try to dis it.
- if not Building.is_ar(filename):
- test_ll = os.path.join(EMSCRIPTEN_TEMP_DIR, 'test.ll')
- Building.llvm_dis(filename, test_ll)
- assert os.path.exists(test_ll)
- try_delete(test_ll)
- except Exception, e:
- if DEBUG: print >> sys.stderr, 'shared.Building.is_bitcode failed to test whether file \'%s\' is a llvm bitcode file! Failed on exception: %s' % (filename, e)
- return False
-
# look for magic signature
b = open(filename, 'r').read(4)
if b[0] == 'B' and b[1] == 'C':
@@ -1267,6 +1262,7 @@ class JCache:
if os.path.exists(chunking_file):
try:
previous_mapping = cPickle.Unpickler(open(chunking_file, 'rb')).load() # maps a function identifier to the chunk number it will be in
+ #if DEBUG: print >> sys.stderr, 'jscache previous mapping', previous_mapping
except:
pass
chunks = []
@@ -1275,20 +1271,25 @@ class JCache:
news = []
for func in funcs:
ident, data = func
+ assert ident, 'need names for jcache chunking'
if not ident in previous_mapping:
news.append(func)
else:
n = previous_mapping[ident]
while n >= len(chunks): chunks.append([])
chunks[n].append(func)
+ if DEBUG: print >> sys.stderr, 'jscache not in previous chunking', len(news)
# add news and adjust for new sizes
spilled = news
- for chunk in chunks:
+ for i in range(len(chunks)):
+ chunk = chunks[i]
size = sum([len(func[1]) for func in chunk])
- while size > 1.5*chunk_size and len(chunk) > 0:
+ #if DEBUG: print >> sys.stderr, 'need spilling?', i, size, len(chunk), 'vs', chunk_size, 1.5*chunk_size
+ while size > 1.5*chunk_size and len(chunk) > 1:
spill = chunk.pop()
spilled.append(spill)
size -= len(spill[1])
+ #if DEBUG: print >> sys.stderr, 'jscache new + spilled', len(spilled)
for chunk in chunks:
size = sum([len(func[1]) for func in chunk])
while size < 0.66*chunk_size and len(spilled) > 0:
@@ -1297,6 +1298,7 @@ class JCache:
size += len(spill[1])
chunks = filter(lambda chunk: len(chunk) > 0, chunks) # might have empty ones, eliminate them
funcs = spilled # we will allocate these into chunks as if they were normal inputs
+ #if DEBUG: print >> sys.stderr, 'leftover spills', len(spilled)
# initialize reasonably, the rest of the funcs we need to split out
curr = []
total_size = 0
@@ -1322,15 +1324,18 @@ class JCache:
for i in range(len(chunks)):
chunk = chunks[i]
for ident, data in chunk:
+ assert ident not in new_mapping, 'cannot have duplicate names in jcache chunking'
new_mapping[ident] = i
cPickle.Pickler(open(chunking_file, 'wb')).dump(new_mapping)
#if DEBUG:
+ # for i in range(len(chunks)):
+ # chunk = chunks[i]
+ # print >> sys.stderr, 'final chunk', i, len(chunk)
+ # print >> sys.stderr, 'new mapping:', new_mapping
# if previous_mapping:
# for ident in set(previous_mapping.keys() + new_mapping.keys()):
# if previous_mapping.get(ident) != new_mapping.get(ident):
# print >> sys.stderr, 'mapping inconsistency', ident, previous_mapping.get(ident), new_mapping.get(ident)
- # for key, value in new_mapping.iteritems():
- # print >> sys.stderr, 'mapping:', key, value
return [''.join([func[1] for func in chunk]) for chunk in chunks] # remove function names
class JS:
diff --git a/tools/test-js-optimizer-regs-output.js b/tools/test-js-optimizer-regs-output.js
index 36006b7c..fe7de5fb 100644
--- a/tools/test-js-optimizer-regs-output.js
+++ b/tools/test-js-optimizer-regs-output.js
@@ -225,4 +225,8 @@ function switchey(r1) {
r9 = r1 + 2;
pp(r9);
}
+function __ZN14NetworkAddressC1EPKcti(r1) {
+ __ZN14NetworkAddressC2EPKcti(r1);
+ return;
+}
diff --git a/tools/test-js-optimizer-regs.js b/tools/test-js-optimizer-regs.js
index 4802afa3..3013e518 100644
--- a/tools/test-js-optimizer-regs.js
+++ b/tools/test-js-optimizer-regs.js
@@ -230,4 +230,8 @@ function switchey(x) {
var aaa = x+2;
pp(aaa);
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test", "primes", "atomic", "fcntl_open", "ex", "switchey"]
+function __ZN14NetworkAddressC1EPKcti($this) {
+ __ZN14NetworkAddressC2EPKcti($this);
+ return;
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test", "primes", "atomic", "fcntl_open", "ex", "switchey", "__ZN14NetworkAddressC1EPKcti"]