@@ -678,6 +678,20 @@ exports.main = function main(argv, options, callback) {
678
678
const passes = [ ] ;
679
679
function add ( pass ) { passes . push ( pass ) ; }
680
680
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
+
681
695
// Optimize the module if requested
682
696
if ( optimizeLevel > 0 || shrinkLevel > 0 ) {
683
697
// Binaryen's default passes with Post-AssemblyScript passes added.
@@ -691,9 +705,15 @@ exports.main = function main(argv, options, callback) {
691
705
add ( "ssa-nomerge" ) ;
692
706
}
693
707
if ( optimizeLevel >= 3 ) {
708
+ add ( "simplify-locals-nostructure" ) ; // differs
709
+ add ( "vacuum" ) ; // differs
710
+ add ( "reorder-locals" ) ; // differs
694
711
add ( "flatten" ) ;
695
712
add ( "local-cse" ) ;
696
713
}
714
+ if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) { // differs
715
+ add ( "rse" ) ;
716
+ }
697
717
if ( hasARC ) { // differs
698
718
if ( optimizeLevel < 3 ) {
699
719
add ( "flatten" ) ;
@@ -703,11 +723,12 @@ exports.main = function main(argv, options, callback) {
703
723
add ( "dce" ) ;
704
724
add ( "remove-unused-brs" ) ;
705
725
add ( "remove-unused-names" ) ;
706
- add ( "optimize-instructions" ) ;
726
+ // add("optimize-instructions"); // differs move 2 lines above
707
727
if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) {
708
728
add ( "pick-load-signs" ) ;
709
729
add ( "simplify-globals-optimizing" ) ; // differs
710
730
}
731
+ add ( "optimize-instructions" ) ; // differs
711
732
if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
712
733
add ( "precompute-propagate" ) ;
713
734
} else {
@@ -717,19 +738,25 @@ exports.main = function main(argv, options, callback) {
717
738
// if (optimizeLevel >= 2 || shrinkLevel >= 2) {
718
739
// add("code-pushing");
719
740
// }
741
+ if ( optimizeLevel >= 3 && shrinkLevel <= 1 ) { // differs
742
+ add ( "licm" ) ;
743
+ }
720
744
add ( "simplify-locals-nostructure" ) ;
721
745
add ( "vacuum" ) ;
722
746
add ( "reorder-locals" ) ;
723
747
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
+ // }
727
751
add ( "coalesce-locals" ) ;
728
752
add ( "simplify-locals" ) ;
729
753
add ( "vacuum" ) ;
730
754
add ( "reorder-locals" ) ;
731
755
add ( "coalesce-locals" ) ;
732
756
add ( "reorder-locals" ) ;
757
+ if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) { // differs
758
+ add ( "merge-locals" ) ;
759
+ }
733
760
add ( "vacuum" ) ;
734
761
if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) {
735
762
add ( "code-folding" ) ;
@@ -789,29 +816,26 @@ exports.main = function main(argv, options, callback) {
789
816
add ( "remove-unused-brs" ) ;
790
817
add ( "vacuum" ) ;
791
818
792
- // replace indirect calls with direct and inline if possible again.
793
- add ( "directize" ) ;
794
- add ( "inlining-optimizing" ) ;
795
819
// move some code after early return which potentially could reduce computations
796
820
// do this after CFG cleanup (originally it was done before)
797
821
// moved from (1)
798
822
add ( "code-pushing" ) ;
799
-
800
- // this quite expensive so do this only for highest opt level
801
- add ( "simplify-globals-optimizing" ) ;
802
823
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" ) ;
806
829
add ( "precompute-propagate" ) ;
830
+ add ( "coalesce-locals" ) ;
831
+ add ( "merge-locals" ) ;
807
832
add ( "simplify-locals-nostructure" ) ;
808
833
add ( "vacuum" ) ;
809
-
810
- add ( "reorder-locals" ) ;
811
- } else {
812
- add ( "simplify-globals-optimizing" ) ;
834
+ add ( "inlining-optimizing" ) ;
835
+ add ( "precompute-propagate" ) ;
813
836
}
814
837
add ( "optimize-instructions" ) ;
838
+ add ( "simplify-globals-optimizing" ) ;
815
839
}
816
840
// remove unused elements of table and pack / reduce memory
817
841
add ( "duplicate-function-elimination" ) ; // differs
0 commit comments