Skip to content

Commit 79d59c3

Browse files
[CodeExtractor] Only rewrite scope of labels that were not inlined
dbg.labels that were inlined from other functions should have their scope preserved upon outlining for the same reasons described in D139669.
1 parent c187182 commit 79d59c3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,11 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
15621562
if (!DII)
15631563
continue;
15641564

1565-
// Point the intrinsic to a fresh label within the new function.
1565+
// Point the intrinsic to a fresh label within the new function if the
1566+
// intrinsic was not inlined from some other function.
15661567
if (auto *DLI = dyn_cast<DbgLabelInst>(&I)) {
1568+
if (DLI->getDebugLoc().getInlinedAt())
1569+
continue;
15671570
DILabel *OldLabel = DLI->getLabel();
15681571
DINode *&NewLabel = RemappedMetadata[OldLabel];
15691572
if (!NewLabel)

llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ target triple = "x86_64-apple-macosx10.14.0"
1212

1313
; CHECK-LABEL: define {{.*}}@foo.cold.1
1414
; CHECK: llvm.dbg.label(metadata [[LABEL:![0-9]+]]), !dbg [[LINE:![0-9]+]]
15+
; CHECK: llvm.dbg.label(metadata [[LABEL_IN_INLINE_ME:![0-9]+]]), !dbg [[LINE2:![0-9]+]]
1516

1617
; CHECK: [[FILE:![0-9]+]] = !DIFile
18+
; CHECK: [[INLINE_ME_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "inline_me"
1719
; CHECK: [[SCOPE:![0-9]+]] = distinct !DISubprogram(name: "foo.cold.1"
1820
; CHECK: [[LINE]] = !DILocation(line: 1, column: 1, scope: [[SCOPE]]
1921
; CHECK: [[LABEL]] = !DILabel(scope: [[SCOPE]], name: "bye", file: [[FILE]], line: 28
22+
; CHECK: [[LABEL_IN_INLINE_ME]] = !DILabel(scope: [[INLINE_ME_SCOPE]], name: "label_in_@inline_me", file: [[FILE]], line: 29
23+
; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[INLINE_ME_SCOPE]], inlinedAt: [[LINE]]
2024

2125
define void @foo(i32 %arg1) !dbg !6 {
2226
entry:
@@ -28,6 +32,7 @@ if.then: ; preds = %entry
2832

2933
if.end: ; preds = %entry
3034
call void @llvm.dbg.label(metadata !12), !dbg !11
35+
call void @llvm.dbg.label(metadata !14), !dbg !15
3136
call void @sink()
3237
ret void
3338
}
@@ -36,6 +41,10 @@ declare void @llvm.dbg.label(metadata)
3641

3742
declare void @sink() cold
3843

44+
define void @inline_me() !dbg !13 {
45+
ret void
46+
}
47+
3948
!llvm.dbg.cu = !{!0}
4049
!llvm.debugify = !{!3, !4}
4150
!llvm.module.flags = !{!5}
@@ -53,3 +62,6 @@ declare void @sink() cold
5362
!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
5463
!11 = !DILocation(line: 1, column: 1, scope: !6)
5564
!12 = !DILabel(scope: !6, name: "bye", file: !1, line: 28)
65+
!13 = distinct !DISubprogram(name: "inline_me", linkageName: "inline_me", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
66+
!14 = !DILabel(scope: !13, name: "label_in_@inline_me", file: !1, line: 29)
67+
!15 = !DILocation(line: 2, column: 2, scope: !13, inlinedAt: !11)

0 commit comments

Comments
 (0)