Context
Integrating new RISC-V extensions (like SpacemiT vmadot) requires coordinated changes across LLVM intrinsics, IREE Attributes (IREECPUAttrs.td), Enums (IREECPUEnums.td), and unit tests. Currently, this is a manual, error-prone process involving scattered C++ and TableGen files. We need a single source of truth (a "Spec") to drive the generation of these artifacts and validat alignment between the LLVM backend and IREE compiler.
Objective
Develop a Python-based ISA Capability Registry (src/tools/isa_registry/) that parses a high-level YAML definition of a machine instruction and generates: 1) MLIR TableGen definitions, 2) MLIR Roundtrip/Lowering tests, and 3) LLVM Intrinsic verification scripts.
Scope of Work
- Schema Definition (
isa_spec_schema.yaml):
- Define a strict schema for RISC-V extensions.
- Fields:
mnemonic, intrinsic_name, tile_shape (M,N,K), operand_types (lhs, rhs, acc), attributes (enums like signed/unsigned).
- Artifact Generator (
gen_compiler_artifacts.py):
- Input: A YAML spec (e.g.,
spacemit_vmadot.yaml).
- Output 1 (TableGen): Snippets for
IREECPUEnums.td (e.g., def VMADOT_I32_4x4x4_I8 : I32EnumAttrCase...) and IREECPUAttrs.td.
- Output 2 (Tests): Fully formed
.mlir test files for:
roundtrip.mlir (verifies attribute parsing).
lower_inner_tiled.mlir (verifies buildUnderlyingOperations logic via Transform dialect).
- Backend Validator (
verify_backend.py):
- Action: Generates a minimal
.ll (LLVM IR) file calling the intrinsic defined in the Spec.
- Check: Runs
llc -march=riscv64 -mattr=+<feature> to ensure the backend actually recognizes the intrinsic (prevents "use of undefined value" errors).
Acceptance Criteria (Definition of Done)
Test 1: Spec-to-TableGen Generation
- Input: A mock spec
test_vmadot.yaml defining a 4x4x4 i8->i32 instruction.
- Condition: Run
gen_compiler_artifacts.py --mode=tablegen.
- Success: Output matches the expected
I32EnumAttrCase definition structure found in IREECPUEnums.td.
Test 2: Automated Test Generation
- Input: The same
test_vmadot.yaml.
- Condition: Run
gen_compiler_artifacts.py --mode=tests.
- Success: Generates a valid
.mlir file containing a func @test_roundtrip with attributes matching #iree_cpu.spacemit_vmadot_mma<...>.
Test 3: Backend Intrinsic Validation
- Input: A spec defining
llvm.riscv.smt.vmadot.
- Condition: Run
verify_backend.py.
- Success:
- If
llc fails (backend missing), the tool returns EXIT_FAILURE and logs "Intrinsic not found in LLVM".
- If
llc succeeds (asm generated), the tool returns EXIT_SUCCESS.
Test 4: Integration with IREE
- Condition: The generated
lower_inner_tiled.mlir file is fed into iree-opt --iree-transform-dialect-interpreter.
- Success:
iree-opt processes the file without crashing, proving the generated test aligns with the C++ buildUnderlyingOperations implementation.
Context
Integrating new RISC-V extensions (like SpacemiT
vmadot) requires coordinated changes across LLVM intrinsics, IREE Attributes (IREECPUAttrs.td), Enums (IREECPUEnums.td), and unit tests. Currently, this is a manual, error-prone process involving scattered C++ and TableGen files. We need a single source of truth (a "Spec") to drive the generation of these artifacts and validat alignment between the LLVM backend and IREE compiler.Objective
Develop a Python-based ISA Capability Registry (
src/tools/isa_registry/) that parses a high-level YAML definition of a machine instruction and generates: 1) MLIR TableGen definitions, 2) MLIR Roundtrip/Lowering tests, and 3) LLVM Intrinsic verification scripts.Scope of Work
isa_spec_schema.yaml):mnemonic,intrinsic_name,tile_shape(M,N,K),operand_types(lhs, rhs, acc),attributes(enums likesigned/unsigned).gen_compiler_artifacts.py):spacemit_vmadot.yaml).IREECPUEnums.td(e.g.,def VMADOT_I32_4x4x4_I8 : I32EnumAttrCase...) andIREECPUAttrs.td..mlirtest files for:roundtrip.mlir(verifies attribute parsing).lower_inner_tiled.mlir(verifiesbuildUnderlyingOperationslogic via Transform dialect).verify_backend.py):.ll(LLVM IR) file calling the intrinsic defined in the Spec.llc -march=riscv64 -mattr=+<feature>to ensure the backend actually recognizes the intrinsic (prevents "use of undefined value" errors).Acceptance Criteria (Definition of Done)
Test 1: Spec-to-TableGen Generation
test_vmadot.yamldefining a 4x4x4 i8->i32 instruction.gen_compiler_artifacts.py --mode=tablegen.I32EnumAttrCasedefinition structure found inIREECPUEnums.td.Test 2: Automated Test Generation
test_vmadot.yaml.gen_compiler_artifacts.py --mode=tests..mlirfile containing afunc @test_roundtripwith attributes matching#iree_cpu.spacemit_vmadot_mma<...>.Test 3: Backend Intrinsic Validation
llvm.riscv.smt.vmadot.verify_backend.py.llcfails (backend missing), the tool returnsEXIT_FAILUREand logs "Intrinsic not found in LLVM".llcsucceeds (asm generated), the tool returnsEXIT_SUCCESS.Test 4: Integration with IREE
lower_inner_tiled.mlirfile is fed intoiree-opt --iree-transform-dialect-interpreter.iree-optprocesses the file without crashing, proving the generated test aligns with the C++buildUnderlyingOperationsimplementation.