[llvm] b432dd2 - [CodeExtractor] Preserve entire scope of labels when moving them

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 12:49:43 PST 2022


Author: Felipe de Azevedo Piovezan
Date: 2022-12-12T15:48:55-05:00
New Revision: b432dd2d4b75847cc51bd3d4b41f4d71ca9bf0bd

URL: https://github.com/llvm/llvm-project/commit/b432dd2d4b75847cc51bd3d4b41f4d71ca9bf0bd
DIFF: https://github.com/llvm/llvm-project/commit/b432dd2d4b75847cc51bd3d4b41f4d71ca9bf0bd.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/CodeExtractor.cpp
    llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 4c373f72e05b6..babe9be9d8f9e 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1569,9 +1569,12 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
         continue;
       DILabel *OldLabel = DLI->getLabel();
       DINode *&NewLabel = RemappedMetadata[OldLabel];
-      if (!NewLabel)
-        NewLabel = DILabel::get(Ctx, NewSP, OldLabel->getName(),
+      if (!NewLabel) {
+        DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram(
+            *OldLabel->getScope(), *NewSP, Ctx, Cache);
+        NewLabel = DILabel::get(Ctx, NewScope, OldLabel->getName(),
                                 OldLabel->getFile(), OldLabel->getLine());
+      }
       DLI->setArgOperand(0, MetadataAsValue::get(Ctx, NewLabel));
       continue;
     }

diff  --git a/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll b/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
index 64fe2fa914502..8209f93915e9c 100644
--- a/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
+++ b/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
@@ -13,6 +13,7 @@ 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: llvm.dbg.label(metadata [[SCOPED_LABEL:![0-9]+]]), !dbg [[LINE]]
 
 ; CHECK: [[FILE:![0-9]+]] = !DIFile
 ; CHECK: [[INLINE_ME_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "inline_me"
@@ -21,6 +22,8 @@ target triple = "x86_64-apple-macosx10.14.0"
 ; CHECK: [[LABEL]] = !DILabel(scope: [[SCOPE]], name: "bye", file: [[FILE]], line: 28
 ; CHECK: [[LABEL_IN_INLINE_ME]] = !DILabel(scope: [[INLINE_ME_SCOPE]], name: "label_in_ at inline_me", file: [[FILE]], line: 29
 ; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[INLINE_ME_SCOPE]], inlinedAt: [[LINE]]
+; CHECK: [[SCOPED_LABEL]] = !DILabel(scope: [[SCOPE_IN_FOO:![0-9]+]], name: "scoped_label_in_foo", file: [[FILE]], line: 30
+; CHECK: [[SCOPE_IN_FOO]] = !DILexicalBlock(scope: [[SCOPE]], file: [[FILE]], line: 31, column: 31)
 
 define void @foo(i32 %arg1) !dbg !6 {
 entry:
@@ -33,6 +36,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 @llvm.dbg.label(metadata !16), !dbg !11
   call void @sink()
   ret void
 }
@@ -65,3 +69,5 @@ define void @inline_me() !dbg !13 {
 !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_ at inline_me", file: !1, line: 29)
 !15 = !DILocation(line: 2, column: 2, scope: !13, inlinedAt: !11)
+!16 = !DILabel(scope: !17, name: "scoped_label_in_foo", file: !1, line: 30)
+!17 = distinct !DILexicalBlock(scope: !6, file: !1, line: 31, column: 31)


        


More information about the llvm-commits mailing list