Skip to content

Commit 24a8379

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 78a2009 commit 24a8379

File tree

6 files changed

+524
-0
lines changed

6 files changed

+524
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
263263
}
264264
InlineAsmArch::SpirV => {}
265265
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
266+
InlineAsmArch::Xtensa => {}
266267
InlineAsmArch::Bpf => {}
267268
InlineAsmArch::Msp430 => {
268269
constraints.push("~{sr}".to_string());
@@ -693,6 +694,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
693694
| X86InlineAsmRegClass::tmm_reg,
694695
) => unreachable!("clobber-only"),
695696
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
697+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
698+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
699+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
696700
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
697701
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
698702
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -755,6 +759,7 @@ fn modifier_to_llvm(
755759
InlineAsmRegClass::Mips(_) => None,
756760
InlineAsmRegClass::Nvptx(_) => None,
757761
InlineAsmRegClass::PowerPC(_) => None,
762+
InlineAsmRegClass::Xtensa(_) => None,
758763
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
759764
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
760765
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -872,6 +877,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
872877
unreachable!("clobber-only")
873878
}
874879
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
880+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
881+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
882+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
875883
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
876884
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
877885
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
@@ -449,6 +449,7 @@ symbols! {
449449
async_for_loop,
450450
async_iterator,
451451
async_iterator_poll_next,
452+
atomctl,
452453
atomic,
453454
atomic_mod,
454455
atomics,
@@ -489,6 +490,7 @@ symbols! {
489490
braced_empty_structs,
490491
branch,
491492
breakpoint,
493+
breg,
492494
bridge,
493495
bswap,
494496
builtin_syntax,
@@ -620,6 +622,7 @@ symbols! {
620622
constant,
621623
constructor,
622624
convert_identity,
625+
coprocessor,
623626
copy,
624627
copy_closures,
625628
copy_nonoverlapping,
@@ -706,6 +709,7 @@ symbols! {
706709
derive_default_enum,
707710
destruct,
708711
destructuring_assignment,
712+
dfpaccel,
709713
diagnostic,
710714
diagnostic_namespace,
711715
direct,
@@ -768,6 +772,7 @@ symbols! {
768772
ermsb_target_feature,
769773
exact_div,
770774
except,
775+
exception,
771776
exchange_malloc,
772777
exclusive_range_pattern,
773778
exhaustive_integer_patterns,
@@ -791,6 +796,7 @@ symbols! {
791796
expr_fragment_specifier_2024,
792797
extended_key_value_attributes,
793798
extended_varargs_abi_support,
799+
extendedl32r,
794800
extern_absolute_paths,
795801
extern_crate_item_prelude,
796802
extern_crate_self,
@@ -894,6 +900,7 @@ symbols! {
894900
format_macro,
895901
format_placeholder,
896902
format_unsafe_arg,
903+
fp,
897904
freeze,
898905
freeze_impls,
899906
freg,
@@ -944,6 +951,7 @@ symbols! {
944951
hash,
945952
hexagon_target_feature,
946953
hidden,
954+
highpriinterrupts,
947955
homogeneous_aggregate,
948956
host,
949957
html_favicon_url,
@@ -1022,6 +1030,8 @@ symbols! {
10221030
instruction_set,
10231031
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
10241032
integral,
1033+
intel,
1034+
interrupt,
10251035
into_async_iter_into_iter,
10261036
into_future,
10271037
into_iter,
@@ -1109,6 +1119,7 @@ symbols! {
11091119
loongarch_target_feature,
11101120
loop_break_value,
11111121
lt,
1122+
mac16,
11121123
macro_at_most_once_rep,
11131124
macro_attributes_in_derive_output,
11141125
macro_escape,
@@ -1151,6 +1162,7 @@ symbols! {
11511162
mem_variant_count,
11521163
mem_zeroed,
11531164
member_constraints,
1165+
memctl,
11541166
memory,
11551167
memtag,
11561168
message,
@@ -1203,6 +1215,8 @@ symbols! {
12031215
mir_unwind_unreachable,
12041216
mir_variant,
12051217
miri,
1218+
misc,
1219+
miscsr,
12061220
mmx_reg,
12071221
modifiers,
12081222
module,
@@ -1412,6 +1426,8 @@ symbols! {
14121426
prelude_import,
14131427
preserves_flags,
14141428
prfchw_target_feature,
1429+
prid,
1430+
primitive,
14151431
print_macro,
14161432
println_macro,
14171433
proc_dash_macro: "proc-macro",
@@ -1658,8 +1674,10 @@ symbols! {
16581674
rustdoc_missing_doc_code_examples,
16591675
rustfmt,
16601676
rvalue_static_promotion,
1677+
rvector,
16611678
rwpi,
16621679
s,
1680+
s32c1i,
16631681
safety,
16641682
sanitize,
16651683
sanitizer_cfi_generalize_pointers,
@@ -1850,9 +1868,11 @@ symbols! {
18501868
thread,
18511869
thread_local,
18521870
thread_local_macro,
1871+
threadptr,
18531872
three_way_compare,
18541873
thumb2,
18551874
thumb_mode: "thumb-mode",
1875+
timerint,
18561876
tmm_reg,
18571877
to_owned_method,
18581878
to_string,
@@ -2027,6 +2047,8 @@ symbols! {
20272047
wasm_import_module,
20282048
wasm_target_feature,
20292049
while_let,
2050+
width,
2051+
windowed,
20302052
windows,
20312053
windows_subsystem,
20322054
with_negative_coherence,
@@ -2044,7 +2066,9 @@ symbols! {
20442066
writeln_macro,
20452067
x87_reg,
20462068
xer,
2069+
xloop,
20472070
xmm_reg,
2071+
xtensa_target_feature,
20482072
yeet_desugar_details,
20492073
yeet_expr,
20502074
yes,

compiler/rustc_target/src/asm/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ mod s390x;
192192
mod spirv;
193193
mod wasm;
194194
mod x86;
195+
mod xtensa;
195196

196197
pub use aarch64::{AArch64InlineAsmReg, AArch64InlineAsmRegClass};
197198
pub use arm::{ArmInlineAsmReg, ArmInlineAsmRegClass};
@@ -209,6 +210,7 @@ pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass};
209210
pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass};
210211
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
211212
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
213+
pub use xtensa::{XtensaInlineAsmReg, XtensaInlineAsmRegClass};
212214
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
213215

214216
#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)]
@@ -231,6 +233,7 @@ pub enum InlineAsmArch {
231233
SpirV,
232234
Wasm32,
233235
Wasm64,
236+
Xtensa,
234237
Bpf,
235238
Avr,
236239
Msp430,
@@ -261,6 +264,7 @@ impl FromStr for InlineAsmArch {
261264
"spirv" => Ok(Self::SpirV),
262265
"wasm32" => Ok(Self::Wasm32),
263266
"wasm64" => Ok(Self::Wasm64),
267+
"xtensa" => Ok(Self::Xtensa),
264268
"bpf" => Ok(Self::Bpf),
265269
"avr" => Ok(Self::Avr),
266270
"msp430" => Ok(Self::Msp430),
@@ -286,6 +290,7 @@ pub enum InlineAsmReg {
286290
S390x(S390xInlineAsmReg),
287291
SpirV(SpirVInlineAsmReg),
288292
Wasm(WasmInlineAsmReg),
293+
Xtensa(XtensaInlineAsmReg),
289294
Bpf(BpfInlineAsmReg),
290295
Avr(AvrInlineAsmReg),
291296
Msp430(Msp430InlineAsmReg),
@@ -307,6 +312,7 @@ impl InlineAsmReg {
307312
Self::LoongArch(r) => r.name(),
308313
Self::Mips(r) => r.name(),
309314
Self::S390x(r) => r.name(),
315+
Self::Xtensa(r) => r.name(),
310316
Self::Bpf(r) => r.name(),
311317
Self::Avr(r) => r.name(),
312318
Self::Msp430(r) => r.name(),
@@ -327,6 +333,7 @@ impl InlineAsmReg {
327333
Self::LoongArch(r) => InlineAsmRegClass::LoongArch(r.reg_class()),
328334
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
329335
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
336+
Self::Xtensa(r) => InlineAsmRegClass::Xtensa(r.reg_class()),
330337
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
331338
Self::Avr(r) => InlineAsmRegClass::Avr(r.reg_class()),
332339
Self::Msp430(r) => InlineAsmRegClass::Msp430(r.reg_class()),
@@ -358,6 +365,9 @@ impl InlineAsmReg {
358365
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
359366
Self::Mips(MipsInlineAsmReg::parse(name)?)
360367
}
368+
InlineAsmArch::Xtensa => {
369+
Self::Xtensa(XtensaInlineAsmReg::parse(name)?)
370+
}
361371
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
362372
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmReg::parse(name)?),
363373
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
@@ -393,6 +403,7 @@ impl InlineAsmReg {
393403
Self::S390x(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
394404
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
395405
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
406+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
396407
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
397408
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
398409
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -418,6 +429,7 @@ impl InlineAsmReg {
418429
Self::LoongArch(r) => r.emit(out, arch, modifier),
419430
Self::Mips(r) => r.emit(out, arch, modifier),
420431
Self::S390x(r) => r.emit(out, arch, modifier),
432+
Self::Xtensa(r) => r.emit(out, arch, modifier),
421433
Self::Bpf(r) => r.emit(out, arch, modifier),
422434
Self::Avr(r) => r.emit(out, arch, modifier),
423435
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -438,6 +450,7 @@ impl InlineAsmReg {
438450
Self::LoongArch(_) => cb(self),
439451
Self::Mips(_) => cb(self),
440452
Self::S390x(_) => cb(self),
453+
Self::Xtensa(_) => cb(self),
441454
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
442455
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
443456
Self::Msp430(_) => cb(self),
@@ -463,6 +476,7 @@ pub enum InlineAsmRegClass {
463476
S390x(S390xInlineAsmRegClass),
464477
SpirV(SpirVInlineAsmRegClass),
465478
Wasm(WasmInlineAsmRegClass),
479+
Xtensa(XtensaInlineAsmRegClass),
466480
Bpf(BpfInlineAsmRegClass),
467481
Avr(AvrInlineAsmRegClass),
468482
Msp430(Msp430InlineAsmRegClass),
@@ -487,6 +501,7 @@ impl InlineAsmRegClass {
487501
Self::S390x(r) => r.name(),
488502
Self::SpirV(r) => r.name(),
489503
Self::Wasm(r) => r.name(),
504+
Self::Xtensa(r) => r.name(),
490505
Self::Bpf(r) => r.name(),
491506
Self::Avr(r) => r.name(),
492507
Self::Msp430(r) => r.name(),
@@ -513,6 +528,7 @@ impl InlineAsmRegClass {
513528
Self::S390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::S390x),
514529
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
515530
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
531+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
516532
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
517533
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
518534
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -542,6 +558,7 @@ impl InlineAsmRegClass {
542558
Self::S390x(r) => r.suggest_modifier(arch, ty),
543559
Self::SpirV(r) => r.suggest_modifier(arch, ty),
544560
Self::Wasm(r) => r.suggest_modifier(arch, ty),
561+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
545562
Self::Bpf(r) => r.suggest_modifier(arch, ty),
546563
Self::Avr(r) => r.suggest_modifier(arch, ty),
547564
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -571,6 +588,7 @@ impl InlineAsmRegClass {
571588
Self::S390x(r) => r.default_modifier(arch),
572589
Self::SpirV(r) => r.default_modifier(arch),
573590
Self::Wasm(r) => r.default_modifier(arch),
591+
Self::Xtensa(r) => r.default_modifier(arch),
574592
Self::Bpf(r) => r.default_modifier(arch),
575593
Self::Avr(r) => r.default_modifier(arch),
576594
Self::Msp430(r) => r.default_modifier(arch),
@@ -599,6 +617,7 @@ impl InlineAsmRegClass {
599617
Self::S390x(r) => r.supported_types(arch),
600618
Self::SpirV(r) => r.supported_types(arch),
601619
Self::Wasm(r) => r.supported_types(arch),
620+
Self::Xtensa(r) => r.supported_types(arch),
602621
Self::Bpf(r) => r.supported_types(arch),
603622
Self::Avr(r) => r.supported_types(arch),
604623
Self::Msp430(r) => r.supported_types(arch),
@@ -636,6 +655,7 @@ impl InlineAsmRegClass {
636655
}
637656
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
638657
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
658+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
639659
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
640660
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
641661
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -658,6 +678,7 @@ impl InlineAsmRegClass {
658678
Self::S390x(r) => r.valid_modifiers(arch),
659679
Self::SpirV(r) => r.valid_modifiers(arch),
660680
Self::Wasm(r) => r.valid_modifiers(arch),
681+
Self::Xtensa(r) => r.valid_modifiers(arch),
661682
Self::Bpf(r) => r.valid_modifiers(arch),
662683
Self::Avr(r) => r.valid_modifiers(arch),
663684
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -702,6 +723,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
702723
/// Set of types which can be used with a particular register class.
703724
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
704725
pub enum InlineAsmType {
726+
I1,
705727
I8,
706728
I16,
707729
I32,
@@ -725,6 +747,7 @@ impl InlineAsmType {
725747

726748
pub fn size(self) -> Size {
727749
Size::from_bytes(match self {
750+
Self::I1 => return Size::from_bits(1),
728751
Self::I8 => 1,
729752
Self::I16 => 2,
730753
Self::I32 => 4,
@@ -746,6 +769,7 @@ impl InlineAsmType {
746769
impl fmt::Display for InlineAsmType {
747770
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
748771
match *self {
772+
Self::I1 => f.write_str("i1"),
749773
Self::I8 => f.write_str("i8"),
750774
Self::I16 => f.write_str("i16"),
751775
Self::I32 => f.write_str("i32"),
@@ -839,6 +863,11 @@ pub fn allocatable_registers(
839863
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
840864
map
841865
}
866+
InlineAsmArch::Xtensa => {
867+
let mut map = xtensa::regclass_map();
868+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
869+
map
870+
}
842871
InlineAsmArch::Bpf => {
843872
let mut map = bpf::regclass_map();
844873
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)