Commit ec6d9c0
[dart2wasm] Inline Pointer constructor
Currently none of dart2wasm or wasm-opt inline `Pointer._`, resulting in
bad code generation when the allocated pointers are directly unboxed.
Example:
```
import 'dart:ffi';
@Native<Pointer<Int64> Function()>()
external Pointer<Int64> intPtr();
@Native<Int64 Function(Pointer<Int64>)>()
external int derefIntPtr(Pointer<Int64> ptr);
void main() {
Pointer<Int64> ptr = intPtr();
ptr += 1;
int i = derefIntPtr(ptr);
print(i);
}
```
Current output:
```
(func $main (;299;)
i32.const 83
call $ffi.intPtr (import)
call $Pointer._
struct.get $_Type $field2
i32.const 8
i32.add
call $Pointer._
struct.get $_Type $field2
call $ffi.derefIntPtr (import)
struct.new $BoxedInt
call $print)
```
With this CL the `Pointer` allocation disappears:
```
(func $main (;299;)
i32.const 83
call $ffi.intPtr (import)
i32.const 8
i32.add
call $ffi.derefIntPtr (import)
struct.new $BoxedInt
call $print)
```
Change-Id: I54a2fd37bc9e8ab26c6394e0b8175d65ecf64cb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399561
Reviewed-by: Martin Kustermann <[email protected]>
Commit-Queue: Ömer Ağacan <[email protected]>1 parent 0c527e1 commit ec6d9c0
1 file changed
+1
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
0 commit comments