Skip to content

Commit 1e1ed2e

Browse files
MabezDevtaiki-eKerryRJ
committed
asm! support for the Xtensa architecture
Co-authored-by: Taiki Endo <te316e89@gmail.com> Co-authored-by: Kerry Jones <kerry@iodrive.co.za>
1 parent c880acd commit 1e1ed2e

File tree

8 files changed

+356
-2
lines changed

8 files changed

+356
-2
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
732732
| X86InlineAsmRegClass::mmx_reg
733733
| X86InlineAsmRegClass::tmm_reg,
734734
) => unreachable!("clobber-only"),
735+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
736+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
735737
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
736738
bug!("GCC backend does not support SPIR-V")
737739
}
@@ -842,6 +844,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
842844
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
843845
bug!("GCC backend does not support SPIR-V")
844846
}
847+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
848+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
845849
InlineAsmRegClass::Err => unreachable!(),
846850
}
847851
}
@@ -1033,6 +1037,7 @@ fn modifier_to_gcc(
10331037
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
10341038
bug!("LLVM backend does not support SPIR-V")
10351039
}
1040+
InlineAsmRegClass::Xtensa(_) => None,
10361041
InlineAsmRegClass::Err => unreachable!(),
10371042
}
10381043
}

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
278278
}
279279
InlineAsmArch::SpirV => {}
280280
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
281+
InlineAsmArch::Xtensa => {}
281282
InlineAsmArch::Bpf => {}
282283
InlineAsmArch::Msp430 => {
283284
constraints.push("~{sr}".to_string());
@@ -682,6 +683,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
682683
| X86InlineAsmRegClass::kreg0
683684
| X86InlineAsmRegClass::tmm_reg,
684685
) => unreachable!("clobber-only"),
686+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
687+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
685688
Wasm(WasmInlineAsmRegClass::local) => "r",
686689
Bpf(BpfInlineAsmRegClass::reg) => "r",
687690
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -787,6 +790,7 @@ fn modifier_to_llvm(
787790
| X86InlineAsmRegClass::kreg0
788791
| X86InlineAsmRegClass::tmm_reg,
789792
) => unreachable!("clobber-only"),
793+
Xtensa(_) => None,
790794
Wasm(WasmInlineAsmRegClass::local) => None,
791795
Bpf(_) => None,
792796
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -862,6 +866,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
862866
| X86InlineAsmRegClass::kreg0
863867
| X86InlineAsmRegClass::tmm_reg,
864868
) => unreachable!("clobber-only"),
869+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
870+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
865871
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
866872
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
867873
Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),

