Crates.io | melior |
lib.rs | melior |
version | |
source | src |
created_at | 2022-07-10 02:06:17.102167 |
updated_at | 2024-12-10 07:19:48.194278 |
description | The rustic MLIR bindings in Rust |
homepage | |
repository | https://github.com/mlir-sys/melior |
max_upload_size | |
id | 622904 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Melior is the MLIR bindings for Rust. It aims to provide a simple, safe, and complete API for MLIR with a reasonably sane ownership model represented by the type system in Rust.
This crate is a wrapper of the MLIR C API.
use melior::{
Context,
dialect::{arith, DialectRegistry, func},
ir::{*, attribute::{StringAttribute, TypeAttribute}, r#type::FunctionType},
utility::register_all_dialects,
};
let registry = DialectRegistry::new();
register_all_dialects(®istry);
let context = Context::new();
context.append_dialect_registry(®istry);
context.load_all_available_dialects();
let location = Location::unknown(&context);
let module = Module::new(location);
let index_type = Type::index(&context);
module.body().append_operation(func::func(
&context,
StringAttribute::new(&context, "add"),
TypeAttribute::new(FunctionType::new(&context, &[index_type, index_type], &[index_type]).into()),
{
let block = Block::new(&[(index_type, location), (index_type, location)]);
let sum = block.append_operation(arith::addi(
block.argument(0).unwrap().into(),
block.argument(1).unwrap().into(),
location
));
block.append_operation(func::r#return( &[sum.result(0).unwrap().into()], location));
let region = Region::new();
region.append_block(block);
region
},
&[],
location,
));
assert!(module.as_operation().verify());
cargo add melior
LLVM/MLIR 19 needs to be installed on your system. On Linux and macOS, you can install it via Homebrew.
brew install llvm@19
On GitHub Pages.
Contribution is welcome! But, Melior is still in the alpha stage as well as the MLIR C API. Note that the API is unstable and can have breaking changes in the future.
&T
for MLIR objects instead of &mut T
to mitigate the intricacy of representing a loose ownership model of the MLIR C API in Rust.Mlir<X>
objects are named <X>
if they have no destructor. Otherwise, they are named <X>
for owned objects and <X>Ref
for borrowed references.mlir<X>Create
functions are renamed as <X>::new
.mlir<X>Get<Y>
functions are renamed as follows:
&self
, they are named <X>::as_<Y>
.<X>::<Y>
and may have arguments, such as position indices.Although Melior aims to be completely type safe, some part of the current API is not.
&self
rather than &mut self
to
return such references.Region::append_block()
RefCell
, for the objects.