make emterpreter optimization story more regular
This commit is contained in:
Родитель
4a41054452
Коммит
4fcace592c
36
emcc
36
emcc
|
@ -1011,7 +1011,7 @@ try:
|
|||
if shared.Settings.EMTERPRETIFY:
|
||||
shared.Settings.FINALIZE_ASM_JS = 0
|
||||
shared.Settings.GLOBAL_BASE = 8*256 # keep enough space at the bottom for a full stack frame
|
||||
debug_level = max(debug_level, 2)
|
||||
shared.Settings.SIMPLIFY_IFS = 0 # this is just harmful for emterpreting
|
||||
|
||||
shared.Settings.RUNNING_FASTCOMP = fastcomp
|
||||
|
||||
|
@ -1432,6 +1432,21 @@ try:
|
|||
final = shared.Building.closure_compiler(final)
|
||||
if DEBUG: save_intermediate('closure')
|
||||
|
||||
def do_minify():
|
||||
global js_optimizer_queue
|
||||
|
||||
if opt_level >= 2:
|
||||
if debug_level < 2 and shared.Settings.ASM_JS and not closure == 2:
|
||||
js_optimizer_queue += ['minifyNames']
|
||||
if emit_symbol_map: js_optimizer_queue += ['symbolMap='+target+'.symbols']
|
||||
if debug_level == 0: js_optimizer_queue += ['minifyWhitespace']
|
||||
|
||||
if shared.Settings.ASM_JS:
|
||||
if closure == 1:
|
||||
js_optimizer_queue += ['closure']
|
||||
elif debug_level <= 2 and not shared.Settings.MAIN_MODULE and shared.Settings.FINALIZE_ASM_JS and not closure:
|
||||
js_optimizer_queue += ['cleanup']
|
||||
|
||||
if js_opts:
|
||||
if shared.Settings.ASM_JS and shared.Settings.SAFE_HEAP: js_optimizer_queue += ['safeHeap']
|
||||
|
||||
|
@ -1447,18 +1462,10 @@ try:
|
|||
|
||||
if shared.Settings.POINTER_MASKING and shared.Settings.ASM_JS: js_optimizer_queue += ['pointerMasking']
|
||||
|
||||
if opt_level >= 2:
|
||||
if debug_level < 2 and shared.Settings.ASM_JS and not closure == 2:
|
||||
js_optimizer_queue += ['minifyNames']
|
||||
if emit_symbol_map: js_optimizer_queue += ['symbolMap='+target+'.symbols']
|
||||
if debug_level == 0: js_optimizer_queue += ['minifyWhitespace']
|
||||
if not shared.Settings.EMTERPRETIFY:
|
||||
do_minify()
|
||||
|
||||
if shared.Settings.ASM_JS:
|
||||
if closure == 1:
|
||||
js_optimizer_queue += ['closure']
|
||||
elif debug_level <= 2 and not shared.Settings.MAIN_MODULE and shared.Settings.FINALIZE_ASM_JS and not closure:
|
||||
js_optimizer_queue += ['cleanup']
|
||||
|
||||
js_optimizer_queue += ['asmLastOpts']
|
||||
|
||||
if shared.Settings.FINALIZE_ASM_JS: js_optimizer_queue += ['last']
|
||||
|
@ -1479,6 +1486,7 @@ try:
|
|||
js_target = unsuffixed(target) + '.js'
|
||||
|
||||
if shared.Settings.EMTERPRETIFY:
|
||||
logging.debug('emterpretifying')
|
||||
assert memory_init_file, 'emterpreter requires a mem init file'
|
||||
try:
|
||||
# move temp js to final position, alongside its mem init file
|
||||
|
@ -1488,6 +1496,12 @@ try:
|
|||
finally:
|
||||
shared.try_delete(js_target)
|
||||
|
||||
# minify (if requested) after emterpreter processing, and finalize output
|
||||
shared.Settings.FINALIZE_ASM_JS = 1
|
||||
do_minify()
|
||||
js_optimizer_queue += ['last']
|
||||
flush_js_optimizer_queue()
|
||||
|
||||
# Remove some trivial whitespace # TODO: do not run when compress has already been done on all parts of the code
|
||||
#src = open(final).read()
|
||||
#src = re.sub(r'\n+[ \n]*\n+', '\n', src)
|
||||
|
|
|
@ -20,18 +20,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
|
|||
self.do_run_from_file(src, output)
|
||||
|
||||
src = open(self.in_dir('src.cpp.o.js')).read()
|
||||
if not self.is_emterpreter():
|
||||
assert 'EMSCRIPTEN_GENERATED_FUNCTIONS' not in src, 'must not emit this unneeded internal thing'
|
||||
else:
|
||||
assert 'function emterpret' in src, 'emterpreter should exist'
|
||||
# and removing calls to the emterpreter break, so it was being used
|
||||
output = open(output).read()
|
||||
out1 = run_js('src.cpp.o.js')
|
||||
assert output in out1
|
||||
open('src.cpp.o.js', 'w').write(src.replace('function emterpret', 'function do_not_find_me'))
|
||||
out2 = run_js('src.cpp.o.js', stderr=PIPE, assert_returncode=None)
|
||||
assert output not in out2, out2
|
||||
assert out1 != out2
|
||||
assert 'EMSCRIPTEN_GENERATED_FUNCTIONS' not in src, 'must not emit this unneeded internal thing'
|
||||
|
||||
def test_intvars(self):
|
||||
if self.emcc_args == None: return self.skip('needs ta2')
|
||||
|
|
|
@ -4147,12 +4147,21 @@ pass: error == ENOTDIR
|
|||
source = 'src.cpp'
|
||||
else:
|
||||
source = path_from_root('tests', source)
|
||||
Popen([PYTHON, EMCC, source, '-O2', '-s', 'EMTERPRETIFY=1']).communicate()
|
||||
Popen([PYTHON, EMCC, source, '-O2', '-s', 'EMTERPRETIFY=1', '-g2']).communicate()
|
||||
self.assertContained(output, run_js('a.out.js', args=args))
|
||||
out = run_js('a.out.js', engine=SPIDERMONKEY_ENGINE, args=args, stderr=PIPE, full_output=True)
|
||||
self.assertContained(output, out)
|
||||
self.validate_asmjs(out)
|
||||
assert 'function emterpret' in open('a.out.js').read()
|
||||
# -g2 enables these
|
||||
src = open('a.out.js').read()
|
||||
assert 'function emterpret' in src, 'emterpreter should exist'
|
||||
# and removing calls to the emterpreter break, so it was being used
|
||||
out1 = run_js('a.out.js')
|
||||
assert output in out1
|
||||
open('a.out.js', 'w').write(src.replace('function emterpret', 'function do_not_find_me'))
|
||||
out2 = run_js('a.out.js', stderr=PIPE, assert_returncode=None)
|
||||
assert output not in out2, out2
|
||||
assert out1 != out2
|
||||
|
||||
def do_test(source, args, output):
|
||||
print
|
||||
|
|
|
@ -7314,8 +7314,7 @@ function emterpretify(ast) {
|
|||
var ignore = !(func[1] in EMTERPRETED_FUNCS);
|
||||
|
||||
if (ignore) {
|
||||
prepDotZero(func);
|
||||
print(fixDotZero(astToSrc(func)));
|
||||
print(astToSrc(func));
|
||||
}
|
||||
|
||||
var asmData = normalizeAsm(func);
|
||||
|
@ -7463,8 +7462,7 @@ function emterpretify(ast) {
|
|||
}
|
||||
// emit trampoline and bytecode
|
||||
denormalizeAsm(func, asmData);
|
||||
prepDotZero(func);
|
||||
print(fixDotZero(astToSrc(func)));
|
||||
print(astToSrc(func));
|
||||
}
|
||||
print('// EMTERPRET_INFO ' + JSON.stringify([func[1], code, absoluteTargets]));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче