Is there any way to add a custom verifier to a built-in operation?

Hi, I’m working on verification logic for my compiler. I’m wondering if there’s a way to add a verifier to built-in operations like func::FuncOp.

I know that the hasVerifier flag allows implementing SomeOp::verify(), but I do not want to modify the base MLIR library.

It is my first post in the LLVM Discourse, and I hope I did not mess up with any community guidelines.

Thank you!

I’d recommend a custom verification pass.

Currently, MLIR does not provide a function hook that allows users to directly modify the verifier. However, you can achieve similar goals through any of the following indirect methods:

  • You can define a custom interface with verifier and regist it to funcop.
  • You can define a custom func op on you own dialect and verify it(need some conversion).
  • As mentioned by matthias, you can also write a custom verification pass.

Thanks for the reply, but I am not thinking of adding a custom verification pass, since I should invoke every single verification pass before and after some passes if I use a custom pass. The reason I was trying to use the default verifier was because it would be automatically called with the passDriver.

I guess the best I can do is generating a custom op that is similar to func::FuncOp. Thanks for the reply :slight_smile:

For FuncOp in particular, downstream projects are generally encouraged to define their own versions, possibly implementing FunctionOpInterface. It’s pretty tricky to define a common implementation for such a generic operation.

I didn’t know there’s a thing such as FunctionInterface. This tool will be a great help for me when creating operations. Thank you!