Skip to content

Commit

Permalink
Disallow z0-z15 in Arm64EC inline assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 9, 2024
1 parent 955d8c6 commit d380cfd
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 151 deletions.
32 changes: 22 additions & 10 deletions compiler/rustc_codegen_gcc/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,14 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
}
// They can be retrieved from https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
InlineAsmRegOrRegClass::RegClass(reg) => match reg {
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => "r",
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg) => "w",
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => "x",
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::reg) => "r",
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::vreg) => "w",
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::vreg_low16) => "x",
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::Arm(ArmInlineAsmRegClass::reg) => "r",
Expand Down Expand Up @@ -698,12 +702,16 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
/// the type is, as long as it is valid for the constraint code.
fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegClass) -> Type<'gcc> {
match reg {
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg)
| InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => {
| InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::vreg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::vreg_low16) => {
cx.type_vector(cx.type_i64(), 2)
}
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::Arm(ArmInlineAsmRegClass::reg) => cx.type_i32(),
Expand Down Expand Up @@ -863,12 +871,16 @@ fn modifier_to_gcc(
// The modifiers can be retrieved from
// https://gcc.gnu.org/onlinedocs/gcc/Modifiers.html#Modifiers
match reg {
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => modifier,
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::reg) => modifier,
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg)
| InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => {
| InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::vreg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::vreg_low16) => {
if modifier == Some('v') { None } else { modifier }
}
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg)
| InlineAsmRegClass::Arm64EC(AArch64InlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::Arm(ArmInlineAsmRegClass::reg) => None,
Expand Down
Loading

0 comments on commit d380cfd

Please sign in to comment.