From 9d0f5bf1bbc3f758336ddf5ffaf94e5fe418b5b2 Mon Sep 17 00:00:00 2001 From: Paul Robinson Date: Fri, 18 Aug 2023 07:33:27 -0700 Subject: [PATCH] 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 5956648fc3ba11dd6b0d0f2d1d9b923e7f80f247. There was a string lifetime issue that is now corrected. Differential Revision: https://reviews.llvm.org/D156571 (cherry picked from commit 1fcc2bc31bb9352a13445ff4a5cccb0bebb8ea5b) --- clang/lib/CodeGen/CGDebugInfo.cpp | 13 ++++++++----- clang/lib/CodeGen/CGDebugInfo.h | 2 +- clang/test/CodeGenCXX/debug-info-function-context.cpp | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index f049a682..d8eb2ae 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -391,12 +391,14 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { SourceManager &SM = CGM.getContext().getSourceManager(); StringRef FileName; FileID FID; + std::optional> CSInfo; if (Loc.isInvalid()) { // The DIFile used by the CU is distinct from the main source file. Call // createFile() below for canonicalization if the source file was specified // with an absolute path. FileName = TheCU->getFile()->getFilename(); + CSInfo = TheCU->getFile()->getChecksum(); } else { PresumedLoc PLoc = SM.getPresumedLoc(Loc); FileName = PLoc.getFilename(); @@ -417,13 +419,14 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { return cast(V); } + // Put Checksum at a scope where it will persist past the createFile call. SmallString<64> Checksum; - - std::optional CSKind = + if (!CSInfo) { + std::optional CSKind = computeChecksum(FID, Checksum); - std::optional> CSInfo; - if (CSKind) - CSInfo.emplace(*CSKind, Checksum); + if (CSKind) + CSInfo.emplace(*CSKind, Checksum); + } return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc))); } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 1fd0862..58ee6dd 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -148,7 +148,7 @@ class CGDebugInfo { llvm::BumpPtrAllocator DebugInfoNames; StringRef CWDName; - llvm::StringMap DIFileCache; + llvm::DenseMap DIFileCache; llvm::DenseMap SPCache; /// Cache declarations relevant to DW_TAG_imported_declarations (C++ /// using declarations and global alias variables) that aren't covered diff --git a/clang/test/CodeGenCXX/debug-info-function-context.cpp b/clang/test/CodeGenCXX/debug-info-function-context.cpp index 8d3309f42..63fdf87 100644 --- a/clang/test/CodeGenCXX/debug-info-function-context.cpp +++ b/clang/test/CodeGenCXX/debug-info-function-context.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s \ -// RUN: -dwarf-version=5 -main-file-name %s -o - | FileCheck %s +// RUN: -dwarf-version=5 -main-file-name debug-info-function-context.cpp -o - | FileCheck %s struct C { void member_function(); @@ -31,8 +31,8 @@ int global_initialized_variable = C::static_member_function(); // The first DIFile is for the CU, the second is what everything else uses. // We're using DWARF v5 so both should have MD5 checksums. -// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5 -// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5 +// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, checksum: [[CKSUM:".*"]] +// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, checksum: [[CKSUM]] // CHECK: ![[C:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C", // CHECK: ![[NS:.*]] = !DINamespace(name: "ns" // CHECK: !DISubprogram(name: "member_function",{{.*}} scope: ![[C]],{{.*}} DISPFlagDefinition -- 2.7.4