Context
Creating a new MLIR dialect requires creating ~10 files (Ops.td, Dialect.cpp, CMakeLists.txt, TypeDetail.h, etc.). This high friction slows down experimental IR development. Furthermore, we need a way to verify that the generated dialect behaves as expected.
Objective
Create a scaffolding tool (src/tools/scaffold_dialect.py) that generates a fully compilable MLIR dialect directory structure, including a LIT-style test suite for verification.
Scope of Work
- Template Engine: Create Jinja2 templates for standard ODS (TableGen), C++ headers, and CMake config.
- Test Scaffolding:
- Generate a
tests/Dialect/{Name} directory.
- Create a
lit.cfg.py configuration file.
- Generate a sample
ops.mlir test file with // CHECK-LABEL: assertions.
- Scaffolder:
- Input:
dialect_name, namespace, cpp_namespace.
- Output: A folder
src/Dialect/{Name} registered in the main CMake build.
Acceptance Criteria
- Test 1: Run
scaffold_dialect.py --name "MyTest" --namespace "mt".
- Condition: Run the main build system.
- Success: The build completes, and
iree-opt --help lists the --convert-mt-to-standard pass.
- Test 2: The generated
Ops.td includes standard boilerplate (mnemonic, description, assemblyFormat) and compiles via mlir-tblgen.
- Test 3 (LIT Verification):
- Input: The tool generates
tests/Dialect/MyTest/ops.mlir.
- Condition: Run
lit tests/Dialect/MyTest.
- Success: The test passes. This proves that
iree-opt can parse the new dialect's IR and that the printed output matches the // CHECK expectations (Round-trip verification).
Context
Creating a new MLIR dialect requires creating ~10 files (
Ops.td,Dialect.cpp,CMakeLists.txt,TypeDetail.h, etc.). This high friction slows down experimental IR development. Furthermore, we need a way to verify that the generated dialect behaves as expected.Objective
Create a scaffolding tool (
src/tools/scaffold_dialect.py) that generates a fully compilable MLIR dialect directory structure, including a LIT-style test suite for verification.Scope of Work
tests/Dialect/{Name}directory.lit.cfg.pyconfiguration file.ops.mlirtest file with// CHECK-LABEL:assertions.dialect_name,namespace,cpp_namespace.src/Dialect/{Name}registered in the main CMake build.Acceptance Criteria
scaffold_dialect.py --name "MyTest" --namespace "mt".iree-opt --helplists the--convert-mt-to-standardpass.Ops.tdincludes standard boilerplate (mnemonic, description, assemblyFormat) and compiles viamlir-tblgen.tests/Dialect/MyTest/ops.mlir.lit tests/Dialect/MyTest.iree-optcan parse the new dialect's IR and that the printed output matches the// CHECKexpectations (Round-trip verification).