Skip to content

Commit baad223

Browse files
committed
Include LLVM value name in alloca report
1 parent f5a6fbd commit baad223

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

llvm/lib/Analysis/KernelInfo.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ static void remarkAlloca(OptimizationRemarkEmitter &ORE, const Function &Caller,
110110
const AllocaInst &Alloca,
111111
TypeSize::ScalarTy StaticSize) {
112112
ORE.emit([&] {
113-
StringRef Name;
113+
StringRef DbgName;
114114
DebugLoc Loc;
115115
bool Artificial = false;
116116
auto DVRs = findDVRDeclares(&const_cast<AllocaInst &>(Alloca));
117117
if (!DVRs.empty()) {
118118
const DbgVariableRecord &DVR = **DVRs.begin();
119-
Name = DVR.getVariable()->getName();
119+
DbgName = DVR.getVariable()->getName();
120120
Loc = DVR.getDebugLoc();
121121
Artificial = DVR.Variable->isArtificial();
122122
}
@@ -127,13 +127,14 @@ static void remarkAlloca(OptimizationRemarkEmitter &ORE, const Function &Caller,
127127
R << ", ";
128128
if (Artificial)
129129
R << "artificial ";
130-
if (Name.empty()) {
131-
R << "unnamed alloca ";
132-
if (DVRs.empty())
133-
R << "(missing debug metadata) ";
134-
} else {
135-
R << "alloca '" << Name << "' ";
136-
}
130+
SmallString<20> ValName;
131+
raw_svector_ostream OS(ValName);
132+
Alloca.printAsOperand(OS, /*PrintType=*/false, Caller.getParent());
133+
R << "alloca ('" << ValName << "') ";
134+
if (!DbgName.empty())
135+
R << "for '" << DbgName << "' ";
136+
else
137+
R << "without debug info ";
137138
R << "with ";
138139
if (StaticSize)
139140
R << "static size of " << itostr(StaticSize) << " bytes";

llvm/test/Analysis/KernelInfo/allocas.ll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,28 @@ target triple = "nvptx64-nvidia-cuda"
99

1010
define void @h() !dbg !3 {
1111
entry:
12-
; CHECK: remark: test.c:0:0: in artificial function 'h', artificial alloca 'dyn_ptr' with static size of 8 bytes
12+
; CHECK: remark: test.c:0:0: in artificial function 'h', artificial alloca ('%dyn_ptr.addr') for 'dyn_ptr' with static size of 8 bytes
1313
%dyn_ptr.addr = alloca ptr, align 8
14-
; CHECK: remark: test.c:14:9: in artificial function 'h', alloca 'i' with static size of 4 bytes
14+
; CHECK: remark: test.c:14:9: in artificial function 'h', alloca ('%i') for 'i' with static size of 4 bytes
1515
%i = alloca i32, align 4
16-
; CHECK: remark: test.c:15:9: in artificial function 'h', alloca 'a' with static size of 8 bytes
16+
; CHECK: remark: test.c:15:9: in artificial function 'h', alloca ('%a') for 'a' with static size of 8 bytes
1717
%a = alloca [2 x i32], align 4
18+
; CHECK: remark: <unknown>:0:0: in artificial function 'h', alloca ('%nodbg') without debug info with static size of 4 bytes
19+
%nodbg = alloca i32, align 4
1820
tail call void @llvm.dbg.declare(metadata ptr %dyn_ptr.addr, metadata !7, metadata !DIExpression()), !dbg !11
1921
tail call void @llvm.dbg.declare(metadata ptr %i, metadata !12, metadata !DIExpression()), !dbg !15
2022
tail call void @llvm.dbg.declare(metadata ptr %a, metadata !16, metadata !DIExpression()), !dbg !20
2123
ret void
2224
}
23-
; CHECK: remark: test.c:13:0: in artificial function 'h', Allocas = 3
24-
; CHECK: remark: test.c:13:0: in artificial function 'h', AllocasStaticSizeSum = 20
25+
; CHECK: remark: test.c:13:0: in artificial function 'h', Allocas = 4
26+
; CHECK: remark: test.c:13:0: in artificial function 'h', AllocasStaticSizeSum = 24
2527
; CHECK: remark: test.c:13:0: in artificial function 'h', AllocasDyn = 0
2628

2729
define void @g() !dbg !21 {
2830
entry:
29-
; CHECK: remark: test.c:4:7: in function 'g', alloca 'i' with static size of 4 bytes
31+
; CHECK: remark: test.c:4:7: in function 'g', alloca ('%i') for 'i' with static size of 4 bytes
3032
%i = alloca i32, align 4
31-
; CHECK: remark: test.c:5:7: in function 'g', alloca 'a' with static size of 8 bytes
33+
; CHECK: remark: test.c:5:7: in function 'g', alloca ('%a') for 'a' with static size of 8 bytes
3234
%a = alloca [2 x i32], align 4
3335
tail call void @llvm.dbg.declare(metadata ptr %i, metadata !23, metadata !DIExpression()), !dbg !24
3436
tail call void @llvm.dbg.declare(metadata ptr %a, metadata !25, metadata !DIExpression()), !dbg !26

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
; RUN: FileCheck -match-full-lines %s
88

99
; CHECK-NOT: remark:
10-
; CHECK: remark: test.c:0:0: in artificial function '[[OFF_FUNC:__omp_offloading_[a-f0-9_]*_h_l12]]_debug__', artificial alloca 'dyn_ptr' with static size of 8 bytes
11-
; CHECK-NEXT: remark: test.c:14:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'i' with static size of 4 bytes
12-
; CHECK-NEXT: remark: test.c:15:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'a' with static size of 8 bytes
10+
; CHECK: remark: test.c:0:0: in artificial function '[[OFF_FUNC:__omp_offloading_[a-f0-9_]*_h_l12]]_debug__', artificial alloca ('%[[#]]') for 'dyn_ptr' with static size of 8 bytes
11+
; CHECK-NEXT: remark: test.c:14:9: in artificial function '[[OFF_FUNC]]_debug__', alloca ('%[[#]]') for 'i' with static size of 4 bytes
12+
; CHECK-NEXT: remark: test.c:15:9: in artificial function '[[OFF_FUNC]]_debug__', alloca ('%[[#]]') for '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
1414
; CHECK-NEXT: remark: test.c:13:3: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@__kmpc_target_init'
1515
; CHECK-NEXT: remark: test.c:16:5: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@f'
@@ -33,7 +33,7 @@
3333
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', Invokes = 0
3434
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', FlatAddrspaceAccesses = 1
3535

36-
; CHECK-NEXT: remark: test.c:0:0: in artificial function '[[OFF_FUNC]]', artificial alloca 'dyn_ptr' with static size of 8 bytes
36+
; CHECK-NEXT: remark: test.c:0:0: in artificial function '[[OFF_FUNC]]', artificial alloca ('%[[#]]') for 'dyn_ptr' with static size of 8 bytes
3737
; CHECK-NEXT: remark: <unknown>:0:0: in artificial function '[[OFF_FUNC]]', 'store' instruction accesses memory in flat address space
3838
; CHECK-NEXT: remark: test.c:12:1: in artificial function '[[OFF_FUNC]]', 'load' instruction ('%[[#]]') accesses memory in flat address space
3939
; CHECK-NEXT: remark: test.c:12:1: in artificial function '[[OFF_FUNC]]', direct call to defined function, callee is artificial '[[OFF_FUNC]]_debug__'
@@ -56,8 +56,8 @@
5656
; CHECK-NEXT: remark: test.c:12:0: in artificial function '[[OFF_FUNC]]', Invokes = 0
5757
; CHECK-NEXT: remark: test.c:12:0: in artificial function '[[OFF_FUNC]]', FlatAddrspaceAccesses = 2
5858

59-
; CHECK-NEXT: remark: test.c:4:7: in function 'g', alloca 'i' with static size of 4 bytes
60-
; CHECK-NEXT: remark: test.c:5:7: in function 'g', alloca 'a' with static size of 8 bytes
59+
; CHECK-NEXT: remark: test.c:4:7: in function 'g', alloca ('%[[#]]') for 'i' with static size of 4 bytes
60+
; CHECK-NEXT: remark: test.c:5:7: in function 'g', alloca ('%[[#]]') for 'a' with static size of 8 bytes
6161
; 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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
; RUN: FileCheck -match-full-lines %s
88

99
; CHECK-NOT: remark:
10-
; CHECK: remark: test.c:0:0: in artificial function '[[OFF_FUNC:__omp_offloading_[a-f0-9_]*_h_l12]]_debug__', artificial alloca 'dyn_ptr' with static size of 8 bytes
11-
; CHECK-NEXT: remark: test.c:14:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'i' with static size of 4 bytes
12-
; CHECK-NEXT: remark: test.c:15:9: in artificial function '[[OFF_FUNC]]_debug__', alloca 'a' with static size of 8 bytes
10+
; CHECK: remark: test.c:0:0: in artificial function '[[OFF_FUNC:__omp_offloading_[a-f0-9_]*_h_l12]]_debug__', artificial alloca ('%[[#]]') for 'dyn_ptr' with static size of 8 bytes
11+
; CHECK-NEXT: remark: test.c:14:9: in artificial function '[[OFF_FUNC]]_debug__', alloca ('%[[#]]') for 'i' with static size of 4 bytes
12+
; CHECK-NEXT: remark: test.c:15:9: in artificial function '[[OFF_FUNC]]_debug__', alloca ('%[[#]]') for '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
1414
; CHECK-NEXT: remark: test.c:13:3: in artificial function '[[OFF_FUNC]]_debug__', direct call to defined function, callee is '@__kmpc_target_init'
1515
; CHECK-NEXT: remark: test.c:16:5: in artificial function '[[OFF_FUNC]]_debug__', direct call, callee is '@f'
@@ -26,7 +26,7 @@
2626
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', Invokes = 0
2727
; CHECK-NEXT: remark: test.c:13:0: in artificial function '[[OFF_FUNC]]_debug__', FlatAddrspaceAccesses = 1
2828

29-
; CHECK-NEXT: remark: test.c:0:0: in artificial function '[[OFF_FUNC]]', artificial alloca 'dyn_ptr' with static size of 8 bytes
29+
; CHECK-NEXT: remark: test.c:0:0: in artificial function '[[OFF_FUNC]]', artificial alloca ('%[[#]]') for 'dyn_ptr' with static size of 8 bytes
3030
; CHECK-NEXT: remark: <unknown>:0:0: in artificial function '[[OFF_FUNC]]', 'store' instruction accesses memory in flat address space
3131
; CHECK-NEXT: remark: test.c:12:1: in artificial function '[[OFF_FUNC]]', 'load' instruction ('%[[#]]') accesses memory in flat address space
3232
; CHECK-NEXT: remark: test.c:12:1: in artificial function '[[OFF_FUNC]]', direct call to defined function, callee is artificial '[[OFF_FUNC]]_debug__'
@@ -43,8 +43,8 @@
4343
; CHECK-NEXT: remark: test.c:12:0: in artificial function '[[OFF_FUNC]]', Invokes = 0
4444
; CHECK-NEXT: remark: test.c:12:0: in artificial function '[[OFF_FUNC]]', FlatAddrspaceAccesses = 2
4545

46-
; CHECK-NEXT: remark: test.c:4:7: in function 'g', alloca 'i' with static size of 4 bytes
47-
; CHECK-NEXT: remark: test.c:5:7: in function 'g', alloca 'a' with static size of 8 bytes
46+
; CHECK-NEXT: remark: test.c:4:7: in function 'g', alloca ('%[[#]]') for 'i' with static size of 4 bytes
47+
; CHECK-NEXT: remark: test.c:5:7: in function 'g', alloca ('%[[#]]') for 'a' with static size of 8 bytes
4848
; 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

0 commit comments

Comments
 (0)