Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial BlockExt trait #618

Merged
merged 4 commits into from
Dec 7, 2024
Merged

Initial BlockExt trait #618

merged 4 commits into from
Dec 7, 2024

Conversation

edg-l
Copy link
Member

@edg-l edg-l commented Dec 2, 2024

Here is the first pr with some utility methods as discussed in #616 , extending it should be easy, also feel free to refactor it or use another name, folder, etc.

I added it behind a feature, because it requires the ods feature.

@raviqqe
Copy link
Member

raviqqe commented Dec 3, 2024

@edg-l It doesn't have to be in this PR but what do you think of splitting the trait into different dialects for extensibility? For example,

pub trait SimpleBlock<'ctx> {
    fn arg(&self, idx: usize) -> Result<Value<'ctx, '_>, Error>;
}

pub trait ArithBlock<'ctx> {
    fn addi(
        &self,
        lhs: Value<'ctx, '_>,
        rhs: Value<'ctx, '_>,
        location: Location<'ctx>,
    ) -> Result<Value<'ctx, '_>, Error>;

    // ...
}

pub trait LlvmBlock<'ctx> {
    fn insert_value(&self, /* ... */) -> Result<Value<'ctx, '_>, Error>;

    // ...
}

And, then users select dialects' block traits as needed:

use melior::block_ext::ArithBlock;
// ...

fn main() {
  // ...

  let z = block.addi(x, y);

  // ...
}

@edg-l
Copy link
Member Author

edg-l commented Dec 3, 2024

I would use ArithBlockExt as a better name because maybe others can confuse it for a Block but i agree with the idea

@raviqqe
Copy link
Member

raviqqe commented Dec 3, 2024

@edg-l do you think actually it's possible to generate these block extensions automatically like the ODS dialects API?

@edg-l
Copy link
Member Author

edg-l commented Dec 3, 2024

@edg-l do you think actually it's possible to generate these block extensions automatically like the ODS dialects API?

Hm probably not since they have some (little) logic in it often

@raviqqe raviqqe merged commit 0573c85 into mlir-rs:main Dec 7, 2024
11 of 12 checks passed
@raviqqe
Copy link
Member

raviqqe commented Dec 7, 2024

Thank you for the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants