[llvm] [DebugInfo][RemoveDIs] Set new-dbg-info flag from Modules correctly (PR #82373)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 07:47:30 PST 2024
https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/82373
It turns out there's a pathway for Functions to be inserted into modules without having the "New" debug-info flag set correctly, which this patch fixes. Sadly there isn't a Module::insert method to instrument out there, everyone touches the list directly.
This fix exposes a path where such functions are produced in the outliner in the wrong mode; requiring a fix there to correctly drop RemoveDIs-mode debug-info. This is covered by test/DebugInfo/AArch64/ir-outliner.ll
>From ed8a764eaed60a6bafd56b3b9753ed94eee342fb Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Tue, 20 Feb 2024 15:39:56 +0000
Subject: [PATCH] [DebugInfo][RemoveDIs] Set new-dbg-info flag from Modules
correctly
It turns out there's a pathway for Functions to be inserted into modules
without having the "New" debug-info flag set correctly, which this patch
fixes.
Doing that exposes a path where such functions are produced in the outliner
in the wrong mode; requiring a fix there to correctly drop RemoveDIs-mode
debug-info. This is covered by test/DebugInfo/AArch64/ir-outliner.ll
---
llvm/lib/IR/Function.cpp | 4 +++-
llvm/lib/Transforms/IPO/IROutliner.cpp | 11 +++++++----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index fceffbc3cea6d7..056e4f31981a72 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -437,8 +437,10 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
if (Ty->getNumParams())
setValueSubclassData(1); // Set the "has lazy arguments" bit.
- if (ParentModule)
+ if (ParentModule) {
ParentModule->getFunctionList().push_back(this);
+ IsNewDbgInfoFormat = ParentModule->IsNewDbgInfoFormat;
+ }
HasLLVMReservedName = getName().starts_with("llvm.");
// Ensure intrinsics have the right parameter attributes.
diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 8e6d0e814372d6..48470bc71ff38a 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -721,6 +721,12 @@ static void moveFunctionData(Function &Old, Function &New,
std::vector<Instruction *> DebugInsts;
for (Instruction &Val : CurrBB) {
+ // Since debug-info originates from many different locations in the
+ // program, it will cause incorrect reporting from a debugger if we keep
+ // the same debug instructions. Drop non-intrinsic DPValues here,
+ // collect intrinsics for removal later.
+ Val.dropDbgValues();
+
// We must handle the scoping of called functions differently than
// other outlined instructions.
if (!isa<CallInst>(&Val)) {
@@ -744,10 +750,7 @@ static void moveFunctionData(Function &Old, Function &New,
// From this point we are only handling call instructions.
CallInst *CI = cast<CallInst>(&Val);
- // We add any debug statements here, to be removed after. Since the
- // instructions originate from many different locations in the program,
- // it will cause incorrect reporting from a debugger if we keep the
- // same debug instructions.
+ // Collect debug intrinsics for later removal.
if (isa<DbgInfoIntrinsic>(CI)) {
DebugInsts.push_back(&Val);
continue;
More information about the llvm-commits
mailing list