Skip to content

Commit 90f4386

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

File tree

6 files changed

+525
-1
lines changed

6 files changed

+525
-1
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());
@@ -667,6 +668,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
667668
| X86InlineAsmRegClass::kreg0
668669
| X86InlineAsmRegClass::tmm_reg,
669670
) => unreachable!("clobber-only"),
671+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
672+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
673+
Xtensa(XtensaInlineAsmRegClass::breg) => "b",
670674
Wasm(WasmInlineAsmRegClass::local) => "r",
671675
Bpf(BpfInlineAsmRegClass::reg) => "r",
672676
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -765,6 +769,7 @@ fn modifier_to_llvm(
765769
| X86InlineAsmRegClass::kreg0
766770
| X86InlineAsmRegClass::tmm_reg,
767771
) => unreachable!("clobber-only"),
772+
Xtensa(_) => None,
768773
Wasm(WasmInlineAsmRegClass::local) => None,
769774
Bpf(_) => None,
770775
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -834,6 +839,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
834839
| X86InlineAsmRegClass::kreg0
835840
| X86InlineAsmRegClass::tmm_reg,
836841
) => unreachable!("clobber-only"),
842+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
843+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
844+
Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
837845
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
838846
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
839847
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
@@ -464,6 +464,7 @@ symbols! {
464464
async_for_loop,
465465
async_iterator,
466466
async_iterator_poll_next,
467+
atomctl,
467468
atomic,
468469
atomic_mod,
469470
atomics,
@@ -509,6 +510,7 @@ symbols! {
509510
braced_empty_structs,
510511
branch,
511512
breakpoint,
513+
breg,
512514
bridge,
513515
bswap,
514516
btreemap_contains_key,
@@ -648,6 +650,7 @@ symbols! {
648650
constant,
649651
constructor,
650652
convert_identity,
653+
coprocessor,
651654
copy,
652655
copy_closures,
653656
copy_nonoverlapping,
@@ -740,6 +743,7 @@ symbols! {
740743
derive_smart_pointer,
741744
destruct,
742745
destructuring_assignment,
746+
dfpaccel,
743747
diagnostic,
744748
diagnostic_namespace,
745749
direct,
@@ -804,6 +808,7 @@ symbols! {
804808
ermsb_target_feature,
805809
exact_div,
806810
except,
811+
exception,
807812
exchange_malloc,
808813
exclusive_range_pattern,
809814
exhaustive_integer_patterns,
@@ -827,6 +832,7 @@ symbols! {
827832
expr_fragment_specifier_2024,
828833
extended_key_value_attributes,
829834
extended_varargs_abi_support,
835+
extendedl32r,
830836
extern_absolute_paths,
831837
extern_crate_item_prelude,
832838
extern_crate_self,
@@ -938,6 +944,7 @@ symbols! {
938944
format_macro,
939945
format_placeholder,
940946
format_unsafe_arg,
947+
fp,
941948
freeze,
942949
freeze_impls,
943950
freg,
@@ -1000,6 +1007,7 @@ symbols! {
10001007
hashset_iter_ty,
10011008
hexagon_target_feature,
10021009
hidden,
1010+
highpriinterrupts,
10031011
hint,
10041012
homogeneous_aggregate,
10051013
host,
@@ -1081,6 +1089,8 @@ symbols! {
10811089
instruction_set,
10821090
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
10831091
integral,
1092+
intel,
1093+
interrupt,
10841094
into_async_iter_into_iter,
10851095
into_future,
10861096
into_iter,
@@ -1172,6 +1182,7 @@ symbols! {
11721182
loongarch_target_feature,
11731183
loop_break_value,
11741184
lt,
1185+
mac16,
11751186
macro_at_most_once_rep,
11761187
macro_attributes_in_derive_output,
11771188
macro_escape,
@@ -1215,6 +1226,7 @@ symbols! {
12151226
mem_variant_count,
12161227
mem_zeroed,
12171228
member_constraints,
1229+
memctl,
12181230
memory,
12191231
memtag,
12201232
message,
@@ -1270,6 +1282,8 @@ symbols! {
12701282
mir_unwind_unreachable,
12711283
mir_variant,
12721284
miri,
1285+
misc,
1286+
miscsr,
12731287
mmx_reg,
12741288
modifiers,
12751289
module,
@@ -1498,6 +1512,8 @@ symbols! {
14981512
prelude_import,
14991513
preserves_flags,
15001514
prfchw_target_feature,
1515+
prid,
1516+
primitive,
15011517
print_macro,
15021518
println_macro,
15031519
proc_dash_macro: "proc-macro",
@@ -1755,8 +1771,10 @@ symbols! {
17551771
rustdoc_missing_doc_code_examples,
17561772
rustfmt,
17571773
rvalue_static_promotion,
1774+
rvector,
17581775
rwpi,
17591776
s,
1777+
s32c1i,
17601778
s390x_target_feature,
17611779
safety,
17621780
sanitize,
@@ -1966,10 +1984,12 @@ symbols! {
19661984
thread,
19671985
thread_local,
19681986
thread_local_macro,
1987+
threadptr,
19691988
three_way_compare,
19701989
thumb2,
19711990
thumb_mode: "thumb-mode",
19721991
time,
1992+
timerint,
19731993
tmm_reg,
19741994
to_owned_method,
19751995
to_string,
@@ -2157,6 +2177,8 @@ symbols! {
21572177
wasm_import_module,
21582178
wasm_target_feature,
21592179
while_let,
2180+
width,
2181+
windowed,
21602182
windows,
21612183
windows_subsystem,
21622184
with_negative_coherence,
@@ -2175,8 +2197,10 @@ symbols! {
21752197
x86_amx_intrinsics,
21762198
x87_reg,
21772199
xer,
2200+
xloop,
21782201
xmm_reg,
21792202
xop_target_feature,
2203+
xtensa_target_feature,
21802204
yeet_desugar_details,
21812205
yeet_expr,
21822206
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),
@@ -622,6 +640,7 @@ impl InlineAsmRegClass {
622640
Self::Sparc(r) => r.supported_types(arch),
623641
Self::SpirV(r) => r.supported_types(arch),
624642
Self::Wasm(r) => r.supported_types(arch),
643+
Self::Xtensa(r) => r.supported_types(arch),
625644
Self::Bpf(r) => r.supported_types(arch),
626645
Self::Avr(r) => r.supported_types(arch),
627646
Self::Msp430(r) => r.supported_types(arch),
@@ -662,6 +681,7 @@ impl InlineAsmRegClass {
662681
}
663682
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(name)?),
664683
InlineAsmArch::Avr => Self::Avr(AvrInlineAsmRegClass::parse(name)?),
684+
InlineAsmArch::Xtensa => Self::Xtensa(XtensaInlineAsmRegClass::parse(name)?),
665685
InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmRegClass::parse(name)?),
666686
InlineAsmArch::M68k => Self::M68k(M68kInlineAsmRegClass::parse(name)?),
667687
InlineAsmArch::CSKY => Self::CSKY(CSKYInlineAsmRegClass::parse(name)?),
@@ -685,6 +705,7 @@ impl InlineAsmRegClass {
685705
Self::Sparc(r) => r.valid_modifiers(arch),
686706
Self::SpirV(r) => r.valid_modifiers(arch),
687707
Self::Wasm(r) => r.valid_modifiers(arch),
708+
Self::Xtensa(r) => r.valid_modifiers(arch),
688709
Self::Bpf(r) => r.valid_modifiers(arch),
689710
Self::Avr(r) => r.valid_modifiers(arch),
690711
Self::Msp430(r) => r.valid_modifiers(arch),
@@ -729,6 +750,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
729750
/// Set of types which can be used with a particular register class.
730751
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
731752
pub enum InlineAsmType {
753+
I1,
732754
I8,
733755
I16,
734756
I32,
@@ -756,6 +778,7 @@ impl InlineAsmType {
756778

757779
pub fn size(self) -> Size {
758780
Size::from_bytes(match self {
781+
Self::I1 => return Size::from_bits(1),
759782
Self::I8 => 1,
760783
Self::I16 => 2,
761784
Self::I32 => 4,
@@ -781,6 +804,7 @@ impl InlineAsmType {
781804
impl fmt::Display for InlineAsmType {
782805
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
783806
match *self {
807+
Self::I1 => f.write_str("i1"),
784808
Self::I8 => f.write_str("i8"),
785809
Self::I16 => f.write_str("i16"),
786810
Self::I32 => f.write_str("i32"),
@@ -883,6 +907,11 @@ pub fn allocatable_registers(
883907
wasm::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
884908
map
885909
}
910+
InlineAsmArch::Xtensa => {
911+
let mut map = xtensa::regclass_map();
912+
xtensa::fill_reg_map(arch, reloc_model, target_features, target, &mut map);
913+
map
914+
}
886915
InlineAsmArch::Bpf => {
887916
let mut map = bpf::regclass_map();
888917
bpf::fill_reg_map(arch, reloc_model, target_features, target, &mut map);

0 commit comments

Comments
 (0)