Stream: git-wasmtime

Topic: wasmtime / PR #4907 [WIP] Initial skeleton for Winch


view this post on Zulip Wasmtime GitHub notifications bot (Sep 13 2022 at 16:55):

saulecabrera opened PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Sep 13 2022 at 16:56):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 22 2022 at 22:16):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2022 at 10:41):

bjorn3 created PR review comment:

This should probably replaced with features on winch that enable the respective feature of cranelift-codegen and additionally enabling the target architecture if no architecture is selected, just like for cranelift-codegen.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2022 at 10:41):

bjorn3 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2022 at 20:19):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2022 at 20:21):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 26 2022 at 23:19):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 27 2022 at 15:22):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2022 at 20:19):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2022 at 20:19):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2022 at 23:05):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2022 at 10:42):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2022 at 10:43):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2022 at 14:16):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2022 at 17:11):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2022 at 10:01):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2022 at 10:02):

saulecabrera edited PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2022 at 10:02):

saulecabrera edited PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2022 at 10:02):

saulecabrera edited PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2022 at 10:02):

saulecabrera edited PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 12 2022 at 10:05):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2022 at 01:16):

saulecabrera updated PR #4907 from winch-skeleton to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2022 at 01:17):

saulecabrera edited PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2022 at 01:19):

saulecabrera edited PR #4907 from winch-skeleton to main:

Ref: https://github.com/bytecodealliance/rfcs/pull/28


This change introduces the initial skeleton for Winch, the "baseline" compiler.

This skeleton contains mostly setup code for the ISA, ABI, registers, and compilation environment abstractions. It also includes the calculation of function local slots.

As of the first commit, the structure of these abstractions looks like the following:

                    +------------------------+
                    |                        v
 +----------+     +-----+     +-----------+-----+-----------------+
 | Compiler | --> | ISA | --> | Registers | ABI | Compilation Env |
 +----------+     +-----+     +-----------+-----+-----------------+
                    |                              ^
                    +------------------------------+

I'm opening this as a draft, since there are several items that I'd like to finish before continuing to iterate in-tree, namely:

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2022 at 02:04):

saulecabrera edited PR #4907 from winch-skeleton to main:

This change introduces the initial skeleton for Winch, the "baseline" compiler, discussed https://github.com/bytecodealliance/rfcs/pull/28

The skeleton contains the just the necessary code for the main abstractions to support the following:

As of this change, the high-level structure of the compiler is as follows:

      +-----------------------+
       |                       |
       |  +-----------+      +---------------------+
       |  | Compiler  | ---> |         ISA         | ---------------------------------------------------------------+
       |  +-----------+      +---------------------+                                                                |
       |                       |                                                                                    |
       |                       |                                                                                    |
       |                       v                                                                                    |
       |  +-----------+-----+----------------------+     +----------------+     +-------+----------------+-------+  |
       +> | Registers | ABI |        CodeGen       | --> | CodeGenContext | --> | Frame | MacroAssembler | Stack |  |
          +-----------+-----+----------------------+     +----------------+     +-------+----------------+-------+  |
                         ^     |                                                                                    |
                         +-----+------------------------------------------------------------------------------------+
                               |
                               |
                               |
                               v
                             +---------------------+
                             | Register Allocation |
                             +---------------------+

Next steps

As mentioned above, this change doesn't use any of Cranelift's backends for code emission, yet. These are the immediate next steps after landing this change:


Misc

Winch's CLI can be used by running `cargo run -- path/to/file.wat --target=<target>

Here's a set of WebAssembly programs and their corresponding x64 output:
<details>
<summary>Basic i32 add</summary>

(module
  (export "main" (func $main))

  (func $main (result i32)
    (i32.const 10)
    (i32.const 20)
    i32.add)
)
push rbp
mov rbp, rsp
mov eax, 10
add eax, 20
pop rbp
ret

</details>

<details>
<summary> i32 add with local operators </summary>

(module
  (export "main" (func $main))

  (func $main (result i32)
    (local $foo i32)
    (local $bar i32)
    (i32.const 10)
    (local.set $foo)
    (i32.const 20)
    (local.set $bar)
    (local.get $foo)
    (local.get $bar)
    i32.add
  )
)
push rbp
mov rbp, rsp
sub rsp, 8
mov qword [rsp], 0
mov eax, 10
mov [rsp + 4], eax
mov ecx, 20
mov [rsp], ecx
mov eax, [rsp]
mov edx, [rsp + 4]
add edx, eax
mov rax, rdx
add rsp, 8
pop rbp
ret

</details>

<details>
<summary>Basic i32 with function arguments </summary>

(module
  (export "main" (func $main))

  (func $main (param i32) (param i32) (result i32)
      (local.get 0)
      (local.get 1)
      i32.add
    )
)
push rbp
mov rbp, rsp
sub rsp, 8
mov [rsp + 4], edi
mov [rsp], esi
mov eax, [rsp]
mov ecx, [rsp + 4]
add ecx, eax
mov rax, rcx
add rsp, 8
pop rbp
ret

</details>

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.


Last updated: Dec 23 2024 at 13:07 UTC