[llvm] [CodeExtractor] Improve debug info for input values. (PR #136016)
Tim Gymnich via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 10:55:31 PDT 2025
================
@@ -1273,14 +1280,49 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
/*LineNo=*/0, SPType, /*ScopeLine=*/0, DINode::FlagZero, SPFlags);
NewFunc.setSubprogram(NewSP);
+ auto UpdateOrInsertDebugRecord = [&](auto *DR, Value *OldLoc, Value *NewLoc,
+ DIExpression *Expr, bool Declare) {
+ if (DR->getParent()->getParent() == &NewFunc)
+ DR->replaceVariableLocationOp(OldLoc, NewLoc);
+ else {
+ if (Declare)
+ DIB.insertDeclare(NewLoc, DR->getVariable(), Expr, DR->getDebugLoc(),
+ &NewFunc.getEntryBlock());
+ else
+ DIB.insertDbgValueIntrinsic(
+ NewLoc, DR->getVariable(), Expr, DR->getDebugLoc(),
+ NewFunc.getEntryBlock().getTerminator()->getIterator());
+ }
+ };
+ for (auto [Input, NewVal] : zip_equal(Inputs, NewValues)) {
+ SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
+ SmallVector<DbgVariableRecord *, 1> DPUsers;
+ findDbgUsers(DbgUsers, Input, &DPUsers);
+ DIExpression *Expr = DIB.createExpression();
+
+ // Iterate the debud users of the Input values. If they are in the extracted
+ // function then update their location with the new value. If they are in
+ // the parent function then create a similar debug record.
+ for (auto *DVI : DbgUsers) {
+ UpdateOrInsertDebugRecord(DVI, Input, NewVal, Expr,
+ isa<DbgDeclareInst>(DVI));
+ }
----------------
tgymnich wrote:
```suggestion
for (auto *DVI : DbgUsers)
UpdateOrInsertDebugRecord(DVI, Input, NewVal, Expr,
isa<DbgDeclareInst>(DVI));
```
https://github.com/llvm/llvm-project/pull/136016
More information about the llvm-commits
mailing list