File: gto_and_cfp_in_O.wast

package info (click to toggle)
binaryen 120-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,284 kB
  • sloc: cpp: 189,449; javascript: 62,189; ansic: 14,087; python: 5,379; pascal: 441; sh: 77; makefile: 30; asm: 27
file content (67 lines) | stat: -rw-r--r-- 2,344 bytes parent folder | download
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
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt -O -all --closed-world -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt -O -all                -S -o - | filecheck %s --check-prefix OPEN_WORLD

;; Test that -O, with nominal typing + GC enabled, will run global type
;; optimization in conjunction with constant field propagation etc. But, in an
;; open world we do not run them.

(module
  ;; OPEN_WORLD:      (type $struct (sub (struct (field (mut funcref)) (field (mut i32)))))
  (type $struct (sub (struct (field (mut funcref)) (field (mut i32)))))

  ;; OPEN_WORLD:      (type $1 (func))

  ;; OPEN_WORLD:      (type $2 (func (result i32)))

  ;; OPEN_WORLD:      (global $glob (ref $struct) (struct.new $struct
  ;; OPEN_WORLD-NEXT:  (ref.func $by-ref)
  ;; OPEN_WORLD-NEXT:  (i32.const 100)
  ;; OPEN_WORLD-NEXT: ))
  (global $glob (ref $struct) (struct.new $struct
    (ref.func $by-ref)
    (i32.const 100)
  ))

  ;; OPEN_WORLD:      (export "main" (func $main))

  ;; OPEN_WORLD:      (func $by-ref (type $1)
  ;; OPEN_WORLD-NEXT:  (struct.set $struct 1
  ;; OPEN_WORLD-NEXT:   (global.get $glob)
  ;; OPEN_WORLD-NEXT:   (i32.const 200)
  ;; OPEN_WORLD-NEXT:  )
  ;; OPEN_WORLD-NEXT: )
  (func $by-ref
    ;; This function is kept alive by the reference in $glob. After we remove
    ;; the field that the funcref is written to, we remove the funcref, which
    ;; means this function can be removed.
    ;;
    ;; Once it is removed, this write no longer exists, and does not hamper
    ;; constant field propagation from inferring the value of the i32 field.
    (struct.set $struct 1
      (global.get $glob)
      (i32.const 200)
    )
  )

  ;; CHECK:      (type $0 (func (result i32)))

  ;; CHECK:      (export "main" (func $main))

  ;; CHECK:      (func $main (type $0) (result i32)
  ;; CHECK-NEXT:  (i32.const 100)
  ;; CHECK-NEXT: )
  ;; OPEN_WORLD:      (func $main (type $2) (result i32)
  ;; OPEN_WORLD-NEXT:  (struct.get $struct 1
  ;; OPEN_WORLD-NEXT:   (global.get $glob)
  ;; OPEN_WORLD-NEXT:  )
  ;; OPEN_WORLD-NEXT: )
  (func $main (export "main") (result i32)
    ;; After all the above optimizations, we can infer that $main should simply
    ;; return 100.
    (struct.get $struct 1
      (global.get $glob)
    )
  )
)