mlir-rs / melior

The rustic MLIR bindings in Rust
https://mlir-rs.github.io/melior/melior/
Apache License 2.0
332 stars 39 forks source link

alternative simpler style API #616

Open edg-l opened 1 week ago

edg-l commented 1 week ago

Would you be interested in an extension trait that implements a inkwell style API on Blocks?

My idea is porting this trait https://github.com/lambdaclass/cairo_native/blob/fb284953b66634d53aba9b43d3d07dff73304538/src/utils/block_ext.rs

to melior, i think it would be useful to others, it allows writing code like this:

// entry is a block
let lhs = entry.arg(0)?;
let rhs = entry.arg(1)?;
let lhs = entry.extui(lhs, i256, location)?;
let rhs = entry.extui(rhs, i256, location)?;
let result = entry.addi(lhs, rhs, location)?;

let prime = entry.const_int_from_type(context, location, PRIME.clone(), i256)?;
let result_mod = entry.append_op_result(arith::subi(result, prime, location))?;
let is_out_of_range = entry.cmpi(context, CmpiPredicate::Uge, result, prime, location)?;
raviqqe commented 2 days ago

I think it's a good idea!

Does it support only built-in and LLVM dialects for now?

edg-l commented 2 days ago

I think it's a good idea!

Does it support only built-in and LLVM dialects for now?

Yeah, and arith, but it can be extended in melior without problem, just wanted to know if this pattern was desired