Files
TheRock/rocm-libraries/shared/stinkytofu/docs/user/remove-instruction-pass.md
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

3.2 KiB

RemoveInstructionPass

RemoveInstructionPass strips instructions whose unified opcode matches a configured target set from every basic block approved by PassContext::shouldProcessBasicBlock.

Typical use cases include experiments that remove specific instruction classes (e.g. tensor_load_to_lds) without hand-editing generated assembly.

gfx1250 pipeline integration

On gfx1250, the pass is registered as the last kernel-scope pass (after AccumulateInstructionSizePass). It is disabled by default: the factory returns nullptr when ModuleOptions.RemoveInstructions is empty, so nothing is removed unless you opt in.

Configuration

Via stinkytofu-opt

Pass mnemonics are comma-separated unified opcode names (the same strings used in GFX:: / HwInstDesc::mnemonic):

./build/tools/stinkytofu-opt/stinkytofu-opt \
    --arch gfx1250 input.stir \
    --RemoveInstructionPass=tensor_load_to_lds \
    --print-output

Remove multiple instruction types in one run:

./build/tools/stinkytofu-opt/stinkytofu-opt \
    --arch gfx1250 input.stir \
    --RemoveInstructionPass=tensor_load_to_lds,ds_load_b128,v_wmma_f32_16x16x16_bf16 \
    --print-output

Mnemonics are resolved against the target architecture at pass run time. Unknown names are skipped with a PASS_DEBUG message; if no valid opcode remains, the pass is a no-op.

Via Tensile / rocisa (ModuleOptions)

Set RemoveInstructions in the options dict passed to rocisa.toStinkyTofuModule(). In KernelWriter.py, add it to stinky_module_options:

stinky_module_options = {
    "OptLevel": stinky_opt_level,
    # ...
    "RemoveInstructions": "tensor_load_to_lds",
}

Comma-separated values remove multiple opcodes, for example:

"RemoveInstructions": "tensor_load_to_lds,ds_load_b128,v_wmma_f32_16x16x16_bf16"

Leave RemoveInstructions unset or as "" to keep the pass disabled.

Programmatic C++ API

// Disabled (returns nullptr)
auto disabled = createRemoveInstructionPass();

// Comma-separated mnemonics (gfx1250 backend uses this form)
auto pass = createRemoveInstructionPass("tensor_load_to_lds,s_nop");
if (pass) pm.addPass(std::move(pass));

// Explicit unified opcodes
pm.addPass(createRemoveInstructionPass(
    std::vector<UnifiedOpcode>{GFX::tensor_load_to_lds}));

// Mnemonic list (resolved at run time)
pm.addPass(createRemoveInstructionPass(
    std::vector<std::string>{"tensor_load_to_lds", "ds_load_b128"}));

Common mnemonics

Mnemonic Instruction class
tensor_load_to_lds Tensor prefetch to LDS
ds_load_b128 DS load (example LDS read)
v_wmma_f32_16x16x16_bf16 WMMA matrix multiply

Use the exact mnemonic string for your target architecture. Operand variants (e.g. different WMMA shapes) are separate unified opcodes.

Tests

  • Unit: tests/unit/asm/RemoveInstructionPassTest.cpp
  • FileCheck: tests/filecheck/remove_instruction.stir
cd build && ctest -R 'RemoveInstructionPassTest|FileCheck.remove_instruction'

Implementation

  • include/stinkytofu/transforms/asm/RemoveInstructionPass.hpp
  • src/transforms/asm/RemoveInstructionPass.cpp
  • src/pipeline/backend/Gfx1250Backend.cpp (conditional pipeline hook)