Skip to content

Commit 8c5b26a

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 3e78dc4 commit 8c5b26a

File tree

6 files changed

+525
-0
lines changed

6 files changed

+525
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+8
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
262262
}
263263
InlineAsmArch::SpirV => {}
264264
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
265+
InlineAsmArch::Xtensa => {}
265266
InlineAsmArch::Bpf => {}
266267
InlineAsmArch::Msp430 => {
267268
constraints.push("~{sr}".to_string());
@@ -692,6 +693,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
692693
| X86InlineAsmRegClass::tmm_reg,
693694
) => unreachable!("clobber-only"),
694695
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
696+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
697+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
698+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
695699
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
696700
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
697701
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -754,6 +758,7 @@ fn modifier_to_llvm(
754758
InlineAsmRegClass::Mips(_) => None,
755759
InlineAsmRegClass::Nvptx(_) => None,
756760
InlineAsmRegClass::PowerPC(_) => None,
761+
InlineAsmRegClass::Xtensa(_) => None,
757762
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
758763
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
759764
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -871,6 +876,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
871876
unreachable!("clobber-only")
872877
}
873878
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
879+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
880+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
881+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
874882
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
875883
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
876884
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),

compiler/rustc_span/src/symbol.rs

+24
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ symbols! {
434434
async_for_loop,
435435
async_iterator,
436436
async_iterator_poll_next,
437+
atomctl,
437438
atomic,
438439
atomic_mod,
439440
atomics,
@@ -474,6 +475,7 @@ symbols! {
474475
braced_empty_structs,
475476
branch,
476477
breakpoint,
478+
breg,
477479
bridge,
478480
bswap,
479481
builtin_syntax,
@@ -597,6 +599,7 @@ symbols! {
597599
constant,
598600
constructor,
599601
convert_identity,
602+
coprocessor,
600603
copy,
601604
copy_closures,
602605
copy_nonoverlapping,
@@ -681,6 +684,7 @@ symbols! {
681684
derive_default_enum,
682685
destruct,
683686
destructuring_assignment,
687+
dfpaccel,
684688
diagnostic,
685689
diagnostic_namespace,
686690
direct,
@@ -741,6 +745,7 @@ symbols! {
741745
ermsb_target_feature,
742746
exact_div,
743747
except,
748+
exception,
744749
exchange_malloc,
745750
exclusive_range_pattern,
746751
exhaustive_integer_patterns,
@@ -762,6 +767,7 @@ symbols! {
762767
expr,
763768
extended_key_value_attributes,
764769
extended_varargs_abi_support,
770+
extendedl32r,
765771
extern_absolute_paths,
766772
extern_crate_item_prelude,
767773
extern_crate_self,
@@ -866,6 +872,7 @@ symbols! {
866872
format_macro,
867873
format_placeholder,
868874
format_unsafe_arg,
875+
fp,
869876
freeze,
870877
freeze_impls,
871878
freg,
@@ -913,6 +920,7 @@ symbols! {
913920
hash,
914921
hexagon_target_feature,
915922
hidden,
923+
highpriinterrupts,
916924
homogeneous_aggregate,
917925
host,
918926
html_favicon_url,
@@ -991,6 +999,8 @@ symbols! {
991999
instruction_set,
9921000
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
9931001
integral,
1002+
intel,
1003+
interrupt,
9941004
into_async_iter_into_iter,
9951005
into_future,
9961006
into_iter,
@@ -1077,6 +1087,7 @@ symbols! {
10771087
loongarch_target_feature,
10781088
loop_break_value,
10791089
lt,
1090+
mac16,
10801091
macro_at_most_once_rep,
10811092
macro_attributes_in_derive_output,
10821093
macro_escape,
@@ -1119,6 +1130,7 @@ symbols! {
11191130
mem_variant_count,
11201131
mem_zeroed,
11211132
member_constraints,
1133+
memctl,
11221134
memory,
11231135
memtag,
11241136
message,
@@ -1170,6 +1182,8 @@ symbols! {
11701182
mir_unwind_unreachable,
11711183
mir_variant,
11721184
miri,
1185+
misc,
1186+
miscsr,
11731187
mmx_reg,
11741188
modifiers,
11751189
module,
@@ -1355,6 +1369,8 @@ symbols! {
13551369
prelude_import,
13561370
preserves_flags,
13571371
prfchw_target_feature,
1372+
prid,
1373+
primitive,
13581374
print_macro,
13591375
println_macro,
13601376
proc_dash_macro: "proc-macro",
@@ -1596,8 +1612,10 @@ symbols! {
15961612
rustdoc_missing_doc_code_examples,
15971613
rustfmt,
15981614
rvalue_static_promotion,
1615+
rvector,
15991616
rwpi,
16001617
s,
1618+
s32c1i,
16011619
safety,
16021620
sanitize,
16031621
sanitizer_cfi_generalize_pointers,
@@ -1786,8 +1804,10 @@ symbols! {
17861804
thread,
17871805
thread_local,
17881806
thread_local_macro,
1807+
threadptr,
17891808
thumb2,
17901809
thumb_mode: "thumb-mode",
1810+
timerint,
17911811
tmm_reg,
17921812
to_owned_method,
17931813
to_string,
@@ -1959,6 +1979,8 @@ symbols! {
19591979
wasm_import_module,
19601980
wasm_target_feature,
19611981
while_let,
1982+
width,
1983+
windowed,
19621984
windows,
19631985
windows_subsystem,
19641986
with_negative_coherence,
@@ -1976,7 +1998,9 @@ symbols! {
19761998
writeln_macro,
19771999
x87_reg,
19782000
xer,
2001+
xloop,
19792002
xmm_reg,
2003+
xtensa_target_feature,
19802004
yeet_desugar_details,
19812005
yeet_expr,
19822006
yes,

compiler/rustc_target/src/asm/mod.rs

+29
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)