Skip to content

Add composite debug fragment support - #1087

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
uurl:feat/226-debug-composite-fragments
Aug 20, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
uurl:feat/226-debug-composite-fragments

Conversation

@uurl

@uurl uurl commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1086
Part of #226

Summary

Add support for rustc MIR composite debug-variable fragments through the MIR-to-LLVM debug pipeline.

This allows scalarized pieces of a source variable to retain their relationship to the original source-level variable and be exported using DW_OP_LLVM_fragment.

Changes

  • add fragment metadata carrying:

    • source variable information
    • bit offset
    • bit size
    • source scope
    • declaration location
  • import supported rustc MIR composite debug fragments instead of discarding them

  • preserve fragment metadata through MIR-to-LLVM lowering

  • preserve fragment metadata when mem2reg salvages a debug-tagged alloca into mir.dbg_value

  • emit fragment-aware llvm.dbg.declare expressions:

    !DIExpression(DW_OP_LLVM_fragment, <offset_bits>, <size_bits>)

* emit the same fragment expression for fragment-aware `llvm.dbg.value`

* reuse one `DILocalVariable` for multiple fragments belonging to the same source variable

* add focused LLVM-export and MIR-lowering tests

* document composite fragment support in the supported-features matrix

## Why

rustc can scalarize a source aggregate and describe the resulting pieces through composite `VarDebugInfo`.

Previously these entries were skipped by the MIR importer, so the source variable could not be reconstructed from its scalarized pieces.

Carrying the fragment range through the existing debug metadata pipeline provides the representation needed for LLVM and debuggers to associate those pieces with the original variable.

This is also groundwork for eventually removing the full-debug `-Zmir-opt-level=0` workaround.

## Non-goals

This PR intentionally does not remove `-Zmir-opt-level=0`.

Full debug therefore keeps its current optimization policy:

* rustc MIR optimization remains disabled by the existing workaround
* Pliron mem2reg remains disabled in full-debug mode
* LLVM `opt -O2` remains disabled
* `llc` remains at `-O0`

Removing the rustc MIR optimization workaround and validating scalarized variables end-to-end in `cuda-gdb` is a follow-up.

This PR also does not add runtime `ProjectionElem::Index` support.

## Validation

Validated with:

```text
cargo fmt --all -- --check

cargo test -p llvm-export \
  full_debug_metadata_emits_scalarized_fragment_dbg_declares \
  -- --nocapture

cargo test -p llvm-export \
  full_debug_metadata_emits_dbg_value_for_promoted_locals \
  -- --nocapture

cargo test -p mir-importer \
  scalar_replacement_debug_fragments_follow_rustc_layout_and_fail_closed \
  -- --nocapture

cargo test -p mir-lower \
  mem2reg_salvages_fragment_only_alloca_into_mir_dbg_value \
  -- --nocapture

cargo test -p mir-lower \
  convert_dbg_value_lowers_to_llvm_dbg_value \
  -- --nocapture

cargo test -p dialect-mir --all-targets
cargo test -p llvm-export --all-targets
cargo test -p mir-lower --all-targets
cargo test -p mir-importer --all-targets

cargo check --workspace --all-targets

cargo clippy --workspace --all-targets -- -D warnings

scripts/debug-smoketest.sh compiler_features

All validation passed.

@uurl
uurl force-pushed the feat/226-debug-composite-fragments branch from 5705b61 to 3c0746d Compare August 20, 2026 06:39
@uurl
uurl force-pushed the feat/226-debug-composite-fragments branch from 3c0746d to 4d6bab7 Compare August 20, 2026 06:42
@nihalpasham nihalpasham added enhancement New feature or request codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) debug info Debug information in generated PTX/IR (line/source maps) labels Aug 20, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Verified end to end: mir-importer 1102 tests green, including the in-process rustc fixture compiled with -Zmir-opt-level=3 on the pinned toolchain so SROA really produces the fragments under test; llvm-export/mir-lower/dialect-mir green; workspace clippy zero errors; scripts/debug-smoketest.sh compiler_features passes under cuda-gdb on sm_120.
  • Merge-checked against current main: the supported-features row auto-merges and the gates re-run green on the merged tree.
  • Folding a full-cover fragment into a whole-variable record matches rustc and avoids LLVM's FragSize verifier rejection; the fail-closed arms (projected storage, non-Field projections, ZSTs, out-of-bounds ranges via checked arithmetic) all check out.

nihalpasham
nihalpasham previously approved these changes Aug 20, 2026
@nihalpasham
nihalpasham merged commit 0a9f357 into NVIDIA:main Aug 20, 2026
50 checks passed
@uurl
uurl deleted the feat/226-debug-composite-fragments branch August 22, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) debug info Debug information in generated PTX/IR (line/source maps) enhancement New feature or request IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support composite debug variable fragments

2 participants