Skip to content

Commit c771461

Browse files
authored
More aggressive inlining / reworked pass pipeline (#1135)
1 parent 2c16369 commit c771461

File tree

98 files changed

+45630
-49988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+45630
-49988
lines changed

cli/asc.js

+41-17
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,20 @@ exports.main = function main(argv, options, callback) {
678678
const passes = [];
679679
function add(pass) { passes.push(pass); }
680680

681+
if (optimizeLevel >= 2 && shrinkLevel === 0) {
682+
// tweak inlining options when speed more preferable than size
683+
module.setAlwaysInlineMaxSize(12);
684+
module.setFlexibleInlineMaxSize(70);
685+
module.setOneCallerInlineMaxSize(200);
686+
} else {
687+
// tweak inlining options when size matters
688+
optimizeLevel === 0 && shrinkLevel >= 0
689+
? module.setAlwaysInlineMaxSize(2)
690+
: module.setAlwaysInlineMaxSize(4); // default: 2
691+
module.setFlexibleInlineMaxSize(65); // default: 20
692+
module.setOneCallerInlineMaxSize(80); // default: 15
693+
}
694+
681695
// Optimize the module if requested
682696
if (optimizeLevel > 0 || shrinkLevel > 0) {
683697
// Binaryen's default passes with Post-AssemblyScript passes added.
@@ -691,9 +705,15 @@ exports.main = function main(argv, options, callback) {
691705
add("ssa-nomerge");
692706
}
693707
if (optimizeLevel >= 3) {
708+
add("simplify-locals-nostructure"); // differs
709+
add("vacuum"); // differs
710+
add("reorder-locals"); // differs
694711
add("flatten");
695712
add("local-cse");
696713
}
714+
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
715+
add("rse");
716+
}
697717
if (hasARC) { // differs
698718
if (optimizeLevel < 3) {
699719
add("flatten");
@@ -703,11 +723,12 @@ exports.main = function main(argv, options, callback) {
703723
add("dce");
704724
add("remove-unused-brs");
705725
add("remove-unused-names");
706-
add("optimize-instructions");
726+
// add("optimize-instructions"); // differs move 2 lines above
707727
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
708728
add("pick-load-signs");
709729
add("simplify-globals-optimizing"); // differs
710730
}
731+
add("optimize-instructions"); // differs
711732
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
712733
add("precompute-propagate");
713734
} else {
@@ -717,19 +738,25 @@ exports.main = function main(argv, options, callback) {
717738
// if (optimizeLevel >= 2 || shrinkLevel >= 2) {
718739
// add("code-pushing");
719740
// }
741+
if (optimizeLevel >= 3 && shrinkLevel <= 1) { // differs
742+
add("licm");
743+
}
720744
add("simplify-locals-nostructure");
721745
add("vacuum");
722746
add("reorder-locals");
723747
add("remove-unused-brs");
724-
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
725-
add("merge-locals");
726-
}
748+
// if (optimizeLevel >= 3 || shrinkLevel >= 2) { // do it later
749+
// add("merge-locals");
750+
// }
727751
add("coalesce-locals");
728752
add("simplify-locals");
729753
add("vacuum");
730754
add("reorder-locals");
731755
add("coalesce-locals");
732756
add("reorder-locals");
757+
if (optimizeLevel >= 3 || shrinkLevel >= 1) { // differs
758+
add("merge-locals");
759+
}
733760
add("vacuum");
734761
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
735762
add("code-folding");
@@ -789,29 +816,26 @@ exports.main = function main(argv, options, callback) {
789816
add("remove-unused-brs");
790817
add("vacuum");
791818

792-
// replace indirect calls with direct and inline if possible again.
793-
add("directize");
794-
add("inlining-optimizing");
795819
// move some code after early return which potentially could reduce computations
796820
// do this after CFG cleanup (originally it was done before)
797821
// moved from (1)
798822
add("code-pushing");
799-
800-
// this quite expensive so do this only for highest opt level
801-
add("simplify-globals-optimizing");
802823
if (optimizeLevel >= 3) {
803-
add("simplify-locals-nostructure");
804-
add("vacuum");
805-
824+
// this quite expensive so do this only for highest opt level
825+
add("simplify-globals");
826+
// replace indirect calls with direct and inline if possible again.
827+
add("directize");
828+
add("dae-optimizing");
806829
add("precompute-propagate");
830+
add("coalesce-locals");
831+
add("merge-locals");
807832
add("simplify-locals-nostructure");
808833
add("vacuum");
809-
810-
add("reorder-locals");
811-
} else {
812-
add("simplify-globals-optimizing");
834+
add("inlining-optimizing");
835+
add("precompute-propagate");
813836
}
814837
add("optimize-instructions");
838+
add("simplify-globals-optimizing");
815839
}
816840
// remove unused elements of table and pack / reduce memory
817841
add("duplicate-function-elimination"); // differs

examples/game-of-life/build/optimized.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ declare module ASModule {
22
type i8 = number;
33
type i16 = number;
44
type i32 = number;
5+
type i64 = BigInt;
6+
type isize = number;
57
type u8 = number;
68
type u16 = number;
79
type u32 = number;
10+
type u64 = BigInt;
11+
type usize = number;
812
type f32 = number;
913
type f64 = number;
1014
type bool = any;
-5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)