Skip to content

Commit a8a2100

Browse files
MabezDevtaiki-e
andcommitted
asm! support for the Xtensa architecture (#68)
Co-authored-by: Taiki Endo <[email protected]>
1 parent 1fe97fc commit a8a2100

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
@@ -278,6 +278,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
278278
}
279279
InlineAsmArch::SpirV => {}
280280
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
281+
InlineAsmArch::Xtensa => {}
281282
InlineAsmArch::Bpf => {}
282283
InlineAsmArch::Msp430 => {
283284
constraints.push("~{sr}".to_string());
@@ -682,6 +683,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
682683
| X86InlineAsmRegClass::kreg0
683684
| X86InlineAsmRegClass::tmm_reg,
684685
) => unreachable!("clobber-only"),
686+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
687+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
688+
Xtensa(XtensaInlineAsmRegClass::breg) => "b",
685689
Wasm(WasmInlineAsmRegClass::local) => "r",
686690
Bpf(BpfInlineAsmRegClass::reg) => "r",
687691
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -781,6 +785,7 @@ fn modifier_to_llvm(
781785
| X86InlineAsmRegClass::kreg0
782786
| X86InlineAsmRegClass::tmm_reg,
783787
) => unreachable!("clobber-only"),
788+
Xtensa(_) => None,
784789
Wasm(WasmInlineAsmRegClass::local) => None,
785790
Bpf(_) => None,
786791
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -850,6 +855,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
850855
| X86InlineAsmRegClass::kreg0
851856
| X86InlineAsmRegClass::tmm_reg,
852857
) => unreachable!("clobber-only"),
858+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
859+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
860+
Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
853861
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
854862
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
855863
Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),

