Skip to content

Commit

Permalink
feat: Add new optimization passes
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 23, 2023
1 parent 10d08b0 commit 14b5afe
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/passes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ let denan = "denan"
(** turns indirect calls into direct ones *)
let directize = "directize"

(** discards global effect info *)
let discard_global_effects = "discard-global-effects"

(** optimizes using the DataFlow SSA IR *)
let dfo = "dfo"

Expand Down Expand Up @@ -81,6 +84,9 @@ let generate_dyncalls = "generate-dyncalls"
(** generate dynCall functions used by emscripten ABI, but only for functions with i64 in their signature (which cannot be invoked via the wasm table without JavaScript BigInt support). *)
let generate_i64_dyncalls = "generate-i64-dyncalls"

(** generate global effect info (helps later passes) *)
let generate_global_effects = "generate-global-effects"

(** generate Stack IR *)
let generate_stack_ir = "generate-stack-ir"

Expand Down Expand Up @@ -117,6 +123,9 @@ let inlining_optimizing = "inlining-optimizing"
(** lower away binaryen intrinsics *)
let intrinsic_lowering = "intrinsic-lowering"

(** wrap imports and exports for JavaScript promise integration *)
let jspi = "jspi"

(** legalizes i64 types on the import/export boundary *)
let legalize_js_interface = "legalize-js-interface"

Expand Down Expand Up @@ -181,6 +190,15 @@ let mod_asyncify_always_and_only_unwind = "mod-asyncify-always-and-only-unwind"
(** apply the assumption that asyncify never unwinds *)
let mod_asyncify_never_unwind = "mod-asyncify-never-unwind"

(** creates specialized versions of functions *)
let monomorphize = "monomorphize"

(** creates specialized versions of functions (even if unhelpful) *)
let monomorphize_always = "monomorphize-always"

(** combines multiple memories into a single memory *)
let multi_memory_lowering = "multi-memory-lowering"

(** name list *)
let nm = "nm"

Expand All @@ -196,6 +214,9 @@ let optimize_added_constants = "optimize-added-constants"
(** optimizes added constants into load/store offsets, propagating them across locals too *)
let optimize_added_constants_propagate = "optimize-added-constants-propagate"

(** eliminate and reuse casts *)
let optimize_casts = "optimize-casts"

(** optimizes instruction combinations *)
let optimize_instructions = "optimize-instructions"

Expand Down Expand Up @@ -269,6 +290,12 @@ let remove_unused_names = "remove-unused-names"
(** sorts functions by access frequency *)
let reorder_functions = "reorder-functions"

(** sorts globals by access frequency *)
let reorder_globals = "reorder-globals"

(** sorts globals by access frequency (even if there are few) *)
let reorder_globals_always = "reorder-globals-always"

(** sorts locals by access frequency *)
let reorder_locals = "reorder-locals"

Expand All @@ -293,6 +320,9 @@ let signature_pruning = "signature-pruning"
(** apply more specific subtypes to signature types where possible *)
let signature_refining = "signature-refining"

(** lower sign-ext operations to wasm mvp *)
let signext_lowering = "signext-lowering"

(** miscellaneous globals-related optimizations *)
let simplify_globals = "simplify-globals"

Expand Down
30 changes: 30 additions & 0 deletions src/passes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ val denan : t
val directize : t
(** turns indirect calls into direct ones *)

val discard_global_effects : t
(** discards global effect info *)

val dfo : t
(** optimizes using the DataFlow SSA IR *)

Expand Down Expand Up @@ -81,6 +84,9 @@ val generate_dyncalls : t
val generate_i64_dyncalls : t
(** generate dynCall functions used by emscripten ABI, but only for functions with i64 in their signature (which cannot be invoked via the wasm table without JavaScript BigInt support). *)

val generate_global_effects : t
(** generate global effect info (helps later passes) *)

val generate_stack_ir : t
(** generate Stack IR *)

Expand Down Expand Up @@ -117,6 +123,9 @@ val inlining_optimizing : t
val intrinsic_lowering : t
(** lower away binaryen intrinsics *)

val jspi : t
(** wrap imports and exports for JavaScript promise integration *)

val legalize_js_interface : t
(** legalizes i64 types on the import/export boundary *)

Expand Down Expand Up @@ -180,6 +189,15 @@ val mod_asyncify_always_and_only_unwind : t
val mod_asyncify_never_unwind : t
(** apply the assumption that asyncify never unwinds *)

val monomorphize : t
(** creates specialized versions of functions *)

val monomorphize_always : t
(** creates specialized versions of functions (even if unhelpful) *)

val multi_memory_lowering : t
(** combines multiple memories into a single memory *)

val nm : t
(** name list *)

Expand All @@ -195,6 +213,9 @@ val optimize_added_constants : t
val optimize_added_constants_propagate : t
(** optimizes added constants into load/store offsets, propagating them across locals too *)

val optimize_casts : t
(** eliminate and reuse casts *)

val optimize_instructions : t
(** optimizes instruction combinations *)

Expand Down Expand Up @@ -267,6 +288,12 @@ val remove_unused_names : t
val reorder_functions : t
(** sorts functions by access frequency *)

val reorder_globals : t
(** sorts globals by access frequency *)

val reorder_globals_always : t
(** sorts globals by access frequency (even if there are few) *)

val reorder_locals : t
(** sorts locals by access frequency *)

Expand All @@ -291,6 +318,9 @@ val signature_pruning : t
val signature_refining : t
(** apply more specific subtypes to signature types where possible *)

val signext_lowering : t
(** lower sign-ext operations to wasm mvp *)

val simplify_globals : t
(** miscellaneous globals-related optimizations *)

Expand Down
7 changes: 7 additions & 0 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,18 @@ let new_mod = Module.read byts
let _ =
Module.run_passes new_mod
[
Passes.generate_global_effects;
Passes.name_types;
Passes.merge_similar_functions;
Passes.spill_pointers;
Passes.gufa;
Passes.gufa_optimizing;
Passes.reorder_globals;
Passes.optimize_casts;
Passes.multi_memory_lowering;
Passes.monomorphize;
Passes.signext_lowering;
Passes.discard_global_effects;
]

let _ =
Expand Down

0 comments on commit 14b5afe

Please sign in to comment.