@grain/binaryen.ml 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.20.1](https://github.com/grain-lang/binaryen.ml/compare/v0.20.0...v0.20.1) (2023-01-19)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add gufa & gufa_optimizing passes ([#180](https://github.com/grain-lang/binaryen.ml/issues/180)) ([7395a1f](https://github.com/grain-lang/binaryen.ml/commit/7395a1fe0591a835eeeeb6e6e58c28c32b69342d))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Properly handle load & store instructions in JS ([#178](https://github.com/grain-lang/binaryen.ml/issues/178)) ([becd3b8](https://github.com/grain-lang/binaryen.ml/commit/becd3b82ac31c7f2ba1055b320c7ff537b58d971))
14
+
3
15
  ## [0.20.0](https://github.com/grain-lang/binaryen.ml/compare/v0.19.0...v0.20.0) (2023-01-13)
4
16
 
5
17
 
@@ -1,5 +1,5 @@
1
1
  opam-version: "2.0"
2
- version: "0.20.0"
2
+ version: "0.20.1"
3
3
  synopsis: "OCaml bindings for Binaryen"
4
4
  maintainer: "oscar@grain-lang.org"
5
5
  author: "Oscar Spencer"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grain/binaryen.ml",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "OCaml bindings for Binaryen.",
5
5
  "author": "Oscar Spencer <oscar@grain-lang.org>",
6
6
  "license": "Apache-2.0",
@@ -189,11 +189,12 @@ function caml_binaryen_load(
189
189
 
190
190
  switch (typ) {
191
191
  case Binaryen.i32: {
192
- if (signed) {
193
- if (bytes === 4) {
194
- return wasm_mod.i32.load(offset, align, ptr, name);
195
- }
192
+ // Using four bytes doesn't matter if it is signed or unsigned
193
+ if (bytes === 4) {
194
+ return wasm_mod.i32.load(offset, align, ptr, name);
195
+ }
196
196
 
197
+ if (signed) {
197
198
  if (bytes === 1) {
198
199
  return wasm_mod.i32.load8_s(offset, align, ptr, name);
199
200
  }
@@ -210,13 +211,16 @@ function caml_binaryen_load(
210
211
  return wasm_mod.i32.load16_u(offset, align, ptr, name);
211
212
  }
212
213
  }
214
+
215
+ break;
213
216
  }
214
217
  case Binaryen.i64: {
215
- if (signed) {
216
- if (bytes === 8) {
217
- return wasm_mod.i64.load(offset, align, ptr, name);
218
- }
218
+ // Using eight bytes doesn't matter if it is signed or unsigned
219
+ if (bytes === 8) {
220
+ return wasm_mod.i64.load(offset, align, ptr, name);
221
+ }
219
222
 
223
+ if (signed) {
220
224
  if (bytes === 1) {
221
225
  return wasm_mod.i64.load8_s(offset, align, ptr, name);
222
226
  }
@@ -241,6 +245,8 @@ function caml_binaryen_load(
241
245
  return wasm_mod.i64.load32_u(offset, align, ptr, name);
242
246
  }
243
247
  }
248
+
249
+ break;
244
250
  }
245
251
  case Binaryen.f32: {
246
252
  return wasm_mod.f32.load(offset, align, ptr, name);
@@ -300,6 +306,8 @@ function caml_binaryen_store(
300
306
  if (bytes === 2) {
301
307
  return wasm_mod.i32.store16(offset, align, ptr, value, name);
302
308
  }
309
+
310
+ break;
303
311
  }
304
312
  case Binaryen.i64: {
305
313
  if (bytes === 8) {
@@ -317,6 +325,8 @@ function caml_binaryen_store(
317
325
  if (bytes === 4) {
318
326
  return wasm_mod.i64.store32(offset, align, ptr, value, name);
319
327
  }
328
+
329
+ break;
320
330
  }
321
331
  case Binaryen.f32: {
322
332
  return wasm_mod.f32.store(offset, align, ptr, value, name);
@@ -87,11 +87,17 @@ let generate_stack_ir = "generate-stack-ir"
87
87
  (** refine the types of globals *)
88
88
  let global_refining = "global-refining"
89
89
 
90
+ (** globally optimize struct values *)
91
+ let gsi = "gsi"
92
+
90
93
  (** globally optimize GC types *)
91
94
  let gto = "gto"
92
95
 
93
- (** globally optimize struct values *)
94
- let gsi = "gsi"
96
+ (** Grand Unified Flow Analysis: optimize the entire program using information about what content can actually appear in each location *)
97
+ let gufa = "gufa"
98
+
99
+ (** GUFA plus local optimizations in functions we modified *)
100
+ let gufa_optimizing = "gufa-optimizing"
95
101
 
96
102
  (** apply more specific subtypes to type fields where possible *)
97
103
  let type_refining = "type-refining"
@@ -87,11 +87,17 @@ val generate_stack_ir : t
87
87
  val global_refining : t
88
88
  (** refine the types of globals *)
89
89
 
90
+ val gsi : t
91
+ (** globally optimize struct values *)
92
+
90
93
  val gto : t
91
94
  (** globally optimize GC types *)
92
95
 
93
- val gsi : t
94
- (** globally optimize struct values *)
96
+ val gufa : t
97
+ (** Grand Unified Flow Analysis: optimize the entire program using information about what content can actually appear in each location *)
98
+
99
+ val gufa_optimizing : t
100
+ (** GUFA plus local optimizations in functions we modified *)
95
101
 
96
102
  val type_refining : t
97
103
  (** apply more specific subtypes to type fields where possible *)
@@ -33,7 +33,7 @@
33
33
  (i32.add
34
34
  (select
35
35
  (local.get $0)
36
- (i32.load8_s
36
+ (i32.load
37
37
  (local.get $1)
38
38
  )
39
39
  (i32.const 1)
@@ -85,7 +85,7 @@
85
85
  (i32.add
86
86
  (select
87
87
  (local.get $0)
88
- (i32.load8_s
88
+ (i32.load
89
89
  (local.get $1)
90
90
  )
91
91
  (i32.const 1)
@@ -133,7 +133,7 @@
133
133
  (i32.add
134
134
  (select
135
135
  (local.get $0)
136
- (i32.load8_s
136
+ (i32.load
137
137
  (local.get $1)
138
138
  )
139
139
  (i32.const 1)
@@ -180,7 +180,7 @@
180
180
  (func $0 (param $0 i32) (param $1 i32) (result i32)
181
181
  local.get $0
182
182
  local.get $1
183
- i32.load8_s $0
183
+ i32.load $0
184
184
  i32.const 1
185
185
  select
186
186
  local.get $1
@@ -58,7 +58,7 @@ let x () = Expression.Local_get.make wasm_mod 0 Type.int32
58
58
  let y () = Expression.Local_get.make wasm_mod 1 Type.int32
59
59
 
60
60
  let load =
61
- Expression.Load.make wasm_mod 1 ~signed:true 0 0 Type.int32 (y ()) "0"
61
+ Expression.Load.make wasm_mod 4 ~signed:false 0 0 Type.int32 (y ()) "0"
62
62
 
63
63
  let select =
64
64
  Expression.Select.make wasm_mod
@@ -204,6 +204,7 @@ let _ =
204
204
  Type.int32)
205
205
 
206
206
  let _ = Export.add_function_export wasm_mod "hello" "hello"
207
+ let _ = Module.validate wasm_mod
207
208
 
208
209
  (* Shouldn't actually do anything since we aren't doing function renames *)
209
210
  let _ = Module.update_maps wasm_mod
@@ -233,7 +234,13 @@ let new_mod = Module.read byts
233
234
 
234
235
  let _ =
235
236
  Module.run_passes new_mod
236
- [ Passes.name_types; Passes.merge_similar_functions; Passes.spill_pointers ]
237
+ [
238
+ Passes.name_types;
239
+ Passes.merge_similar_functions;
240
+ Passes.spill_pointers;
241
+ Passes.gufa;
242
+ Passes.gufa_optimizing;
243
+ ]
237
244
 
238
245
  let _ =
239
246
  Module.set_features new_mod