Skip to content

Commit baf1c8d

Browse files
[CodeExtractor] Preserve entire scope of labels when moving them
When a dbg.label is moved into a new function, its corresponding scope should be preserved, with the exception of the subprogram at the end of the scope chain, which should now be the subprogram of the destination function. See D139671. Differential Revision: https://reviews.llvm.org/D139849
1 parent 4962be3 commit baf1c8d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,9 +1564,12 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
15641564
continue;
15651565
DILabel *OldLabel = DLI->getLabel();
15661566
DINode *&NewLabel = RemappedMetadata[OldLabel];
1567-
if (!NewLabel)
1568-
NewLabel = DILabel::get(Ctx, NewSP, OldLabel->getName(),
1567+
if (!NewLabel) {
1568+
DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram(
1569+
*OldLabel->getScope(), *NewSP, Ctx, Cache);
1570+
NewLabel = DILabel::get(Ctx, NewScope, OldLabel->getName(),
15691571
OldLabel->getFile(), OldLabel->getLine());
1572+
}
15701573
DLI->setArgOperand(0, MetadataAsValue::get(Ctx, NewLabel));
15711574
continue;
15721575
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target triple = "x86_64-apple-macosx10.14.0"
1313
; CHECK-LABEL: define {{.*}}@foo.cold.1
1414
; CHECK: llvm.dbg.label(metadata [[LABEL:![0-9]+]]), !dbg [[LINE:![0-9]+]]
1515
; CHECK: llvm.dbg.label(metadata [[LABEL_IN_INLINE_ME:![0-9]+]]), !dbg [[LINE2:![0-9]+]]
16+
; CHECK: llvm.dbg.label(metadata [[SCOPED_LABEL:![0-9]+]]), !dbg [[LINE]]
1617

1718
; CHECK: [[FILE:![0-9]+]] = !DIFile
1819
; CHECK: [[INLINE_ME_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "inline_me"
@@ -21,6 +22,8 @@ target triple = "x86_64-apple-macosx10.14.0"
2122
; CHECK: [[LABEL]] = !DILabel(scope: [[SCOPE]], name: "bye", file: [[FILE]], line: 28
2223
; CHECK: [[LABEL_IN_INLINE_ME]] = !DILabel(scope: [[INLINE_ME_SCOPE]], name: "label_in_@inline_me", file: [[FILE]], line: 29
2324
; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[INLINE_ME_SCOPE]], inlinedAt: [[LINE]]
25+
; CHECK: [[SCOPED_LABEL]] = !DILabel(scope: [[SCOPE_IN_FOO:![0-9]+]], name: "scoped_label_in_foo", file: [[FILE]], line: 30
26+
; CHECK: [[SCOPE_IN_FOO]] = !DILexicalBlock(scope: [[SCOPE]], file: [[FILE]], line: 31, column: 31)
2427

2528
define void @foo(i32 %arg1) !dbg !6 {
2629
entry:
@@ -33,6 +36,7 @@ if.then: ; preds = %entry
3336
if.end: ; preds = %entry
3437
call void @llvm.dbg.label(metadata !12), !dbg !11
3538
call void @llvm.dbg.label(metadata !14), !dbg !15
39+
call void @llvm.dbg.label(metadata !16), !dbg !11
3640
call void @sink()
3741
ret void
3842
}
@@ -65,3 +69,5 @@ define void @inline_me() !dbg !13 {
6569
!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)
6670
!14 = !DILabel(scope: !13, name: "label_in_@inline_me", file: !1, line: 29)
6771
!15 = !DILocation(line: 2, column: 2, scope: !13, inlinedAt: !11)
72+
!16 = !DILabel(scope: !17, name: "scoped_label_in_foo", file: !1, line: 30)
73+
!17 = distinct !DILexicalBlock(scope: !6, file: !1, line: 31, column: 31)

0 commit comments

Comments
 (0)