Skip to content

Commit 2e4d2d8

Browse files
committed
Reapply "[DebugInfo] Alternate (more efficient) MD5 fix"
D155991 changed the file lookup to do a full string compare on the filename; however, this added ~0.5% to compile time with -g. Go back to the previous pointer-based lookup, but capture the main file's checksum as well as its name to use when creating the extra DIFile entry. This causes all entries to be consistent and also avoids computing the checksum twice. This reverts commit 21e7f73. I'm unable to find a reason for the memory management issues that caused the revert, so trying again.
1 parent d158ee5 commit 2e4d2d8

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,14 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
391391
SourceManager &SM = CGM.getContext().getSourceManager();
392392
StringRef FileName;
393393
FileID FID;
394+
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
394395

395396
if (Loc.isInvalid()) {
396397
// The DIFile used by the CU is distinct from the main source file. Call
397398
// createFile() below for canonicalization if the source file was specified
398399
// with an absolute path.
399400
FileName = TheCU->getFile()->getFilename();
401+
CSInfo = TheCU->getFile()->getChecksum();
400402
} else {
401403
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
402404
FileName = PLoc.getFilename();
@@ -417,13 +419,13 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
417419
return cast<llvm::DIFile>(V);
418420
}
419421

420-
SmallString<64> Checksum;
421-
422-
std::optional<llvm::DIFile::ChecksumKind> CSKind =
422+
if (!CSInfo) {
423+
SmallString<64> Checksum;
424+
std::optional<llvm::DIFile::ChecksumKind> CSKind =
423425
computeChecksum(FID, Checksum);
424-
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
425-
if (CSKind)
426-
CSInfo.emplace(*CSKind, Checksum);
426+
if (CSKind)
427+
CSInfo.emplace(*CSKind, Checksum);
428+
}
427429
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
428430
}
429431

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class CGDebugInfo {
148148
llvm::BumpPtrAllocator DebugInfoNames;
149149
StringRef CWDName;
150150

151-
llvm::StringMap<llvm::TrackingMDRef> DIFileCache;
151+
llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
152152
llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
153153
/// Cache declarations relevant to DW_TAG_imported_declarations (C++
154154
/// using declarations and global alias variables) that aren't covered

clang/test/CodeGenCXX/debug-info-function-context.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s \
2-
// RUN: -dwarf-version=5 -main-file-name %s -o - | FileCheck %s
2+
// RUN: -dwarf-version=5 -main-file-name debug-info-function-context.cpp -o - | FileCheck %s
33

44
struct C {
55
void member_function();
@@ -31,8 +31,8 @@ int global_initialized_variable = C::static_member_function();
3131

3232
// The first DIFile is for the CU, the second is what everything else uses.
3333
// We're using DWARF v5 so both should have MD5 checksums.
34-
// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5
35-
// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5
34+
// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, checksum: [[CKSUM:".*"]]
35+
// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, checksum: [[CKSUM]]
3636
// CHECK: ![[C:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C",
3737
// CHECK: ![[NS:.*]] = !DINamespace(name: "ns"
3838
// CHECK: !DISubprogram(name: "member_function",{{.*}} scope: ![[C]],{{.*}} DISPFlagDefinition

0 commit comments

Comments
 (0)