Skip to content

Commit 222357d

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 8b6b15b commit 222357d

File tree

7 files changed

+351
-0
lines changed

7 files changed

+351
-0
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
724724
| X86InlineAsmRegClass::mmx_reg
725725
| X86InlineAsmRegClass::tmm_reg,
726726
) => unreachable!("clobber-only"),
727+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
728+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
727729
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
728730
bug!("GCC backend does not support SPIR-V")
729731
}
@@ -834,6 +836,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
834836
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
835837
bug!("GCC backend does not support SPIR-V")
836838
}
839+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
840+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
837841
InlineAsmRegClass::Err => unreachable!(),
838842
}
839843
}
@@ -1018,6 +1022,7 @@ fn modifier_to_gcc(
10181022
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
10191023
bug!("LLVM backend does not support SPIR-V")
10201024
}
1025+
InlineAsmRegClass::Xtensa(_) => None,
10211026
InlineAsmRegClass::Err => unreachable!(),
10221027
}
10231028
}

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
280280
}
281281
InlineAsmArch::SpirV => {}
282282
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
283+
InlineAsmArch::Xtensa => {}
283284
InlineAsmArch::Bpf => {}
284285
InlineAsmArch::Msp430 => {
285286
constraints.push("~{sr}".to_string());
@@ -683,6 +684,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
683684
| X86InlineAsmRegClass::kreg0
684685
| X86InlineAsmRegClass::tmm_reg,
685686
) => unreachable!("clobber-only"),
687+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
688+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
686689
Wasm(WasmInlineAsmRegClass::local) => "r",
687690
Bpf(BpfInlineAsmRegClass::reg) => "r",
688691
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -782,6 +785,7 @@ fn modifier_to_llvm(
782785
| X86InlineAsmRegClass::kreg0
783786
| X86InlineAsmRegClass::tmm_reg,
784787
) => unreachable!("clobber-only"),
788+
Xtensa(_) => None,
785789
Wasm(WasmInlineAsmRegClass::local) => None,
786790
Bpf(_) => None,
787791
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -856,6 +860,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
856860
| X86InlineAsmRegClass::kreg0
857861
| X86InlineAsmRegClass::tmm_reg,
858862
) => unreachable!("clobber-only"),
863+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
864+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
859865
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
860866
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
861867
Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),

