Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winch(x64): Add support for loop, br and br_if #6603

Merged

Conversation

saulecabrera
Copy link
Member

Part of #6528

This change adds support for the loop, br and br_if instructions as well as unreachable code handling. Whenever an instruction that affects reachability is emitted (br in the case of this PR), the compiler will enter into an unreachable code state, essentially ignoring most of the subsequent instructions. When handling the unreachable code state some instructions are still observed, in order to determine if reachability should be restored.

This change, particulary the handling of unreachable code, adds all the necessary building blocks to the compiler to emit other instructions that affect reachability (e.g unreachable, return).

I decided to bundle these instructions together to be able to test more complex scenarios with loop, but I'm happy to split this change into two (or more).

@saulecabrera saulecabrera requested review from a team as code owners June 19, 2023 10:49
@saulecabrera saulecabrera requested review from alexcrichton, jameysharp and cfallin and removed request for a team, alexcrichton and jameysharp June 19, 2023 10:49
@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure winch Winch issues or pull requests labels Jun 19, 2023
@github-actions
Copy link

Subscribe to Label Action

cc @fitzgen, @saulecabrera

This issue or pull request has been labeled: "fuzzing", "winch"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing
  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@cfallin
Copy link
Member

cfallin commented Jun 20, 2023

I decided to bundle these instructions together to be able to test more complex scenarios with loop, but I'm happy to split this change into two (or more).

That's totally fine; we'll have to review it anyway and IMHO when closely coupled it's better to see the pieces together. I'll try to get to this today!

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts but overall I like how this is turning out -- the abstractions around the ControlStackFrame are very clean!

winch/codegen/src/codegen/mod.rs Outdated Show resolved Hide resolved
winch/codegen/src/codegen/mod.rs Outdated Show resolved Hide resolved
winch/codegen/src/codegen/mod.rs Outdated Show resolved Hide resolved
winch/codegen/src/codegen/control.rs Outdated Show resolved Hide resolved
winch/codegen/src/codegen/mod.rs Show resolved Hide resolved
@saulecabrera
Copy link
Member Author

@cfallin I've addressed all of your comments, I think this is ready for another pass. Regarding the visitor vs match-on-op discussion above, I've updated the approach to rely only on the visitor approach, by extending the existing validate_then_visit macro as suggested by @alexcrichton.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Seems good to me but I'd defer to @cfallin still for other technical review bits

winch/codegen/src/codegen/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, thanks! A few comments below but feel free to merge when addressed.

winch/codegen/src/codegen/mod.rs Show resolved Hide resolved
winch/codegen/src/codegen/mod.rs Outdated Show resolved Hide resolved
winch/codegen/src/codegen/mod.rs Outdated Show resolved Hide resolved
This change adds support for the `loop`, `br` and `br_if` instructions
as well as unreachable code handling. Whenever an instruction that
affects reachability is emitted (`br` in the case of this PR), the
compiler will enter into an unreachable code state, essentially ignoring
most of the subsequent instructions. When handling the unreachable code
state some instructions are still observed, in order to determine if
reachability should be restored.

This change, particulary the handling of unreachable code, adds all the
necessary building blocks to the compiler to emit other instructions
that affect reachability (e.g `unreachable`, `return`).

Address review feedback

* Rename `branch_target` to `is_branch_target`
* Use the visitor pattern to handle unreachable code

Avoid string comparison and split unreachable handling functions
@saulecabrera
Copy link
Member Author

Seems that the Fuzz Targets step is having issues trying to fetch OCaml:

E: Failed to fetch http://azure.archive.ubuntu.com/ubuntu/pool/universe/o/ocaml/ocaml-compiler-libs_4.13.1-3ubuntu1_amd64.deb  Error reading from server. Remote end closed connection [IP: 52.154.174.208 80]
E: Failed to fetch http://azure.archive.ubuntu.com/ubuntu/pool/universe/o/ocaml/ocaml-interp_4.13.1-3ubuntu1_amd64.deb  Error reading from server. Remote end closed connection [IP: 52.154.174.208 80]
E: Failed to fetch http://azure.archive.ubuntu.com/ubuntu/pool/universe/o/ocaml/ocaml_4.13.1-3ubuntu1_amd64.deb  Error reading from server. Remote end closed connection [IP: 52.154.174.208 80]

@saulecabrera
Copy link
Member Author

Seems to be fixed!

@saulecabrera saulecabrera added this pull request to the merge queue Jun 21, 2023
Merged via the queue into bytecodealliance:main with commit 1bc4ff3 Jun 21, 2023
@saulecabrera saulecabrera deleted the winch-control-flow-loop branch June 21, 2023 11:02
saulecabrera added a commit to saulecabrera/wasmtime that referenced this pull request Jun 21, 2023
This change adds support for the `return` and `unreachable`
instructions. This change builds on top of the control flow building
blocks introduced in bytecodealliance#6603
github-merge-queue bot pushed a commit that referenced this pull request Jun 21, 2023
This change adds support for the `return` and `unreachable`
instructions. This change builds on top of the control flow building
blocks introduced in #6603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants