spv-opt

Implements SPIRV-Tools optimizer passes with IR manipulation and PassTest registration.

1.0k|108|Updated Nov 20, 2020
One-click install
npx skills add https://github.com/LuisaGroup/LuisaCompute --skill spv-opt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spv-opt
Source: https://github.com/LuisaGroup/LuisaCompute/tree/main/.agents/skills/spv-opt
Command: npx skills add https://github.com/LuisaGroup/LuisaCompute --skill spv-opt

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing custom SPIR-V optimizer passes requires deep knowledge of SPIRV-Tools internals like IRContext, InstructionBuilder, def-use management, and pass registration plumbing, which is poorly documented and error-prone.

Core Features & Use Cases

  • Pass Skeletons: Provides ready templates for deriving from Pass or MemPass, implementing Process(), and declaring preserved analyses.
  • IR Manipulation Reference: Covers Instruction, BasicBlock, Function, and InstructionBuilder APIs for building, replacing, and killing instructions safely.
  • Testing & Registration: Documents the PassTest fixture helpers (SinglePassRunAndCheck, SinglePassRunAndMatch) and the full pass registration flow in optimizer.cpp and CMake.
  • Use Case: You need to add a new optimization pass to the SPIRV-Tools fork in LuisaCompute; use this Skill to scaffold the pass, write Effcee-based match tests, and wire up the CLI flag.

Quick Start

Write a new SPIRV-Tools optimizer pass that removes redundant stores and register it with a CLI flag.

Frequently Asked Questions about spv-opt

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a custom SPIRV-Tools optimizer pass?

Derive a class from spvtools::opt::Pass, implement name() and Process(), and declare preserved analyses in GetPreservedAnalyses(). Iterate functions, blocks, and instructions via get_module(), then return SuccessWithChange or SuccessWithoutChange.

How do I test a SPIR-V optimizer pass with PassTest?

Use the PassTest fixture with SinglePassRunAndCheck for exact output matching or SinglePassRunAndMatch with embedded Effcee CHECK comments in the assembly. Tests live in test/opt/ and support multi-pass pipelines via AddPass and RunAndCheck.

When should I use MemPass instead of Pass in SPIRV-Tools?

Use MemPass for memory-oriented passes like load/store elimination, since it provides helpers such as GetPtr, IsTargetVar, CollectTargetVars, and Type2Undef. Derive from the base Pass class for general IR transformations.

Why does my SPIR-V pass break after modifying instructions?

Modifications invalidate analyses not listed in GetPreservedAnalyses(), and InstructionBuilder only preserves def-use and instruction-to-block mappings. Invalidate stale analyses explicitly and avoid deleting instructions during iteration; collect them first and kill afterward.

How do I register a new pass with a CLI flag in SPIRV-Tools?

Add a CreateMyPassPass factory declaration in optimizer.hpp, implement it in optimizer.cpp, and map the flag name inside RegisterPassFromFlag. Also add the sources to source/opt/CMakeLists.txt and create a test file under test/opt/.