[llvm] 60f406c - [CodeExtractor] Only rewrite scope of non-inlined variables
Felipe de Azevedo Piovezan via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 10 11:38:43 PST 2022
Author: Felipe de Azevedo Piovezan
Date: 2022-12-10T14:38:09-05:00
New Revision: 60f406c4db5ba1ed6d66567ddaef4b86386496e1
URL: https://github.com/llvm/llvm-project/commit/60f406c4db5ba1ed6d66567ddaef4b86386496e1
DIFF: https://github.com/llvm/llvm-project/commit/60f406c4db5ba1ed6d66567ddaef4b86386496e1.diff
LOG: [CodeExtractor] Only rewrite scope of non-inlined variables
When a dbg.value instruction for a variable V is extracted into a new
function, the scope of the underlying variable should be set to the new
function iff V was in the scope of the old function (i.e. it hadn't been
inlined). Prior to this patch, the code extractor would always update
the scope of V.
Differential Revision: https://reviews.llvm.org/D139669
Added:
Modified:
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 08e224e097328..999744378dd9b 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1588,17 +1588,20 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
DebugIntrinsicsToDelete.push_back(DVI);
continue;
}
-
- // Point the intrinsic to a fresh variable within the new function.
- DILocalVariable *OldVar = DVI->getVariable();
- DINode *&NewVar = RemappedMetadata[OldVar];
- if (!NewVar)
- NewVar = DIB.createAutoVariable(
- NewSP, OldVar->getName(), OldVar->getFile(), OldVar->getLine(),
- OldVar->getType(), /*AlwaysPreserve=*/false, DINode::FlagZero,
- OldVar->getAlignInBits());
- DVI->setVariable(cast<DILocalVariable>(NewVar));
+ // If the variable was in the scope of the old function, i.e. it was not
+ // inlined, point the intrinsic to a fresh variable within the new function.
+ if (!DVI->getDebugLoc().getInlinedAt()) {
+ DILocalVariable *OldVar = DVI->getVariable();
+ DINode *&NewVar = RemappedMetadata[OldVar];
+ if (!NewVar)
+ NewVar = DIB.createAutoVariable(
+ NewSP, OldVar->getName(), OldVar->getFile(), OldVar->getLine(),
+ OldVar->getType(), /*AlwaysPreserve=*/false, DINode::FlagZero,
+ OldVar->getAlignInBits());
+ DVI->setVariable(cast<DILocalVariable>(NewVar));
+ }
}
+
for (auto *DII : DebugIntrinsicsToDelete)
DII->eraseFromParent();
DIB.finalizeSubprogram(NewSP);
diff --git a/llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll b/llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
index f9191cdf675c7..b296bbbdac632 100644
--- a/llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
+++ b/llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
@@ -31,6 +31,10 @@ target triple = "x86_64-apple-macosx10.14.0"
; CHECK-NEXT: call void @sink(i32 [[ADD1]]), !dbg [[LINE2:![0-9]+]]
; CHECK-NEXT: call void @sink(i32 [[ADD1]]), !dbg [[LINE3:![0-9]+]]
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[ADD1]]
+; CHECK-SAME: metadata [[VAR_FROM_INLINE_ME:![0-9]+]]
+; CHECK-SAME: !dbg [[LINE2]]
+
; - The DISubprogram for @foo.cold.1 has an empty DISubroutineType
; CHECK: [[FILE:![0-9]+]] = !DIFile(filename: "<stdin>"
; CHECK: [[EMPTY_MD:![0-9]+]] = !{}
@@ -47,6 +51,9 @@ target triple = "x86_64-apple-macosx10.14.0"
; CHECK: [[INLINED_SCOPE1]] = !DILexicalBlock(scope: [[INLINED_SCOPE2:![0-9]*]], file: [[FILE]], line: 4, column: 4)
; CHECK: [[INLINED_SCOPE2]] = !DILexicalBlock(scope: [[NEWSCOPE]], file: [[FILE]], line: 5, column: 5)
+; CHECK: [[VAR_FROM_INLINE_ME]] = !DILocalVariable(name: "var_from_inline_me",
+; CHECK-SAME: scope: [[INLINE_ME_SCOPE]]
+
define void @foo(i32 %arg1) !dbg !6 {
entry:
%var = add i32 0, 0, !dbg !11
@@ -64,6 +71,7 @@ if.end: ; preds = %entry
call void @llvm.dbg.value(metadata i32 %add1, metadata !9, metadata !DIExpression(DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !11
call void @sink(i32 %add1), !dbg !13 ; inlined from @inline_me
call void @sink(i32 %add1), !dbg !14 ; not inlined, but inside some scope of foo
+ call void @llvm.dbg.value(metadata i32 %add1, metadata !17, metadata !DIExpression()), !dbg !13 ; variable from @inline_me, should preserve scope in !17.
ret void
}
@@ -96,3 +104,4 @@ define void @inline_me() !dbg !12{
!14 = !DILocation(line: 3, column: 3, scope: !15)
!15 = distinct !DILexicalBlock(scope: !16, file: !1, line: 4, column: 4)
!16 = distinct !DILexicalBlock(scope: !6, file: !1, line: 5, column: 5)
+!17 = !DILocalVariable(name: "var_from_inline_me", scope: !12, file: !1, line: 1, type: !10)
More information about the llvm-commits
mailing list