compiler/rustc_span/src/symbol.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ symbols! {
525525
async_iterator,
526526
async_iterator_poll_next,
527527
async_trait_bounds,
528+
atomctl,
528529
atomic,
529530
atomic_and,
530531
atomic_cxchg,
@@ -768,6 +769,7 @@ symbols! {
768769
contracts_requires,
769770
convert,
770771
convert_identity,
772+
coprocessor,
771773
copy,
772774
copy_closures,
773775
copy_nonoverlapping,
@@ -954,6 +956,7 @@ symbols! {
954956
ermsb_target_feature,
955957
exact_div,
956958
except,
959+
exception,
957960
exception_handling: "exception-handling",
958961
exchange_malloc,
959962
exclusive_range_pattern,
@@ -980,6 +983,7 @@ symbols! {
980983
expr_fragment_specifier_2024,
981984
extended_key_value_attributes,
982985
extended_varargs_abi_support,
986+
extendedl32r,
983987
extern_absolute_paths,
984988
extern_crate_item_prelude,
985989
extern_crate_self,
@@ -1097,6 +1101,9 @@ symbols! {
10971101
format_argument,
10981102
format_arguments,
10991103
format_macro,
1104+
format_placeholder,
1105+
format_unsafe_arg,
1106+
fp,
11001107
framework,
11011108
freeze,
11021109
freeze_impls,
@@ -1170,6 +1177,7 @@ symbols! {
11701177
hexagon_target_feature,
11711178
hidden,
11721179
hide,
1180+
highpriinterrupts,
11731181
hint,
11741182
homogeneous_aggregate,
11751183
host,
@@ -1256,6 +1264,7 @@ symbols! {
12561264
integral,
12571265
internal,
12581266
internal_features,
1267+
interrupt,
12591268
into_async_iter_into_iter,
12601269
into_future,
12611270
into_iter,
@@ -1362,6 +1371,7 @@ symbols! {
13621371
lt,
13631372
m68k,
13641373
m68k_target_feature,
1374+
mac16,
13651375
macro_at_most_once_rep,
13661376
macro_attr,
13671377
macro_attributes_in_derive_output,
@@ -1415,6 +1425,7 @@ symbols! {
14151425
mem_variant_count,
14161426
mem_zeroed,
14171427
member_constraints,
1428+
memctl,
14181429
memory,
14191430
memtag,
14201431
message,
@@ -1477,6 +1488,8 @@ symbols! {
14771488
mir_unwind_unreachable,
14781489
mir_variant,
14791490
miri,
1491+
misc,
1492+
miscsr,
14801493
mmx_reg,
14811494
modifiers,
14821495
module,
@@ -1731,6 +1744,8 @@ symbols! {
17311744
prelude_import,
17321745
preserves_flags,
17331746
prfchw_target_feature,
1747+
prid,
1748+
primitive,
17341749
print_macro,
17351750
println_macro,
17361751
proc_dash_macro: "proc-macro",
@@ -2001,8 +2016,10 @@ symbols! {
20012016
rustdoc_missing_doc_code_examples,
20022017
rustfmt,
20032018
rvalue_static_promotion,
2019+
rvector,
20042020
rwpi,
20052021
s,
2022+
s32c1i,
20062023
s390x,
20072024
s390x_target_feature,
20082025
s390x_target_feature_vector,
@@ -2245,9 +2262,12 @@ symbols! {
22452262
thread,
22462263
thread_local,
22472264
thread_local_macro,
2265+
threadptr,
22482266
three_way_compare,
22492267
thumb2,
22502268
thumb_mode: "thumb-mode",
2269+
time,
2270+
timerint,
22512271
tmm_reg,
22522272
to_owned_method,
22532273
to_string,
@@ -2467,6 +2487,7 @@ symbols! {
24672487
while_let,
24682488
whole_dash_archive: "whole-archive",
24692489
width,
2490+
windowed,
24702491
windows,
24712492
windows_subsystem,
24722493
with_negative_coherence,
@@ -2490,9 +2511,11 @@ symbols! {
24902511
x87_reg,
24912512
x87_target_feature,
24922513
xer,
2514+
xloop,
24932515
xmm_reg,
24942516
xop_target_feature,
24952517
xtensa,
2518+
xtensa_target_feature,
24962519
yeet_desugar_details,
24972520
yeet_expr,
24982521
yes,

compiler/rustc_target/src/asm/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ mod sparc;
194194
mod spirv;
195195
mod wasm;
196196
mod x86;
197+
mod xtensa;
197198

198199
pub use aarch64::{AArch64InlineAsmReg, AArch64InlineAsmRegClass};
199200
pub use arm::{ArmInlineAsmReg, ArmInlineAsmRegClass};
@@ -213,6 +214,7 @@ pub use sparc::{SparcInlineAsmReg, SparcInlineAsmRegClass};
213214
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
214215
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
215216
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
217+
pub use xtensa::{XtensaInlineAsmReg, XtensaInlineAsmRegClass};
216218

217219
#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)]
218220
pub enum InlineAsmArch {
@@ -237,6 +239,7 @@ pub enum InlineAsmArch {
237239
SpirV,
238240
Wasm32,
239241
Wasm64,
242+
Xtensa,
240243
Bpf,
241244
Avr,
242245
Msp430,
@@ -273,7 +276,8 @@ impl InlineAsmArch {
273276
Arch::Msp430 => Some(Self::Msp430),
274277
Arch::M68k => Some(Self::M68k),
275278
Arch::CSky => Some(Self::CSKY),
276-
Arch::AmdGpu | Arch::Xtensa | Arch::Other(_) => None,
279+
Arch::Xtensa => Some(Self::Xtensa),
280+
Arch::AmdGpu | Arch::Other(_) => None,
277281
}
278282
}
279283
}
@@ -294,6 +298,7 @@ pub enum InlineAsmReg {
294298
Sparc(SparcInlineAsmReg),
295299
SpirV(SpirVInlineAsmReg),
296300
Wasm(WasmInlineAsmReg),
301+
Xtensa(XtensaInlineAsmReg),
297302
Bpf(BpfInlineAsmReg),
298303
Avr(AvrInlineAsmReg),
299304
Msp430(Msp430InlineAsmReg),
@@ -316,6 +321,7 @@ impl InlineAsmReg {
316321
Self::Mips(r) => r.name(),
317322
Self::S390x(r) => r.name(),
318323
Self::Sparc(r) => r.name(),
324+
Self::Xtensa(r) => r.name(),
319325
Self::Bpf(r) => r.name(),
320326
Self::Avr(r) => r.name(),
321327
Self::Msp430(r) => r.name(),
@@ -337,6 +343,7 @@ impl InlineAsmReg {
337343
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
338344
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
339345
Self::Sparc(r) => InlineAsmRegClass::Sparc(r.reg_class()),
346+
Self::Xtensa(r) => InlineAsmRegClass::Xtensa(r.reg_class()),
340347
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
341348
Self::Avr(r) => InlineAsmRegClass::Avr(r.reg_class()),
342349
Self::Msp430(r) => InlineAsmRegClass::Msp430(r.reg_class()),
@@ -370,6 +377,7 @@ impl InlineAsmReg {
370377
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
371378
Self::Mips(MipsInlineAsmReg::parse(name)?)
372379
}
380+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmReg::parse(name)?),
373381
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
374382
InlineAsmArch::Sparc | InlineAsmArch::Sparc64 => {
375383
Self::Sparc(SparcInlineAsmReg::parse(name)?)
@@ -409,6 +417,7 @@ impl InlineAsmReg {
409417
Self::Sparc(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
410418
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
411419
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
420+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
412421
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
413422
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
414423
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -435,6 +444,7 @@ impl InlineAsmReg {
435444
Self::Mips(r) => r.emit(out, arch, modifier),
436445
Self::S390x(r) => r.emit(out, arch, modifier),
437446
Self::Sparc(r) => r.emit(out, arch, modifier),
447+
Self::Xtensa(r) => r.emit(out, arch, modifier),
438448
Self::Bpf(r) => r.emit(out, arch, modifier),
439449
Self::Avr(r) => r.emit(out, arch, modifier),
440450
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -456,6 +466,7 @@ impl InlineAsmReg {
456466
Self::Mips(_) => cb(self),
457467
Self::S390x(r) => r.overlapping_regs(|r| cb(Self::S390x(r))),
458468
Self::Sparc(_) => cb(self),
469+
Self::Xtensa(_) => cb(self),
459470
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
460471
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
461472
Self::Msp430(_) => cb(self),
@@ -482,6 +493,7 @@ pub enum InlineAsmRegClass {
482493
Sparc(SparcInlineAsmRegClass),
483494
SpirV(SpirVInlineAsmRegClass),
484495
Wasm(WasmInlineAsmRegClass),
496+
Xtensa(XtensaInlineAsmRegClass),
485497
Bpf(BpfInlineAsmRegClass),
486498
Avr(AvrInlineAsmRegClass),
487499
Msp430(Msp430InlineAsmRegClass),
@@ -507,6 +519,7 @@ impl InlineAsmRegClass {
507519
Self::Sparc(r) => r.name(),
508520
Self::SpirV(r) => r.name(),
509521
Self::Wasm(r) => r.name(),
522+
Self::Xtensa(r) => r.name(),
510523
Self::Bpf(r) => r.name(),
511524
Self::Avr(r) => r.name(),
512525
Self::Msp430(r) => r.name(),
@@ -534,6 +547,7 @@ impl InlineAsmRegClass {
534547
Self::Sparc(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Sparc),
535548
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
536549
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
550+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
537551
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
538552
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
539553
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -564,6 +578,7 @@ impl InlineAsmRegClass {
564578
Self::Sparc(r) => r.suggest_modifier(arch, ty),
565579
Self::SpirV(r) => r.suggest_modifier(arch, ty),
566580
Self::Wasm(r) => r.suggest_modifier(arch, ty),
581+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
567582
Self::Bpf(r) => r.suggest_modifier(arch, ty),
568583
Self::Avr(r) => r.suggest_modifier(arch, ty),
569584
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -594,6 +609,7 @@ impl InlineAsmRegClass {
594609
Self::Sparc(r) => r.default_modifier(arch),
595610
Self::SpirV(r) => r.default_modifier(arch),
596611
Self::Wasm(r) => r.default_modifier(arch),
612+
Self::Xtensa(r) => r.default_modifier(arch),
597613
Self::Bpf(r) => r.default_modifier(arch),
598614
Self::Avr(r) => r.default_modifier(arch),
599615
Self::Msp430(r) => r.default_modifier(arch),
@@ -627,6 +643,7 @@ impl InlineAsmRegClass {
627643
Self::Sparc(r) => r.supported_types(arch),
628644
Self::SpirV(r) => r.supported_types(arch),
629645
Self::Wasm(r) => r.supported_types(arch),
646+
Self::Xtensa(r) => r.supported_types(arch),
630647
Self::Bpf(r) => r.supported_types(arch),
631648
Self::Avr(r) => r.supported_types(arch),
632649
Self::Msp430(r) => r.supported_types(arch),
@@ -669,6 +686,7 @@ impl InlineAsmRegClass {
669686
}
670687
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
671688
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
689+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
672690
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
673691
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
674692
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -692,6 +710,7 @@ impl InlineAsmRegClass {
692710
Self::Sparc(r) => r.valid_modifiers(arch),
693711
Self::SpirV(r) => r.valid_modifiers(arch),
694712
Self::Wasm(r) => r.valid_modifiers(arch),
713+
Self::Xtensa(r) => r.valid_modifiers(arch),
695714
Self::Bpf(r) => r.valid_modifiers(arch),
696715
Self::Avr(r) => r.valid_modifiers(arch),
697716
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -893,6 +912,11 @@ pub fn allocatable_registers(
893912
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
894913
map
895914
}
915+
InlineAsmArch::Xtensa => {
916+
let mut map = xtensa::regclass_map();
917+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
918+
map
919+
}
896920
InlineAsmArch::Bpf => {
897921
let mut map = bpf::regclass_map();
898922
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)