-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 likesigned/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...) andIREECPUAttrs.td. - Output 2 (Tests): Fully formed
.mlirtest files for:roundtrip.mlir(verifies attribute parsing).lower_inner_tiled.mlir(verifiesbuildUnderlyingOperationslogic via Transform dialect).
- Input: A YAML spec (e.g.,
- 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).
- Action: Generates a minimal
Acceptance Criteria (Definition of Done)
Test 1: Spec-to-TableGen Generation
- Input: A mock spec
test_vmadot.yamldefining a 4x4x4 i8->i32 instruction. - Condition: Run
gen_compiler_artifacts.py --mode=tablegen. - Success: Output matches the expected
I32EnumAttrCasedefinition structure found inIREECPUEnums.td.
Test 2: Automated Test Generation
- Input: The same
test_vmadot.yaml. - Condition: Run
gen_compiler_artifacts.py --mode=tests. - Success: Generates a valid
.mlirfile containing afunc @test_roundtripwith 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
llcfails (backend missing), the tool returnsEXIT_FAILUREand logs "Intrinsic not found in LLVM". - If
llcsucceeds (asm generated), the tool returnsEXIT_SUCCESS.
- If
Test 4: Integration with IREE
- Condition: The generated
lower_inner_tiled.mlirfile is fed intoiree-opt --iree-transform-dialect-interpreter. - Success:
iree-optprocesses the file without crashing, proving the generated test aligns with the C++buildUnderlyingOperationsimplementation.