Skip to content

Commit 8e82eda

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

File tree

6 files changed

+525
-0
lines changed

6 files changed

+525
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
279279
}
280280
InlineAsmArch::SpirV => {}
281281
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
282+
InlineAsmArch::Xtensa => {}
282283
InlineAsmArch::Bpf => {}
283284
InlineAsmArch::Msp430 => {
284285
constraints.push("~{sr}".to_string());
@@ -684,6 +685,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
684685
| X86InlineAsmRegClass::kreg0
685686
| X86InlineAsmRegClass::tmm_reg,
686687
) => unreachable!("clobber-only"),
688+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
689+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
690+
Xtensa(XtensaInlineAsmRegClass::breg) => "b",
687691
Wasm(WasmInlineAsmRegClass::local) => "r",
688692
Bpf(BpfInlineAsmRegClass::reg) => "r",
689693
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -783,6 +787,7 @@ fn modifier_to_llvm(
783787
| X86InlineAsmRegClass::kreg0
784788
| X86InlineAsmRegClass::tmm_reg,
785789
) => unreachable!("clobber-only"),
790+
Xtensa(_) => None,
786791
Wasm(WasmInlineAsmRegClass::local) => None,
787792
Bpf(_) => None,
788793
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -852,6 +857,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
852857
| X86InlineAsmRegClass::kreg0
853858
| X86InlineAsmRegClass::tmm_reg,
854859
) => unreachable!("clobber-only"),
860+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
861+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
862+
Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
855863
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
856864
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
857865
Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),

