[PATCH] D139848: [CodeExtractor] Only rewrite scope of labels that were not inlined

Felipe de Azevedo Piovezan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 08:28:14 PST 2022


fdeazeve created this revision.
fdeazeve added a reviewer: aprantl.
Herald added a subscriber: hiraditya.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

dbg.labels that were inlined from other functions should have their
scope preserved upon outlining for the same reasons described in
D139669 <https://reviews.llvm.org/D139669>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139848

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


Index: llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
===================================================================
--- llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
+++ llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
@@ -12,11 +12,15 @@
 
 ; 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_ at 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.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 @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 @@
 !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_ at inline_me", file: !1, line: 29)
+!15 = !DILocation(line: 2, column: 2, scope: !13, inlinedAt: !11)
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1562,8 +1562,11 @@
     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<DbgLabelInst>(&I)) {
+      if (DLI->getDebugLoc().getInlinedAt())
+        continue;
       DILabel *OldLabel = DLI->getLabel();
       DINode *&NewLabel = RemappedMetadata[OldLabel];
       if (!NewLabel)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139848.482142.patch
Type: text/x-patch
Size: 2794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221212/deaec42a/attachment.bin>


More information about the llvm-commits mailing list