compiler/rustc_span/src/symbol.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ symbols! {
518518
async_iterator,
519519
async_iterator_poll_next,
520520
async_trait_bounds,
521+
atomctl,
521522
atomic,
522523
atomic_and,
523524
atomic_cxchg,
@@ -755,6 +756,7 @@ symbols! {
755756
contracts_requires,
756757
convert,
757758
convert_identity,
759+
coprocessor,
758760
copy,
759761
copy_closures,
760762
copy_nonoverlapping,
@@ -940,6 +942,7 @@ symbols! {
940942
ermsb_target_feature,
941943
exact_div,
942944
except,
945+
exception,
943946
exception_handling: "exception-handling",
944947
exchange_malloc,
945948
exclusive_range_pattern,
@@ -966,6 +969,7 @@ symbols! {
966969
expr_fragment_specifier_2024,
967970
extended_key_value_attributes,
968971
extended_varargs_abi_support,
972+
extendedl32r,
969973
extern_absolute_paths,
970974
extern_crate_item_prelude,
971975
extern_crate_self,
@@ -1082,6 +1086,7 @@ symbols! {
10821086
format_macro,
10831087
format_placeholder,
10841088
format_unsafe_arg,
1089+
fp,
10851090
framework,
10861091
freeze,
10871092
freeze_impls,
@@ -1152,6 +1157,7 @@ symbols! {
11521157
hexagon_target_feature,
11531158
hidden,
11541159
hide,
1160+
highpriinterrupts,
11551161
hint,
11561162
homogeneous_aggregate,
11571163
host,
@@ -1238,6 +1244,7 @@ symbols! {
12381244
integral,
12391245
internal,
12401246
internal_features,
1247+
interrupt,
12411248
into_async_iter_into_iter,
12421249
into_future,
12431250
into_iter,
@@ -1341,6 +1348,7 @@ symbols! {
13411348
lr,
13421349
lt,
13431350
m68k_target_feature,
1351+
mac16,
13441352
macro_at_most_once_rep,
13451353
macro_attr,
13461354
macro_attributes_in_derive_output,
@@ -1392,6 +1400,7 @@ symbols! {
13921400
mem_variant_count,
13931401
mem_zeroed,
13941402
member_constraints,
1403+
memctl,
13951404
memory,
13961405
memtag,
13971406
message,
@@ -1451,6 +1460,8 @@ symbols! {
14511460
mir_unwind_unreachable,
14521461
mir_variant,
14531462
miri,
1463+
misc,
1464+
miscsr,
14541465
mmx_reg,
14551466
modifiers,
14561467
module,
@@ -1697,6 +1708,8 @@ symbols! {
16971708
prelude_import,
16981709
preserves_flags,
16991710
prfchw_target_feature,
1711+
prid,
1712+
primitive,
17001713
print_macro,
17011714
println_macro,
17021715
proc_dash_macro: "proc-macro",
@@ -1963,8 +1976,10 @@ symbols! {
19631976
rustdoc_missing_doc_code_examples,
19641977
rustfmt,
19651978
rvalue_static_promotion,
1979+
rvector,
19661980
rwpi,
19671981
s,
1982+
s32c1i,
19681983
s390x_target_feature,
19691984
safety,
19701985
sanitize,
@@ -2202,9 +2217,12 @@ symbols! {
22022217
thread,
22032218
thread_local,
22042219
thread_local_macro,
2220+
threadptr,
22052221
three_way_compare,
22062222
thumb2,
22072223
thumb_mode: "thumb-mode",
2224+
time,
2225+
timerint,
22082226
tmm_reg,
22092227
to_owned_method,
22102228
to_string,
@@ -2418,6 +2436,7 @@ symbols! {
24182436
while_let,
24192437
whole_dash_archive: "whole-archive",
24202438
width,
2439+
windowed,
24212440
windows,
24222441
windows_subsystem,
24232442
with_negative_coherence,
@@ -2439,8 +2458,10 @@ symbols! {
24392458
x87_reg,
24402459
x87_target_feature,
24412460
xer,
2461+
xloop,
24422462
xmm_reg,
24432463
xop_target_feature,
2464+
xtensa_target_feature,
24442465
yeet_desugar_details,
24452466
yeet_expr,
24462467
yes,

compiler/rustc_target/src/asm/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ mod sparc;
195195
mod spirv;
196196
mod wasm;
197197
mod x86;
198+
mod xtensa;
198199

199200
pub use aarch64::{AArch64InlineAsmReg, AArch64InlineAsmRegClass};
200201
pub use arm::{ArmInlineAsmReg, ArmInlineAsmRegClass};
@@ -214,6 +215,7 @@ pub use sparc::{SparcInlineAsmReg, SparcInlineAsmRegClass};
214215
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
215216
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
216217
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
218+
pub use xtensa::{XtensaInlineAsmReg, XtensaInlineAsmRegClass};
217219

218220
#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)]
219221
pub enum InlineAsmArch {
@@ -238,6 +240,7 @@ pub enum InlineAsmArch {
238240
SpirV,
239241
Wasm32,
240242
Wasm64,
243+
Xtensa,
241244
Bpf,
242245
Avr,
243246
Msp430,
@@ -271,6 +274,7 @@ impl FromStr for InlineAsmArch {
271274
"spirv" => Ok(Self::SpirV),
272275
"wasm32" => Ok(Self::Wasm32),
273276
"wasm64" => Ok(Self::Wasm64),
277+
"xtensa" => Ok(Self::Xtensa),
274278
"bpf" => Ok(Self::Bpf),
275279
"avr" => Ok(Self::Avr),
276280
"msp430" => Ok(Self::Msp430),
@@ -297,6 +301,7 @@ pub enum InlineAsmReg {
297301
Sparc(SparcInlineAsmReg),
298302
SpirV(SpirVInlineAsmReg),
299303
Wasm(WasmInlineAsmReg),
304+
Xtensa(XtensaInlineAsmReg),
300305
Bpf(BpfInlineAsmReg),
301306
Avr(AvrInlineAsmReg),
302307
Msp430(Msp430InlineAsmReg),
@@ -319,6 +324,7 @@ impl InlineAsmReg {
319324
Self::Mips(r) => r.name(),
320325
Self::S390x(r) => r.name(),
321326
Self::Sparc(r) => r.name(),
327+
Self::Xtensa(r) => r.name(),
322328
Self::Bpf(r) => r.name(),
323329
Self::Avr(r) => r.name(),
324330
Self::Msp430(r) => r.name(),
@@ -340,6 +346,7 @@ impl InlineAsmReg {
340346
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
341347
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
342348
Self::Sparc(r) => InlineAsmRegClass::Sparc(r.reg_class()),
349+
Self::Xtensa(r) => InlineAsmRegClass::Xtensa(r.reg_class()),
343350
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
344351
Self::Avr(r) => InlineAsmRegClass::Avr(r.reg_class()),
345352
Self::Msp430(r) => InlineAsmRegClass::Msp430(r.reg_class()),
@@ -373,6 +380,7 @@ impl InlineAsmReg {
373380
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
374381
Self::Mips(MipsInlineAsmReg::parse(name)?)
375382
}
383+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmReg::parse(name)?),
376384
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
377385
InlineAsmArch::Sparc | InlineAsmArch::Sparc64 => {
378386
Self::Sparc(SparcInlineAsmReg::parse(name)?)
@@ -412,6 +420,7 @@ impl InlineAsmReg {
412420
Self::Sparc(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
413421
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
414422
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
423+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
415424
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
416425
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
417426
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -438,6 +447,7 @@ impl InlineAsmReg {
438447
Self::Mips(r) => r.emit(out, arch, modifier),
439448
Self::S390x(r) => r.emit(out, arch, modifier),
440449
Self::Sparc(r) => r.emit(out, arch, modifier),
450+
Self::Xtensa(r) => r.emit(out, arch, modifier),
441451
Self::Bpf(r) => r.emit(out, arch, modifier),
442452
Self::Avr(r) => r.emit(out, arch, modifier),
443453
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -459,6 +469,7 @@ impl InlineAsmReg {
459469
Self::Mips(_) => cb(self),
460470
Self::S390x(r) => r.overlapping_regs(|r| cb(Self::S390x(r))),
461471
Self::Sparc(_) => cb(self),
472+
Self::Xtensa(_) => cb(self),
462473
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
463474
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
464475
Self::Msp430(_) => cb(self),
@@ -485,6 +496,7 @@ pub enum InlineAsmRegClass {
485496
Sparc(SparcInlineAsmRegClass),
486497
SpirV(SpirVInlineAsmRegClass),
487498
Wasm(WasmInlineAsmRegClass),
499+
Xtensa(XtensaInlineAsmRegClass),
488500
Bpf(BpfInlineAsmRegClass),
489501
Avr(AvrInlineAsmRegClass),
490502
Msp430(Msp430InlineAsmRegClass),
@@ -510,6 +522,7 @@ impl InlineAsmRegClass {
510522
Self::Sparc(r) => r.name(),
511523
Self::SpirV(r) => r.name(),
512524
Self::Wasm(r) => r.name(),
525+
Self::Xtensa(r) => r.name(),
513526
Self::Bpf(r) => r.name(),
514527
Self::Avr(r) => r.name(),
515528
Self::Msp430(r) => r.name(),
@@ -537,6 +550,7 @@ impl InlineAsmRegClass {
537550
Self::Sparc(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Sparc),
538551
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
539552
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
553+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
540554
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
541555
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
542556
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -567,6 +581,7 @@ impl InlineAsmRegClass {
567581
Self::Sparc(r) => r.suggest_modifier(arch, ty),
568582
Self::SpirV(r) => r.suggest_modifier(arch, ty),
569583
Self::Wasm(r) => r.suggest_modifier(arch, ty),
584+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
570585
Self::Bpf(r) => r.suggest_modifier(arch, ty),
571586
Self::Avr(r) => r.suggest_modifier(arch, ty),
572587
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -597,6 +612,7 @@ impl InlineAsmRegClass {
597612
Self::Sparc(r) => r.default_modifier(arch),
598613
Self::SpirV(r) => r.default_modifier(arch),
599614
Self::Wasm(r) => r.default_modifier(arch),
615+
Self::Xtensa(r) => r.default_modifier(arch),
600616
Self::Bpf(r) => r.default_modifier(arch),
601617
Self::Avr(r) => r.default_modifier(arch),
602618
Self::Msp430(r) => r.default_modifier(arch),
@@ -630,6 +646,7 @@ impl InlineAsmRegClass {
630646
Self::Sparc(r) => r.supported_types(arch),
631647
Self::SpirV(r) => r.supported_types(arch),
632648
Self::Wasm(r) => r.supported_types(arch),
649+
Self::Xtensa(r) => r.supported_types(arch),
633650
Self::Bpf(r) => r.supported_types(arch),
634651
Self::Avr(r) => r.supported_types(arch),
635652
Self::Msp430(r) => r.supported_types(arch),
@@ -672,6 +689,7 @@ impl InlineAsmRegClass {
672689
}
673690
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
674691
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
692+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
675693
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
676694
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
677695
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -695,6 +713,7 @@ impl InlineAsmRegClass {
695713
Self::Sparc(r) => r.valid_modifiers(arch),
696714
Self::SpirV(r) => r.valid_modifiers(arch),
697715
Self::Wasm(r) => r.valid_modifiers(arch),
716+
Self::Xtensa(r) => r.valid_modifiers(arch),
698717
Self::Bpf(r) => r.valid_modifiers(arch),
699718
Self::Avr(r) => r.valid_modifiers(arch),
700719
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -896,6 +915,11 @@ pub fn allocatable_registers(
896915
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
897916
map
898917
}
918+
InlineAsmArch::Xtensa => {
919+
let mut map = xtensa::regclass_map();
920+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
921+
map
922+
}
899923
InlineAsmArch::Bpf => {
900924
let mut map = bpf::regclass_map();
901925
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)