Create a custom type

Hello,

I am a beginner with MLIR and I am trying to create a (very) simple custom type : a kind of Bool (which abstracts i1).
I follow the different steps of the tutorial :

  • Create the enum “Kind” in wich FIRST_PRIVATE_EXPERIMENTAL_0_TYPE is used and the type class with get, kindof and getWidth.
  • Override parseType and printType in my dialect class.
  • Registrate the custom type with addTypes.

But when I try to use it in a MLIR file (with the keyword choosen in “parseType”), let’s say as a function parameter, I get an error saying “expected non-function type”.

Am I missing something ?

Regards,

Can you provide some more details? Like what does the mlir file look like? Into what tool do you pass it?

Let’s say my type is named “bool”.
I use this minimal input whit mlir-opt :
func @f(%b: bool) → (bool) {
return %b: bool
}

Do you get the same error if you just changed your MLIR snippet to use boolabc? If so, it looks like your type isn’t registered or parsing support for it is somehow missing.

1 Like

It isn’t possible to have a type named “bool” that is defined by a dialect.
(The doc on mlir.llvm.org is a bit lacking on this.)
All dialect defined types are prefixed with !<dialect-namespace>. From there you can either end up with !<dialect-namespace>.<type-data> or !<dialect-namespace><"<type-data>"> depending on how ‘simple’ the type-data is. Simpler types can use the prettier left form, otherwise the second form gets used. When printing and parsing, the !<dialect-namespace part of the type is handled by the AsmPrinter/Parser, i.e. you will never see them or deal with them. For parsing, the !<dialect-namespace> is how the parser knows to call into your dialect for parsing. Without it, the parser tries to parse another builtin type and provides you with the message you see now.

Thank you very much. I didn’t know about the prefix. It works now ^^