From 79d59c3f3e8abb66a758793bfd9acd8ea6b3d92b Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Mon, 12 Dec 2022 10:22:44 -0500 Subject: [PATCH] [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. --- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 5 ++++- llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index feb2a0e..4c373f7 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1562,8 +1562,11 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, if (!DII) continue; - // Point the intrinsic to a fresh label within the new function. + // Point the intrinsic to a fresh label within the new function if the + // intrinsic was not inlined from some other function. if (auto *DLI = dyn_cast(&I)) { + if (DLI->getDebugLoc().getInlinedAt()) + continue; DILabel *OldLabel = DLI->getLabel(); DINode *&NewLabel = RemappedMetadata[OldLabel]; if (!NewLabel) diff --git a/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll b/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll index e62f13b..64fe2fa 100644 --- a/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll +++ b/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll @@ -12,11 +12,15 @@ target triple = "x86_64-apple-macosx10.14.0" ; CHECK-LABEL: define {{.*}}@foo.cold.1 ; CHECK: llvm.dbg.label(metadata [[LABEL:![0-9]+]]), !dbg [[LINE:![0-9]+]] +; CHECK: llvm.dbg.label(metadata [[LABEL_IN_INLINE_ME:![0-9]+]]), !dbg [[LINE2:![0-9]+]] ; CHECK: [[FILE:![0-9]+]] = !DIFile +; CHECK: [[INLINE_ME_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "inline_me" ; CHECK: [[SCOPE:![0-9]+]] = distinct !DISubprogram(name: "foo.cold.1" ; CHECK: [[LINE]] = !DILocation(line: 1, column: 1, scope: [[SCOPE]] ; CHECK: [[LABEL]] = !DILabel(scope: [[SCOPE]], name: "bye", file: [[FILE]], line: 28 +; CHECK: [[LABEL_IN_INLINE_ME]] = !DILabel(scope: [[INLINE_ME_SCOPE]], name: "label_in_@inline_me", file: [[FILE]], line: 29 +; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[INLINE_ME_SCOPE]], inlinedAt: [[LINE]] define void @foo(i32 %arg1) !dbg !6 { entry: @@ -28,6 +32,7 @@ if.then: ; preds = %entry if.end: ; preds = %entry call void @llvm.dbg.label(metadata !12), !dbg !11 + call void @llvm.dbg.label(metadata !14), !dbg !15 call void @sink() ret void } @@ -36,6 +41,10 @@ declare void @llvm.dbg.label(metadata) declare void @sink() cold +define void @inline_me() !dbg !13 { + ret void +} + !llvm.dbg.cu = !{!0} !llvm.debugify = !{!3, !4} !llvm.module.flags = !{!5} @@ -53,3 +62,6 @@ declare void @sink() cold !10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned) !11 = !DILocation(line: 1, column: 1, scope: !6) !12 = !DILabel(scope: !6, name: "bye", file: !1, line: 28) +!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) +!14 = !DILabel(scope: !13, name: "label_in_@inline_me", file: !1, line: 29) +!15 = !DILocation(line: 2, column: 2, scope: !13, inlinedAt: !11) -- 2.7.4