diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1144,6 +1144,7 @@ // non-integrated assemblers don't recognize .cgprofile section. PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS; PTO.Coroutines = LangOpts.Coroutines; + PTO.UniqueLinkageNames = CodeGenOpts.UniqueInternalLinkageNames; PassInstrumentationCallbacks PIC; StandardInstrumentations SI(CodeGenOpts.DebugPassManager); @@ -1325,11 +1326,6 @@ MPM = PB.buildPerModuleDefaultPipeline(Level); } - // Add UniqueInternalLinkageNames Pass which renames internal linkage - // symbols with unique names. - if (CodeGenOpts.UniqueInternalLinkageNames) - MPM.addPass(UniqueInternalLinkageNamesPass()); - if (!CodeGenOpts.MemoryProfileOutput.empty()) { MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass())); MPM.addPass(ModuleMemProfilerPass()); diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -127,6 +127,9 @@ /// Tuning option to enable/disable function merging. Its default value is /// false. bool MergeFunctions; + + /// Uniquefy function linkage name. Its default value is false. + bool UniqueLinkageNames; }; /// This class provides access to building LLVM's passes. diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1001,6 +1001,11 @@ ThinLTOPhase Phase) { ModulePassManager MPM(DebugLogging); + // Add UniqueInternalLinkageNames Pass which renames internal linkage + // symbols with unique names. + if (PTO.UniqueLinkageNames) + MPM.addPass(UniqueInternalLinkageNamesPass()); + // Place pseudo probe instrumentation as the first pass of the pipeline to // minimize the impact of optimization changes. if (PGOOpt && PGOOpt->PseudoProbeForProfiling && @@ -1764,6 +1769,11 @@ ModulePassManager MPM(DebugLogging); + // Add UniqueInternalLinkageNames Pass which renames internal linkage + // symbols with unique names. + if (PTO.UniqueLinkageNames) + MPM.addPass(UniqueInternalLinkageNamesPass()); + if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr || PGOOpt->Action == PGOOptions::IRUse)) addPGOInstrPassesForO0( diff --git a/llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll b/llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll @@ -0,0 +1,36 @@ +; RUN: opt -S -passes=unique-internal-linkage-names < %s | FileCheck %s + +define internal i32 @foo() !dbg !15 { +entry: + ret i32 0, !dbg !18 +} + +define dso_local i32 (...)* @bar() !dbg !7 { +entry: + ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*), !dbg !14 +} + +!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} +!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!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) +!14 = !DILocation(line: 10, column: 3, scope: !7) +!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} +!18 = !DILocation(line: 6, column: 3, scope: !15) + +; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() [[ATTR:#[0-9]+]] !dbg ![[#DBG:]] +; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}