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: Implement aarch64 call, trapz, address_at_vmctx #9751

Merged
merged 14 commits into from
Dec 9, 2024

Conversation

MarinPostma
Copy link
Contributor

Implement the following MASM instruction for the aarch64 platform:

  • call
  • address_at_vmctx
  • trapz

I initially planned to only implement call, but implementing the tests uncovered the necessity to implement the other two as prerequisite for indirect calls.

Right now the calling convention is hardcoded to SystemV, but maybe we also want to support AppleAarch64?

#8321

@MarinPostma MarinPostma requested review from a team as code owners December 6, 2024 15:25
@MarinPostma MarinPostma requested review from abrown and fitzgen and removed request for a team December 6, 2024 15:25
@github-actions github-actions bot added the winch Winch issues or pull requests label Dec 6, 2024
@saulecabrera
Copy link
Member

I can help taking a look at this one.

@saulecabrera saulecabrera self-requested a review December 6, 2024 16:16
Copy link

github-actions bot commented Dec 6, 2024

Subscribe to Label Action

cc @saulecabrera

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

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

  • saulecabrera: winch

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

Learn more.

saulecabrera added a commit to saulecabrera/wasmtime that referenced this pull request Dec 6, 2024
This commit aims to improve the consistency of call emission in Winch.

Prior to this commit, the calling convention at Winch's assembler layer
was hardcoded. Even though the calling convention invariants are
correctly handled early on in the code generation process and this has
no effect on the generated code, it could lead to subtle bugs if
Cranelift's emission infrastructure changes. It could also be confusing
when trying to implement call instrutions for other backends.

This change is motivated by some of the questions in bytecodealliance#9751
Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

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

Generally looks great, thanks. Left some inline nitpicks.

@@ -724,6 +723,14 @@ impl Assembler {
});
}

/// Trap if rn is 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Trap if rn is 0
/// Trap if `rn` is zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in f1a56f1

Comment on lines 911 to 944

pub fn call_with_name(&mut self, name: UserExternalNameRef) {
self.emit(Inst::Call {
info: Box::new(cranelift_codegen::CallInfo::empty(
ExternalName::user(name),
CallConv::SystemV,
)),
})
}

pub fn call_with_reg(&mut self, callee: Reg) {
self.emit(Inst::CallInd {
info: Box::new(cranelift_codegen::CallInfo::empty(
callee.into(),
CallConv::SystemV,
)),
})
}

pub fn call_with_lib(&mut self, lib: LibCall, dst: Reg) {
let name = ExternalName::LibCall(lib);
self.emit(Inst::LoadExtName {
rd: writable!(dst.into()),
name: name.into(),
offset: 0,
});
self.call_with_reg(dst)
}
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding some comments to these methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in f1a56f1

self.emit(Inst::CallInd {
info: Box::new(cranelift_codegen::CallInfo::empty(
callee.into(),
CallConv::SystemV,
Copy link
Member

Choose a reason for hiding this comment

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

Right now the calling convention is hardcoded to SystemV, but maybe we also want to support AppleAarch64?

I see why this might be confusing. Even though the CallConv is hard coded here, there are two things to note:

  • All the infrastructure to handle the calling convention differences, is handled very early on in the compilation process in Winch (and in Cranelift as well) e.g., when constructing the signature for the callee, at that point, you'll note that Winch correctly handles the default and apple-aarch64 calling conventions.
  • Winch relies on Cranelift's binary emission infrastructure, and in this concrete case, as you can note, you're constructing a CallInfo::empty(), which signals that none of the other Cranelift-specific invariants must be taken into account when emitting calls (some of them depend on the calling convention that is passed here).

I've opened #9757 to refactor call emission a bit with the hope of making this part more consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That refactor makes a lot of sense to me 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in f4a6cf7

github-merge-queue bot pushed a commit that referenced this pull request Dec 6, 2024
* winch: Track the callee calling convention

This commit aims to improve the consistency of call emission in Winch.

Prior to this commit, the calling convention at Winch's assembler layer
was hardcoded. Even though the calling convention invariants are
correctly handled early on in the code generation process and this has
no effect on the generated code, it could lead to subtle bugs if
Cranelift's emission infrastructure changes. It could also be confusing
when trying to implement call instrutions for other backends.

This change is motivated by some of the questions in #9751

* Clippy fixes
@MarinPostma MarinPostma force-pushed the aarch64-call branch 2 times, most recently from 8d4f591 to af504b5 Compare December 6, 2024 20:31
@saulecabrera
Copy link
Member

There are some failures in CI -- I'm trying to figure out if they are related to your changes or not.

@@ -0,0 +1,40 @@
;;! target = "aarch64"
;;! test = "compile"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure if this is the source of the failure, but here you need to specify

Suggested change
;;! test = "compile"
;;! test = "winch"

Else this will use Cranelift

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some submodule update sneaked into one of my commits. That's what's messing with the CI, I'll fix that tommorow

@MarinPostma
Copy link
Contributor Author

Alright, I updated the submodule, ci looks good now

Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

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

Thanks!

@saulecabrera saulecabrera added this pull request to the merge queue Dec 9, 2024
Merged via the queue into bytecodealliance:main with commit 9495060 Dec 9, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants