Skip to content

Commit 0327b5d

Browse files
authored
Rollup merge of #79917 - sivadeilra:asm_symbols, r=petrochenkov
Use Symbol for inline asm register class names This takes care of one "FIXME": // FIXME: use direct symbol comparison for register class names Instead of using string literals, this uses Symbol for register class names. This is part of work I am doing to improve how Symbol interning works.
2 parents 3a46a6b + 40ed0f6 commit 0327b5d

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

Diff for: compiler/rustc_span/src/symbol.rs

+23
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ symbols! {
460460
document_private_items,
461461
dotdot_in_tuple_patterns,
462462
dotdoteq_in_patterns,
463+
dreg,
464+
dreg_low16,
465+
dreg_low8,
463466
drop,
464467
drop_in_place,
465468
drop_types_in_const,
@@ -544,6 +547,7 @@ symbols! {
544547
format_args_capture,
545548
format_args_nl,
546549
freeze,
550+
freg,
547551
frem_fast,
548552
from,
549553
from_desugaring,
@@ -627,6 +631,7 @@ symbols! {
627631
iter,
628632
keyword,
629633
kind,
634+
kreg,
630635
label,
631636
label_break_value,
632637
lang,
@@ -652,6 +657,7 @@ symbols! {
652657
lint_reasons,
653658
literal,
654659
llvm_asm,
660+
local,
655661
local_inner_macros,
656662
log10f32,
657663
log10f64,
@@ -854,6 +860,9 @@ symbols! {
854860
pub_restricted,
855861
pure,
856862
pushpop_unsafe,
863+
qreg,
864+
qreg_low4,
865+
qreg_low8,
857866
quad_precision_float,
858867
question_mark,
859868
quote,
@@ -875,6 +884,13 @@ symbols! {
875884
reexport_test_harness_main,
876885
reference,
877886
reflect,
887+
reg,
888+
reg16,
889+
reg32,
890+
reg64,
891+
reg_abcd,
892+
reg_byte,
893+
reg_thumb,
878894
register_attr,
879895
register_tool,
880896
relaxed_adts,
@@ -1060,6 +1076,8 @@ symbols! {
10601076
spotlight,
10611077
sqrtf32,
10621078
sqrtf64,
1079+
sreg,
1080+
sreg_low16,
10631081
sse4a_target_feature,
10641082
stable,
10651083
staged_api,
@@ -1215,6 +1233,8 @@ symbols! {
12151233
volatile_load,
12161234
volatile_set_memory,
12171235
volatile_store,
1236+
vreg,
1237+
vreg_low16,
12181238
warn,
12191239
wasm_import_module,
12201240
wasm_target_feature,
@@ -1226,6 +1246,9 @@ symbols! {
12261246
wrapping_mul,
12271247
wrapping_sub,
12281248
write_bytes,
1249+
xmm_reg,
1250+
ymm_reg,
1251+
zmm_reg,
12291252
}
12301253
}
12311254

Diff for: compiler/rustc_target/src/asm/mod.rs

+22-29
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ macro_rules! def_reg_class {
2020
}
2121

2222
impl $arch_regclass {
23-
pub fn name(self) -> &'static str {
23+
pub fn name(self) -> rustc_span::Symbol {
2424
match self {
25-
$(Self::$class => stringify!($class),)*
25+
$(Self::$class => rustc_span::symbol::sym::$class,)*
2626
}
2727
}
2828

29-
pub fn parse(_arch: super::InlineAsmArch, name: &str) -> Result<Self, &'static str> {
29+
pub fn parse(_arch: super::InlineAsmArch, name: rustc_span::Symbol) -> Result<Self, &'static str> {
3030
match name {
3131
$(
32-
stringify!($class) => Ok(Self::$class),
32+
rustc_span::sym::$class => Ok(Self::$class),
3333
)*
3434
_ => Err("unknown register class"),
3535
}
@@ -327,7 +327,7 @@ pub enum InlineAsmRegClass {
327327
}
328328

329329
impl InlineAsmRegClass {
330-
pub fn name(self) -> &'static str {
330+
pub fn name(self) -> Symbol {
331331
match self {
332332
Self::X86(r) => r.name(),
333333
Self::Arm(r) => r.name(),
@@ -422,29 +422,22 @@ impl InlineAsmRegClass {
422422
}
423423

424424
pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static str> {
425-
// FIXME: use direct symbol comparison for register class names
426-
name.with(|name| {
427-
Ok(match arch {
428-
InlineAsmArch::X86 | InlineAsmArch::X86_64 => {
429-
Self::X86(X86InlineAsmRegClass::parse(arch, name)?)
430-
}
431-
InlineAsmArch::Arm => Self::Arm(ArmInlineAsmRegClass::parse(arch, name)?),
432-
InlineAsmArch::AArch64 => {
433-
Self::AArch64(AArch64InlineAsmRegClass::parse(arch, name)?)
434-
}
435-
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {
436-
Self::RiscV(RiscVInlineAsmRegClass::parse(arch, name)?)
437-
}
438-
InlineAsmArch::Nvptx64 => Self::Nvptx(NvptxInlineAsmRegClass::parse(arch, name)?),
439-
InlineAsmArch::Hexagon => {
440-
Self::Hexagon(HexagonInlineAsmRegClass::parse(arch, name)?)
441-
}
442-
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
443-
Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
444-
}
445-
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
446-
InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
447-
})
425+
Ok(match arch {
426+
InlineAsmArch::X86 | InlineAsmArch::X86_64 => {
427+
Self::X86(X86InlineAsmRegClass::parse(arch, name)?)
428+
}
429+
InlineAsmArch::Arm => Self::Arm(ArmInlineAsmRegClass::parse(arch, name)?),
430+
InlineAsmArch::AArch64 => Self::AArch64(AArch64InlineAsmRegClass::parse(arch, name)?),
431+
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {
432+
Self::RiscV(RiscVInlineAsmRegClass::parse(arch, name)?)
433+
}
434+
InlineAsmArch::Nvptx64 => Self::Nvptx(NvptxInlineAsmRegClass::parse(arch, name)?),
435+
InlineAsmArch::Hexagon => Self::Hexagon(HexagonInlineAsmRegClass::parse(arch, name)?),
436+
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
437+
Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
438+
}
439+
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
440+
InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
448441
})
449442
}
450443

@@ -484,7 +477,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
484477
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
485478
match self {
486479
Self::Reg(r) => write!(f, "\"{}\"", r.name()),
487-
Self::RegClass(r) => f.write_str(r.name()),
480+
Self::RegClass(r) => write!(f, "{}", r.name()),
488481
}
489482
}
490483
}

0 commit comments

Comments
 (0)