Skip to content

Commit af76d48

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 47bb8cd commit af76d48

File tree

6 files changed

+524
-0
lines changed

6 files changed

+524
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+8
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
270270
}
271271
InlineAsmArch::SpirV => {}
272272
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
273+
InlineAsmArch::Xtensa => {}
273274
InlineAsmArch::Bpf => {}
274275
InlineAsmArch::Msp430 => {
275276
constraints.push("~{sr}".to_string());
@@ -701,6 +702,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
701702
| X86InlineAsmRegClass::tmm_reg,
702703
) => unreachable!("clobber-only"),
703704
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
705+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
706+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
707+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
704708
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
705709
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
706710
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -763,6 +767,7 @@ fn modifier_to_llvm(
763767
InlineAsmRegClass::Mips(_) => None,
764768
InlineAsmRegClass::Nvptx(_) => None,
765769
InlineAsmRegClass::PowerPC(_) => None,
770+
InlineAsmRegClass::Xtensa(_) => None,
766771
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
767772
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
768773
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -880,6 +885,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
880885
unreachable!("clobber-only")
881886
}
882887
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
888+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
889+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
890+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
883891
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
884892
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
885893
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),

compiler/rustc_span/src/symbol.rs

+24
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ symbols! {
466466
async_for_loop,
467467
async_iterator,
468468
async_iterator_poll_next,
469+
atomctl,
469470
atomic,
470471
atomic_mod,
471472
atomics,
@@ -507,6 +508,7 @@ symbols! {
507508
braced_empty_structs,
508509
branch,
509510
breakpoint,
511+
breg,
510512
bridge,
511513
bswap,
512514
builtin_syntax,
@@ -641,6 +643,7 @@ symbols! {
641643
constant,
642644
constructor,
643645
convert_identity,
646+
coprocessor,
644647
copy,
645648
copy_closures,
646649
copy_nonoverlapping,
@@ -731,6 +734,7 @@ symbols! {
731734
derive_smart_pointer,
732735
destruct,
733736
destructuring_assignment,
737+
dfpaccel,
734738
diagnostic,
735739
diagnostic_namespace,
736740
direct,
@@ -794,6 +798,7 @@ symbols! {
794798
ermsb_target_feature,
795799
exact_div,
796800
except,
801+
exception,
797802
exchange_malloc,
798803
exclusive_range_pattern,
799804
exhaustive_integer_patterns,
@@ -817,6 +822,7 @@ symbols! {
817822
expr_fragment_specifier_2024,
818823
extended_key_value_attributes,
819824
extended_varargs_abi_support,
825+
extendedl32r,
820826
extern_absolute_paths,
821827
extern_crate_item_prelude,
822828
extern_crate_self,
@@ -921,6 +927,7 @@ symbols! {
921927
format_macro,
922928
format_placeholder,
923929
format_unsafe_arg,
930+
fp,
924931
freeze,
925932
freeze_impls,
926933
freg,
@@ -972,6 +979,7 @@ symbols! {
972979
hash,
973980
hexagon_target_feature,
974981
hidden,
982+
highpriinterrupts,
975983
homogeneous_aggregate,
976984
host,
977985
html_favicon_url,
@@ -1050,6 +1058,8 @@ symbols! {
10501058
instruction_set,
10511059
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
10521060
integral,
1061+
intel,
1062+
interrupt,
10531063
into_async_iter_into_iter,
10541064
into_future,
10551065
into_iter,
@@ -1137,6 +1147,7 @@ symbols! {
11371147
loongarch_target_feature,
11381148
loop_break_value,
11391149
lt,
1150+
mac16,
11401151
macro_at_most_once_rep,
11411152
macro_attributes_in_derive_output,
11421153
macro_escape,
@@ -1180,6 +1191,7 @@ symbols! {
11801191
mem_variant_count,
11811192
mem_zeroed,
11821193
member_constraints,
1194+
memctl,
11831195
memory,
11841196
memtag,
11851197
message,
@@ -1234,6 +1246,8 @@ symbols! {
12341246
mir_unwind_unreachable,
12351247
mir_variant,
12361248
miri,
1249+
misc,
1250+
miscsr,
12371251
mmx_reg,
12381252
modifiers,
12391253
module,
@@ -1450,6 +1464,8 @@ symbols! {
14501464
prelude_import,
14511465
preserves_flags,
14521466
prfchw_target_feature,
1467+
prid,
1468+
primitive,
14531469
print_macro,
14541470
println_macro,
14551471
proc_dash_macro: "proc-macro",
@@ -1702,8 +1718,10 @@ symbols! {
17021718
rustdoc_missing_doc_code_examples,
17031719
rustfmt,
17041720
rvalue_static_promotion,
1721+
rvector,
17051722
rwpi,
17061723
s,
1724+
s32c1i,
17071725
s390x_target_feature,
17081726
safety,
17091727
sanitize,
@@ -1900,10 +1918,12 @@ symbols! {
19001918
thread,
19011919
thread_local,
19021920
thread_local_macro,
1921+
threadptr,
19031922
three_way_compare,
19041923
thumb2,
19051924
thumb_mode: "thumb-mode",
19061925
time,
1926+
timerint,
19071927
tmm_reg,
19081928
to_owned_method,
19091929
to_string,
@@ -2081,6 +2101,8 @@ symbols! {
20812101
wasm_import_module,
20822102
wasm_target_feature,
20832103
while_let,
2104+
width,
2105+
windowed,
20842106
windows,
20852107
windows_subsystem,
20862108
with_negative_coherence,
@@ -2099,8 +2121,10 @@ symbols! {
20992121
x86_amx_intrinsics,
21002122
x87_reg,
21012123
xer,
2124+
xloop,
21022125
xmm_reg,
21032126
xop_target_feature,
2127+
xtensa_target_feature,
21042128
yeet_desugar_details,
21052129
yeet_expr,
21062130
yes,

compiler/rustc_target/src/asm/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ mod s390x;
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};
@@ -211,6 +212,7 @@ pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass};
211212
pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass};
212213
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
213214
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
215+
pub use xtensa::{XtensaInlineAsmReg, XtensaInlineAsmRegClass};
214216
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
215217

216218
#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)]
@@ -233,6 +235,7 @@ pub enum InlineAsmArch {
233235
SpirV,
234236
Wasm32,
235237
Wasm64,
238+
Xtensa,
236239
Bpf,
237240
Avr,
238241
Msp430,
@@ -263,6 +266,7 @@ impl FromStr for InlineAsmArch {
263266
"spirv" => Ok(Self::SpirV),
264267
"wasm32" => Ok(Self::Wasm32),
265268
"wasm64" => Ok(Self::Wasm64),
269+
"xtensa" => Ok(Self::Xtensa),
266270
"bpf" => Ok(Self::Bpf),
267271
"avr" => Ok(Self::Avr),
268272
"msp430" => Ok(Self::Msp430),
@@ -288,6 +292,7 @@ pub enum InlineAsmReg {
288292
S390x(S390xInlineAsmReg),
289293
SpirV(SpirVInlineAsmReg),
290294
Wasm(WasmInlineAsmReg),
295+
Xtensa(XtensaInlineAsmReg),
291296
Bpf(BpfInlineAsmReg),
292297
Avr(AvrInlineAsmReg),
293298
Msp430(Msp430InlineAsmReg),
@@ -309,6 +314,7 @@ impl InlineAsmReg {
309314
Self::LoongArch(r) => r.name(),
310315
Self::Mips(r) => r.name(),
311316
Self::S390x(r) => r.name(),
317+
Self::Xtensa(r) => r.name(),
312318
Self::Bpf(r) => r.name(),
313319
Self::Avr(r) => r.name(),
314320
Self::Msp430(r) => r.name(),
@@ -329,6 +335,7 @@ impl InlineAsmReg {
329335
Self::LoongArch(r) => InlineAsmRegClass::LoongArch(r.reg_class()),
330336
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
331337
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
338+
Self::Xtensa(r) => InlineAsmRegClass::Xtensa(r.reg_class()),
332339
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
333340
Self::Avr(r) => InlineAsmRegClass::Avr(r.reg_class()),
334341
Self::Msp430(r) => InlineAsmRegClass::Msp430(r.reg_class()),
@@ -360,6 +367,9 @@ impl InlineAsmReg {
360367
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
361368
Self::Mips(MipsInlineAsmReg::parse(name)?)
362369
}
370+
InlineAsmArch::Xtensa => {
371+
Self::Xtensa(XtensaInlineAsmReg::parse(name)?)
372+
}
363373
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
364374
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmReg::parse(name)?),
365375
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
@@ -395,6 +405,7 @@ impl InlineAsmReg {
395405
Self::S390x(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
396406
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
397407
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
408+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
398409
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
399410
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
400411
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -420,6 +431,7 @@ impl InlineAsmReg {
420431
Self::LoongArch(r) => r.emit(out, arch, modifier),
421432
Self::Mips(r) => r.emit(out, arch, modifier),
422433
Self::S390x(r) => r.emit(out, arch, modifier),
434+
Self::Xtensa(r) => r.emit(out, arch, modifier),
423435
Self::Bpf(r) => r.emit(out, arch, modifier),
424436
Self::Avr(r) => r.emit(out, arch, modifier),
425437
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -440,6 +452,7 @@ impl InlineAsmReg {
440452
Self::LoongArch(_) => cb(self),
441453
Self::Mips(_) => cb(self),
442454
Self::S390x(_) => cb(self),
455+
Self::Xtensa(_) => cb(self),
443456
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
444457
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
445458
Self::Msp430(_) => cb(self),
@@ -465,6 +478,7 @@ pub enum InlineAsmRegClass {
465478
S390x(S390xInlineAsmRegClass),
466479
SpirV(SpirVInlineAsmRegClass),
467480
Wasm(WasmInlineAsmRegClass),
481+
Xtensa(XtensaInlineAsmRegClass),
468482
Bpf(BpfInlineAsmRegClass),
469483
Avr(AvrInlineAsmRegClass),
470484
Msp430(Msp430InlineAsmRegClass),
@@ -489,6 +503,7 @@ impl InlineAsmRegClass {
489503
Self::S390x(r) => r.name(),
490504
Self::SpirV(r) => r.name(),
491505
Self::Wasm(r) => r.name(),
506+
Self::Xtensa(r) => r.name(),
492507
Self::Bpf(r) => r.name(),
493508
Self::Avr(r) => r.name(),
494509
Self::Msp430(r) => r.name(),
@@ -515,6 +530,7 @@ impl InlineAsmRegClass {
515530
Self::S390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::S390x),
516531
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
517532
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
533+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
518534
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
519535
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
520536
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -544,6 +560,7 @@ impl InlineAsmRegClass {
544560
Self::S390x(r) => r.suggest_modifier(arch, ty),
545561
Self::SpirV(r) => r.suggest_modifier(arch, ty),
546562
Self::Wasm(r) => r.suggest_modifier(arch, ty),
563+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
547564
Self::Bpf(r) => r.suggest_modifier(arch, ty),
548565
Self::Avr(r) => r.suggest_modifier(arch, ty),
549566
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -573,6 +590,7 @@ impl InlineAsmRegClass {
573590
Self::S390x(r) => r.default_modifier(arch),
574591
Self::SpirV(r) => r.default_modifier(arch),
575592
Self::Wasm(r) => r.default_modifier(arch),
593+
Self::Xtensa(r) => r.default_modifier(arch),
576594
Self::Bpf(r) => r.default_modifier(arch),
577595
Self::Avr(r) => r.default_modifier(arch),
578596
Self::Msp430(r) => r.default_modifier(arch),
@@ -601,6 +619,7 @@ impl InlineAsmRegClass {
601619
Self::S390x(r) => r.supported_types(arch),
602620
Self::SpirV(r) => r.supported_types(arch),
603621
Self::Wasm(r) => r.supported_types(arch),
622+
Self::Xtensa(r) => r.supported_types(arch),
604623
Self::Bpf(r) => r.supported_types(arch),
605624
Self::Avr(r) => r.supported_types(arch),
606625
Self::Msp430(r) => r.supported_types(arch),
@@ -638,6 +657,7 @@ impl InlineAsmRegClass {
638657
}
639658
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
640659
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
660+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
641661
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
642662
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
643663
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -660,6 +680,7 @@ impl InlineAsmRegClass {
660680
Self::S390x(r) => r.valid_modifiers(arch),
661681
Self::SpirV(r) => r.valid_modifiers(arch),
662682
Self::Wasm(r) => r.valid_modifiers(arch),
683+
Self::Xtensa(r) => r.valid_modifiers(arch),
663684
Self::Bpf(r) => r.valid_modifiers(arch),
664685
Self::Avr(r) => r.valid_modifiers(arch),
665686
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -704,6 +725,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
704725
/// Set of types which can be used with a particular register class.
705726
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
706727
pub enum InlineAsmType {
728+
I1,
707729
I8,
708730
I16,
709731
I32,
@@ -731,6 +753,7 @@ impl InlineAsmType {
731753

732754
pub fn size(self) -> Size {
733755
Size::from_bytes(match self {
756+
Self::I1 => return Size::from_bits(1),
734757
Self::I8 => 1,
735758
Self::I16 => 2,
736759
Self::I32 => 4,
@@ -756,6 +779,7 @@ impl InlineAsmType {
756779
impl fmt::Display for InlineAsmType {
757780
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
758781
match *self {
782+
Self::I1 => f.write_str("i1"),
759783
Self::I8 => f.write_str("i8"),
760784
Self::I16 => f.write_str("i16"),
761785
Self::I32 => f.write_str("i32"),
@@ -853,6 +877,11 @@ pub fn allocatable_registers(
853877
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
854878
map
855879
}
880+
InlineAsmArch::Xtensa => {
881+
let mut map = xtensa::regclass_map();
882+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
883+
map
884+
}
856885
InlineAsmArch::Bpf => {
857886
let mut map = bpf::regclass_map();
858887
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)