Skip to content

Commit d351210

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent b421de0 commit d351210

File tree

6 files changed

+525
-0
lines changed

6 files changed

+525
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
255255
}
256256
InlineAsmArch::SpirV => {}
257257
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
258+
InlineAsmArch::Xtensa => {}
258259
InlineAsmArch::Bpf => {}
259260
InlineAsmArch::Msp430 => {
260261
constraints.push("~{sr}".to_string());
@@ -682,6 +683,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
682683
| X86InlineAsmRegClass::tmm_reg,
683684
) => unreachable!("clobber-only"),
684685
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
686+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
687+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
688+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
685689
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
686690
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
687691
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -743,6 +747,7 @@ fn modifier_to_llvm(
743747
InlineAsmRegClass::Mips(_) => None,
744748
InlineAsmRegClass::Nvptx(_) => None,
745749
InlineAsmRegClass::PowerPC(_) => None,
750+
InlineAsmRegClass::Xtensa(_) => None,
746751
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
747752
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
748753
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -860,6 +865,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
860865
unreachable!("clobber-only")
861866
}
862867
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
868+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
869+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
870+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
863871
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
864872
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
865873
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),

compiler/rustc_span/src/symbol.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ symbols! {
427427
async_fn_in_trait,
428428
async_fn_track_caller,
429429
async_iterator,
430+
atomctl,
430431
atomic,
431432
atomic_mod,
432433
atomics,
@@ -467,6 +468,7 @@ symbols! {
467468
braced_empty_structs,
468469
branch,
469470
breakpoint,
471+
breg,
470472
bridge,
471473
bswap,
472474
builtin_syntax,
@@ -583,6 +585,7 @@ symbols! {
583585
constant,
584586
constructor,
585587
convert_identity,
588+
coprocessor,
586589
copy,
587590
copy_closures,
588591
copy_nonoverlapping,
@@ -661,6 +664,7 @@ symbols! {
661664
derive_default_enum,
662665
destruct,
663666
destructuring_assignment,
667+
dfpaccel,
664668
diagnostic,
665669
diagnostic_namespace,
666670
direct,
@@ -721,6 +725,7 @@ symbols! {
721725
ermsb_target_feature,
722726
exact_div,
723727
except,
728+
exception,
724729
exchange_malloc,
725730
exclusive_range_pattern,
726731
exhaustive_integer_patterns,
@@ -738,6 +743,7 @@ symbols! {
738743
expr,
739744
extended_key_value_attributes,
740745
extended_varargs_abi_support,
746+
extendedl32r,
741747
extern_absolute_paths,
742748
extern_crate_item_prelude,
743749
extern_crate_self,
@@ -797,6 +803,7 @@ symbols! {
797803
format_macro,
798804
format_placeholder,
799805
format_unsafe_arg,
806+
fp,
800807
freeze,
801808
freg,
802809
frem_fast,
@@ -840,6 +847,7 @@ symbols! {
840847
hash,
841848
hexagon_target_feature,
842849
hidden,
850+
highpriinterrupts,
843851
homogeneous_aggregate,
844852
host,
845853
html_favicon_url,
@@ -893,6 +901,8 @@ symbols! {
893901
instruction_set,
894902
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
895903
integral,
904+
intel,
905+
interrupt,
896906
into_future,
897907
into_iter,
898908
intra_doc_pointers,
@@ -965,6 +975,7 @@ symbols! {
965975
loongarch_target_feature,
966976
loop_break_value,
967977
lt,
978+
mac16,
968979
macro_at_most_once_rep,
969980
macro_attributes_in_derive_output,
970981
macro_escape,
@@ -1005,6 +1016,7 @@ symbols! {
10051016
mem_variant_count,
10061017
mem_zeroed,
10071018
member_constraints,
1019+
memctl,
10081020
memory,
10091021
memtag,
10101022
message,
@@ -1051,6 +1063,8 @@ symbols! {
10511063
mir_unwind_unreachable,
10521064
mir_variant,
10531065
miri,
1066+
misc,
1067+
miscsr,
10541068
mmx_reg,
10551069
modifiers,
10561070
module,
@@ -1225,6 +1239,8 @@ symbols! {
12251239
prelude,
12261240
prelude_import,
12271241
preserves_flags,
1242+
prid,
1243+
primitive,
12281244
print_macro,
12291245
println_macro,
12301246
proc_dash_macro: "proc-macro",
@@ -1455,8 +1471,10 @@ symbols! {
14551471
rustdoc_missing_doc_code_examples,
14561472
rustfmt,
14571473
rvalue_static_promotion,
1474+
rvector,
14581475
rwpi,
14591476
s,
1477+
s32c1i,
14601478
safety,
14611479
sanitize,
14621480
sanitizer_cfi_generalize_pointers,
@@ -1644,8 +1662,10 @@ symbols! {
16441662
thread,
16451663
thread_local,
16461664
thread_local_macro,
1665+
threadptr,
16471666
thumb2,
16481667
thumb_mode: "thumb-mode",
1668+
timerint,
16491669
tmm_reg,
16501670
to_owned_method,
16511671
to_string,
@@ -1784,6 +1804,8 @@ symbols! {
17841804
wasm_import_module,
17851805
wasm_target_feature,
17861806
while_let,
1807+
width,
1808+
windowed,
17871809
windows,
17881810
windows_subsystem,
17891811
with_negative_coherence,
@@ -1801,7 +1823,9 @@ symbols! {
18011823
writeln_macro,
18021824
x87_reg,
18031825
xer,
1826+
xloop,
18041827
xmm_reg,
1828+
xtensa_target_feature,
18051829
yeet_desugar_details,
18061830
yeet_expr,
18071831
yield_expr,

compiler/rustc_target/src/asm/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ mod s390x;
180180
mod spirv;
181181
mod wasm;
182182
mod x86;
183+
mod xtensa;
183184

184185
pub use aarch64::{AArch64InlineAsmReg, AArch64InlineAsmRegClass};
185186
pub use arm::{ArmInlineAsmReg, ArmInlineAsmRegClass};
@@ -197,6 +198,7 @@ pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass};
197198
pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass};
198199
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
199200
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
201+
pub use xtensa::{XtensaInlineAsmReg, XtensaInlineAsmRegClass};
200202
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
201203

202204
#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)]
@@ -218,6 +220,7 @@ pub enum InlineAsmArch {
218220
SpirV,
219221
Wasm32,
220222
Wasm64,
223+
Xtensa,
221224
Bpf,
222225
Avr,
223226
Msp430,
@@ -247,6 +250,7 @@ impl FromStr for InlineAsmArch {
247250
"spirv" => Ok(Self::SpirV),
248251
"wasm32" => Ok(Self::Wasm32),
249252
"wasm64" => Ok(Self::Wasm64),
253+
"xtensa" => Ok(Self::Xtensa),
250254
"bpf" => Ok(Self::Bpf),
251255
"avr" => Ok(Self::Avr),
252256
"msp430" => Ok(Self::Msp430),
@@ -272,6 +276,7 @@ pub enum InlineAsmReg {
272276
S390x(S390xInlineAsmReg),
273277
SpirV(SpirVInlineAsmReg),
274278
Wasm(WasmInlineAsmReg),
279+
Xtensa(XtensaInlineAsmReg),
275280
Bpf(BpfInlineAsmReg),
276281
Avr(AvrInlineAsmReg),
277282
Msp430(Msp430InlineAsmReg),
@@ -293,6 +298,7 @@ impl InlineAsmReg {
293298
Self::LoongArch(r) => r.name(),
294299
Self::Mips(r) => r.name(),
295300
Self::S390x(r) => r.name(),
301+
Self::Xtensa(r) => r.name(),
296302
Self::Bpf(r) => r.name(),
297303
Self::Avr(r) => r.name(),
298304
Self::Msp430(r) => r.name(),
@@ -313,6 +319,7 @@ impl InlineAsmReg {
313319
Self::LoongArch(r) => InlineAsmRegClass::LoongArch(r.reg_class()),
314320
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
315321
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
322+
Self::Xtensa(r) => InlineAsmRegClass::Xtensa(r.reg_class()),
316323
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
317324
Self::Avr(r) => InlineAsmRegClass::Avr(r.reg_class()),
318325
Self::Msp430(r) => InlineAsmRegClass::Msp430(r.reg_class()),
@@ -342,6 +349,9 @@ impl InlineAsmReg {
342349
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
343350
Self::Mips(MipsInlineAsmReg::parse(name)?)
344351
}
352+
InlineAsmArch::Xtensa => {
353+
Self::Xtensa(XtensaInlineAsmReg::parse(name)?)
354+
}
345355
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
346356
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmReg::parse(name)?),
347357
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
@@ -377,6 +387,7 @@ impl InlineAsmReg {
377387
Self::S390x(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
378388
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
379389
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
390+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
380391
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
381392
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
382393
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -402,6 +413,7 @@ impl InlineAsmReg {
402413
Self::LoongArch(r) => r.emit(out, arch, modifier),
403414
Self::Mips(r) => r.emit(out, arch, modifier),
404415
Self::S390x(r) => r.emit(out, arch, modifier),
416+
Self::Xtensa(r) => r.emit(out, arch, modifier),
405417
Self::Bpf(r) => r.emit(out, arch, modifier),
406418
Self::Avr(r) => r.emit(out, arch, modifier),
407419
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -422,6 +434,7 @@ impl InlineAsmReg {
422434
Self::LoongArch(_) => cb(self),
423435
Self::Mips(_) => cb(self),
424436
Self::S390x(_) => cb(self),
437+
Self::Xtensa(_) => cb(self),
425438
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
426439
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
427440
Self::Msp430(_) => cb(self),
@@ -447,6 +460,7 @@ pub enum InlineAsmRegClass {
447460
S390x(S390xInlineAsmRegClass),
448461
SpirV(SpirVInlineAsmRegClass),
449462
Wasm(WasmInlineAsmRegClass),
463+
Xtensa(XtensaInlineAsmRegClass),
450464
Bpf(BpfInlineAsmRegClass),
451465
Avr(AvrInlineAsmRegClass),
452466
Msp430(Msp430InlineAsmRegClass),
@@ -471,6 +485,7 @@ impl InlineAsmRegClass {
471485
Self::S390x(r) => r.name(),
472486
Self::SpirV(r) => r.name(),
473487
Self::Wasm(r) => r.name(),
488+
Self::Xtensa(r) => r.name(),
474489
Self::Bpf(r) => r.name(),
475490
Self::Avr(r) => r.name(),
476491
Self::Msp430(r) => r.name(),
@@ -497,6 +512,7 @@ impl InlineAsmRegClass {
497512
Self::S390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::S390x),
498513
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
499514
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
515+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
500516
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
501517
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
502518
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -530,6 +546,7 @@ impl InlineAsmRegClass {
530546
Self::S390x(r) => r.suggest_modifier(arch, ty),
531547
Self::SpirV(r) => r.suggest_modifier(arch, ty),
532548
Self::Wasm(r) => r.suggest_modifier(arch, ty),
549+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
533550
Self::Bpf(r) => r.suggest_modifier(arch, ty),
534551
Self::Avr(r) => r.suggest_modifier(arch, ty),
535552
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -559,6 +576,7 @@ impl InlineAsmRegClass {
559576
Self::S390x(r) => r.default_modifier(arch),
560577
Self::SpirV(r) => r.default_modifier(arch),
561578
Self::Wasm(r) => r.default_modifier(arch),
579+
Self::Xtensa(r) => r.default_modifier(arch),
562580
Self::Bpf(r) => r.default_modifier(arch),
563581
Self::Avr(r) => r.default_modifier(arch),
564582
Self::Msp430(r) => r.default_modifier(arch),
@@ -587,6 +605,7 @@ impl InlineAsmRegClass {
587605
Self::S390x(r) => r.supported_types(arch),
588606
Self::SpirV(r) => r.supported_types(arch),
589607
Self::Wasm(r) => r.supported_types(arch),
608+
Self::Xtensa(r) => r.supported_types(arch),
590609
Self::Bpf(r) => r.supported_types(arch),
591610
Self::Avr(r) => r.supported_types(arch),
592611
Self::Msp430(r) => r.supported_types(arch),
@@ -622,6 +641,7 @@ impl InlineAsmRegClass {
622641
}
623642
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
624643
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
644+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
625645
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
626646
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
627647
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -644,6 +664,7 @@ impl InlineAsmRegClass {
644664
Self::S390x(r) => r.valid_modifiers(arch),
645665
Self::SpirV(r) => r.valid_modifiers(arch),
646666
Self::Wasm(r) => r.valid_modifiers(arch),
667+
Self::Xtensa(r) => r.valid_modifiers(arch),
647668
Self::Bpf(r) => r.valid_modifiers(arch),
648669
Self::Avr(r) => r.valid_modifiers(arch),
649670
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -688,6 +709,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
688709
/// Set of types which can be used with a particular register class.
689710
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
690711
pub enum InlineAsmType {
712+
I1,
691713
I8,
692714
I16,
693715
I32,
@@ -711,6 +733,7 @@ impl InlineAsmType {
711733

712734
pub fn size(self) -> Size {
713735
Size::from_bytes(match self {
736+
Self::I1 => return Size::from_bits(1),
714737
Self::I8 => 1,
715738
Self::I16 => 2,
716739
Self::I32 => 4,
@@ -732,6 +755,7 @@ impl InlineAsmType {
732755
impl fmt::Display for InlineAsmType {
733756
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
734757
match *self {
758+
Self::I1 => f.write_str("i1"),
735759
Self::I8 => f.write_str("i8"),
736760
Self::I16 => f.write_str("i16"),
737761
Self::I32 => f.write_str("i32"),
@@ -825,6 +849,11 @@ pub fn allocatable_registers(
825849
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
826850
map
827851
}
852+
InlineAsmArch::Xtensa => {
853+
let mut map = xtensa::regclass_map();
854+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
855+
map
856+
}
828857
InlineAsmArch::Bpf => {
829858
let mut map = bpf::regclass_map();
830859
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)