Skip to content

Commit

Permalink
Improve pass pipeline (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey authored Apr 21, 2020
1 parent 53e314c commit f96d3fc
Show file tree
Hide file tree
Showing 62 changed files with 9,840 additions and 10,328 deletions.
46 changes: 29 additions & 17 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,48 +694,47 @@ exports.main = function main(argv, options, callback) {

// PassRunner::addDefaultGlobalOptimizationPrePasses
add("duplicate-function-elimination");
add("remove-unused-module-elements"); // differs

// PassRunner::addDefaultFunctionOptimizationPasses
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("ssa-nomerge");
}
if (optimizeLevel >= 3) {
add("simplify-locals-nostructure"); // differs
add("flatten"); // differs
add("simplify-locals-notee-nostructure"); // differs
add("vacuum"); // differs
add("reorder-locals"); // differs
add("code-folding"); // differs
add("flatten");
add("local-cse");
add("reorder-locals"); // differs
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
add("rse");
add("vacuum");
}
if (hasARC) { // differs
if (optimizeLevel < 3) {
add("flatten");
}
add("post-assemblyscript");
}
add("optimize-instructions"); // differs
add("inlining"); // differs
add("dce");
add("remove-unused-brs");
add("remove-unused-names");
// add("optimize-instructions"); // differs move 2 lines above
add("inlining-optimizing"); // differs
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("pick-load-signs");
add("simplify-globals-optimizing"); // differs
}
add("optimize-instructions"); // differs
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
add("precompute-propagate");
} else {
add("precompute");
}
if (module.getLowMemoryUnused()) {
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("optimize-added-constants-propagate");
} else {
add("optimize-added-constants");
}
}
add("vacuum"); // differs
// this will be done later (1)
// if (optimizeLevel >= 2 || shrinkLevel >= 2) {
// add("code-pushing");
Expand Down Expand Up @@ -776,25 +775,36 @@ exports.main = function main(argv, options, callback) {
// } else {
// add("precompute");
// }
add("optimize-instructions");
if (optimizeLevel >= 3) {
add("optimize-instructions");
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("rse");
}
add("vacuum");
// PassRunner::addDefaultGlobalOptimizationPostPasses
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("simplify-globals-optimizing"); // differs
add("dae-optimizing");
}
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("inlining-optimizing");
}
if (module.getLowMemoryUnused()) {
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("optimize-added-constants-propagate");
} else {
add("optimize-added-constants");
}
}
// "duplicate-function-elimination" will better done later
// add("duplicate-function-elimination");
add("duplicate-import-elimination");
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("simplify-globals-optimizing");
} else {
add("simplify-globals");
add("vacuum"); // differs
}
// moved from (2)
// it works better after globals optimizations like simplify-globals, inlining-optimizing and etc
Expand All @@ -814,28 +824,30 @@ exports.main = function main(argv, options, callback) {
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
add("rse");
// rearrange / reduce switch cases again
add("remove-unused-brs");
add("vacuum");

// move some code after early return which potentially could reduce computations
// do this after CFG cleanup (originally it was done before)
// moved from (1)
add("code-pushing");
if (optimizeLevel >= 3) {
// this quite expensive so do this only for highest opt level
add("simplify-globals");
add("vacuum");
// replace indirect calls with direct and inline if possible again.
add("inlining-optimizing");
add("directize");
add("dae-optimizing");
add("precompute-propagate");
add("coalesce-locals");
add("vacuum");
add("merge-locals");
add("coalesce-locals");
add("simplify-locals-nostructure");
add("vacuum");
add("inlining-optimizing");
add("precompute-propagate");
}
add("remove-unused-brs");
add("remove-unused-names");
add("vacuum");
add("optimize-instructions");
add("simplify-globals-optimizing");
}
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/assert-nonnull.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@
(local $1 i32)
local.get $0
call_indirect (type $none_=>_i32)
local.tee $0
local.get $0
local.tee $1
local.get $1
i32.eqz
if
i32.const 0
Expand All @@ -235,8 +235,8 @@
local.get $0
i32.load offset=4
call_indirect (type $none_=>_i32)
local.tee $0
local.get $0
local.tee $1
local.get $1
i32.eqz
if
i32.const 0
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/builtins.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@
local.set $2
local.get $3
if
local.get $1
local.get $0
i32.load16_u
local.tee $3
local.get $0
local.get $1
i32.load16_u
local.tee $4
i32.ne
if
local.get $4
local.get $3
local.get $4
i32.sub
return
end
Expand Down
15 changes: 2 additions & 13 deletions tests/compiler/comma.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,10 @@
global.set $comma/b
i32.const 2
global.set $comma/a
global.get $comma/a
i32.const 2
global.set $comma/b
global.get $comma/b
global.set $comma/a
global.get $comma/a
i32.const 2
i32.ne
if
i32.const 0
i32.const 1040
i32.const 18
i32.const 1
call $~lib/builtins/abort
unreachable
end
global.set $comma/a
global.get $comma/b
i32.const 2
i32.ne
Expand Down
Loading

0 comments on commit f96d3fc

Please sign in to comment.