[CodeExtractor] Use scope reparenting helper to update loop dbg loc
authorFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Mon, 12 Dec 2022 17:00:49 +0000 (12:00 -0500)
committerFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Mon, 12 Dec 2022 20:50:52 +0000 (15:50 -0500)
Apply the same strategy from D139217 to loop debug locations.

Differential Revision: https://reviews.llvm.org/D139851

llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll

index babe9be..3aa16eb 100644 (file)
@@ -1624,10 +1624,9 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
           DebugLoc::replaceInlinedAtSubprogram(DL, *NewSP, Ctx, Cache));
 
     // Loop info metadata may contain line locations. Fix them up.
-    auto updateLoopInfoLoc = [&Ctx, NewSP](Metadata *MD) -> Metadata * {
+    auto updateLoopInfoLoc = [&Ctx, &Cache, NewSP](Metadata *MD) -> Metadata * {
       if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
-        return DILocation::get(Ctx, Loc->getLine(), Loc->getColumn(), NewSP,
-                               nullptr);
+        return DebugLoc::replaceInlinedAtSubprogram(Loc, *NewSP, Ctx, Cache);
       return MD;
     };
     updateLoopMetadataDebugLocations(I, updateLoopInfoLoc);
index 44e8f80..97ec3b5 100644 (file)
@@ -11,8 +11,10 @@ target triple = "x86_64-apple-macosx10.14.0"
 
 ; The scope for these debug locations should be @basic.cold.1, not @basic.
 ; CHECK: [[SCOPE:![0-9]+]] = distinct !DISubprogram(name: "basic.cold.1"
-; CHECK: [[LOOP_MD]] = distinct !{[[LOOP_MD]], [[LINE:![0-9]+]], [[LINE]]}
+; CHECK: [[LOOP_MD]] = distinct !{[[LOOP_MD]], [[LINE:![0-9]+]], [[LINE2:![0-9]+]]}
 ; CHECK: [[LINE]] = !DILocation(line: 1, column: 1, scope: [[SCOPE]])
+; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[LEX_SCOPE:![0-9]+]])
+; CHECK: [[LEX_SCOPE]] = !DILexicalBlock(scope: [[SCOPE]], file: !{{[0-9]+}}, line: 3, column: 3)
 
 define void @basic(ptr %p, i32 %k) !dbg !6 {
 entry:
@@ -55,4 +57,6 @@ declare void @sink() cold
 !7 = !DISubroutineType(types: !2)
 !8 = !{}
 !9 = !DILocation(line: 1, column: 1, scope: !6)
-!10 = distinct !{!10, !9, !9}
+!10 = distinct !{!10, !9, !11}
+!11 = !DILocation(line: 2, column: 2, scope: !12)
+!12 = !DILexicalBlock(scope: !6, file: !1, line: 3, column: 3)