compiler/rustc_span/src/symbol.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ symbols! {
513513
async_iterator,
514514
async_iterator_poll_next,
515515
async_trait_bounds,
516+
atomctl,
516517
atomic,
517518
atomic_and,
518519
atomic_cxchg,
@@ -579,6 +580,7 @@ symbols! {
579580
braced_empty_structs,
580581
branch,
581582
breakpoint,
583+
breg,
582584
bridge,
583585
bswap,
584586
btreemap_contains_key,
@@ -742,6 +744,7 @@ symbols! {
742744
contracts_internals,
743745
contracts_requires,
744746
convert_identity,
747+
coprocessor,
745748
copy,
746749
copy_closures,
747750
copy_nonoverlapping,
@@ -845,6 +848,7 @@ symbols! {
845848
derive_smart_pointer,
846849
destruct,
847850
destructuring_assignment,
851+
dfpaccel,
848852
diagnostic,
849853
diagnostic_namespace,
850854
direct,
@@ -922,6 +926,7 @@ symbols! {
922926
ermsb_target_feature,
923927
exact_div,
924928
except,
929+
exception,
925930
exchange_malloc,
926931
exclusive_range_pattern,
927932
exhaustive_integer_patterns,
@@ -947,6 +952,7 @@ symbols! {
947952
expr_fragment_specifier_2024,
948953
extended_key_value_attributes,
949954
extended_varargs_abi_support,
955+
extendedl32r,
950956
extern_absolute_paths,
951957
extern_crate_item_prelude,
952958
extern_crate_self,
@@ -1061,6 +1067,7 @@ symbols! {
10611067
format_macro,
10621068
format_placeholder,
10631069
format_unsafe_arg,
1070+
fp,
10641071
freeze,
10651072
freeze_impls,
10661073
freg,
@@ -1129,6 +1136,7 @@ symbols! {
11291136
hashset_iter_ty,
11301137
hexagon_target_feature,
11311138
hidden,
1139+
highpriinterrupts,
11321140
hint,
11331141
homogeneous_aggregate,
11341142
host,
@@ -1212,6 +1220,7 @@ symbols! {
12121220
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
12131221
integral,
12141222
internal_features,
1223+
interrupt,
12151224
into_async_iter_into_iter,
12161225
into_future,
12171226
into_iter,
@@ -1309,6 +1318,7 @@ symbols! {
13091318
loop_match,
13101319
lt,
13111320
m68k_target_feature,
1321+
mac16,
13121322
macro_at_most_once_rep,
13131323
macro_attributes_in_derive_output,
13141324
macro_concat,
@@ -1358,6 +1368,7 @@ symbols! {
13581368
mem_variant_count,
13591369
mem_zeroed,
13601370
member_constraints,
1371+
memctl,
13611372
memory,
13621373
memtag,
13631374
message,
@@ -1416,6 +1427,8 @@ symbols! {
14161427
mir_unwind_unreachable,
14171428
mir_variant,
14181429
miri,
1430+
misc,
1431+
miscsr,
14191432
mmx_reg,
14201433
modifiers,
14211434
module,
@@ -1656,6 +1669,8 @@ symbols! {
16561669
prelude_import,
16571670
preserves_flags,
16581671
prfchw_target_feature,
1672+
prid,
1673+
primitive,
16591674
print_macro,
16601675
println_macro,
16611676
proc_dash_macro: "proc-macro",
@@ -1915,8 +1930,10 @@ symbols! {
19151930
rustdoc_missing_doc_code_examples,
19161931
rustfmt,
19171932
rvalue_static_promotion,
1933+
rvector,
19181934
rwpi,
19191935
s,
1936+
s32c1i,
19201937
s390x_target_feature,
19211938
safety,
19221939
sanitize,
@@ -2151,9 +2168,12 @@ symbols! {
21512168
thread,
21522169
thread_local,
21532170
thread_local_macro,
2171+
threadptr,
21542172
three_way_compare,
21552173
thumb2,
21562174
thumb_mode: "thumb-mode",
2175+
time,
2176+
timerint,
21572177
tmm_reg,
21582178
to_owned_method,
21592179
to_string,
@@ -2359,6 +2379,7 @@ symbols! {
23592379
where_clause_attrs,
23602380
while_let,
23612381
width,
2382+
windowed,
23622383
windows,
23632384
windows_subsystem,
23642385
with_negative_coherence,
@@ -2380,8 +2401,10 @@ symbols! {
23802401
x87_reg,
23812402
x87_target_feature,
23822403
xer,
2404+
xloop,
23832405
xmm_reg,
23842406
xop_target_feature,
2407+
xtensa_target_feature,
23852408
yeet_desugar_details,
23862409
yeet_expr,
23872410
yes,

compiler/rustc_target/src/asm/mod.rs

Lines changed: 29 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};
@@ -213,6 +214,7 @@ pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass};
213214
pub use sparc::{SparcInlineAsmReg, SparcInlineAsmRegClass};
214215
pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass};
215216
pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass};
217+
pub use xtensa::{XtensaInlineAsmReg, XtensaInlineAsmRegClass};
216218
pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass};
217219

218220
#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)]
@@ -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,9 @@ impl InlineAsmReg {
373380
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
374381
Self::Mips(MipsInlineAsmReg::parse(name)?)
375382
}
383+
InlineAsmArch::Xtensa => {
384+
Self::Xtensa(XtensaInlineAsmReg::parse(name)?)
385+
}
376386
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
377387
InlineAsmArch::Sparc | InlineAsmArch::Sparc64 => {
378388
Self::Sparc(SparcInlineAsmReg::parse(name)?)
@@ -412,6 +422,7 @@ impl InlineAsmReg {
412422
Self::Sparc(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
413423
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
414424
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
425+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
415426
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
416427
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
417428
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -438,6 +449,7 @@ impl InlineAsmReg {
438449
Self::Mips(r) => r.emit(out, arch, modifier),
439450
Self::S390x(r) => r.emit(out, arch, modifier),
440451
Self::Sparc(r) => r.emit(out, arch, modifier),
452+
Self::Xtensa(r) => r.emit(out, arch, modifier),
441453
Self::Bpf(r) => r.emit(out, arch, modifier),
442454
Self::Avr(r) => r.emit(out, arch, modifier),
443455
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -459,6 +471,7 @@ impl InlineAsmReg {
459471
Self::Mips(_) => cb(self),
460472
Self::S390x(r) => r.overlapping_regs(|r| cb(Self::S390x(r))),
461473
Self::Sparc(_) => cb(self),
474+
Self::Xtensa(_) => cb(self),
462475
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
463476
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
464477
Self::Msp430(_) => cb(self),
@@ -485,6 +498,7 @@ pub enum InlineAsmRegClass {
485498
Sparc(SparcInlineAsmRegClass),
486499
SpirV(SpirVInlineAsmRegClass),
487500
Wasm(WasmInlineAsmRegClass),
501+
Xtensa(XtensaInlineAsmRegClass),
488502
Bpf(BpfInlineAsmRegClass),
489503
Avr(AvrInlineAsmRegClass),
490504
Msp430(Msp430InlineAsmRegClass),
@@ -510,6 +524,7 @@ impl InlineAsmRegClass {
510524
Self::Sparc(r) => r.name(),
511525
Self::SpirV(r) => r.name(),
512526
Self::Wasm(r) => r.name(),
527+
Self::Xtensa(r) => r.name(),
513528
Self::Bpf(r) => r.name(),
514529
Self::Avr(r) => r.name(),
515530
Self::Msp430(r) => r.name(),
@@ -537,6 +552,7 @@ impl InlineAsmRegClass {
537552
Self::Sparc(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Sparc),
538553
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
539554
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
555+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
540556
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
541557
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
542558
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -567,6 +583,7 @@ impl InlineAsmRegClass {
567583
Self::Sparc(r) => r.suggest_modifier(arch, ty),
568584
Self::SpirV(r) => r.suggest_modifier(arch, ty),
569585
Self::Wasm(r) => r.suggest_modifier(arch, ty),
586+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
570587
Self::Bpf(r) => r.suggest_modifier(arch, ty),
571588
Self::Avr(r) => r.suggest_modifier(arch, ty),
572589
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -597,6 +614,7 @@ impl InlineAsmRegClass {
597614
Self::Sparc(r) => r.default_modifier(arch),
598615
Self::SpirV(r) => r.default_modifier(arch),
599616
Self::Wasm(r) => r.default_modifier(arch),
617+
Self::Xtensa(r) => r.default_modifier(arch),
600618
Self::Bpf(r) => r.default_modifier(arch),
601619
Self::Avr(r) => r.default_modifier(arch),
602620
Self::Msp430(r) => r.default_modifier(arch),
@@ -630,6 +648,7 @@ impl InlineAsmRegClass {
630648
Self::Sparc(r) => r.supported_types(arch),
631649
Self::SpirV(r) => r.supported_types(arch),
632650
Self::Wasm(r) => r.supported_types(arch),
651+
Self::Xtensa(r) => r.supported_types(arch),
633652
Self::Bpf(r) => r.supported_types(arch),
634653
Self::Avr(r) => r.supported_types(arch),
635654
Self::Msp430(r) => r.supported_types(arch),
@@ -672,6 +691,7 @@ impl InlineAsmRegClass {
672691
}
673692
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
674693
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
694+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
675695
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
676696
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
677697
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -695,6 +715,7 @@ impl InlineAsmRegClass {
695715
Self::Sparc(r) => r.valid_modifiers(arch),
696716
Self::SpirV(r) => r.valid_modifiers(arch),
697717
Self::Wasm(r) => r.valid_modifiers(arch),
718+
Self::Xtensa(r) => r.valid_modifiers(arch),
698719
Self::Bpf(r) => r.valid_modifiers(arch),
699720
Self::Avr(r) => r.valid_modifiers(arch),
700721
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -742,6 +763,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
742763
/// Set of types which can be used with a particular register class.
743764
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
744765
pub enum InlineAsmType {
766+
I1,
745767
I8,
746768
I16,
747769
I32,
@@ -769,6 +791,7 @@ impl InlineAsmType {
769791

770792
pub fn size(self) -> Size {
771793
Size::from_bytes(match self {
794+
Self::I1 => return Size::from_bits(1),
772795
Self::I8 => 1,
773796
Self::I16 => 2,
774797
Self::I32 => 4,
@@ -794,6 +817,7 @@ impl InlineAsmType {
794817
impl fmt::Display for InlineAsmType {
795818
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
796819
match *self {
820+
Self::I1 => f.write_str("i1"),
797821
Self::I8 => f.write_str("i8"),
798822
Self::I16 => f.write_str("i16"),
799823
Self::I32 => f.write_str("i32"),
@@ -896,6 +920,11 @@ pub fn allocatable_registers(
896920
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
897921
map
898922
}
923+
InlineAsmArch::Xtensa => {
924+
let mut map = xtensa::regclass_map();
925+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
926+
map
927+
}
899928
InlineAsmArch::Bpf => {
900929
let mut map = bpf::regclass_map();
901930
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)