@@ -248,12 +248,6 @@ exports.main = function main(argv, options, callback) {
248248 assemblyscript . setNoUnsafe ( compilerOptions , args . noUnsafe ) ;
249249 assemblyscript . setPedantic ( compilerOptions , args . pedantic ) ;
250250
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" ) ;
256-
257251 // Add or override aliases if specified
258252 if ( args . use ) {
259253 let aliases = args . use ;
@@ -678,6 +672,20 @@ exports.main = function main(argv, options, callback) {
678672 const passes = [ ] ;
679673 function add ( pass ) { passes . push ( pass ) ; }
680674
675+ if ( optimizeLevel >= 2 && shrinkLevel === 0 ) {
676+ // tweak inlining options when speed more preferable than size
677+ module . setAlwaysInlineMaxSize ( 12 ) ;
678+ module . setFlexibleInlineMaxSize ( 70 ) ;
679+ module . setOneCallerInlineMaxSize ( 200 ) ;
680+ } else {
681+ // tweak inlining options when size matters
682+ optimizeLevel === 0 && shrinkLevel >= 0
683+ ? module . setAlwaysInlineMaxSize ( 2 )
684+ : module . setAlwaysInlineMaxSize ( 4 ) ; // default: 2
685+ module . setFlexibleInlineMaxSize ( 65 ) ; // default: 20
686+ module . setOneCallerInlineMaxSize ( 80 ) ; // default: 15
687+ }
688+
681689 // Optimize the module if requested
682690 if ( optimizeLevel > 0 || shrinkLevel > 0 ) {
683691 // Binaryen's default passes with Post-AssemblyScript passes added.
@@ -691,9 +699,15 @@ exports.main = function main(argv, options, callback) {
691699 add ( "ssa-nomerge" ) ;
692700 }
693701 if ( optimizeLevel >= 3 ) {
702+ add ( "simplify-locals-nostructure" ) ; // differs
703+ add ( "vacuum" ) ; // differs
704+ add ( "reorder-locals" ) ; // differs
694705 add ( "flatten" ) ;
695706 add ( "local-cse" ) ;
696707 }
708+ if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) { // differs
709+ add ( "rse" ) ;
710+ }
697711 if ( hasARC ) { // differs
698712 if ( optimizeLevel < 3 ) {
699713 add ( "flatten" ) ;
@@ -703,11 +717,12 @@ exports.main = function main(argv, options, callback) {
703717 add ( "dce" ) ;
704718 add ( "remove-unused-brs" ) ;
705719 add ( "remove-unused-names" ) ;
706- add ( "optimize-instructions" ) ;
720+ // add("optimize-instructions"); // differs move 2 lines above
707721 if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) {
708722 add ( "pick-load-signs" ) ;
709723 add ( "simplify-globals-optimizing" ) ; // differs
710724 }
725+ add ( "optimize-instructions" ) ; // differs
711726 if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
712727 add ( "precompute-propagate" ) ;
713728 } else {
@@ -717,19 +732,25 @@ exports.main = function main(argv, options, callback) {
717732 // if (optimizeLevel >= 2 || shrinkLevel >= 2) {
718733 // add("code-pushing");
719734 // }
735+ if ( optimizeLevel >= 3 && shrinkLevel <= 1 ) { // differs
736+ add ( "licm" ) ;
737+ }
720738 add ( "simplify-locals-nostructure" ) ;
721739 add ( "vacuum" ) ;
722740 add ( "reorder-locals" ) ;
723741 add ( "remove-unused-brs" ) ;
724- if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
725- add ( "merge-locals" ) ;
726- }
742+ // if (optimizeLevel >= 3 || shrinkLevel >= 2) { // do it later
743+ // add("merge-locals");
744+ // }
727745 add ( "coalesce-locals" ) ;
728746 add ( "simplify-locals" ) ;
729747 add ( "vacuum" ) ;
730748 add ( "reorder-locals" ) ;
731749 add ( "coalesce-locals" ) ;
732750 add ( "reorder-locals" ) ;
751+ if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) { // differs
752+ add ( "merge-locals" ) ;
753+ }
733754 add ( "vacuum" ) ;
734755 if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) {
735756 add ( "code-folding" ) ;
@@ -789,29 +810,26 @@ exports.main = function main(argv, options, callback) {
789810 add ( "remove-unused-brs" ) ;
790811 add ( "vacuum" ) ;
791812
792- // replace indirect calls with direct and inline if possible again.
793- add ( "directize" ) ;
794- add ( "inlining-optimizing" ) ;
795813 // move some code after early return which potentially could reduce computations
796814 // do this after CFG cleanup (originally it was done before)
797815 // moved from (1)
798816 add ( "code-pushing" ) ;
799-
800- // this quite expensive so do this only for highest opt level
801- add ( "simplify-globals-optimizing" ) ;
802817 if ( optimizeLevel >= 3 ) {
803- add ( "simplify-locals-nostructure" ) ;
804- add ( "vacuum" ) ;
805-
818+ // this quite expensive so do this only for highest opt level
819+ add ( "simplify-globals" ) ;
820+ // replace indirect calls with direct and inline if possible again.
821+ add ( "directize" ) ;
822+ add ( "dae-optimizing" ) ;
806823 add ( "precompute-propagate" ) ;
824+ add ( "coalesce-locals" ) ;
825+ add ( "merge-locals" ) ;
807826 add ( "simplify-locals-nostructure" ) ;
808827 add ( "vacuum" ) ;
809-
810- add ( "reorder-locals" ) ;
811- } else {
812- add ( "simplify-globals-optimizing" ) ;
828+ add ( "inlining-optimizing" ) ;
829+ add ( "precompute-propagate" ) ;
813830 }
814831 add ( "optimize-instructions" ) ;
832+ add ( "simplify-globals-optimizing" ) ;
815833 }
816834 // remove unused elements of table and pack / reduce memory
817835 add ( "duplicate-function-elimination" ) ; // differs
0 commit comments