Skip to content

Commit

Permalink
asm! support for the Xtensa architecture (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Aug 24, 2022
1 parent 1591795 commit d89202f
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
InlineAsmArch::S390x => {}
InlineAsmArch::SpirV => {}
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
InlineAsmArch::Xtensa => {}
InlineAsmArch::Bpf => {}
InlineAsmArch::Msp430 => {
constraints.push("~{sr}".to_string());
Expand Down Expand Up @@ -608,6 +609,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
| X86InlineAsmRegClass::tmm_reg,
) => unreachable!("clobber-only"),
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
Expand Down Expand Up @@ -661,6 +665,7 @@ fn modifier_to_llvm(
InlineAsmRegClass::Mips(_) => None,
InlineAsmRegClass::Nvptx(_) => None,
InlineAsmRegClass::PowerPC(_) => None,
InlineAsmRegClass::Xtensa(_) => None,
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
Expand Down Expand Up @@ -774,6 +779,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
unreachable!("clobber-only")
}
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),
Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("reference-types", Some(sym::wasm_target_feature)),
];

const XTENSA_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("fp", Some(sym::xtensa_target_feature)),
("windowed", Some(sym::xtensa_target_feature)),
("bool", Some(sym::xtensa_target_feature)),
("loop", Some(sym::xtensa_target_feature)),
("sext", Some(sym::xtensa_target_feature)),
("nsa", Some(sym::xtensa_target_feature)),
("mul32", Some(sym::xtensa_target_feature)),
("mul32high", Some(sym::xtensa_target_feature)),
("div32", Some(sym::xtensa_target_feature)),
("mac16", Some(sym::xtensa_target_feature)),
("dfpaccel", Some(sym::xtensa_target_feature)),
("s32c1i", Some(sym::xtensa_target_feature)),
("threadptr", Some(sym::xtensa_target_feature)),
("extendedl32r", Some(sym::xtensa_target_feature)),
("atomctl", Some(sym::xtensa_target_feature)),
("memctl", Some(sym::xtensa_target_feature)),
("debug", Some(sym::xtensa_target_feature)),
("exception", Some(sym::xtensa_target_feature)),
("highpriinterrupts", Some(sym::xtensa_target_feature)),
("coprocessor", Some(sym::xtensa_target_feature)),
("interrupt", Some(sym::xtensa_target_feature)),
("rvector", Some(sym::xtensa_target_feature)),
("timerint", Some(sym::xtensa_target_feature)),
("prid", Some(sym::xtensa_target_feature)),
("regprotect", Some(sym::xtensa_target_feature)),
("miscsr", Some(sym::xtensa_target_feature)),
];

const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];

/// When rustdoc is running, provide a list of all known features so that all their respective
Expand All @@ -267,6 +296,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
.chain(MIPS_ALLOWED_FEATURES.iter())
.chain(RISCV_ALLOWED_FEATURES.iter())
.chain(WASM_ALLOWED_FEATURES.iter())
.chain(XTENSA_ALLOWED_FEATURES.iter())
.chain(BPF_ALLOWED_FEATURES.iter())
.cloned()
}
Expand All @@ -281,6 +311,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
"xtensa" => XTENSA_ALLOWED_FEATURES,
"bpf" => BPF_ALLOWED_FEATURES,
_ => &[],
}
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ symbols! {
assume_init,
async_await,
async_closure,
atomctl,
atomic,
atomic_mod,
atomics,
Expand Down Expand Up @@ -414,6 +415,7 @@ symbols! {
braced_empty_structs,
branch,
breakpoint,
breg,
bridge,
bswap,
c_str,
Expand Down Expand Up @@ -525,6 +527,7 @@ symbols! {
contents,
context,
convert,
coprocessor,
copy,
copy_closures,
copy_nonoverlapping,
Expand Down Expand Up @@ -591,6 +594,7 @@ symbols! {
derive_default_enum,
destruct,
destructuring_assignment,
dfpaccel,
diagnostic,
direct,
discriminant_kind,
Expand Down Expand Up @@ -648,6 +652,7 @@ symbols! {
ermsb_target_feature,
exact_div,
except,
exception,
exchange_malloc,
exclusive_range_pattern,
exhaustive_integer_patterns,
Expand All @@ -663,6 +668,7 @@ symbols! {
export_name,
expr,
extended_key_value_attributes,
extendedl32r,
extern_absolute_paths,
extern_crate_item_prelude,
extern_crate_self,
Expand Down Expand Up @@ -757,6 +763,7 @@ symbols! {
hash,
hexagon_target_feature,
hidden,
highpriinterrupts,
homogeneous_aggregate,
html_favicon_url,
html_logo_url,
Expand Down Expand Up @@ -804,6 +811,7 @@ symbols! {
integer_: "integer",
integral,
intel,
interrupt,
into_future,
into_iter,
intra_doc_pointers,
Expand Down Expand Up @@ -864,6 +872,7 @@ symbols! {
logf64,
loop_break_value,
lt,
mac16,
macro_at_most_once_rep,
macro_attributes_in_derive_output,
macro_escape,
Expand Down Expand Up @@ -902,6 +911,7 @@ symbols! {
mem_variant_count,
mem_zeroed,
member_constraints,
memctl,
memory,
memtag,
message,
Expand All @@ -919,6 +929,7 @@ symbols! {
mips_target_feature,
miri,
misc,
miscsr,
mmx_reg,
modifiers,
module,
Expand Down Expand Up @@ -1071,6 +1082,7 @@ symbols! {
prelude,
prelude_import,
preserves_flags,
prid,
primitive,
print_macro,
println_macro,
Expand Down Expand Up @@ -1255,7 +1267,9 @@ symbols! {
rustdoc_internals,
rustfmt,
rvalue_static_promotion,
rvector,
s,
s32c1i,
sanitize,
sanitizer_runtime,
saturating_add,
Expand Down Expand Up @@ -1424,8 +1438,10 @@ symbols! {
thread,
thread_local,
thread_local_macro,
threadptr,
thumb2,
thumb_mode: "thumb-mode",
timerint,
tmm_reg,
todo_macro,
tool_attributes,
Expand Down Expand Up @@ -1548,6 +1564,7 @@ symbols! {
wasm_target_feature,
while_let,
width,
windowed,
windows,
windows_subsystem,
with_negative_coherence,
Expand All @@ -1561,7 +1578,9 @@ symbols! {
writeln_macro,
x87_reg,
xer,
xloop,
xmm_reg,
xtensa_target_feature,
yeet_desugar_details,
yeet_expr,
ymm_reg,
Expand Down
Loading

0 comments on commit d89202f

Please sign in to comment.