Skip to content

Replace hand-rolled DI scope rewriter with mlir::AttrTypeReplacer#199

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/di-fixer-attr-type-replacer
Jul 11, 2026
Merged

Replace hand-rolled DI scope rewriter with mlir::AttrTypeReplacer#199
ASDAlexander77 merged 1 commit into
mainfrom
refactor/di-fixer-attr-type-replacer

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

LLVMDebugInfoHelperFixer completes each function's DISubprogramAttr with real signature DI types at lowering time (they need LLVM layout info that doesn't exist at MLIRGen time), then must remap every reference to the old scope. That remapping was ~450 lines of hand-written recursive location/attribute rewriting; mlir::AttrTypeReplacer does the same job generically with a single DISubprogramAttr replacement rule, transitively rebuilding any attribute or location containing the old scope (lexical blocks, local variables, labels, nested subprograms).

Net: 61 insertions, 456 deletions in LLVMDebugInfoFixer.h.

Bugs the old rewriter had (fixed by this change)

  • The CallSiteLoc case compared the new caller against getCallee() and never rewrote callee scopes, leaking stale empty-signature subprograms into DWARF as duplicate DISubprogram nodes (3–7 duplicates per file observed in --di output of 00class/00funcs/02numbers; gone after this change).
  • The DbgValueOp branch compared against dbgDeclare (null in that branch) — latent null-op dereference.
  • Unknown Location kinds hit llvm_unreachable; AttrTypeReplacer handles all location kinds generically.

Also removes the never-referenced LLVMDebugInfoHelperCreator and unused stripMetadata/removeAllMetadata/walkMetadata/debugPrint helpers.

Test plan

  • --di LLVM IR compared before/after on 00funcs, 00class, 19forof_capture, 02numbers: identical except removal of the duplicate DISubprogram nodes (modulo pre-existing nondeterministic name hashes, confirmed by same-binary self-diff).
  • Full test suite: 683/683 pass.
  • JIT smoke run with --di enabled.

🤖 Generated with Claude Code

LLVMDebugInfoHelperFixer completes each function's DISubprogramAttr with
real signature DI types at lowering time (they need LLVM layout info that
does not exist at MLIRGen time), then must remap every reference to the
old scope. That remapping was ~450 lines of hand-written recursive
location/attribute rewriting; mlir::AttrTypeReplacer does the same job
generically with a single DISubprogramAttr replacement rule, rebuilding
any attribute or location that contains the old scope transitively.

Also fixes real defects the old rewriter had:
- CallSiteLoc handling compared the new caller against getCallee() and
  never rewrote callee scopes, leaking stale empty-signature subprograms
  into DWARF as duplicate DISubprogram nodes (3-7 duplicates per test
  file in 00class/00funcs/02numbers --di output; gone after this change,
  otherwise byte-identical debug info modulo nondeterministic name
  hashes).
- The DbgValueOp branch compared against dbgDeclare (null there), a
  latent null-op dereference.
- Unknown Location kinds hit llvm_unreachable; AttrTypeReplacer handles
  all location kinds.

Also removes the never-referenced LLVMDebugInfoHelperCreator and the
unused stripMetadata/removeAllMetadata/walkMetadata/debugPrint helpers.

Verified: --di LLVM IR compared before/after on 00funcs, 00class,
19forof_capture, 02numbers (identical except duplicate removal); full
test suite 683/683; JIT smoke run with --di.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 merged commit 392fbff into main Jul 11, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/di-fixer-attr-type-replacer branch July 11, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant