Skip to content

Commit 75c95c0

Browse files
HerrCai0907atc-github
authored andcommitted
chore(doc): document for immutable_load_eliminate (#130)
1 parent 1576e5a commit 75c95c0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
During coding, there are always lots of never changed static data which is similar as .text section in ELF.
2+
3+
In AS, this type of immutable data mainly includes string literals and function object.
4+
5+
## Function Object
6+
7+
For function objects, if we can identify this kinds of data, we can simplify lots of indirect function call.
8+
9+
Considering below example for function object:
10+
11+
```ts
12+
function v(fn: () => void): void {
13+
fn();
14+
}
15+
v(() => {});
16+
```
17+
18+
Arrow function `() => {}` will be compiled as function object which stored in static data area with function index `I`.
19+
The function `v` will accept a `ptr` which is pointing to the function object. During calling `fn`, the function index will be load from `ptr` and call arrow function by `call_indirect`.
20+
21+
After eliminate the load data from immutable data area, subsequence compilation optimization can infer the function index in `call_indirect` is never changed and simplify it as `call`.
22+
23+
## String Literal
24+
25+
not implement yet.
26+
27+
## How
28+
29+
Binaryen cannot optimize this cases directly because this semantics cannot be properly expressed in a wasm spec.
30+
31+
The pass rely on the additional information `ImmutableDataElementRanges` passed in `AsModule` which define the ranges of immutable data.
32+
33+
When load data inside this range, the load instruction will be replaced as const instruction.

0 commit comments

Comments
 (0)