hoy updated this revision to Diff 314259. hoy added a comment. Adding a switch.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93747/new/ https://reviews.llvm.org/D93747 Files: llvm/include/llvm/IR/DebugInfoMetadata.h llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll =================================================================== --- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll +++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll @@ -3,8 +3,10 @@ ; RUN: opt -S -passes='default<O2>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE ; RUN: opt -S -passes='thinlto-pre-link<O1>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE ; RUN: opt -S -passes='thinlto-pre-link<O2>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE +; RUN: opt -S -passes=unique-internal-linkage-names -unqiue-debug-linkage-names=0 < %s -o - | FileCheck %s --check-prefix=NODBG +; RUN: opt -S -passes=unique-internal-linkage-names < %s -o - | FileCheck %s --check-prefix=DBG -define internal i32 @foo() { +define internal i32 @foo() !dbg !15 { entry: ret i32 0 } @@ -14,6 +16,25 @@ ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*) } +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2) +!1 = !DIFile(filename: "test.c", directory: "") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!8 = !DISubroutineType(types: !9) +!9 = !{!10} +!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) +!11 = !DISubroutineType(types: !12) +!12 = !{!13, null} +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2) +!16 = !DISubroutineType(types: !17) +!17 = !{!13} + ; O0: Running pass: UniqueInternalLinkageNamesPass ;; Check UniqueInternalLinkageNamesPass is scheduled before SampleProfileProbePass. @@ -22,3 +43,6 @@ ; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() ; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}} + +; NODBG: distinct !DISubprogram(name: "foo", scope: ![[#]] +; DBG: distinct !DISubprogram(name: "foo", linkageName: "foo.__uniq.{{[0-9a-f]+}}", scope: ![[#]] Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp =================================================================== --- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp +++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp @@ -13,13 +13,21 @@ #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h" #include "llvm/ADT/SmallString.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/MDBuilder.h" #include "llvm/IR/Module.h" #include "llvm/InitializePasses.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/MD5.h" #include "llvm/Transforms/Utils/ModuleUtils.h" using namespace llvm; +static cl::opt<bool> + UniqueDebugLinakgeNames("unqiue-debug-linkage-names", cl::init(true), + cl::Hidden, + cl::desc("Uniqueify debug linkage Names")); + static bool uniqueifyInternalLinkageNames(Module &M) { llvm::MD5 Md5; Md5.update(M.getSourceFileName()); @@ -31,11 +39,18 @@ // this symbol is of internal linkage type. std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str(); bool Changed = false; + MDBuilder MDB(M.getContext()); // Append the module hash to all internal linkage functions. for (auto &F : M) { if (F.hasInternalLinkage()) { F.setName(F.getName() + ModuleNameHash); + if (UniqueDebugLinakgeNames) { + if (DISubprogram *SP = F.getSubprogram()) { + auto *Name = MDB.createString(F.getName()); + SP->replaceRawLinkageName(Name); + } + } Changed = true; } } Index: llvm/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/include/llvm/IR/DebugInfoMetadata.h +++ llvm/include/llvm/IR/DebugInfoMetadata.h @@ -2053,6 +2053,10 @@ return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr; } + void replaceRawLinkageName(MDString *LinkageName) { + replaceOperandWith(3, LinkageName); + } + /// Check if this subprogram describes the given function. /// /// FIXME: Should this be looking through bitcasts?
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits