aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-12 12:15:41 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-12 12:15:41 -0800
commit832358c2951f9c57ffebda3693e42473b679cedc (patch)
tree7f0d0cd26eb19bbd5a41d065b2782c797d865756
parent23fbe4113290f07b8fbb03f63e0e9ef636fb3aed (diff)
refactor use of asm in js optimizer
-rwxr-xr-xemcc16
-rwxr-xr-xtests/runner.py6
-rw-r--r--tools/js-optimizer.js28
3 files changed, 15 insertions, 35 deletions
diff --git a/emcc b/emcc
index 4c4c3d97..5d429cc2 100755
--- a/emcc
+++ b/emcc
@@ -1200,6 +1200,8 @@ try:
js_optimizer_queue = []
def flush_js_optimizer_queue():
global final, js_optimizer_queue
+ if shared.Settings.ASM_JS:
+ js_optimizer_queue = ['asm'] + js_optimizer_queue
if len(js_optimizer_queue) > 0:
if DEBUG < 2:
if DEBUG: print >> sys.stderr, 'emcc: applying js optimization passes:', js_optimizer_queue
@@ -1221,20 +1223,12 @@ try:
if DEBUG: save_intermediate('pretty')
def get_eliminate():
- if shared.Settings.ASM_JS:
- return 'eliminateAsm'
- elif shared.Settings.ALLOW_MEMORY_GROWTH:
+ if shared.Settings.ALLOW_MEMORY_GROWTH:
return 'eliminateMemSafe'
else:
return 'eliminate'
- def get_simplify_pre():
- if shared.Settings.ASM_JS:
- return 'simplifyExpressionsPreAsm'
- else:
- return 'simplifyExpressionsPre'
-
- js_optimizer_queue += [get_eliminate(), get_simplify_pre()]
+ js_optimizer_queue += [get_eliminate(), 'simplifyExpressionsPre']
if shared.Settings.RELOOP:
js_optimizer_queue += ['optimizeShiftsAggressive', get_eliminate()] # aggressive shifts optimization requires loops, it breaks on switches
@@ -1246,7 +1240,7 @@ try:
final = shared.Building.closure_compiler(final)
if DEBUG: save_intermediate('closure')
elif shared.Settings.ASM_JS and shared.Settings.RELOOP:
- js_optimizer_queue += ['registerizeAsm'] # we can't use closure in asm, but this does much of the same
+ js_optimizer_queue += ['registerize'] # we can't use closure in asm, but this does much of the same
if opt_level >= 1:
if DEBUG: print >> sys.stderr, 'emcc: running post-closure post-opts'
diff --git a/tests/runner.py b/tests/runner.py
index d3471f62..3340ad64 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -8980,11 +8980,11 @@ f.close()
(path_from_root('tools', 'eliminator', 'safe-eliminator-test.js'), open(path_from_root('tools', 'eliminator', 'safe-eliminator-test-output.js')).read(),
['eliminateMemSafe']),
(path_from_root('tools', 'eliminator', 'asm-eliminator-test.js'), open(path_from_root('tools', 'eliminator', 'asm-eliminator-test-output.js')).read(),
- ['eliminateAsm']),
+ ['asm', 'eliminate']),
(path_from_root('tools', 'test-js-optimizer-asm-regs.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-output.js')).read(),
- ['registerizeAsm']),
+ ['asm', 'registerize']),
(path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(),
- ['simplifyExpressionsPreAsm']),
+ ['asm', 'simplifyExpressionsPre']),
]:
output = Popen([NODE_JS, path_from_root('tools', 'js-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).communicate()[0]
self.assertIdentical(expected, output.replace('\r\n', '\n').replace('\n\n', '\n'))
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 8874dc88..5358a21f 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -404,7 +404,7 @@ function removeUnneededLabelSettings(ast) {
// Various expression simplifications. Pre run before closure (where we still have metadata), Post run after.
-function simplifyExpressionsPre(ast, asm) {
+function simplifyExpressionsPre(ast) {
// When there is a bunch of math like (((8+5)|0)+12)|0, only the external |0 is needed, one correction is enough.
// At each node, ((X|0)+Y)|0 can be transformed into (X+Y): The inner corrections are not needed
// TODO: Is the same is true for 0xff, 0xffff?
@@ -529,10 +529,6 @@ function simplifyExpressionsPre(ast, asm) {
// simplifyZeroComp(ast); TODO: investigate performance
}
-function simplifyExpressionsPreAsm(ast) {
- simplifyExpressionsPre(ast, true);
-}
-
// In typed arrays mode 2, we can have
// HEAP[x >> 2]
// very often. We can in some cases do the shift on the variable itself when it is set,
@@ -1384,7 +1380,7 @@ function denormalizeAsm(func, data) {
// TODO: Consider how this fits in with the rest of the optimization toolchain. Do
// we still need the eliminator? Closure? And in what order? Perhaps just
// closure simple?
-function registerize(ast, asm) {
+function registerize(ast) {
traverseGeneratedFunctions(ast, function(fun) {
if (asm) var asmData = normalizeAsm(fun);
// Add parameters as a first (fake) var (with assignment), so they get taken into consideration
@@ -1608,10 +1604,6 @@ function registerize(ast, asm) {
});
}
-function registerizeAsm(ast) {
- registerize(ast, true);
-}
-
// Eliminator aka Expressionizer
//
// The goal of this pass is to eliminate unneeded variables (which represent one of the infinite registers in the LLVM
@@ -1649,7 +1641,7 @@ var NODES_WITHOUT_ELIMINATION_SIDE_EFFECTS = set('name', 'num', 'string', 'binar
var IGNORABLE_ELIMINATOR_SCAN_NODES = set('num', 'toplevel', 'string', 'break', 'continue', 'dot'); // dot can only be STRING_TABLE.*
var ABORTING_ELIMINATOR_SCAN_NODES = set('new', 'object', 'function', 'defun', 'switch', 'for', 'while', 'array', 'throw'); // we could handle some of these, TODO, but nontrivial (e.g. for while, the condition is hit multiple times after the body)
-function eliminate(ast, memSafe, asm) {
+function eliminate(ast, memSafe) {
// Find variables that have a single use, and if they can be eliminated, do so
traverseGeneratedFunctions(ast, function(func, type) {
if (asm) var asmData = normalizeAsm(func);
@@ -2142,13 +2134,9 @@ function eliminateMemSafe(ast) {
eliminate(ast, true);
}
-function eliminateAsm(ast) {
- eliminate(ast, false, true);
-}
-
// Passes table
-var compress = false, printMetadata = true;
+var compress = false, printMetadata = true, asm = false;
var passes = {
dumpAst: dumpAst,
@@ -2157,19 +2145,17 @@ var passes = {
removeAssignsToUndefined: removeAssignsToUndefined,
//removeUnneededLabelSettings: removeUnneededLabelSettings,
simplifyExpressionsPre: simplifyExpressionsPre,
- simplifyExpressionsPreAsm: simplifyExpressionsPreAsm,
optimizeShiftsConservative: optimizeShiftsConservative,
optimizeShiftsAggressive: optimizeShiftsAggressive,
simplifyExpressionsPost: simplifyExpressionsPost,
hoistMultiples: hoistMultiples,
loopOptimizer: loopOptimizer,
registerize: registerize,
- registerizeAsm: registerizeAsm,
eliminate: eliminate,
eliminateMemSafe: eliminateMemSafe,
- eliminateAsm: eliminateAsm,
- compress: function() { compress = true; },
- noPrintMetadata: function() { printMetadata = false; }
+ compress: function() { compress = true },
+ noPrintMetadata: function() { printMetadata = false },
+ asm: function() { asm = true }
};
// Main