Skip to content

Commit 1400074

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

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
@@ -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());
@@ -697,6 +698,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
697698
| X86InlineAsmRegClass::kreg0
698699
| X86InlineAsmRegClass::tmm_reg,
699700
) => unreachable!("clobber-only"),
701+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
702+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
703+
Xtensa(XtensaInlineAsmRegClass::breg) => "b",
700704
Wasm(WasmInlineAsmRegClass::local) => "r",
701705
Bpf(BpfInlineAsmRegClass::reg) => "r",
702706
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -793,6 +797,7 @@ fn modifier_to_llvm(
793797
| X86InlineAsmRegClass::kreg0
794798
| X86InlineAsmRegClass::tmm_reg,
795799
) => unreachable!("clobber-only"),
800+
Xtensa(_) => None,
796801
Wasm(WasmInlineAsmRegClass::local) => None,
797802
Bpf(_) => None,
798803
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -859,6 +864,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
859864
| X86InlineAsmRegClass::kreg0
860865
| X86InlineAsmRegClass::tmm_reg,
861866
) => unreachable!("clobber-only"),
867+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
868+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
869+
Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
862870
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
863871
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
864872
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
@@ -471,6 +471,7 @@ symbols! {
471471
async_for_loop,
472472
async_iterator,
473473
async_iterator_poll_next,
474+
atomctl,
474475
atomic,
475476
atomic_mod,
476477
atomics,
@@ -514,6 +515,7 @@ symbols! {
514515
braced_empty_structs,
515516
branch,
516517
breakpoint,
518+
breg,
517519
bridge,
518520
bswap,
519521
btreemap_contains_key,
@@ -651,6 +653,7 @@ symbols! {
651653
constant,
652654
constructor,
653655
convert_identity,
656+
coprocessor,
654657
copy,
655658
copy_closures,
656659
copy_nonoverlapping,
@@ -742,6 +745,7 @@ symbols! {
742745
derive_smart_pointer,
743746
destruct,
744747
destructuring_assignment,
748+
dfpaccel,
745749
diagnostic,
746750
diagnostic_namespace,
747751
direct,
@@ -806,6 +810,7 @@ symbols! {
806810
ermsb_target_feature,
807811
exact_div,
808812
except,
813+
exception,
809814
exchange_malloc,
810815
exclusive_range_pattern,
811816
exhaustive_integer_patterns,
@@ -829,6 +834,7 @@ symbols! {
829834
expr_fragment_specifier_2024,
830835
extended_key_value_attributes,
831836
extended_varargs_abi_support,
837+
extendedl32r,
832838
extern_absolute_paths,
833839
extern_crate_item_prelude,
834840
extern_crate_self,
@@ -940,6 +946,7 @@ symbols! {
940946
format_macro,
941947
format_placeholder,
942948
format_unsafe_arg,
949+
fp,
943950
freeze,
944951
freeze_impls,
945952
freg,
@@ -1002,6 +1009,7 @@ symbols! {
10021009
hashset_iter_ty,
10031010
hexagon_target_feature,
10041011
hidden,
1012+
highpriinterrupts,
10051013
homogeneous_aggregate,
10061014
host,
10071015
html_favicon_url,
@@ -1082,6 +1090,8 @@ symbols! {
10821090
instruction_set,
10831091
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
10841092
integral,
1093+
intel,
1094+
interrupt,
10851095
into_async_iter_into_iter,
10861096
into_future,
10871097
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,
@@ -1269,6 +1281,8 @@ symbols! {
12691281
mir_unwind_unreachable,
12701282
mir_variant,
12711283
miri,
1284+
misc,
1285+
miscsr,
12721286
mmx_reg,
12731287
modifiers,
12741288
module,
@@ -1497,6 +1511,8 @@ symbols! {
14971511
prelude_import,
14981512
preserves_flags,
14991513
prfchw_target_feature,
1514+
prid,
1515+
primitive,
15001516
print_macro,
15011517
println_macro,
15021518
proc_dash_macro: "proc-macro",
@@ -1751,8 +1767,10 @@ symbols! {
17511767
rustdoc_missing_doc_code_examples,
17521768
rustfmt,
17531769
rvalue_static_promotion,
1770+
rvector,
17541771
rwpi,
17551772
s,
1773+
s32c1i,
17561774
s390x_target_feature,
17571775
safety,
17581776
sanitize,
@@ -1960,10 +1978,12 @@ symbols! {
19601978
thread,
19611979
thread_local,
19621980
thread_local_macro,
1981+
threadptr,
19631982
three_way_compare,
19641983
thumb2,
19651984
thumb_mode: "thumb-mode",
19661985
time,
1986+
timerint,
19671987
tmm_reg,
19681988
to_owned_method,
19691989
to_string,
@@ -2150,6 +2170,8 @@ symbols! {
21502170
wasm_import_module,
21512171
wasm_target_feature,
21522172
while_let,
2173+
width,
2174+
windowed,
21532175
windows,
21542176
windows_subsystem,
21552177
with_negative_coherence,
@@ -2168,8 +2190,10 @@ symbols! {
21682190
x86_amx_intrinsics,
21692191
x87_reg,
21702192
xer,
2193+
xloop,
21712194
xmm_reg,
21722195
xop_target_feature,
2196+
xtensa_target_feature,
21732197
yeet_desugar_details,
21742198
yeet_expr,
21752199
yes,

compiler/rustc_target/src/asm/mod.rs

Lines changed: 29 additions & 0 deletions
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(r) => r.overlapping_regs(|r| cb(Self::S390x(r))),
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)