Skip to content

Commit 571181b

Browse files
committed
For function name, use debug info or keep @
1 parent 5a4b873 commit 571181b

File tree

4 files changed

+73
-60
lines changed

4 files changed

+73
-60
lines changed

llvm/lib/Analysis/KernelInfo.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,27 @@ static bool isKernelFunction(Function &F) {
8080
return F.hasFnAttribute("kernel");
8181
}
8282

83-
static void identifyFunction(OptimizationRemark &R, const Function &F) {
84-
if (auto *SubProgram = F.getSubprogram()) {
85-
if (SubProgram->isArtificial())
86-
R << "artificial ";
83+
static void identifyCallee(OptimizationRemark &R, const Module *M,
84+
const Value *V, StringRef Kind = "") {
85+
SmallString<100> Name; // might be function name or asm expression
86+
if (const Function *F = dyn_cast<Function>(V)) {
87+
if (auto *SubProgram = F->getSubprogram()) {
88+
if (SubProgram->isArtificial())
89+
R << "artificial ";
90+
Name = SubProgram->getName();
91+
}
8792
}
88-
R << "function '" << F.getName() << "'";
93+
if (Name.empty()) {
94+
raw_svector_ostream OS(Name);
95+
V->printAsOperand(OS, /*PrintType=*/false, M);
96+
}
97+
if (!Kind.empty())
98+
R << Kind << " ";
99+
R << "'" << Name << "'";
100+
}
101+
102+
static void identifyFunction(OptimizationRemark &R, const Function &F) {
103+
identifyCallee(R, F.getParent(), &F, "function");
89104
}
90105

91106
static void remarkAlloca(OptimizationRemarkEmitter &ORE, const Function &Caller,
@@ -132,21 +147,8 @@ static void remarkCall(OptimizationRemarkEmitter &ORE, const Function &Caller,
132147
OptimizationRemark R(DEBUG_TYPE, RemarkKind, &Call);
133148
R << "in ";
134149
identifyFunction(R, Caller);
135-
R << ", " << CallKind << ", callee is";
136-
Value *Callee = Call.getCalledOperand();
137-
SmallString<100> Name; // might be function name or asm expression
138-
if (const Function *FnCallee = dyn_cast<Function>(Callee)) {
139-
if (auto *SubProgram = FnCallee->getSubprogram()) {
140-
if (SubProgram->isArtificial())
141-
R << " artificial";
142-
}
143-
Name = FnCallee->getName();
144-
}
145-
if (Name.empty()) {
146-
raw_svector_ostream OS(Name);
147-
Callee->printAsOperand(OS, /*PrintType=*/false, Caller.getParent());
148-
}
149-
R << " '" << Name << "'";
150+
R << ", " << CallKind << ", callee is ";
151+
identifyCallee(R, Caller.getParent(), Call.getCalledOperand());
150152
return R;
151153
});
152154
}

llvm/test/Analysis/KernelInfo/calls.ll

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ declare void @personality()
1111

1212
define void @h() personality ptr @personality !dbg !100 {
1313
entry:
14-
; CHECK: remark: test.c:16:5: in artificial function 'h', direct call, callee is 'f'
14+
; CHECK: remark: test.c:16:5: in artificial function 'h_dbg', direct call, callee is '@f'
1515
call void @f(), !dbg !102
16-
; CHECK: remark: test.c:17:5: in artificial function 'h', direct call to defined function, callee is 'g'
16+
; CHECK: remark: test.c:17:5: in artificial function 'h_dbg', direct call to defined function, callee is 'g_dbg'
1717
call void @g(), !dbg !104
18-
; CHECK: remark: test.c:18:5: in artificial function 'h', direct call to defined function, callee is artificial 'h'
18+
; CHECK: remark: test.c:18:5: in artificial function 'h_dbg', direct call to defined function, callee is artificial 'h_dbg'
1919
call void @h(), !dbg !105
20-
; CHECK: remark: test.c:24:5: in artificial function 'h', direct call to inline assembly, callee is 'asm sideeffect "eieio", ""'
20+
; CHECK: remark: test.c:24:5: in artificial function 'h_dbg', direct call to inline assembly, callee is 'asm sideeffect "eieio", ""'
2121
call void asm sideeffect "eieio", ""(), !dbg !111
2222
%fnPtr = load ptr, ptr null, align 8
23-
; CHECK: remark: test.c:19:5: in artificial function 'h', indirect call, callee is '%fnPtr'
23+
; CHECK: remark: test.c:19:5: in artificial function 'h_dbg', indirect call, callee is '%fnPtr'
2424
call void %fnPtr(), !dbg !106
25-
; CHECK: remark: test.c:20:5: in artificial function 'h', direct invoke, callee is 'f'
25+
; CHECK: remark: test.c:20:5: in artificial function 'h_dbg', direct invoke, callee is '@f'
2626
invoke void @f() to label %fcont unwind label %cleanup, !dbg !107
2727
fcont:
28-
; CHECK: remark: test.c:21:5: in artificial function 'h', direct invoke to defined function, callee is 'g'
28+
; CHECK: remark: test.c:21:5: in artificial function 'h_dbg', direct invoke to defined function, callee is 'g_dbg'
2929
invoke void @g() to label %gcont unwind label %cleanup, !dbg !108
3030
gcont:
31-
; CHECK: remark: test.c:22:5: in artificial function 'h', direct invoke to defined function, callee is artificial 'h'
31+
; CHECK: remark: test.c:22:5: in artificial function 'h_dbg', direct invoke to defined function, callee is artificial 'h_dbg'
3232
invoke void @h() to label %hcont unwind label %cleanup, !dbg !109
3333
hcont:
34-
; CHECK: remark: test.c:25:5: in artificial function 'h', direct invoke to inline assembly, callee is 'asm sideeffect "eieio", ""'
34+
; CHECK: remark: test.c:25:5: in artificial function 'h_dbg', direct invoke to inline assembly, callee is 'asm sideeffect "eieio", ""'
3535
invoke void asm sideeffect "eieio", ""() to label %asmcont unwind label %cleanup, !dbg !112
3636
asmcont:
37-
; CHECK: remark: test.c:23:5: in artificial function 'h', indirect invoke, callee is '%fnPtr'
37+
; CHECK: remark: test.c:23:5: in artificial function 'h_dbg', indirect invoke, callee is '%fnPtr'
3838
invoke void %fnPtr() to label %end unwind label %cleanup, !dbg !110
3939
cleanup:
4040
%ll = landingpad { ptr, i32 }
@@ -43,40 +43,40 @@ cleanup:
4343
end:
4444
ret void
4545
}
46-
; CHECK: remark: test.c:13:0: in artificial function 'h', DirectCalls = 8
47-
; CHECK: remark: test.c:13:0: in artificial function 'h', IndirectCalls = 2
48-
; CHECK: remark: test.c:13:0: in artificial function 'h', DirectCallsToDefinedFunctions = 4
49-
; CHECK: remark: test.c:13:0: in artificial function 'h', InlineAssemblyCalls = 2
50-
; CHECK: remark: test.c:13:0: in artificial function 'h', Invokes = 5
46+
; CHECK: remark: test.c:13:0: in artificial function 'h_dbg', DirectCalls = 8
47+
; CHECK: remark: test.c:13:0: in artificial function 'h_dbg', IndirectCalls = 2
48+
; CHECK: remark: test.c:13:0: in artificial function 'h_dbg', DirectCallsToDefinedFunctions = 4
49+
; CHECK: remark: test.c:13:0: in artificial function 'h_dbg', InlineAssemblyCalls = 2
50+
; CHECK: remark: test.c:13:0: in artificial function 'h_dbg', Invokes = 5
5151

5252
declare void @f()
5353

5454
define void @g() personality ptr @personality !dbg !200 {
5555
entry:
56-
; CHECK: remark: test.c:6:3: in function 'g', direct call, callee is 'f'
56+
; CHECK: remark: test.c:6:3: in function 'g_dbg', direct call, callee is '@f'
5757
call void @f(), !dbg !202
58-
; CHECK: remark: test.c:7:3: in function 'g', direct call to defined function, callee is 'g'
58+
; CHECK: remark: test.c:7:3: in function 'g_dbg', direct call to defined function, callee is 'g_dbg'
5959
call void @g(), !dbg !203
60-
; CHECK: remark: test.c:8:3: in function 'g', direct call to defined function, callee is artificial 'h'
60+
; CHECK: remark: test.c:8:3: in function 'g_dbg', direct call to defined function, callee is artificial 'h_dbg'
6161
call void @h(), !dbg !204
62-
; CHECK: remark: test.c:14:3: in function 'g', direct call to inline assembly, callee is 'asm sideeffect "eieio", ""'
62+
; CHECK: remark: test.c:14:3: in function 'g_dbg', direct call to inline assembly, callee is 'asm sideeffect "eieio", ""'
6363
call void asm sideeffect "eieio", ""(), !dbg !210
6464
%fnPtr = load ptr, ptr null, align 8
65-
; CHECK: remark: test.c:9:3: in function 'g', indirect call, callee is '%fnPtr'
65+
; CHECK: remark: test.c:9:3: in function 'g_dbg', indirect call, callee is '%fnPtr'
6666
call void %fnPtr(), !dbg !205
67-
; CHECK: remark: test.c:10:3: in function 'g', direct invoke, callee is 'f'
67+
; CHECK: remark: test.c:10:3: in function 'g_dbg', direct invoke, callee is '@f'
6868
invoke void @f() to label %fcont unwind label %cleanup, !dbg !206
6969
fcont:
70-
; CHECK: remark: test.c:11:3: in function 'g', direct invoke to defined function, callee is 'g'
70+
; CHECK: remark: test.c:11:3: in function 'g_dbg', direct invoke to defined function, callee is 'g_dbg'
7171
invoke void @g() to label %gcont unwind label %cleanup, !dbg !207
7272
gcont:
73-
; CHECK: remark: test.c:12:3: in function 'g', direct invoke to defined function, callee is artificial 'h'
73+
; CHECK: remark: test.c:12:3: in function 'g_dbg', direct invoke to defined function, callee is artificial 'h_dbg'
7474
invoke void @h() to label %hcont unwind label %cleanup, !dbg !208
7575
hcont:
76-
; CHECK: remark: test.c:15:3: in function 'g', direct invoke to inline assembly, callee is 'asm sideeffect "eieio", ""'
76+
; CHECK: remark: test.c:15:3: in function 'g_dbg', direct invoke to inline assembly, callee is 'asm sideeffect "eieio", ""'
7777
invoke void asm sideeffect "eieio", ""() to label %asmcont unwind label %cleanup, !dbg !211
7878
asmcont:
79-
; CHECK: remark: test.c:13:3: in function 'g', indirect invoke, callee is '%fnPtr'
79+
; CHECK: remark: test.c:13:3: in function 'g_dbg', indirect invoke, callee is '%fnPtr'
8080
invoke void %fnPtr() to label %end unwind label %cleanup, !dbg !209
8181
cleanup:
8282
%ll = landingpad { ptr, i32 }
@@ -85,11 +85,22 @@ cleanup:
8585
end:
8686
ret void
8787
}
88-
; CHECK: remark: test.c:3:0: in function 'g', DirectCalls = 8
89-
; CHECK: remark: test.c:3:0: in function 'g', IndirectCalls = 2
90-
; CHECK: remark: test.c:3:0: in function 'g', DirectCallsToDefinedFunctions = 4
91-
; CHECK: remark: test.c:3:0: in function 'g', InlineAssemblyCalls = 2
92-
; CHECK: remark: test.c:3:0: in function 'g', Invokes = 5
88+
; CHECK: remark: test.c:3:0: in function 'g_dbg', DirectCalls = 8
89+
; CHECK: remark: test.c:3:0: in function 'g_dbg', IndirectCalls = 2
90+
; CHECK: remark: test.c:3:0: in function 'g_dbg', DirectCallsToDefinedFunctions = 4
91+
; CHECK: remark: test.c:3:0: in function 'g_dbg', InlineAssemblyCalls = 2
92+
; CHECK: remark: test.c:3:0: in function 'g_dbg', Invokes = 5
93+
94+
define void @i() {
95+
; CHECK: remark: <unknown>:0:0: in function '@i', direct call, callee is '@f'
96+
call void @f()
97+
ret void
98+
}
99+
; CHECK: remark: <unknown>:0:0: in function '@i', DirectCalls = 1
100+
; CHECK: remark: <unknown>:0:0: in function '@i', IndirectCalls = 0
101+
; CHECK: remark: <unknown>:0:0: in function '@i', DirectCallsToDefinedFunctions = 0
102+
; CHECK: remark: <unknown>:0:0: in function '@i', InlineAssemblyCalls = 0
103+
; CHECK: remark: <unknown>:0:0: in function '@i', Invokes = 0
93104

94105
!llvm.module.flags = !{!0}
95106
!llvm.dbg.cu = !{!1}
@@ -100,7 +111,7 @@ end:
100111
!3 = !{null}
101112
!4 = !{}
102113

103-
!100 = distinct !DISubprogram(name: "h", scope: !2, file: !2, line: 13, type: !101, scopeLine: 13, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !1, retainedNodes: !4)
114+
!100 = distinct !DISubprogram(name: "h_dbg", scope: !2, file: !2, line: 13, type: !101, scopeLine: 13, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !1, retainedNodes: !4)
104115
!101 = distinct !DISubroutineType(types: !3)
105116
!102 = !DILocation(line: 16, column: 5, scope: !103)
106117
!103 = distinct !DILexicalBlock(scope: !100, file: !2, line: 13, column: 3)
@@ -114,7 +125,7 @@ end:
114125
!111 = !DILocation(line: 24, column: 5, scope: !103)
115126
!112 = !DILocation(line: 25, column: 5, scope: !103)
116127

117-
!200 = distinct !DISubprogram(name: "g", scope: !2, file: !2, line: 3, type: !201, scopeLine: 3, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !4)
128+
!200 = distinct !DISubprogram(name: "g_dbg", scope: !2, file: !2, line: 3, type: !201, scopeLine: 3, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !4)
118129
!201 = !DISubroutineType(types: !3)
119130
!202 = !DILocation(line: 6, column: 3, scope: !200)
120131
!203 = !DILocation(line: 7, column: 3, scope: !200)

llvm/test/Analysis/KernelInfo/openmp/amdgpu.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
; CHECK-NEXT: remark: test.c:14:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'i' with static size of 4 bytes
1212
; CHECK-NEXT: remark: test.c:15:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'a' with static size of 8 bytes
1313
; CHECK-NEXT: remark: <unknown>:0:0: in artificial function '[[OFF_FUNC]]_debug__', 'store' instruction accesses memory in flat address space
14-
; CHECK-NEXT: remark: test.c:13:3: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '__kmpc_target_init'
15-
; CHECK-NEXT: remark: test.c:16:5: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is 'f'
14+
; CHECK-NEXT: remark: test.c:13:3: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@__kmpc_target_init'
15+
; CHECK-NEXT: remark: test.c:16:5: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@f'
1616
; CHECK-NEXT: remark: test.c:17:5: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is 'g'
17-
; CHECK-NEXT: remark: test.c:18:3: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '__kmpc_target_deinit'
17+
; CHECK-NEXT: remark: test.c:18:3: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@__kmpc_target_deinit'
1818
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', ExternalNotKernel = 0
1919
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', omp_target_thread_limit = 256
2020
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', amdgpu-max-num-workgroups[0] = 0
@@ -58,7 +58,7 @@
5858

5959
; CHECK-NEXT: remark: test.c:4:7: in function 'g', alloca 'i' with static size of 4 bytes
6060
; CHECK-NEXT: remark: test.c:5:7: in function 'g', alloca 'a' with static size of 8 bytes
61-
; CHECK-NEXT: remark: test.c:6:3: in function 'g', direct call, callee is 'f'
61+
; CHECK-NEXT: remark: test.c:6:3: in function 'g', direct call, callee is '@f'
6262
; CHECK-NEXT: remark: test.c:7:3: in function 'g', direct call to defined function, callee is 'g'
6363
; CHECK-NEXT: remark: test.c:3:0: in function 'g', ExternalNotKernel = 1
6464
; CHECK-NEXT: remark: test.c:3:0: in function 'g', amdgpu-max-num-workgroups[0] = 0

llvm/test/Analysis/KernelInfo/openmp/nvptx.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
; CHECK-NEXT: remark: test.c:14:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'i' with static size of 4 bytes
1212
; CHECK-NEXT: remark: test.c:15:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'a' with static size of 8 bytes
1313
; CHECK-NEXT: remark: <unknown>:0:0: in artificial function '[[OFF_FUNC]]_debug__', 'store' instruction accesses memory in flat address space
14-
; CHECK-NEXT: remark: test.c:13:3: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is '__kmpc_target_init'
15-
; CHECK-NEXT: remark: test.c:16:5: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is 'f'
14+
; CHECK-NEXT: remark: test.c:13:3: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is '@__kmpc_target_init'
15+
; CHECK-NEXT: remark: test.c:16:5: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@f'
1616
; CHECK-NEXT: remark: test.c:17:5: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is 'g'
17-
; CHECK-NEXT: remark: test.c:18:3: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is '__kmpc_target_deinit'
17+
; CHECK-NEXT: remark: test.c:18:3: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is '@__kmpc_target_deinit'
1818
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', ExternalNotKernel = 0
1919
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', omp_target_thread_limit = 128
2020
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', maxntidx = 128
@@ -45,7 +45,7 @@
4545

4646
; CHECK-NEXT: remark: test.c:4:7: in function 'g', alloca 'i' with static size of 4 bytes
4747
; CHECK-NEXT: remark: test.c:5:7: in function 'g', alloca 'a' with static size of 8 bytes
48-
; CHECK-NEXT: remark: test.c:6:3: in function 'g', direct call, callee is 'f'
48+
; CHECK-NEXT: remark: test.c:6:3: in function 'g', direct call, callee is '@f'
4949
; CHECK-NEXT: remark: test.c:7:3: in function 'g', direct call to defined function, callee is 'g'
5050
; CHECK-NEXT: remark: test.c:3:0: in function 'g', ExternalNotKernel = 1
5151
; CHECK-NEXT: remark: test.c:3:0: in function 'g', Allocas = 2

0 commit comments

Comments
 (0)