Skip to content

Commit f9a5b79

Browse files
[CodeExtractor] Consider Value arguments of dbg.assign (llvm#67987)
Currently, the code extractor functionality deletes a debug intrinsic if its "Location" argument is not part of the extracted function. The location is the first argument (or the first few arguments in case of a DIArgList) of all debug intrinsics. However, according to the docs, the signature of dbg.assign is: ``` void @llvm.dbg.assign(Value *Value, DIExpression *ValueExpression, DILocalVariable *Variable, DIAssignID *ID, Value *Address, DIExpression *AddressExpression) ``` That is, there are two `Value` arguments to it: the usual location argument and an "Address" argument. This Address argument should also receive the same treatment. (cherry picked from commit 5064ca8)
1 parent c5a1c23 commit f9a5b79

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,12 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
15781578
DebugIntrinsicsToDelete.push_back(DVI);
15791579
continue;
15801580
}
1581+
// DbgAssign intrinsics have an extra Value argument:
1582+
if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
1583+
DAI && IsInvalidLocation(DAI->getAddress())) {
1584+
DebugIntrinsicsToDelete.push_back(DVI);
1585+
continue;
1586+
}
15811587
// If the variable was in the scope of the old function, i.e. it was not
15821588
// inlined, point the intrinsic to a fresh variable within the new function.
15831589
if (!DVI->getDebugLoc().getInlinedAt()) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: opt -passes=hotcoldsplit -hotcoldsplit-threshold=-1 -S %s | FileCheck %s
2+
declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
3+
4+
; CHECK: define void @foo
5+
; CHECK-NOT: dbg.assign
6+
; CHECK: call void @foo.cold
7+
; CHECK-NOT: dbg.assign
8+
; CHECK: define internal void @foo.cold
9+
; CHECK-NOT: dbg.assign
10+
define void @foo() !dbg !10 {
11+
%buf.i = alloca i32, align 4, !DIAssignID !8
12+
br i1 false, label %if.else, label %if.then
13+
14+
if.then: ; preds = %0
15+
call void @llvm.dbg.assign(metadata i1 undef, metadata !9, metadata !DIExpression(), metadata !8, metadata ptr %buf.i, metadata !DIExpression()), !dbg !14
16+
unreachable
17+
18+
if.else: ; preds = %0
19+
ret void
20+
}
21+
22+
23+
!llvm.dbg.cu = !{!0}
24+
!llvm.module.flags = !{!3}
25+
26+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "blah", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2)
27+
!1 = !DIFile(filename: "blah", directory: "blah")
28+
!2 = !{}
29+
!3 = !{i32 2, !"Debug Info Version", i32 3}
30+
!6 = distinct !DISubroutineType(types: !7)
31+
!7 = !{null}
32+
!8 = distinct !DIAssignID()
33+
!9 = !DILocalVariable(name: "buf", scope: !10, file: !1, line: 1774, type: !13)
34+
!10 = distinct !DISubprogram(name: "blah", scope: !1, file: !1, line: 1771, type: !11, scopeLine: 1773, unit: !0, retainedNodes: !2)
35+
!11 = !DISubroutineType(cc: DW_CC_nocall, types: !7)
36+
!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
37+
!14 = !DILocation(line: 0, scope: !10)

0 commit comments

Comments
 (0)