Skip to content

Commit 90a6819

Browse files
[MemProf] Update the DISubprogram linkageName for clones (#145385)
This corrects the debug information for the cloned functions so that it contains the correct linkage name.
1 parent ca04d74 commit 90a6819

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,6 +4001,9 @@ ModuleCallsiteContextGraph::cloneFunctionForCallsite(
40014001
std::string Name = getMemProfFuncName(Func.func()->getName(), CloneNo);
40024002
assert(!Func.func()->getParent()->getFunction(Name));
40034003
NewFunc->setName(Name);
4004+
if (auto *SP = NewFunc->getSubprogram())
4005+
SP->replaceLinkageName(
4006+
MDString::get(NewFunc->getParent()->getContext(), Name));
40044007
for (auto &Inst : CallsWithMetadataInFunc) {
40054008
// This map always has the initial version in it.
40064009
assert(Inst.cloneNo() == 0);
@@ -4939,6 +4942,9 @@ static SmallVector<std::unique_ptr<ValueToValueMapTy>, 4> createFunctionClones(
49394942
PrevF->eraseFromParent();
49404943
} else
49414944
NewF->setName(Name);
4945+
if (auto *SP = NewF->getSubprogram())
4946+
SP->replaceLinkageName(
4947+
MDString::get(NewF->getParent()->getContext(), Name));
49424948
ORE.emit(OptimizationRemark(DEBUG_TYPE, "MemprofClone", &F)
49434949
<< "created clone " << ore::NV("NewFunction", NewF));
49444950

llvm/test/ThinLTO/X86/memprof-basic.ll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ declare void @_ZdaPv()
100100

101101
declare i32 @sleep()
102102

103-
define internal ptr @_Z3barv() #0 {
103+
define internal ptr @_Z3barv() #0 !dbg !15 {
104104
entry:
105105
%call = call ptr @_Znam(i64 0), !memprof !2, !callsite !7
106106
ret ptr null
@@ -125,6 +125,9 @@ uselistorder ptr @_Z3foov, { 1, 0 }
125125

126126
attributes #0 = { noinline optnone }
127127

128+
!llvm.dbg.cu = !{!13}
129+
!llvm.module.flags = !{!20, !21}
130+
128131
!0 = !{i64 8632435727821051414}
129132
!1 = !{i64 -3421689549917153178}
130133
!2 = !{!3, !5}
@@ -138,7 +141,15 @@ attributes #0 = { noinline optnone }
138141
!10 = !{i64 123, i64 100}
139142
!11 = !{i64 456, i64 200}
140143
!12 = !{i64 789, i64 300}
141-
144+
!13 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !14, producer: "clang version 21.0.0git (git@github.com:llvm/llvm-project.git e391301e0e4d9183fe06e69602e87b0bc889aeda)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
145+
!14 = !DIFile(filename: "basic.cc", directory: "", checksumkind: CSK_MD5, checksum: "8636c46e81402013b9d54e8307d2f149")
146+
!15 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !14, file: !14, line: 1, type: !16, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !13)
147+
!16 = !DISubroutineType(types: !17)
148+
!17 = !{!18}
149+
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
150+
!19 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
151+
!20 = !{i32 7, !"Dwarf Version", i32 5}
152+
!21 = !{i32 2, !"Debug Info Version", i32 3}
142153

143154
; DUMP: CCG before cloning:
144155
; DUMP: Callsite Context Graph:
@@ -301,14 +312,16 @@ attributes #0 = { noinline optnone }
301312
; IR: call {{.*}} @_Z3barv()
302313
; IR: define internal {{.*}} @_Z3foov()
303314
; IR: call {{.*}} @_Z3bazv()
304-
; IR: define internal {{.*}} @_Z3barv.memprof.1()
315+
; IR: define internal {{.*}} @_Z3barv.memprof.1() {{.*}} !dbg ![[SP:[0-9]+]]
305316
; IR: call {{.*}} @_Znam(i64 0) #[[COLD:[0-9]+]]
306317
; IR: define internal {{.*}} @_Z3bazv.memprof.1()
307318
; IR: call {{.*}} @_Z3barv.memprof.1()
308319
; IR: define internal {{.*}} @_Z3foov.memprof.1()
309320
; IR: call {{.*}} @_Z3bazv.memprof.1()
310321
; IR: attributes #[[NOTCOLD]] = { "memprof"="notcold" }
311322
; IR: attributes #[[COLD]] = { "memprof"="cold" }
323+
;; Make sure the clone's linkageName was updated.
324+
; IR: ![[SP]] = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv.memprof.1"
312325

313326

314327
; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned)

llvm/test/Transforms/MemProfContextDisambiguation/basic.ll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1
7171
; Function Attrs: nobuiltin
7272
declare void @_ZdaPv() #2
7373

74-
define internal ptr @_Z3barv() #3 {
74+
define internal ptr @_Z3barv() #3 !dbg !15 {
7575
entry:
7676
%call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #6, !memprof !2, !callsite !7
7777
ret ptr null
@@ -103,6 +103,9 @@ attributes #4 = { "stack-protector-buffer-size"="8" }
103103
attributes #5 = { noinline }
104104
attributes #6 = { builtin }
105105

106+
!llvm.dbg.cu = !{!13}
107+
!llvm.module.flags = !{!20, !21}
108+
106109
!0 = !{i64 8632435727821051414}
107110
!1 = !{i64 -3421689549917153178}
108111
!2 = !{!3, !5}
@@ -116,7 +119,15 @@ attributes #6 = { builtin }
116119
!10 = !{i64 123, i64 100}
117120
!11 = !{i64 456, i64 200}
118121
!12 = !{i64 789, i64 300}
119-
122+
!13 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !14, producer: "clang version 21.0.0git (git@github.com:llvm/llvm-project.git e391301e0e4d9183fe06e69602e87b0bc889aeda)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
123+
!14 = !DIFile(filename: "basic.cc", directory: "", checksumkind: CSK_MD5, checksum: "8636c46e81402013b9d54e8307d2f149")
124+
!15 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !14, file: !14, line: 1, type: !16, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !13)
125+
!16 = !DISubroutineType(types: !17)
126+
!17 = !{!18}
127+
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
128+
!19 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
129+
!20 = !{i32 7, !"Dwarf Version", i32 5}
130+
!21 = !{i32 2, !"Debug Info Version", i32 3}
120131

