Skip to content

Commit f13eed0

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 3babe81 commit f13eed0

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
@@ -269,6 +269,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
269269
}
270270
InlineAsmArch::SpirV => {}
271271
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
272+
InlineAsmArch::Xtensa => {}
272273
InlineAsmArch::Bpf => {}
273274
InlineAsmArch::Msp430 => {
274275
constraints.push("~{sr}".to_string());
@@ -700,6 +701,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
700701
| X86InlineAsmRegClass::tmm_reg,
701702
) => unreachable!("clobber-only"),
702703
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
704+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
705+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
706+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
703707
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
704708
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
705709
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -762,6 +766,7 @@ fn modifier_to_llvm(
762766
InlineAsmRegClass::Mips(_) => None,
763767
InlineAsmRegClass::Nvptx(_) => None,
764768
InlineAsmRegClass::PowerPC(_) => None,
769+
InlineAsmRegClass::Xtensa(_) => None,
765770
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
766771
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
767772
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -879,6 +884,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
879884
unreachable!("clobber-only")
880885
}
881886
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
887+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
888+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
889+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
882890
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
883891
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
884892
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
@@ -463,6 +463,7 @@ symbols! {
463463
async_for_loop,
464464
async_iterator,
465465
async_iterator_poll_next,
466+
atomctl,
466467
atomic,
467468
atomic_mod,
468469
atomics,
@@ -503,6 +504,7 @@ symbols! {
503504
braced_empty_structs,
504505
branch,
505506
breakpoint,
507+
breg,
506508
bridge,
507509
bswap,
508510
builtin_syntax,
@@ -634,6 +636,7 @@ symbols! {
634636
constant,
635637
constructor,
636638
convert_identity,
639+
coprocessor,
637640
copy,
638641
copy_closures,
639642
copy_nonoverlapping,
@@ -723,6 +726,7 @@ symbols! {
723726
derive_smart_pointer,
724727
destruct,
725728
destructuring_assignment,
729+
dfpaccel,
726730
diagnostic,
727731
diagnostic_namespace,
728732
direct,
@@ -786,6 +790,7 @@ symbols! {
786790
ermsb_target_feature,
787791
exact_div,
788792
except,
793+
exception,
789794
exchange_malloc,
790795
exclusive_range_pattern,
791796
exhaustive_integer_patterns,
@@ -809,6 +814,7 @@ symbols! {
809814
expr_fragment_specifier_2024,
810815
extended_key_value_attributes,
811816
extended_varargs_abi_support,
817+
extendedl32r,
812818
extern_absolute_paths,
813819
extern_crate_item_prelude,
814820
extern_crate_self,
@@ -912,6 +918,7 @@ symbols! {
912918
format_macro,
913919
format_placeholder,
914920
format_unsafe_arg,
921+
fp,
915922
freeze,
916923
freeze_impls,
917924
freg,
@@ -962,6 +969,7 @@ symbols! {
962969
hash,
963970
hexagon_target_feature,
964971
hidden,
972+
highpriinterrupts,
965973
homogeneous_aggregate,
966974
host,
967975
html_favicon_url,
@@ -1040,6 +1048,8 @@ symbols! {
10401048
instruction_set,
10411049
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
10421050
integral,
1051+
intel,
1052+
interrupt,
10431053
into_async_iter_into_iter,
10441054
into_future,
10451055
into_iter,
@@ -1127,6 +1137,7 @@ symbols! {
11271137
loongarch_target_feature,
11281138
loop_break_value,
11291139
lt,
1140+
mac16,
11301141
macro_at_most_once_rep,
11311142
macro_attributes_in_derive_output,
11321143
macro_escape,
@@ -1170,6 +1181,7 @@ symbols! {
11701181
mem_variant_count,
11711182
mem_zeroed,
11721183
member_constraints,
1184+
memctl,
11731185
memory,
11741186
memtag,
11751187
message,
@@ -1223,6 +1235,8 @@ symbols! {
12231235
mir_unwind_unreachable,
12241236
mir_variant,
12251237
miri,
1238+
misc,
1239+
miscsr,
12261240
mmx_reg,
12271241
modifiers,
12281242
module,
@@ -1437,6 +1451,8 @@ symbols! {
14371451
prelude_import,
14381452
preserves_flags,
14391453
prfchw_target_feature,
1454+
prid,
1455+
primitive,
14401456
print_macro,
14411457
println_macro,
14421458
proc_dash_macro: "proc-macro",
@@ -1687,8 +1703,10 @@ symbols! {
16871703
rustdoc_missing_doc_code_examples,
16881704
rustfmt,
16891705
rvalue_static_promotion,
1706+
rvector,
16901707
rwpi,
16911708
s,
1709+
s32c1i,
16921710
safety,
16931711
sanitize,
16941712
sanitizer_cfi_generalize_pointers,
@@ -1880,10 +1898,12 @@ symbols! {
18801898
thread,
18811899
thread_local,
18821900
thread_local_macro,
1901+
threadptr,
18831902
three_way_compare,
18841903
thumb2,
18851904
thumb_mode: "thumb-mode",
18861905
time,
1906+
timerint,
18871907
tmm_reg,
18881908
to_owned_method,
18891909
to_string,
@@ -2059,6 +2079,8 @@ symbols! {
20592079
wasm_import_module,
20602080
wasm_target_feature,
20612081
while_let,
2082+
width,
2083+
windowed,
20622084
windows,
20632085
windows_subsystem,
20642086
with_negative_coherence,
@@ -2077,8 +2099,10 @@ symbols! {
20772099
x86_amx_intrinsics,
20782100
x87_reg,
20792101
xer,
2102+
xloop,
20802103
xmm_reg,
20812104
xop_target_feature,
2105+
xtensa_target_feature,
20822106
yeet_desugar_details,
20832107
yeet_expr,
20842108
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,
@@ -729,6 +751,7 @@ impl InlineAsmType {
729751

730752
pub fn size(self) -> Size {
731753
Size::from_bytes(match self {
754+
Self::I1 => return Size::from_bits(1),
732755
Self::I8 => 1,
733756
Self::I16 => 2,
734757
Self::I32 => 4,
@@ -754,6 +777,7 @@ impl InlineAsmType {
754777
impl fmt::Display for InlineAsmType {
755778
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
756779
match *self {
780+
Self::I1 => f.write_str("i1"),
757781
Self::I8 => f.write_str("i8"),
758782
Self::I16 => f.write_str("i16"),
759783
Self::I32 => f.write_str("i32"),
@@ -851,6 +875,11 @@ pub fn allocatable_registers(
851875
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
852876
map
853877
}
878+
InlineAsmArch::Xtensa => {
879+
let mut map = xtensa::regclass_map();
880+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
881+
map
882+
}
854883
InlineAsmArch::Bpf => {
855884
let mut map = bpf::regclass_map();
856885
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)