Skip to content

Commit 1fcc2bc

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 5956648. There was a string lifetime issue that is now corrected. Differential Revision: https://reviews.llvm.org/D156571
1 parent 1c66d08 commit 1fcc2bc

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 8 additions & 5 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,14 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
417419
return cast<llvm::DIFile>(V);
418420
}
419421

422+
// Put Checksum at a scope where it will persist past the createFile call.
420423
SmallString<64> Checksum;
421-
422-
std::optional<llvm::DIFile::ChecksumKind> CSKind =
424+
if (!CSInfo) {
425+
std::optional<llvm::DIFile::ChecksumKind> CSKind =
423426
computeChecksum(FID, Checksum);
424-
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
425-
if (CSKind)
426-
CSInfo.emplace(*CSKind, Checksum);
427+
if (CSKind)
428+
CSInfo.emplace(*CSKind, Checksum);
429+
}
427430
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
428431
}
429432

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)