121132
; DUMP: CCG before cloning:
122133
; DUMP: Callsite Context Graph:
@@ -270,14 +281,16 @@ attributes #6 = { builtin }
270281
; IR: call {{.*}} @_Z3barv()
271282
; IR: define internal {{.*}} @_Z3foov()
272283
; IR: call {{.*}} @_Z3bazv()
273-
; IR: define internal {{.*}} @_Z3barv.memprof.1()
284+
; IR: define internal {{.*}} @_Z3barv.memprof.1() {{.*}} !dbg ![[SP:[0-9]+]]
274285
; IR: call {{.*}} @_Znam(i64 noundef 10) #[[COLD:[0-9]+]]
275286
; IR: define internal {{.*}} @_Z3bazv.memprof.1()
276287
; IR: call {{.*}} @_Z3barv.memprof.1()
277288
; IR: define internal {{.*}} @_Z3foov.memprof.1()
278289
; IR: call {{.*}} @_Z3bazv.memprof.1()
279290
; IR: attributes #[[NOTCOLD]] = { builtin "memprof"="notcold" }
280291
; IR: attributes #[[COLD]] = { builtin "memprof"="cold" }
292+
;; Make sure the clone's linkageName was updated.
293+
; IR: ![[SP]] = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv.memprof.1"
281294

282295

283296
; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned)

0 commit comments

Comments
 (0)