Skip to content

[stinkytofu] Make hwreg() a typed StinkyRegister::HwReg operand variant#7729

Open
darrenhsieh-amd wants to merge 9 commits into
developfrom
users/darrenh/stinkytofu-hwreg-tablegen-v2
Open

[stinkytofu] Make hwreg() a typed StinkyRegister::HwReg operand variant#7729
darrenhsieh-amd wants to merge 9 commits into
developfrom
users/darrenh/stinkytofu-hwreg-tablegen-v2

Conversation

@darrenhsieh-amd
Copy link
Copy Markdown
Contributor

@darrenhsieh-amd darrenhsieh-amd commented May 25, 2026

Motivation

Insts s_setreg / s_getreg carry their hwreg(id, offset, size) operand as a plain LiteralString register, and that is opaque to
every pass. Any analysis that wants to reason about HWREG writes (e.g. detecting writers of a specific sub-field like
SCHED_MODE.DEP_MODE) has to pattern-match free-form text. This PR replaces the text blob with a typed StinkyRegister::HwReg operand variant and adds arch-aware name lookups so passes can interrogate the operand structurally.

This PR is on top of #7097

Technical Details

  • Tablegen-generated HWREG name tables
    • Per-arch table from DEF_HWREG blocks in each arch's formats file
    • Maps symbolic HW_REG_* names <-> numeric ids
  • Arch-aware lookup API
    • Name <-> id resolution backed by the generated tables
    • Sub-field accessors for SCHED_MODE.DEP_MODE, DISABLE_XDL_ARB_STALL, etc.
  • hwreg(...) as a typed operand variant of the register type
    • Replaces the opaque string with structured {id, offset, size}
    • Lives in the standard operand slot: destination for setreg, source for getreg
  • Helpers for the operand
    • Id-string resolution (symbolic <-> numeric)
    • Canonical emit with default-field suppression
    • Sub-field match predicate for pass-side detection
  • Round-trip wired through every boundary
    • Raw asm parser, IR text parser, asm emitter, IR text printer
    • Rocisa -> stinkytofu convertion

This branch stacks on top of users/darrenh/rawasmparser-coverage (which lands the per-field operand dispatch the parser dispatch relies on).

Test Plan

  • New FileCheck round-trip: tests/filecheck/hwreg_operand_roundtrip.s (parse -> emit produces canonical hwreg(...) form for each variant).
  • New tablegen check: test_gen_instructions asserts the per-arch <Arch>_hwreg.inc file is emitted with the expected array + a known entry.
  • Full ctest .

Test Result

Test Plan all passed.

Submission Checklist

@darrenhsieh-amd
Copy link
Copy Markdown
Contributor Author

darrenhsieh-amd commented May 25, 2026

This PR's commits start from f70894d . Earlier commits is on top of #7097

@darrenhsieh-amd darrenhsieh-amd changed the title [stinkytofu] Add tablegen-driven arch-aware HwReg model [draft][stinkytofu] Add tablegen-driven arch-aware HwReg model May 25, 2026
@darrenhsieh-amd darrenhsieh-amd changed the title [draft][stinkytofu] Add tablegen-driven arch-aware HwReg model [draft][stinkytofu] Add tablegen-driven HwReg model May 25, 2026
@darrenhsieh-amd darrenhsieh-amd changed the title [draft][stinkytofu] Add tablegen-driven HwReg model [stinkytofu] Make hwreg() a typed StinkyRegister::HwReg operand variant May 25, 2026
@darrenhsieh-amd darrenhsieh-amd force-pushed the users/darrenh/stinkytofu-hwreg-tablegen-v2 branch from 39d34f6 to f263a8f Compare May 25, 2026 15:50
…tions

- Operand loop walks operandFields and dispatches by FieldType.
- s_delay_alu / s_wait_alu / s_setreg_IMM32_b32 etc. no longer fall to TEXTBLOCK.
- Enables mixed-type instructions (hwreg + simm32 in s_setreg_IMM32_b32).
- Map MC_VOP3PX2/MC_VOP3PX3 → mod.matrix_fmt (typed MatrixFmtModifiers).
- Store key:Identifier modifier values in fields instead of marking unrepresentable.
- matrix_*_reuse cross-attaches to mod.mfma so one asm line yields both modifier types.
- inferModKeyFromFields detects dpp_ctrl/encoding-side keys → mod.dpp.
- Reconstruct asm-form token (e.g. "row_xmask:8") and feed parseDppCtrlFromAsm.
- DPP layers on many VOP formats, so MC-format alone can't pre-assign it.
Modifiers like `offset:8704*2` previously fell to TEXTBLOCK because
evalExpr only knew `+`/`-`; passes saw no typed offset. Now evaluated
to `17408`. Round-trip is no longer byte-identical for these cases
(emitted in folded form) — passes need the int, and storing both
original text and value would require dual-tracking through every
modifier.
- Add entry to availablePasses.
- Mark createCFGBuilderPass STINKYTOFU_EXPORT so the tool can link it.
- `--debug-pass FooPass` was treating "debug-pass" as a pass name.
- Skip the value argument like `-o`'s two-arg form.
- Replace unordered_map with order-preserving wrapper (same operator[]/iter API).
- Outer-key insertion order = canonical assembler trailing-modifier order.
- Inner field map stays unordered (each serializeVisit emits in fixed order).
…enerator

- DEF_HWREG(NAME, ID) blocks in each arch's Formats.def feed a constexpr NamedId table.
- Consumer (HwReg.cpp) lands in the next commit.
- hardware/HwReg.{hpp,cpp}: Id enum, name<->id, SCHED_MODE sub-field accessors
- StinkyRegister::HwReg variant with {id, offset, size}
- HwRegHelpers.hpp: parseId, printOperand, isSetregTo
- RawAsmParser, IRParser, AsmEmitter, AsmPrinter, rocisa bridge: use the variant
@darrenhsieh-amd darrenhsieh-amd force-pushed the users/darrenh/stinkytofu-hwreg-tablegen-v2 branch from f263a8f to 7090df9 Compare May 25, 2026 15:51
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project status has failed because the head coverage (77.83%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7729      +/-   ##
===========================================
- Coverage    61.94%   61.87%   -0.07%     
===========================================
  Files         2086     2086              
  Lines       357068   357219     +151     
  Branches     53779    53842      +63     
===========================================
- Hits        221171   221013     -158     
- Misses      117093   117410     +317     
+ Partials     18804    18796       -8     
Flag Coverage Δ *Carryforward flag
TensileLite 26.07% <ø> (-0.37%) ⬇️
hipBLAS 90.65% <ø> (ø) Carriedforward from 2cec672
hipBLASLt 41.27% <ø> (ø) Carriedforward from 2cec672
hipCUB 82.21% <ø> (ø) Carriedforward from 2cec672
hipDNN 85.87% <ø> (ø) Carriedforward from 2cec672
hipFFT 50.00% <ø> (ø) Carriedforward from 2cec672
hipRAND 76.12% <ø> (ø) Carriedforward from 2cec672
hipSOLVER 69.24% <ø> (ø) Carriedforward from 2cec672
hipSPARSE 85.09% <ø> (ø) Carriedforward from 2cec672
rocBLAS 48.11% <ø> (ø) Carriedforward from 2cec672
rocFFT 52.07% <ø> (ø) Carriedforward from 2cec672
rocRAND 57.04% <ø> (ø) Carriedforward from 2cec672
rocSOLVER 77.83% <ø> (ø) Carriedforward from 2cec672
rocSPARSE 72.68% <ø> (ø) Carriedforward from 2cec672

*This pull request uses carry forward flags. Click here to find out more.
see 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants