@@ -247,12 +247,7 @@ exports.main = function main(argv, options, callback) {
247
247
assemblyscript . setSourceMap ( compilerOptions , args . sourceMap != null ) ;
248
248
assemblyscript . setNoUnsafe ( compilerOptions , args . noUnsafe ) ;
249
249
assemblyscript . setPedantic ( compilerOptions , args . pedantic ) ;
250
-
251
- // Initialize default aliases
252
- assemblyscript . setGlobalAlias ( compilerOptions , "Math" , "NativeMath" ) ;
253
- assemblyscript . setGlobalAlias ( compilerOptions , "Mathf" , "NativeMathf" ) ;
254
- assemblyscript . setGlobalAlias ( compilerOptions , "abort" , "~lib/builtins/abort" ) ;
255
- assemblyscript . setGlobalAlias ( compilerOptions , "trace" , "~lib/builtins/trace" ) ;
250
+ assemblyscript . setLowMemoryLimit ( compilerOptions , args . lowMemoryLimit >>> 0 ) ;
256
251
257
252
// Add or override aliases if specified
258
253
if ( args . use ) {
@@ -678,6 +673,20 @@ exports.main = function main(argv, options, callback) {
678
673
const passes = [ ] ;
679
674
function add ( pass ) { passes . push ( pass ) ; }
680
675
676
+ if ( optimizeLevel >= 2 && shrinkLevel === 0 ) {
677
+ // tweak inlining options when speed more preferable than size
678
+ module . setAlwaysInlineMaxSize ( 12 ) ;
679
+ module . setFlexibleInlineMaxSize ( 70 ) ;
680
+ module . setOneCallerInlineMaxSize ( 200 ) ;
681
+ } else {
682
+ // tweak inlining options when size matters
683
+ optimizeLevel === 0 && shrinkLevel >= 0
684
+ ? module . setAlwaysInlineMaxSize ( 2 )
685
+ : module . setAlwaysInlineMaxSize ( 4 ) ; // default: 2
686
+ module . setFlexibleInlineMaxSize ( 65 ) ; // default: 20
687
+ module . setOneCallerInlineMaxSize ( 80 ) ; // default: 15
688
+ }
689
+
681
690
// Optimize the module if requested
682
691
if ( optimizeLevel > 0 || shrinkLevel > 0 ) {
683
692
// Binaryen's default passes with Post-AssemblyScript passes added.
@@ -691,9 +700,15 @@ exports.main = function main(argv, options, callback) {
691
700
add ( "ssa-nomerge" ) ;
692
701
}
693
702
if ( optimizeLevel >= 3 ) {
703
+ add ( "simplify-locals-nostructure" ) ; // differs
704
+ add ( "vacuum" ) ; // differs
705
+ add ( "reorder-locals" ) ; // differs
694
706
add ( "flatten" ) ;
695
707
add ( "local-cse" ) ;
696
708
}
709
+ if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) { // differs
710
+ add ( "rse" ) ;
711
+ }
697
712
if ( hasARC ) { // differs
698
713
if ( optimizeLevel < 3 ) {
699
714
add ( "flatten" ) ;
@@ -703,33 +718,47 @@ exports.main = function main(argv, options, callback) {
703
718
add ( "dce" ) ;
704
719
add ( "remove-unused-brs" ) ;
705
720
add ( "remove-unused-names" ) ;
706
- add ( "optimize-instructions" ) ;
721
+ // add("optimize-instructions"); // differs move 2 lines above
707
722
if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) {
708
723
add ( "pick-load-signs" ) ;
709
724
add ( "simplify-globals-optimizing" ) ; // differs
710
725
}
726
+ add ( "optimize-instructions" ) ; // differs
711
727
if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
712
728
add ( "precompute-propagate" ) ;
713
729
} else {
714
730
add ( "precompute" ) ;
715
731
}
732
+ if ( module . getLowMemoryUnused ( ) ) {
733
+ if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) {
734
+ add ( "optimize-added-constants-propagate" ) ;
735
+ } else {
736
+ add ( "optimize-added-constants" ) ;
737
+ }
738
+ }
716
739
// this will be done later (1)
717
740
// if (optimizeLevel >= 2 || shrinkLevel >= 2) {
718
741
// add("code-pushing");
719
742
// }
743
+ if ( optimizeLevel >= 3 && shrinkLevel <= 1 ) { // differs
744
+ add ( "licm" ) ;
745
+ }
720
746
add ( "simplify-locals-nostructure" ) ;
721
747
add ( "vacuum" ) ;
722
748
add ( "reorder-locals" ) ;
723
749
add ( "remove-unused-brs" ) ;
724
- if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
725
- add ( "merge-locals" ) ;
726
- }
750
+ // if (optimizeLevel >= 3 || shrinkLevel >= 2) { // do it later
751
+ // add("merge-locals");
752
+ // }
727
753
add ( "coalesce-locals" ) ;
728
754
add ( "simplify-locals" ) ;
729
755
add ( "vacuum" ) ;
730
756
add ( "reorder-locals" ) ;
731
757
add ( "coalesce-locals" ) ;
732
758
add ( "reorder-locals" ) ;
759
+ if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) { // differs
760
+ add ( "merge-locals" ) ;
761
+ }
733
762
add ( "vacuum" ) ;
734
763
if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) {
735
764
add ( "code-folding" ) ;
@@ -789,29 +818,26 @@ exports.main = function main(argv, options, callback) {
789
818
add ( "remove-unused-brs" ) ;
790
819
add ( "vacuum" ) ;
791
820
792
- // replace indirect calls with direct and inline if possible again.
793
- add ( "directize" ) ;
794
- add ( "inlining-optimizing" ) ;
795
821
// move some code after early return which potentially could reduce computations
796
822
// do this after CFG cleanup (originally it was done before)
797
823
// moved from (1)
798
824
add ( "code-pushing" ) ;
799
-
800
- // this quite expensive so do this only for highest opt level
801
- add ( "simplify-globals-optimizing" ) ;
802
825
if ( optimizeLevel >= 3 ) {
803
- add ( "simplify-locals-nostructure" ) ;
804
- add ( "vacuum" ) ;
805
-
826
+ // this quite expensive so do this only for highest opt level
827
+ add ( "simplify-globals" ) ;
828
+ // replace indirect calls with direct and inline if possible again.
829
+ add ( "directize" ) ;
830
+ add ( "dae-optimizing" ) ;
806
831
add ( "precompute-propagate" ) ;
832
+ add ( "coalesce-locals" ) ;
833
+ add ( "merge-locals" ) ;
807
834
add ( "simplify-locals-nostructure" ) ;
808
835
add ( "vacuum" ) ;
809
-
810
- add ( "reorder-locals" ) ;
811
- } else {
812
- add ( "simplify-globals-optimizing" ) ;
836
+ add ( "inlining-optimizing" ) ;
837
+ add ( "precompute-propagate" ) ;
813
838
}
814
839
add ( "optimize-instructions" ) ;
840
+ add ( "simplify-globals-optimizing" ) ;
815
841
}
816
842
// remove unused elements of table and pack / reduce memory
817
843
add ( "duplicate-function-elimination" ) ; // differs
0 commit comments