Expand description
§tpt-uir-dialects
Dialect definitions and analysis passes for the TPT Unified Intermediate Representation (TPT-UIR).
This crate builds on tpt-uir-core and provides:
tpt_gpudialect (GpuDialect,GpuOp) for GPU operationscrucibledialect (CrucibleDialect,CrucibleOp)memorydialect (MemOp) for memory operations- A
ValidateDialecttrait for dialect-level validation - Analysis passes (e.g. liveness)
§Installation
Not yet on crates.io — depend on it via git or a path within this workspace:
[dependencies]
tpt-uir-dialects = { git = "https://github.com/tpt-solutions/tpt-uir", package = "tpt-uir-dialects" }§Example
use tpt_uir_core::op_name::TPT_GPU_LAUNCH;
use tpt_uir_core::OpName;
use tpt_uir_dialects::GpuOp;
let op = GpuOp::build(
1,
OpName::parse(TPT_GPU_LAUNCH).unwrap(),
vec![],
vec![],
vec![],
vec![],
)
.unwrap();
println!("{}", op.op_name);§Dialect versioning
Every dialect exposes a current_version() (starting at 1) via the
ValidateDialect trait. Producers pin the dialect version they target by
attaching one of two attributes to the relevant operations:
dialect_version(dialect-wide) — set once on a representative op, e.g. a function/module entry op.op_dialect_version(per-op override) — set when a single op uses a newer capability than the surrounding dialect version.
Both attributes reuse the existing i64 wire representation, so they introduce
no new serde/postcard surface. Consumers should record the dialect version
when serializing and check it on load. The migration story is additive:
- A dialect adds a new capability in version
N. - Producers emit
dialect_version = N(orop_dialect_version = Nfor the specific ops that need it). - Older consumers that only understand
N-1read the attribute, see a version they do not recognise, and can reject or degrade gracefully instead of misinterpreting the IR. - The wire format never renumbers existing enum variants, so a serialized IR remains decodable by both old and new readers.
Validate with ValidateDialect::validate_all, which runs the dialect’s
structural checks and prefix/version checks together and reports every
violation:
use tpt_uir_core::op_name::TPT_GPU_LAUNCH;
use tpt_uir_core::{attr::Attribute, op_name::OpName, Operation};
use tpt_uir_dialects::GpuDialect;
use tpt_uir_dialects::ValidateDialect;
let op = Operation {
id: 1,
op_name: OpName::parse(TPT_GPU_LAUNCH).unwrap(),
operands: vec![],
results: vec![],
regions: vec![],
attributes: vec![Attribute::dialect_version(1)],
};
let region = tpt_uir_core::Region {
blocks: vec![tpt_uir_core::Block {
arguments: vec![],
operations: vec![op],
}],
};
assert!(GpuDialect::validate_all(®ion).is_ok());See CHANGELOG.md for release notes.
§License
Licensed under either of MIT or Apache-2.0 at your option.
Re-exports§
pub use crucible::CrucibleDialect;pub use crucible::CrucibleOp;pub use gpu::GpuDialect;pub use gpu::GpuOp;pub use memory::MemOp;pub use validate::ValidateDialect;