aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-06 17:16:30 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-06-06 17:16:30 -0700
commitb970a019bfcf5413dec74f944a25cef633927f1c (patch)
tree24e0cfece9a57dbc65bdb2a4d2b3997da10a6e9d
parent24807a6d8f657b27e0ae6b73e73fa987a0672480 (diff)
move asm loop optimization into last phase
-rwxr-xr-xtests/runner.py4
-rw-r--r--tools/js-optimizer.js36
-rw-r--r--tools/test-js-optimizer-asm-last-output.js5
-rw-r--r--tools/test-js-optimizer-asm-last.js11
-rw-r--r--tools/test-js-optimizer-regs-output.js5
-rw-r--r--tools/test-js-optimizer-regs.js10
6 files changed, 39 insertions, 32 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 53eb56fe..b3485657 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -13095,7 +13095,7 @@ elif 'benchmark' in str(sys.argv):
Building.COMPILER_TEST_OPTS = []
- TEST_REPS = 2
+ TEST_REPS = 1
TOTAL_TESTS = 8
# standard arguments for timing:
@@ -13160,7 +13160,7 @@ elif 'benchmark' in str(sys.argv):
'-O2', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0',
'--llvm-lto', '1', '--memory-init-file', '0',
'-s', 'TOTAL_MEMORY=128*1024*1024',
- '--closure', '1',
+ '--closure', '1', '-g',
'-o', final_filename] + shared_args + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate()
assert os.path.exists(final_filename), 'Failed to compile file: ' + output[0]
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 57c9cf79..df71ab86 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1805,21 +1805,6 @@ function registerize(ast) {
}
denormalizeAsm(fun, finalAsmData);
}
-
- // Post-registerize optimizations. This is near the end of the pipeline, we can assume all other optimizations except for minification are done
- traverse(fun, function(node, type) {
- if (type == 'while' && node[1][0] == 'num' && node[1][1] == 1 && node[2][0] == 'block') {
- // while (1) { .. if (..) { break } } ==> do { .. } while(..)
- var stats = node[2][1];
- var last = stats[stats.length-1];
- if (last[0] == 'if' && !last[3] && last[2][0] == 'block' && last[2][1][0][0] == 'break' && !last[2][1][0][1]) {
- var conditionToBreak = last[1];
- stats.pop();
- node[0] = 'do';
- node[1] = simplifyNotComps(['unary-prefix', '!', conditionToBreak]);
- }
- }
- });
});
}
@@ -2471,6 +2456,26 @@ function fixDotZero(js) {
});
}
+function asmLoopOptimizer(ast) {
+ traverseGeneratedFunctions(ast, function(fun) {
+ // This is at the end of the pipeline, we can assume all other optimizations are done, and we modify loops
+ // into shapes that might confuse other passes
+ traverse(fun, function(node, type) {
+ if (type == 'while' && node[1][0] == 'num' && node[1][1] == 1 && node[2][0] == 'block') {
+ // while (1) { .. if (..) { break } } ==> do { .. } while(..)
+ var stats = node[2][1];
+ var last = stats[stats.length-1];
+ if (last[0] == 'if' && !last[3] && last[2][0] == 'block' && last[2][1][0][0] == 'break' && !last[2][1][0][1]) {
+ var conditionToBreak = last[1];
+ stats.pop();
+ node[0] = 'do';
+ node[1] = simplifyNotComps(['unary-prefix', '!', conditionToBreak]);
+ }
+ }
+ });
+ });
+}
+
// Passes table
var compress = false, printMetadata = true, asm = false, last = false;
@@ -2514,6 +2519,7 @@ arguments_.slice(1).forEach(function(arg) {
passes[arg](ast);
});
if (asm && last) {
+ asmLoopOptimizer(ast);
prepDotZero(ast);
}
var js = astToSrc(ast, compress), old;
diff --git a/tools/test-js-optimizer-asm-last-output.js b/tools/test-js-optimizer-asm-last-output.js
index c10cc6b0..02605db8 100644
--- a/tools/test-js-optimizer-asm-last-output.js
+++ b/tools/test-js-optimizer-asm-last-output.js
@@ -32,4 +32,9 @@ function finall(x) {
a = -0xde0b6b000000000;
return 12.0e10;
}
+function looop() {
+ do {
+ do_it();
+ } while (!condition());
+}
diff --git a/tools/test-js-optimizer-asm-last.js b/tools/test-js-optimizer-asm-last.js
index 6e97b687..d3dffcae 100644
--- a/tools/test-js-optimizer-asm-last.js
+++ b/tools/test-js-optimizer-asm-last.js
@@ -32,4 +32,13 @@ function finall(x) {
a = -0xde0b6b000000000;
return +12e10;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["finall"]
+function looop() {
+ while (1) {
+ do_it();
+ if (condition()) {
+ break;
+ }
+ }
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["finall", "looop"]
+
diff --git a/tools/test-js-optimizer-regs-output.js b/tools/test-js-optimizer-regs-output.js
index c1c9ec87..fe7de5fb 100644
--- a/tools/test-js-optimizer-regs-output.js
+++ b/tools/test-js-optimizer-regs-output.js
@@ -229,9 +229,4 @@ function __ZN14NetworkAddressC1EPKcti(r1) {
__ZN14NetworkAddressC2EPKcti(r1);
return;
}
-function looop() {
- do {
- do_it();
- } while (!condition());
-}
diff --git a/tools/test-js-optimizer-regs.js b/tools/test-js-optimizer-regs.js
index b38760cc..3013e518 100644
--- a/tools/test-js-optimizer-regs.js
+++ b/tools/test-js-optimizer-regs.js
@@ -234,12 +234,4 @@ function __ZN14NetworkAddressC1EPKcti($this) {
__ZN14NetworkAddressC2EPKcti($this);
return;
}
-function looop() {
- while (1) {
- do_it();
- if (condition()) {
- break;
- }
- }
-}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test", "primes", "atomic", "fcntl_open", "ex", "switchey", "__ZN14NetworkAddressC1EPKcti", "looop"]
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test", "primes", "atomic", "fcntl_open", "ex", "switchey", "__ZN14NetworkAddressC1EPKcti"]