Add initial asm!() support for PowerPC
This includes GPRs and FPRs only
This commit is contained in:
parent
5c02926546
commit
b1bb5d662c
6 changed files with 356 additions and 1 deletions
|
@ -154,6 +154,7 @@ mod arm;
|
|||
mod hexagon;
|
||||
mod mips;
|
||||
mod nvptx;
|
||||
mod powerpc;
|
||||
mod riscv;
|
||||
mod spirv;
|
||||
mod wasm;
|
||||
|
@ -164,6 +165,7 @@ pub use arm::{ArmInlineAsmReg, ArmInlineAsmRegClass};
|
|||
pub use hexagon::{HexagonInlineAsmReg, HexagonInlineAsmRegClass};
|
||||
pub use mips::{MipsInlineAsmReg, MipsInlineAsmRegClass};
|
||||
pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass};
|
||||
pub use powerpc::{PowerPCInlineAsmReg, PowerPCInlineAsmRegClass};
|
||||
pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass};
|
||||
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
|
||||
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
|
||||
|
@ -181,6 +183,7 @@ pub enum InlineAsmArch {
|
|||
Hexagon,
|
||||
Mips,
|
||||
Mips64,
|
||||
PowerPC,
|
||||
SpirV,
|
||||
Wasm32,
|
||||
}
|
||||
|
@ -197,6 +200,7 @@ impl FromStr for InlineAsmArch {
|
|||
"riscv32" => Ok(Self::RiscV32),
|
||||
"riscv64" => Ok(Self::RiscV64),
|
||||
"nvptx64" => Ok(Self::Nvptx64),
|
||||
"powerpc" => Ok(Self::PowerPC),
|
||||
"hexagon" => Ok(Self::Hexagon),
|
||||
"mips" => Ok(Self::Mips),
|
||||
"mips64" => Ok(Self::Mips64),
|
||||
|
@ -225,6 +229,7 @@ pub enum InlineAsmReg {
|
|||
AArch64(AArch64InlineAsmReg),
|
||||
RiscV(RiscVInlineAsmReg),
|
||||
Nvptx(NvptxInlineAsmReg),
|
||||
PowerPC(PowerPCInlineAsmReg),
|
||||
Hexagon(HexagonInlineAsmReg),
|
||||
Mips(MipsInlineAsmReg),
|
||||
SpirV(SpirVInlineAsmReg),
|
||||
|
@ -240,6 +245,7 @@ impl InlineAsmReg {
|
|||
Self::Arm(r) => r.name(),
|
||||
Self::AArch64(r) => r.name(),
|
||||
Self::RiscV(r) => r.name(),
|
||||
Self::PowerPC(r) => r.name(),
|
||||
Self::Hexagon(r) => r.name(),
|
||||
Self::Mips(r) => r.name(),
|
||||
Self::Err => "<reg>",
|
||||
|
@ -252,6 +258,7 @@ impl InlineAsmReg {
|
|||
Self::Arm(r) => InlineAsmRegClass::Arm(r.reg_class()),
|
||||
Self::AArch64(r) => InlineAsmRegClass::AArch64(r.reg_class()),
|
||||
Self::RiscV(r) => InlineAsmRegClass::RiscV(r.reg_class()),
|
||||
Self::PowerPC(r) => InlineAsmRegClass::PowerPC(r.reg_class()),
|
||||
Self::Hexagon(r) => InlineAsmRegClass::Hexagon(r.reg_class()),
|
||||
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
|
||||
Self::Err => InlineAsmRegClass::Err,
|
||||
|
@ -283,6 +290,9 @@ impl InlineAsmReg {
|
|||
InlineAsmArch::Nvptx64 => {
|
||||
Self::Nvptx(NvptxInlineAsmReg::parse(arch, has_feature, target, &name)?)
|
||||
}
|
||||
InlineAsmArch::PowerPC => {
|
||||
Self::PowerPC(PowerPCInlineAsmReg::parse(arch, has_feature, target, &name)?)
|
||||
}
|
||||
InlineAsmArch::Hexagon => {
|
||||
Self::Hexagon(HexagonInlineAsmReg::parse(arch, has_feature, target, &name)?)
|
||||
}
|
||||
|
@ -311,6 +321,7 @@ impl InlineAsmReg {
|
|||
Self::Arm(r) => r.emit(out, arch, modifier),
|
||||
Self::AArch64(r) => r.emit(out, arch, modifier),
|
||||
Self::RiscV(r) => r.emit(out, arch, modifier),
|
||||
Self::PowerPC(r) => r.emit(out, arch, modifier),
|
||||
Self::Hexagon(r) => r.emit(out, arch, modifier),
|
||||
Self::Mips(r) => r.emit(out, arch, modifier),
|
||||
Self::Err => unreachable!("Use of InlineAsmReg::Err"),
|
||||
|
@ -323,6 +334,7 @@ impl InlineAsmReg {
|
|||
Self::Arm(r) => r.overlapping_regs(|r| cb(Self::Arm(r))),
|
||||
Self::AArch64(_) => cb(self),
|
||||
Self::RiscV(_) => cb(self),
|
||||
Self::PowerPC(_) => cb(self),
|
||||
Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))),
|
||||
Self::Mips(_) => cb(self),
|
||||
Self::Err => unreachable!("Use of InlineAsmReg::Err"),
|
||||
|
@ -348,6 +360,7 @@ pub enum InlineAsmRegClass {
|
|||
AArch64(AArch64InlineAsmRegClass),
|
||||
RiscV(RiscVInlineAsmRegClass),
|
||||
Nvptx(NvptxInlineAsmRegClass),
|
||||
PowerPC(PowerPCInlineAsmRegClass),
|
||||
Hexagon(HexagonInlineAsmRegClass),
|
||||
Mips(MipsInlineAsmRegClass),
|
||||
SpirV(SpirVInlineAsmRegClass),
|
||||
|
@ -364,6 +377,7 @@ impl InlineAsmRegClass {
|
|||
Self::AArch64(r) => r.name(),
|
||||
Self::RiscV(r) => r.name(),
|
||||
Self::Nvptx(r) => r.name(),
|
||||
Self::PowerPC(r) => r.name(),
|
||||
Self::Hexagon(r) => r.name(),
|
||||
Self::Mips(r) => r.name(),
|
||||
Self::SpirV(r) => r.name(),
|
||||
|
@ -382,6 +396,7 @@ impl InlineAsmRegClass {
|
|||
Self::AArch64(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::AArch64),
|
||||
Self::RiscV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::RiscV),
|
||||
Self::Nvptx(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Nvptx),
|
||||
Self::PowerPC(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::PowerPC),
|
||||
Self::Hexagon(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Hexagon),
|
||||
Self::Mips(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Mips),
|
||||
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
|
||||
|
@ -407,6 +422,7 @@ impl InlineAsmRegClass {
|
|||
Self::AArch64(r) => r.suggest_modifier(arch, ty),
|
||||
Self::RiscV(r) => r.suggest_modifier(arch, ty),
|
||||
Self::Nvptx(r) => r.suggest_modifier(arch, ty),
|
||||
Self::PowerPC(r) => r.suggest_modifier(arch, ty),
|
||||
Self::Hexagon(r) => r.suggest_modifier(arch, ty),
|
||||
Self::Mips(r) => r.suggest_modifier(arch, ty),
|
||||
Self::SpirV(r) => r.suggest_modifier(arch, ty),
|
||||
|
@ -428,6 +444,7 @@ impl InlineAsmRegClass {
|
|||
Self::AArch64(r) => r.default_modifier(arch),
|
||||
Self::RiscV(r) => r.default_modifier(arch),
|
||||
Self::Nvptx(r) => r.default_modifier(arch),
|
||||
Self::PowerPC(r) => r.default_modifier(arch),
|
||||
Self::Hexagon(r) => r.default_modifier(arch),
|
||||
Self::Mips(r) => r.default_modifier(arch),
|
||||
Self::SpirV(r) => r.default_modifier(arch),
|
||||
|
@ -448,6 +465,7 @@ impl InlineAsmRegClass {
|
|||
Self::AArch64(r) => r.supported_types(arch),
|
||||
Self::RiscV(r) => r.supported_types(arch),
|
||||
Self::Nvptx(r) => r.supported_types(arch),
|
||||
Self::PowerPC(r) => r.supported_types(arch),
|
||||
Self::Hexagon(r) => r.supported_types(arch),
|
||||
Self::Mips(r) => r.supported_types(arch),
|
||||
Self::SpirV(r) => r.supported_types(arch),
|
||||
|
@ -467,6 +485,7 @@ impl InlineAsmRegClass {
|
|||
Self::RiscV(RiscVInlineAsmRegClass::parse(arch, name)?)
|
||||
}
|
||||
InlineAsmArch::Nvptx64 => Self::Nvptx(NvptxInlineAsmRegClass::parse(arch, name)?),
|
||||
InlineAsmArch::PowerPC => Self::PowerPC(PowerPCInlineAsmRegClass::parse(arch, name)?),
|
||||
InlineAsmArch::Hexagon => Self::Hexagon(HexagonInlineAsmRegClass::parse(arch, name)?),
|
||||
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
|
||||
Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
|
||||
|
@ -485,6 +504,7 @@ impl InlineAsmRegClass {
|
|||
Self::AArch64(r) => r.valid_modifiers(arch),
|
||||
Self::RiscV(r) => r.valid_modifiers(arch),
|
||||
Self::Nvptx(r) => r.valid_modifiers(arch),
|
||||
Self::PowerPC(r) => r.valid_modifiers(arch),
|
||||
Self::Hexagon(r) => r.valid_modifiers(arch),
|
||||
Self::Mips(r) => r.valid_modifiers(arch),
|
||||
Self::SpirV(r) => r.valid_modifiers(arch),
|
||||
|
@ -633,6 +653,11 @@ pub fn allocatable_registers(
|
|||
nvptx::fill_reg_map(arch, has_feature, target, &mut map);
|
||||
map
|
||||
}
|
||||
InlineAsmArch::PowerPC => {
|
||||
let mut map = powerpc::regclass_map();
|
||||
powerpc::fill_reg_map(arch, has_feature, target, &mut map);
|
||||
map
|
||||
}
|
||||
InlineAsmArch::Hexagon => {
|
||||
let mut map = hexagon::regclass_map();
|
||||
hexagon::fill_reg_map(arch, has_feature, target, &mut map);
|
||||
|
|
146
compiler/rustc_target/src/asm/powerpc.rs
Normal file
146
compiler/rustc_target/src/asm/powerpc.rs
Normal file
|
@ -0,0 +1,146 @@
|
|||
use super::{InlineAsmArch, InlineAsmType};
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use std::fmt;
|
||||
|
||||
def_reg_class! {
|
||||
PowerPC PowerPCInlineAsmRegClass {
|
||||
reg,
|
||||
reg_nonzero,
|
||||
freg,
|
||||
}
|
||||
}
|
||||
|
||||
impl PowerPCInlineAsmRegClass {
|
||||
pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] {
|
||||
&[]
|
||||
}
|
||||
|
||||
pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option<Self> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn suggest_modifier(
|
||||
self,
|
||||
_arch: InlineAsmArch,
|
||||
_ty: InlineAsmType,
|
||||
) -> Option<(char, &'static str)> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn supported_types(
|
||||
self,
|
||||
_arch: InlineAsmArch,
|
||||
) -> &'static [(InlineAsmType, Option<&'static str>)] {
|
||||
match self {
|
||||
Self::reg | Self::reg_nonzero => types! { _: I8, I16, I32; },
|
||||
Self::freg => types! { _: F32, F64; },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def_regs! {
|
||||
PowerPC PowerPCInlineAsmReg PowerPCInlineAsmRegClass {
|
||||
r0: reg = ["r0", "0"],
|
||||
r3: reg, reg_nonzero = ["r3", "3"],
|
||||
r4: reg, reg_nonzero = ["r4", "4"],
|
||||
r5: reg, reg_nonzero = ["r5", "5"],
|
||||
r6: reg, reg_nonzero = ["r6", "6"],
|
||||
r7: reg, reg_nonzero = ["r7", "7"],
|
||||
r8: reg, reg_nonzero = ["r8", "8"],
|
||||
r9: reg, reg_nonzero = ["r9", "9"],
|
||||
r10: reg, reg_nonzero = ["r10", "10"],
|
||||
r11: reg, reg_nonzero = ["r11", "11"],
|
||||
r12: reg, reg_nonzero = ["r12", "12"],
|
||||
r14: reg, reg_nonzero = ["r14", "14"],
|
||||
r15: reg, reg_nonzero = ["r15", "15"],
|
||||
r16: reg, reg_nonzero = ["r16", "16"],
|
||||
r17: reg, reg_nonzero = ["r17", "17"],
|
||||
r18: reg, reg_nonzero = ["r18", "18"],
|
||||
r19: reg, reg_nonzero = ["r19", "19"],
|
||||
r20: reg, reg_nonzero = ["r20", "20"],
|
||||
r21: reg, reg_nonzero = ["r21", "21"],
|
||||
r22: reg, reg_nonzero = ["r22", "22"],
|
||||
r23: reg, reg_nonzero = ["r23", "23"],
|
||||
r24: reg, reg_nonzero = ["r24", "24"],
|
||||
r25: reg, reg_nonzero = ["r25", "25"],
|
||||
r26: reg, reg_nonzero = ["r26", "26"],
|
||||
r27: reg, reg_nonzero = ["r27", "27"],
|
||||
r28: reg, reg_nonzero = ["r28", "28"],
|
||||
f0: freg = ["f0", "fr0"],
|
||||
f1: freg = ["f1", "fr1"],
|
||||
f2: freg = ["f2", "fr2"],
|
||||
f3: freg = ["f3", "fr3"],
|
||||
f4: freg = ["f4", "fr4"],
|
||||
f5: freg = ["f5", "fr5"],
|
||||
f6: freg = ["f6", "fr6"],
|
||||
f7: freg = ["f7", "fr7"],
|
||||
f8: freg = ["f8", "fr8"],
|
||||
f9: freg = ["f9", "fr9"],
|
||||
f10: freg = ["f10", "fr10"],
|
||||
f11: freg = ["f11", "fr11"],
|
||||
f12: freg = ["f12", "fr12"],
|
||||
f13: freg = ["f13", "fr13"],
|
||||
f14: freg = ["f14", "fr14"],
|
||||
f15: freg = ["f15", "fr15"],
|
||||
f16: freg = ["f16", "fr16"],
|
||||
f17: freg = ["f17", "fr17"],
|
||||
f18: freg = ["f18", "fr18"],
|
||||
f19: freg = ["f19", "fr19"],
|
||||
f20: freg = ["f20", "fr20"],
|
||||
f21: freg = ["f21", "fr21"],
|
||||
f22: freg = ["f22", "fr22"],
|
||||
f23: freg = ["f23", "fr23"],
|
||||
f24: freg = ["f24", "fr24"],
|
||||
f25: freg = ["f25", "fr25"],
|
||||
f26: freg = ["f26", "fr26"],
|
||||
f27: freg = ["f27", "fr27"],
|
||||
f28: freg = ["f28", "fr28"],
|
||||
f29: freg = ["f29", "fr29"],
|
||||
f30: freg = ["f30", "fr30"],
|
||||
f31: freg = ["f31", "fr31"],
|
||||
#error = ["r1", "1", "sp"] =>
|
||||
"the stack pointer cannot be used as an operand for inline asm",
|
||||
#error = ["r2", "2"] =>
|
||||
"r2 is a system reserved register and cannot be used as an operand for inline asm",
|
||||
#error = ["r13", "13"] =>
|
||||
"r13 is a system reserved register and cannot be used as an operand for inline asm",
|
||||
#error = ["r29", "29"] =>
|
||||
"r29 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["r30", "30"] =>
|
||||
"r30 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["r31", "31", "fp"] =>
|
||||
"the frame pointer cannot be used as an operand for inline asm",
|
||||
#error = ["lr"] =>
|
||||
"the link register cannot be used as an operand for inline asm",
|
||||
#error = ["ctr"] =>
|
||||
"the counter register cannot be used as an operand for inline asm",
|
||||
#error = ["vrsave"] =>
|
||||
"the vrsave register cannot be used as an operand for inline asm",
|
||||
}
|
||||
}
|
||||
|
||||
impl PowerPCInlineAsmReg {
|
||||
pub fn emit(
|
||||
self,
|
||||
out: &mut dyn fmt::Write,
|
||||
_arch: InlineAsmArch,
|
||||
_modifier: Option<char>,
|
||||
) -> fmt::Result {
|
||||
// Strip off the leading prefix.
|
||||
if self as u32 <= Self::r28 as u32 {
|
||||
let index = self as u32 - Self::r28 as u32;
|
||||
write!(out, "{}", index)
|
||||
} else if self as u32 >= Self::f0 as u32 && self as u32 <= Self::f31 as u32 {
|
||||
let index = self as u32 - Self::f31 as u32;
|
||||
write!(out, "{}", index)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn overlapping_regs(self, mut _cb: impl FnMut(PowerPCInlineAsmReg)) {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue