[Mlir-commits] [mlir] [mlir][LLVMIR] Avoid duplicate retained local variables (PR #209911)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 18 17:31:24 PDT 2026
qyingwu wrote:
> How does the debug info look if we export it back to LLVM IR?
>
> It may be ok if we have a duplication in MLIR as long as the exported debug information is correct.
>
> Also looking at the IR above, I wonder why the di_local_variable1 is not recursive if we traverse it starting from the debug intrinsic?
> How does the debug info look if we export it back to LLVM IR?
I checked this. With the subprogram-recursive import path, the MLIR still has two local variable attrs, but exporting it back to LLVM IR produces a single `DILocalVariable` metadata node. Both the `dbg.value` and the subprogram `retainedNodes` reference the same node:
```llvm
#dbg_value(i32 %0, !8, !DIExpression(), !9)
!3 = distinct !DISubprogram(name: "fn_with_retained_local", ..., retainedNodes: !7)
!7 = !{!8}
!8 = !DILocalVariable(name: "n", arg: 1, scope: !3, file: !1, line: 1, type: !6)
> It may be ok if we have a duplication in MLIR as long as the exported debug information is correct.
That makes sense.
I simplified the patch in that direction: it no longer extends the recursive debug-info machinery or tries to remove the MLIR-side duplication. The updated patch only adds export coverage showing that this duplicated MLIR shape is emitted as non-duplicated LLVM debug metadata.
> Also looking at the IR above, I wonder why the di_local_variable1 is not recursive if we traverse it starting from the debug intrinsic?
The repeated node during the retainedNodes traversal is the DISubprogram, so the cycle is broken there.
The local variable imported from retainedNodes is scoped by the self-recursive subprogram placeholder.
Later, when the debug intrinsic is imported, the subprogram has already been finalized. At that point, translating the same DILocalVariable no longer re-enters an active recursive traversal, so the local variable itself is not treated as recursive and is imported as a concrete local variable scoped by the finalized subprogram.
https://github.com/llvm/llvm-project/pull/209911
More information about the Mlir-commits
mailing list