compiler/rustc_span/src/symbol.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ symbols! {
501501
async_iterator,
502502
async_iterator_poll_next,
503503
async_trait_bounds,
504+
atomctl,
504505
atomic,
505506
atomic_mod,
506507
atomics,
@@ -547,6 +548,7 @@ symbols! {
547548
braced_empty_structs,
548549
branch,
549550
breakpoint,
551+
breg,
550552
bridge,
551553
bswap,
552554
btreemap_contains_key,
@@ -703,6 +705,7 @@ symbols! {
703705
contracts_internals,
704706
contracts_requires,
705707
convert_identity,
708+
coprocessor,
706709
copy,
707710
copy_closures,
708711
copy_nonoverlapping,
@@ -795,6 +798,7 @@ symbols! {
795798
derive_smart_pointer,
796799
destruct,
797800
destructuring_assignment,
801+
dfpaccel,
798802
diagnostic,
799803
diagnostic_namespace,
800804
direct,
@@ -862,6 +866,7 @@ symbols! {
862866
ermsb_target_feature,
863867
exact_div,
864868
except,
869+
exception,
865870
exchange_malloc,
866871
exclusive_range_pattern,
867872
exhaustive_integer_patterns,
@@ -885,6 +890,7 @@ symbols! {
885890
expr_fragment_specifier_2024,
886891
extended_key_value_attributes,
887892
extended_varargs_abi_support,
893+
extendedl32r,
888894
extern_absolute_paths,
889895
extern_crate_item_prelude,
890896
extern_crate_self,
@@ -998,6 +1004,7 @@ symbols! {
9981004
format_macro,
9991005
format_placeholder,
10001006
format_unsafe_arg,
1007+
fp,
10011008
freeze,
10021009
freeze_impls,
10031010
freg,
@@ -1064,6 +1071,7 @@ symbols! {
10641071
hashset_iter_ty,
10651072
hexagon_target_feature,
10661073
hidden,
1074+
highpriinterrupts,
10671075
hint,
10681076
homogeneous_aggregate,
10691077
host,
@@ -1146,6 +1154,8 @@ symbols! {
11461154
instruction_set,
11471155
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
11481156
integral,
1157+
intel,
1158+
interrupt,
11491159
into_async_iter_into_iter,
11501160
into_future,
11511161
into_iter,
@@ -1240,6 +1250,7 @@ symbols! {
12401250
loop_break_value,
12411251
lt,
12421252
m68k_target_feature,
1253+
mac16,
12431254
macro_at_most_once_rep,
12441255
macro_attributes_in_derive_output,
12451256
macro_escape,
@@ -1283,6 +1294,7 @@ symbols! {
12831294
mem_variant_count,
12841295
mem_zeroed,
12851296
member_constraints,
1297+
memctl,
12861298
memory,
12871299
memtag,
12881300
message,
@@ -1338,6 +1350,8 @@ symbols! {
13381350
mir_unwind_unreachable,
13391351
mir_variant,
13401352
miri,
1353+
misc,
1354+
miscsr,
13411355
mmx_reg,
13421356
modifiers,
13431357
module,
@@ -1565,6 +1579,8 @@ symbols! {
15651579
prelude_import,
15661580
preserves_flags,
15671581
prfchw_target_feature,
1582+
prid,
1583+
primitive,
15681584
print_macro,
15691585
println_macro,
15701586
proc_dash_macro: "proc-macro",
@@ -1819,8 +1835,10 @@ symbols! {
18191835
rustdoc_missing_doc_code_examples,
18201836
rustfmt,
18211837
rvalue_static_promotion,
1838+
rvector,
18221839
rwpi,
18231840
s,
1841+
s32c1i,
18241842
s390x_target_feature,
18251843
safety,
18261844
sanitize,
@@ -2037,10 +2055,12 @@ symbols! {
20372055
thread,
20382056
thread_local,
20392057
thread_local_macro,
2058+
threadptr,
20402059
three_way_compare,
20412060
thumb2,
20422061
thumb_mode: "thumb-mode",
20432062
time,
2063+
timerint,
20442064
tmm_reg,
20452065
to_owned_method,
20462066
to_string,
@@ -2235,6 +2255,8 @@ symbols! {
22352255
wasm_import_module,
22362256
wasm_target_feature,
22372257
while_let,
2258+
width,
2259+
windowed,
22382260
windows,
22392261
windows_subsystem,
22402262
with_negative_coherence,
@@ -2256,8 +2278,10 @@ symbols! {
22562278
x87_reg,
22572279
x87_target_feature,
22582280
xer,
2281+
xloop,
22592282
xmm_reg,
22602283
xop_target_feature,
2284+
xtensa_target_feature,
22612285
yeet_desugar_details,
22622286
yeet_expr,
22632287
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)]
@@ -237,6 +239,7 @@ pub enum InlineAsmArch {
237239
SpirV,
238240
Wasm32,
239241
Wasm64,
242+
Xtensa,
240243
Bpf,
241244
Avr,
242245
Msp430,
@@ -269,6 +272,7 @@ impl FromStr for InlineAsmArch {
269272
"spirv" => Ok(Self::SpirV),
270273
"wasm32" => Ok(Self::Wasm32),
271274
"wasm64" => Ok(Self::Wasm64),
275+
"xtensa" => Ok(Self::Xtensa),
272276
"bpf" => Ok(Self::Bpf),
273277
"avr" => Ok(Self::Avr),
274278
"msp430" => Ok(Self::Msp430),
@@ -295,6 +299,7 @@ pub enum InlineAsmReg {
295299
Sparc(SparcInlineAsmReg),
296300
SpirV(SpirVInlineAsmReg),
297301
Wasm(WasmInlineAsmReg),
302+
Xtensa(XtensaInlineAsmReg),
298303
Bpf(BpfInlineAsmReg),
299304
Avr(AvrInlineAsmReg),
300305
Msp430(Msp430InlineAsmReg),
@@ -317,6 +322,7 @@ impl InlineAsmReg {
317322
Self::Mips(r) => r.name(),
318323
Self::S390x(r) => r.name(),
319324
Self::Sparc(r) => r.name(),
325+
Self::Xtensa(r) => r.name(),
320326
Self::Bpf(r) => r.name(),
321327
Self::Avr(r) => r.name(),
322328
Self::Msp430(r) => r.name(),
@@ -338,6 +344,7 @@ impl InlineAsmReg {
338344
Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()),
339345
Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()),
340346
Self::Sparc(r) => InlineAsmRegClass::Sparc(r.reg_class()),
347+
Self::Xtensa(r) => InlineAsmRegClass::Xtensa(r.reg_class()),
341348
Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()),
342349
Self::Avr(r) => InlineAsmRegClass::Avr(r.reg_class()),
343350
Self::Msp430(r) => InlineAsmRegClass::Msp430(r.reg_class()),
@@ -369,6 +376,9 @@ impl InlineAsmReg {
369376
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
370377
Self::Mips(MipsInlineAsmReg::parse(name)?)
371378
}
379+
InlineAsmArch::Xtensa => {
380+
Self::Xtensa(XtensaInlineAsmReg::parse(name)?)
381+
}
372382
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse(name)?),
373383
InlineAsmArch::Sparc | InlineAsmArch::Sparc64 => {
374384
Self::Sparc(SparcInlineAsmReg::parse(name)?)
@@ -408,6 +418,7 @@ impl InlineAsmReg {
408418
Self::Sparc(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
409419
Self::Bpf(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
410420
Self::Avr(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
421+
Self::Xtensa(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
411422
Self::Msp430(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
412423
Self::M68k(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
413424
Self::CSKY(r) => r.validate(arch, reloc_model, target_features, target, is_clobber),
@@ -434,6 +445,7 @@ impl InlineAsmReg {
434445
Self::Mips(r) => r.emit(out, arch, modifier),
435446
Self::S390x(r) => r.emit(out, arch, modifier),
436447
Self::Sparc(r) => r.emit(out, arch, modifier),
448+
Self::Xtensa(r) => r.emit(out, arch, modifier),
437449
Self::Bpf(r) => r.emit(out, arch, modifier),
438450
Self::Avr(r) => r.emit(out, arch, modifier),
439451
Self::Msp430(r) => r.emit(out, arch, modifier),
@@ -455,6 +467,7 @@ impl InlineAsmReg {
455467
Self::Mips(_) => cb(self),
456468
Self::S390x(r) => r.overlapping_regs(|r| cb(Self::S390x(r))),
457469
Self::Sparc(_) => cb(self),
470+
Self::Xtensa(_) => cb(self),
458471
Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))),
459472
Self::Avr(r) => r.overlapping_regs(|r| cb(Self::Avr(r))),
460473
Self::Msp430(_) => cb(self),
@@ -481,6 +494,7 @@ pub enum InlineAsmRegClass {
481494
Sparc(SparcInlineAsmRegClass),
482495
SpirV(SpirVInlineAsmRegClass),
483496
Wasm(WasmInlineAsmRegClass),
497+
Xtensa(XtensaInlineAsmRegClass),
484498
Bpf(BpfInlineAsmRegClass),
485499
Avr(AvrInlineAsmRegClass),
486500
Msp430(Msp430InlineAsmRegClass),
@@ -506,6 +520,7 @@ impl InlineAsmRegClass {
506520
Self::Sparc(r) => r.name(),
507521
Self::SpirV(r) => r.name(),
508522
Self::Wasm(r) => r.name(),
523+
Self::Xtensa(r) => r.name(),
509524
Self::Bpf(r) => r.name(),
510525
Self::Avr(r) => r.name(),
511526
Self::Msp430(r) => r.name(),
@@ -533,6 +548,7 @@ impl InlineAsmRegClass {
533548
Self::Sparc(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Sparc),
534549
Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV),
535550
Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm),
551+
Self::Xtensa(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Xtensa),
536552
Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf),
537553
Self::Avr(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Avr),
538554
Self::Msp430(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Msp430),
@@ -563,6 +579,7 @@ impl InlineAsmRegClass {
563579
Self::Sparc(r) => r.suggest_modifier(arch, ty),
564580
Self::SpirV(r) => r.suggest_modifier(arch, ty),
565581
Self::Wasm(r) => r.suggest_modifier(arch, ty),
582+
Self::Xtensa(r) => r.suggest_modifier(arch, ty),
566583
Self::Bpf(r) => r.suggest_modifier(arch, ty),
567584
Self::Avr(r) => r.suggest_modifier(arch, ty),
568585
Self::Msp430(r) => r.suggest_modifier(arch, ty),
@@ -593,6 +610,7 @@ impl InlineAsmRegClass {
593610
Self::Sparc(r) => r.default_modifier(arch),
594611
Self::SpirV(r) => r.default_modifier(arch),
595612
Self::Wasm(r) => r.default_modifier(arch),
613+
Self::Xtensa(r) => r.default_modifier(arch),
596614
Self::Bpf(r) => r.default_modifier(arch),
597615
Self::Avr(r) => r.default_modifier(arch),
598616
Self::Msp430(r) => r.default_modifier(arch),
@@ -626,6 +644,7 @@ impl InlineAsmRegClass {
626644
Self::Sparc(r) => r.supported_types(arch),
627645
Self::SpirV(r) => r.supported_types(arch),
628646
Self::Wasm(r) => r.supported_types(arch),
647+
Self::Xtensa(r) => r.supported_types(arch),
629648
Self::Bpf(r) => r.supported_types(arch),
630649
Self::Avr(r) => r.supported_types(arch),
631650
Self::Msp430(r) => r.supported_types(arch),
@@ -666,6 +685,7 @@ impl InlineAsmRegClass {
666685
}
667686
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
668687
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
688+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
669689
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
670690
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
671691
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -689,6 +709,7 @@ impl InlineAsmRegClass {
689709
Self::Sparc(r) => r.valid_modifiers(arch),
690710
Self::SpirV(r) => r.valid_modifiers(arch),
691711
Self::Wasm(r) => r.valid_modifiers(arch),
712+
Self::Xtensa(r) => r.valid_modifiers(arch),
692713
Self::Bpf(r) => r.valid_modifiers(arch),
693714
Self::Avr(r) => r.valid_modifiers(arch),
694715
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -736,6 +757,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
736757
/// Set of types which can be used with a particular register class.
737758
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
738759
pub enum InlineAsmType {
760+
I1,
739761
I8,
740762
I16,
741763
I32,
@@ -763,6 +785,7 @@ impl InlineAsmType {
763785

764786
pub fn size(self) -> Size {
765787
Size::from_bytes(match self {
788+
Self::I1 => return Size::from_bits(1),
766789
Self::I8 => 1,
767790
Self::I16 => 2,
768791
Self::I32 => 4,
@@ -788,6 +811,7 @@ impl InlineAsmType {
788811
impl fmt::Display for InlineAsmType {
789812
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
790813
match *self {
814+
Self::I1 => f.write_str("i1"),
791815
Self::I8 => f.write_str("i8"),
792816
Self::I16 => f.write_str("i16"),
793817
Self::I32 => f.write_str("i32"),
@@ -890,6 +914,11 @@ pub fn allocatable_registers(
890914
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
891915
map
892916
}
917+
InlineAsmArch::Xtensa => {
918+
let mut map = xtensa::regclass_map();
919+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
920+
map
921+
}
893922
InlineAsmArch::Bpf => {
894923
let mut map = bpf::regclass_map();
895924
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)