-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
asm! support for the Xtensa architecture #147302
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
base: main
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also missing an update to the unstable book entry for asm_experimental_arch.
| def_reg_class! { | ||
| Xtensa XtensaInlineAsmRegClass { | ||
| reg, | ||
| freg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM doesn't seem to support this. XtensaTargetLowering::getRegForInlineAsmConstraint only handles r constraints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will just not yet. I'll back out the floating point bits for now, unless you think it's okay to land ready for the LLVM updates.
|
☔ The latest upstream changes (presumably #147645) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Taiki Endo <[email protected]> Co-authored-by: Kerry Jones <[email protected]>
|
I've made most of the updates here (sorry for the delay!). It turns out we'll need a patch that landed just after rust branched LLVM: https://github.com/rust-lang/llvm-project/tree/rustc/21.1-2025-08-01/llvm/lib/Target/Xtensa , otherwise the asm tests fail :(. The good news is that we've since landed FP support in LLVM upstream too, so maybe the next time rust branches LLVM 21 (I guess 21.2?) we can rerun CI on this PR and it will be green. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| // The Xtensa arch doesn't require, nor use, a dedicated frame pointer register | ||
| // therefore if it is not force enabled, we can assume it won't be generated. | ||
| // If frame pointers are enabled, we cannot use the register as a general purpose one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that's not exactly true. LLVM will force the use of a frame pointer if the stack frame has variable-sized objects. While this currently isn't possible in Rust, it is possible when doing cross-language LTO with C code. Therefore we should always reject the use of the frame pointer in asm.
| a4: reg = ["a4"], | ||
| a5: reg = ["a5"], | ||
| a6: reg = ["a6"], | ||
| a7: reg = ["a7"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the LLVM code, it seems use a7 instead of a15 as the frame pointer when the windowed ABI is used.
| a13: reg = ["a13"], | ||
| a14: reg = ["a14"], | ||
| a15: reg = ["a15"] % is_frame_pointer, | ||
| sar: reg = ["sar"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be part of the reg class since it doesn't usually make sense for asm to select this regiser for the reg constraint. It should probably be in its own clobber-only register class.
This implements the asm! support for Xtensa. We've been using this code for a few years in our fork and it's been working well. I finally found some time to clean it up a bit and start the upstreaming process. This should be one of the final PRs for Xtensa support on the Rust side (minus bug fixes of course). After this, we're mostly just waiting on the LLVM upstreaming which is going well. This PR doesn't cover all possible asm options for Xtensa, but the base ISA plus a few extras that are used in Espressif chips.
r? Amanieu