[clang] [clang] Call getOrCreateFile() just once in AddStringLiteralDebugInfo() (PR #240382)
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 06:07:28 PST 2026
https://github.com/nico created https://github.com/llvm/llvm-project/pull/240382
getOrCreateFile(Loc) is stored in a variable `File` 3 lines up,
so use that variable instead of calling the function again.
Mostly for code cleanliness, but for usb_ids_gen.cc (from #229808)
this is also a small (0.4%) reduction in retired instructions.
No behavior change.
>From afc44a2db2b491307eec639a8a71ad609c4e4aeb Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 9 Nov 2026 09:01:43 -0500
Subject: [PATCH 1/2] [clang] Call getOrCreateFile() just once in
AddStringLiteralDebugInfo()
getOrCreateFile(Loc) is stored in a variable `File` 3 lines up,
so use that variable instead of calling the function again.
Mostly for code cleanliness, but for usb_ids_gen.cc (from #229808)
this is also a small (0.4%) reduction in retired instructions.
No behavior change.
---
clang/lib/CodeGen/CGDebugInfo.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 63cf4110d9d0ad..460dba41449c16 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6619,7 +6619,7 @@ void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
llvm::DIFile *File = getOrCreateFile(Loc);
llvm::DIGlobalVariableExpression *Debug =
DBuilder.createGlobalVariableExpression(
- nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
+ nullptr, StringRef(), StringRef(), File,
getLineNumber(Loc), getOrCreateType(S->getType(), File), true);
GV->addDebugInfo(Debug);
}
>From 3a02b1a02dc13b4a178c64517bfd16643e1ba00e Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 9 Nov 2026 09:06:04 -0500
Subject: [PATCH 2/2] format
---
clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 460dba41449c16..3aa7eccb433cca 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6619,8 +6619,8 @@ void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
llvm::DIFile *File = getOrCreateFile(Loc);
llvm::DIGlobalVariableExpression *Debug =
DBuilder.createGlobalVariableExpression(
- nullptr, StringRef(), StringRef(), File,
- getLineNumber(Loc), getOrCreateType(S->getType(), File), true);
+ nullptr, StringRef(), StringRef(), File, getLineNumber(Loc),
+ getOrCreateType(S->getType(), File), true);
GV->addDebugInfo(Debug);
}
More information about the cfe-commits
mailing list