package binaryen

  1. Overview
  2. Docs

Source file passes.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
type t = string

(** lower unaligned loads and stores to smaller aligned ones *)
let alignment_lowering = "alignment-lowering"

(** async/await style transform, allowing pausing and resuming *)
let asyncify = "asyncify"

(** Tries to avoid reinterpret operations via more loads *)
let avoid_reinterprets = "avoid-reinterprets"

(** removes arguments to calls in an lto-like manner *)
let dae = "dae"

(** removes arguments to calls in an lto-like manner, and optimizes where we
    removed *)
let dae_optimizing = "dae-optimizing"

(** refine and merge abstract (never-created) types *)
let abstract_type_refining = "abstract-type-refining"

(** reduce # of locals by coalescing *)
let coalesce_locals = "coalesce-locals"

(** reduce # of locals by coalescing and learning *)
let coalesce_locals_learning = "coalesce-locals-learning"

(** push code forward, potentially making it not always execute *)
let code_pushing = "code-pushing"

(** fold code, merging duplicates *)
let code_folding = "code-folding"

(** hoist repeated constants to a local *)
let const_hoisting = "const-hoisting"

(** propagate constant struct field values *)
let cfp = "cfp"

(** propagate constant struct field values, using ref.test *)
let cfp_reftest = "cfp-reftest"

(** removes unreachable code *)
let dce = "dce"

(** forces all loads and stores to have alignment 1 *)
let dealign = "dealign"

(** propagate debug location from parents or previous siblings to child nodes *)
let propagate_debug_locs = "propagate-debug-locs"

(** instrument the wasm to convert NaNs into 0 at runtime *)
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"

(** dump DWARF debug info sections from the read binary *)
let dwarfdump = "dwarfdump"

(** removes duplicate imports *)
let duplicate_import_elimination = "duplicate-import-elimination"

(** removes duplicate functions *)
let duplicate_function_elimination = "duplicate-function-elimination"

(** emit the target features section in the output *)
let emit_target_features = "emit-target-features"

(** modify the wasm (destructively) for closed-world *)
let enclose_world = "enclose-world"

(** leaves just one function (useful for debugging) *)
let extract_function = "extract-function"

(** leaves just one function selected by index *)
let extract_function_index = "extract-function-index"

(** flattens out code, removing nesting *)
let flatten = "flatten"

(** emulates function pointer casts, allowing incorrect indirect calls to
    (sometimes) work *)
let fpcast_emu = "fpcast-emu"

(** reports function metrics *)
let func_metrics = "func-metrics"

(** generate dynCall fuctions used by emscripten ABI *)
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"

(** refine the types of globals *)
let global_refining = "global-refining"

(** globally optimize struct values *)
let gsi = "gsi"

(** globally optimize GC types *)
let gto = "gto"

(** Grand Unified Flow Analysis: optimize the entire program using information
    about what content can actually appear in each location *)
let gufa = "gufa"

(** GUFA plus add casts for all inferences *)
let gufa_cast_all = "gufa-cast-all"

(** GUFA plus local optimizations in functions we modified *)
let gufa_optimizing = "gufa-optimizing"

(** optimizes J2CL specific constructs. *)
let optimize_j2cl = "optimize-j2cl"

(** Merges itable structures into vtables to make types more compact *)
let merge_j2cl_itables = "merge-j2cl-itables"

(** apply more specific subtypes to type fields where possible *)
let type_refining = "type-refining"

(** apply more specific subtypes to type fields where possible (using GUFA) *)
let type_refining_gufa = "type-refining-gufa"

(** replace GC allocations with locals *)
let heap2local = "heap2local"

(** optimize heap (GC) stores *)
let heap_store_optimization = "heap-store-optimization"

(** inline __original_main into main *)
let inline_main = "inline-main"

(** inline functions (you probably want inlining-optimizing) *)
let inlining = "inlining"

(** inline functions and optimizes where we inlined *)
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"

(** legalizes the import/export boundary and prunes when needed *)
let legalize_and_prune_js_interface = "legalize-and-prune-js-interface"

(** common subexpression elimination inside basic blocks *)
let local_cse = "local-cse"

(** apply more specific subtypes to locals where possible *)
let local_subtyping = "local-subtyping"

(** instrument the build with logging of where execution goes *)
let log_execution = "log-execution"

(** lower all uses of i64s to use i32s instead *)
let i64_to_i32_lowering = "i64-to-i32-lowering"

(** instrument the build with code to intercept specific function calls *)
let trace_calls = "trace-calls"

(** instrument the build with code to intercept all loads and stores *)
let instrument_locals = "instrument-locals"

(** instrument the build with code to intercept all loads and stores *)
let instrument_memory = "instrument-memory"

(** loop invariant code motion *)
let licm = "licm"

(** attempt to merge segments to fit within web limits *)
let limit_segments = "limit-segments"

(** lower loads and stores to a 64-bit memory to instead use a 32-bit one *)
let memory64_lowering = "memory64-lowering"

(** alias for memory64-lowering *)
let table64_lowering = "table64-lowering"

(** Lower memory.copy and memory.fill to wasm mvp and disable the bulk-memory
    feature. *)
let llvm_memory_copy_fill_lowering = "llvm-memory-copy-fill-lowering"

(** packs memory into separate segments, skipping zeros *)
let memory_packing = "memory-packing"

(** merges blocks to their parents *)
let merge_blocks = "merge-blocks"

(** merges similar functions when benefical *)
let merge_similar_functions = "merge-similar-functions"

(** merges locals when beneficial *)
let merge_locals = "merge-locals"

(** reports metrics *)
let metrics = "metrics"

(** minifies import names (only those, and not export names), and emits a
    mapping to the minified ones *)
let minify_imports = "minify-imports"

(** minifies both import and export names, and emits a mapping to the minified
    ones *)
let minify_imports_and_exports = "minify-imports-and-exports"

(** minifies both import and export names, and emits a mapping to the minified
    ones, and minifies the modules as well *)
let minify_imports_and_exports_and_modules =
  "minify-imports-and-exports-and-modules"

(** Split types into minimal recursion groups *)
let minimize_rec_groups = "minimize-rec-groups"

(** apply the assumption that asyncify imports always unwind, and we never
    rewind *)
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"

(** combines multiple memories into a single memory, trapping if the read or
    write is larger than the length of the memory's data *)
let multi_memory_lowering_with_bounds_checks =
  "multi-memory-lowering-with-bounds-checks"

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

(** (re)name all heap types *)
let name_types = "name-types"

(** mark functions as no-inline *)
let no_inline = "no-inline"

(** mark functions as no-inline (for full inlining only) *)
let no_full_inline = "no-full-inline"

(** mark functions as no-inline (for partial inlining only) *)
let no_partial_inline = "no-partial-inline"

(** lower nontrapping float-to-int operations to wasm mvp and disable the
    nontrapping fptoint feature *)
let llvm_nontrapping_fptoint_lowering = "llvm-nontrapping-fptoint-lowering"

(** reduces calls to code that only runs once *)
let once_reduction = "once-reduction"

(** optimizes added constants into load/store offsets *)
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"

(** pick load signs based on their uses *)
let pick_load_signs = "pick-load-signs"

(** Tranform Binaryen IR into Poppy IR *)
let poppify = "poppify"

(** miscellaneous optimizations for Emscripten-generated code *)
let post_emscripten = "post-emscripten"

(** early optimize of the instruction combinations for js *)
let optimize_for_js = "optimize-for-js"

(** computes compile-time evaluatable expressions *)
let precompute = "precompute"

(** computes compile-time evaluatable expressions and propagates them through
    locals *)
let precompute_propagate = "precompute-propagate"

(** print in s-expression format *)
let print = "print"

(** print in minified s-expression format *)
let print_minified = "print-minified"

(** print options for enabled features *)
let print_features = "print-features"

(** print in full s-expression format *)
let print_full = "print-full"

(** print call graph *)
let print_call_graph = "print-call-graph"

(** print a map of function indexes to names *)
let print_function_map = "print-function-map"

(** alias for print_function_map *)
let symbolmap = "symbolmap"

(** removes operations incompatible with js *)
let remove_non_js_ops = "remove-non-js-ops"

(** removes imports and replaces them with nops *)
let remove_imports = "remove-imports"

(** removes memory initialization *)
let remove_memory_init = "remove-memory-init"

(** removes memory segments *)
let remove_memory = "remove-memory"

(** removes breaks from locations that are not needed *)
let remove_unused_brs = "remove-unused-brs"

(** removes unused module elements *)
let remove_unused_module_elements = "remove-unused-module-elements"

(** removes unused module elements that are not functions *)
let remove_unused_nonfunction_module_elements =
  "remove-unused-nonfunction-module-elements"

(** removes names from locations that are never branched to *)
let remove_unused_names = "remove-unused-names"

(** remove unused private GC types *)
let remove_unused_types = "remove-unused-types"

(** sorts functions by name (useful for debugging) *)
let reorder_functions_by_name = "reorder-functions-by-name"

(** sorts functions by access frequency *)
let reorder_functions = "reorder-functions"

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

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

(** re-optimize control flow using the relooper algorithm *)
let rereloop = "rereloop"

(** remove redundant local.sets *)
let rse = "rse"

(** write the module to binary, then read it *)
let roundtrip = "roundtrip"

(** instrument loads and stores to check for invalid behavior *)
let safe_heap = "safe-heap"

(** sets specified globals to specified values *)
let set_globals = "set-globals"

(** write data segments to a file and strip them from the module *)
let separate_data_segments = "separate-data-segments"

(** remove params from function signature types where possible *)
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 and disable the sign extension feature
*)
let signext_lowering = "signext-lowering"

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

(** miscellaneous globals-related optimizations, and optimizes where we replaced
    global.gets with constants *)
let simplify_globals_optimizing = "simplify-globals-optimizing"

(** miscellaneous locals-related optimizations *)
let simplify_locals = "simplify-locals"

(** miscellaneous locals-related optimizations (no nesting at all; preserves
    flatness) *)
let simplify_locals_nonesting = "simplify-locals-nonesting"

(** miscellaneous locals-related optimizations (no tees) *)
let simplify_locals_notee = "simplify-locals-notee"

(** miscellaneous locals-related optimizations (no structure) *)
let simplify_locals_nostructure = "simplify-locals-nostructure"

(** miscellaneous locals-related optimizations (no tees or structure) *)
let simplify_locals_notee_nostructure = "simplify-locals-notee-nostructure"

(** emit Souper IR in text form *)
let souperify = "souperify"

(** emit Souper IR in text form (single-use nodes only) *)
let souperify_single_use = "souperify-single-use"

(** spill pointers to the C stack (useful for Boehm-style GC) *)
let spill_pointers = "spill-pointers"

(** stub out unsupported JS operations *)
let stub_unsupported_js = "stub-unsupported-js"

(** ssa-ify variables so that they have a single assignment *)
let ssa = "ssa"

(** ssa-ify variables so that they have a single assignment, ignoring merges *)
let ssa_nomerge = "ssa-nomerge"

(** gathers wasm strings to globals *)
let string_gathering = "string-gathering"

(** lift string imports to wasm strings *)
let string_lifting = "string-lifting"

(** lowers wasm strings and operations to imports *)
let string_lowering = "string-lowering"

(** same as string-lowering, but encodes well-formed strings as magic imports *)
let string_lowering_magic_imports = "string-lowering-magic-imports"

(** same as string-lowering-magic-imports, but raise a fatal error if there are
    invalid strings *)
let string_lowering_magic_imports_assert =
  "string-lowering-magic-imports-assert"

(** deprecated; same as strip-debug *)
let strip = "strip"

(** enforce limits on llvm's __stack_pointer global *)
let stack_check = "stack-check"

(** strip debug info (including the names section) *)
let strip_debug = "strip-debug"

(** strip dwarf debug info *)
let strip_dwarf = "strip-dwarf"

(** strip the wasm producers section *)
let strip_producers = "strip-producers"

(** strip EH instructions *)
let strip_eh = "strip-eh"

(** strip the wasm target features section *)
let strip_target_features = "strip-target-features"

(** translate old Phase 3 EH instructions to new ones with exnref *)
let translate_to_exnref = "translate-to-exnref"

(** replace trapping operations with clamping semantics *)
let trap_mode_clamp = "trap-mode-clamp"

(** replace trapping operations with js semantics *)
let trap_mode_js = "trap-mode-js"

(** optimize trivial tuples away *)
let tuple_optimization = "tuple-optimization"

(** mark all leaf types as final *)
let type_finalizing = "type-finalizing"

(** merge types to their supertypes where possible *)
let type_merging = "type-merging"

(** create new nominal types to help other optimizations *)
let type_ssa = "type-ssa"

(** mark all types as non-final (open) *)
let type_unfinalizing = "type-unfinalizing"

(** removes removes unnecessary subtyping relationships *)
let unsubtyping = "unsubtyping"

(** removes local.tees, replacing them with sets and gets *)
let untee = "untee"

(** removes obviously unneeded code *)
let vacuum = "vacuum"