Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

12.0 KB
Raw Blame
;;! target = "x86_64"
;;! test = "optimize"
;;! filter = "function"
;;! flags = "-C inlining=n -Wconcurrency-support=n"

;; Same as `known-imported-entities.wat` except that `$N` additionally
;; re-exports the memory, global, and table that it imports, and `$P` imports
;; them from `$N` rather than directly from `$M`.
;;
;; Every module is still instantiated exactly once and nothing else in the
;; component can get its hands on these entities, so the transitive import
;; through `$N`'s re-export is unambiguous: all three of `$M`, `$N`, and `$P`
;; must use the same precise `DefinedMemory`/`DefinedGlobal`/`DefinedTable`
;; region for `$M`'s definitions. If `$P` fell back to the conservative
;; `PublicMemory`/`PublicGlobal`/`PublicTable` regions while `$M` and `$N` used
;; the precise ones, then inlining across those modules would access the same
;; entity through two different alias regions, which is invalid.

(component
  (core module $M
    (memory (export "mem") 1)
    (global (export "g") (mut i32) (i32.const 0))
    (table (export "t") 1 funcref)

    (func (export "load-mem") (result i32)
      (i32.load (i32.const 0)))
    (func (export "get-global") (result i32)
      (global.get 0))
    (func (export "get-table") (result funcref)
      (table.get 0 (i32.const 0)))
  )

  (core instance $m (instantiate $M))

  (core module $N
    (import "" "mem" (memory 1))
    (import "" "g" (global (mut i32)))
    (import "" "t" (table 1 funcref))

    ;; Re-export our imports.
    (export "mem" (memory 0))
    (export "g" (global 0))
    (export "t" (table 0))

    (func (export "load-mem") (result i32)
      (i32.load (i32.const 0)))
    (func (export "get-global") (result i32)
      (global.get 0))
    (func (export "get-table") (result funcref)
      (table.get 0 (i32.const 0)))
  )

  (core instance $n (instantiate $N (with "" (instance $m))))

  (core module $P
    (import "" "mem" (memory 1))
    (import "" "g" (global (mut i32)))
    (import "" "t" (table 1 funcref))

    (func (export "load-mem") (result i32)
      (i32.load (i32.const 0)))
    (func (export "get-global") (result i32)
      (global.get 0))
    (func (export "get-table") (result funcref)
      (table.get 0 (i32.const 0)))
  )

  (core instance $p (instantiate $P (with "" (instance $n))))
)
;; function u0:0(i64 vmctx, i64) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 215 ""
;;     region3 = 105 ""
;;     region4 = 171 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0073                               v4 = load.i64 notrap aligned readonly can_move region2 v0+56
;; @0073                               v6 = load.i32 little region4 v4
;; @0076                               jump block1
;;
;;                                 block1:
;; @0076                               return v6
;; }
;;
;; function u0:1(i64 vmctx, i64) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 250 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0079                               v2 = load.i32 notrap aligned region2 v0+96
;; @007b                               jump block1
;;
;;                                 block1:
;; @007b                               return v2
;; }
;;
;; function u0:2(i64 vmctx, i64) -> i64 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 93 ""
;;     region3 = 211 ""
;;     region4 = 117 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     sig0 = (i64 vmctx, i32, i64) -> i64 tail
;;     fn0 = colocated u805306368:6 sig0
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0080                               v3 = load.i64 notrap aligned region3 v0+80
;; @0080                               v7 = load.i64 notrap aligned region2 v0+72
;; @0080                               v4 = ireduce.i32 v3
;; @007e                               v2 = iconst.i32 0
;;                                     v21 = icmp eq v4, v2  ; v2 = 0
;;                                     v24 = iconst.i64 0
;; @0080                               v12 = select_spectre_guard v21, v24, v7  ; v24 = 0
;; @0080                               v13 = load.i64 user6 aligned region4 v12
;; @0080                               v14 = iconst.i64 -2
;; @0080                               v15 = band v13, v14  ; v14 = -2
;; @0080                               brif v13, block3(v15), block2
;;
;;                                 block2 cold:
;; @007e                               v25 = iconst.i32 0
;;                                     v26 = iconst.i64 0
;; @0080                               v19 = call fn0(v0, v25, v26)  ; v25 = 0, v26 = 0
;; @0080                               jump block3(v19)
;;
;;                                 block3(v16: i64):
;; @0082                               jump block1
;;
;;                                 block1:
;; @0082                               return v16
;; }
;;
;; function u1:0(i64 vmctx, i64) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 75 ""
;;     region3 = 215 ""
;;     region4 = 105 ""
;;     region5 = 171 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0104                               v4 = load.i64 notrap aligned readonly can_move region2 v0+48
;; @0104                               v5 = load.i64 notrap aligned readonly can_move region3 v4
;; @0104                               v7 = load.i32 little region5 v5
;; @0107                               jump block1
;;
;;                                 block1:
;; @0107                               return v7
;; }
;;
;; function u1:1(i64 vmctx, i64) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 57 ""
;;     region3 = 250 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @010a                               v2 = load.i64 notrap aligned readonly can_move region2 v0+96
;; @010a                               v3 = load.i32 notrap aligned region3 v2
;; @010c                               jump block1
;;
;;                                 block1:
;; @010c                               return v3
;; }
;;
;; function u1:2(i64 vmctx, i64) -> i64 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 13 ""
;;     region3 = 93 ""
;;     region4 = 211 ""
;;     region5 = 117 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     sig0 = (i64 vmctx, i32, i64) -> i64 tail
;;     fn0 = colocated u805306368:6 sig0
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0111                               v3 = load.i64 notrap aligned readonly can_move region2 v0+72
;; @0111                               v4 = load.i64 notrap aligned region4 v3+8
;; @0111                               v9 = load.i64 notrap aligned region3 v3
;; @0111                               v5 = ireduce.i32 v4
;; @010f                               v2 = iconst.i32 0
;;                                     v23 = icmp eq v5, v2  ; v2 = 0
;;                                     v26 = iconst.i64 0
;; @0111                               v14 = select_spectre_guard v23, v26, v9  ; v26 = 0
;; @0111                               v15 = load.i64 user6 aligned region5 v14
;; @0111                               v16 = iconst.i64 -2
;; @0111                               v17 = band v15, v16  ; v16 = -2
;; @0111                               brif v15, block3(v17), block2
;;
;;                                 block2 cold:
;; @010f                               v27 = iconst.i32 0
;;                                     v28 = iconst.i64 0
;; @0111                               v21 = call fn0(v0, v27, v28)  ; v27 = 0, v28 = 0
;; @0111                               jump block3(v21)
;;
;;                                 block3(v18: i64):
;; @0113                               jump block1
;;
;;                                 block1:
;; @0113                               return v18
;; }
;;
;; function u2:0(i64 vmctx, i64) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 75 ""
;;     region3 = 215 ""
;;     region4 = 105 ""
;;     region5 = 171 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0189                               v4 = load.i64 notrap aligned readonly can_move region2 v0+48
;; @0189                               v5 = load.i64 notrap aligned readonly can_move region3 v4
;; @0189                               v7 = load.i32 little region5 v5
;; @018c                               jump block1
;;
;;                                 block1:
;; @018c                               return v7
;; }
;;
;; function u2:1(i64 vmctx, i64) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 57 ""
;;     region3 = 250 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @018f                               v2 = load.i64 notrap aligned readonly can_move region2 v0+96
;; @018f                               v3 = load.i32 notrap aligned region3 v2
;; @0191                               jump block1
;;
;;                                 block1:
;; @0191                               return v3
;; }
;;
;; function u2:2(i64 vmctx, i64) -> i64 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     region2 = 13 ""
;;     region3 = 93 ""
;;     region4 = 211 ""
;;     region5 = 117 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     sig0 = (i64 vmctx, i32, i64) -> i64 tail
;;     fn0 = colocated u805306368:6 sig0
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64):
;; @0196                               v3 = load.i64 notrap aligned readonly can_move region2 v0+72
;; @0196                               v4 = load.i64 notrap aligned region4 v3+8
;; @0196                               v9 = load.i64 notrap aligned region3 v3
;; @0196                               v5 = ireduce.i32 v4
;; @0194                               v2 = iconst.i32 0
;;                                     v23 = icmp eq v5, v2  ; v2 = 0
;;                                     v26 = iconst.i64 0
;; @0196                               v14 = select_spectre_guard v23, v26, v9  ; v26 = 0
;; @0196                               v15 = load.i64 user6 aligned region5 v14
;; @0196                               v16 = iconst.i64 -2
;; @0196                               v17 = band v15, v16  ; v16 = -2
;; @0196                               brif v15, block3(v17), block2
;;
;;                                 block2 cold:
;; @0194                               v27 = iconst.i32 0
;;                                     v28 = iconst.i64 0
;; @0196                               v21 = call fn0(v0, v27, v28)  ; v27 = 0, v28 = 0
;; @0196                               jump block3(v21)
;;
;;                                 block3(v18: i64):
;; @0198                               jump block1
;;
;;                                 block1:
;; @0198                               return v18
;; }