Skip to content

Commit 8a454f8

Browse files
Rollup merge of #89072 - bjorn3:less_symbol_as_str, r=michaelwoerister
Avoid a couple of Symbol::as_str calls in cg_llvm This should improve performance a tiny bit. Also remove `Symbol::len` and make `SymbolIndex` private.
2 parents ee2e97c + df72749 commit 8a454f8

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
9696
let arg_tys = sig.inputs();
9797
let ret_ty = sig.output();
9898
let name = tcx.item_name(def_id);
99-
let name_str = &*name.as_str();
10099

101100
let llret_ty = self.layout_of(ret_ty).llvm_type(self);
102101
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
@@ -230,9 +229,14 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
230229
&[args[0].immediate(), y],
231230
)
232231
}
233-
sym::ctlz_nonzero | sym::cttz_nonzero => {
232+
sym::ctlz_nonzero => {
234233
let y = self.const_bool(true);
235-
let llvm_name = &format!("llvm.{}.i{}", &name_str[..4], width);
234+
let llvm_name = &format!("llvm.ctlz.i{}", width);
235+
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
236+
}
237+
sym::cttz_nonzero => {
238+
let y = self.const_bool(true);
239+
let llvm_name = &format!("llvm.cttz.i{}", width);
236240
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
237241
}
238242
sym::ctpop => self.call_intrinsic(
@@ -353,7 +357,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
353357
return;
354358
}
355359

356-
_ if name_str.starts_with("simd_") => {
360+
_ if name.as_str().starts_with("simd_") => {
357361
match generic_simd_intrinsic(self, name, callee_ty, args, ret_ty, llret_ty, span) {
358362
Ok(llval) => llval,
359363
Err(()) => return,
@@ -843,7 +847,6 @@ fn generic_simd_intrinsic(
843847
let sig =
844848
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
845849
let arg_tys = sig.inputs();
846-
let name_str = &*name.as_str();
847850

848851
if name == sym::simd_select_bitmask {
849852
let in_ty = arg_tys[0];
@@ -917,7 +920,7 @@ fn generic_simd_intrinsic(
917920
));
918921
}
919922

920-
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
923+
if let Some(stripped) = name.as_str().strip_prefix("simd_shuffle") {
921924
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
922925
// If there is no suffix, use the index array length.
923926
let n: u64 = if stripped.is_empty() {

compiler/rustc_expand/src/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl server::Literal for Rustc<'_> {
577577
}
578578

579579
// Synthesize a new symbol that includes the minus sign.
580-
let symbol = Symbol::intern(&s[..1 + lit.symbol.len()]);
580+
let symbol = Symbol::intern(&s[..1 + lit.symbol.as_str().len()]);
581581
lit = token::Lit::new(lit.kind, symbol, lit.suffix);
582582
}
583583

compiler/rustc_span/src/symbol.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ impl fmt::Display for MacroRulesNormalizedIdent {
16181618
pub struct Symbol(SymbolIndex);
16191619

16201620
rustc_index::newtype_index! {
1621-
pub struct SymbolIndex { .. }
1621+
struct SymbolIndex { .. }
16221622
}
16231623

16241624
impl Symbol {
@@ -1644,10 +1644,6 @@ impl Symbol {
16441644
self.0.as_u32()
16451645
}
16461646

1647-
pub fn len(self) -> usize {
1648-
with_session_globals(|session_globals| session_globals.symbol_interner.get(self).len())
1649-
}
1650-
16511647
pub fn is_empty(self) -> bool {
16521648
self == kw::Empty
16531649
}

0 commit comments

Comments
 (0)