https://github.com/AnonMiraj created 
https://github.com/llvm/llvm-project/pull/229550

https://llvm-compile-time-tracker.com/compare.php?from=018a46162a84070109760677031bcd636ed6026e&to=a8e612de635e58322015a27282bc49036f3cdd41&stat=instructions%3Au

>From a8e612de635e58322015a27282bc49036f3cdd41 Mon Sep 17 00:00:00 2001
From: Anonmiraj <[email protected]>
Date: Sun, 4 Oct 2026 21:24:36 +0300
Subject: [PATCH] [clang] Reuse the PresumedLoc setLocation already computed

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 22 ++++++++++++++--------
 clang/lib/CodeGen/CGDebugInfo.h   |  4 ++++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index c63a840dedf7ce..84fa65397d3c8a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -367,7 +367,7 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
     CurLocLine = PCLoc.getLine();
     if (CGM.getCodeGenOpts().DebugColumnInfo)
       CurLocColumn = PCLoc.getColumn();
-    CurLocFile = getOrCreateFile(CurLoc);
+    CurLocFile = getOrCreateFile(CurLoc, PCLoc);
   }
 
   // If we've changed files in the middle of a lexical scope go ahead
@@ -584,6 +584,18 @@ std::optional<StringRef> CGDebugInfo::getSource(const 
SourceManager &SM,
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
+  if (Loc.isInvalid())
+    return getOrCreateFile(Loc, PresumedLoc());
+
+  Loc = getMacroDebugLoc(CGM, Loc);
+  if (Loc == CurLoc && CurLocFile)
+    return CurLocFile;
+  return getOrCreateFile(Loc,
+                         
CGM.getContext().getSourceManager().getPresumedLoc(Loc));
+}
+
+llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc,
+                                           const PresumedLoc &PLoc) {
   SourceManager &SM = CGM.getContext().getSourceManager();
   StringRef FileName;
   FileID FID;
@@ -596,11 +608,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation 
Loc) {
     FileName = TheCU->getFile()->getFilename();
     CSInfo = TheCU->getFile()->getChecksum();
   } else {
-    Loc = getMacroDebugLoc(CGM, Loc);
-    if (Loc == CurLoc && CurLocFile)
-      return CurLocFile;
-
-    PresumedLoc PLoc = SM.getPresumedLoc(Loc);
     FileName = PLoc.getFilename();
 
     if (FileName.empty()) {
@@ -627,8 +634,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation 
Loc) {
     if (CSKind)
       CSInfo.emplace(*CSKind, Checksum);
   }
-  return createFile(FileName, CSInfo,
-                    getSource(SM, SM.getFileID(getMacroDebugLoc(CGM, Loc))));
+  return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
 }
 
 llvm::DIFile *CGDebugInfo::createFile(
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 37520394812b44..3e0189dd3733ac 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -778,6 +778,10 @@ class CGDebugInfo {
   /// location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
 
+  /// Same as above, for a Loc that getMacroDebugLoc() has already been
+  /// applied to, and whose presumed location \p PLoc the caller has computed.
+  llvm::DIFile *getOrCreateFile(SourceLocation Loc, const PresumedLoc &PLoc);
+
   /// Create a file debug info descriptor for a source file.
   llvm::DIFile *
   createFile(StringRef FileName,

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to