Skip to content

Commit

Permalink
Auto merge of rust-lang#122567 - erikdesjardins:noname, r=<try>
Browse files Browse the repository at this point in the history
Avoid naming LLVM basic blocks when `fewer_names` is true

This may be a small perf win.

r? `@ghost`
  • Loading branch information
bors committed Mar 15, 2024
2 parents 72d7897 + 32fb9cd commit 6034f04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {

fn append_block(cx: &'a CodegenCx<'ll, 'tcx>, llfn: &'ll Value, name: &str) -> &'ll BasicBlock {
unsafe {
let name = SmallCStr::new(name);
llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, name.as_ptr())
let c_str_name;
let name_ptr = if cx.tcx.sess.fewer_names() {
const { c"".as_ptr().cast() }
} else {
c_str_name = SmallCStr::new(name);
c_str_name.as_ptr()
};
llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, name_ptr)
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![feature(exact_size_is_empty)]
#![feature(extern_types)]
#![feature(hash_raw_entry)]
#![feature(inline_const)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(impl_trait_in_assoc_type)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
match self.cached_llbbs[bb] {
CachedLlbb::None => {
// FIXME(eddyb) only name the block if `fewer_names` is `false`.
let llbb = Bx::append_block(self.cx, self.llfn, &format!("{bb:?}"));
self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
Some(llbb)
Expand Down

0 comments on commit 6034f04

Please sign in to comment.