Type template-like parametrization in MLIR-text

Hello everyone. Suffice it to say that I am very new to the MLIR project and I must apologise in advance if the topic of the question was described in one of the tutorials/examples, yet no matter how I looked I still could not wrap my head around it.

Right now I am trying to design (at least partially) a dataflow engine dialect, where one of the main abstractions is a Stream, and each stream refers to one of the primitive/complex types for the data it has to encompass - int, uint and so on.
If I am to implement the idea the way I see it, both Stream and, let’s say, int are types I need to implement in the dialect, and if I wanted to “declare a dataflow stream named x of 32-bit unsigned type”, I would write something like this:

%x = dfcir.input<!dfcir.uint(32)>("x");

, where %x would have the type Stream<uint(32)>, for example.

As far as I understand the concepts behind TableGen ODS, the def-records are “complete” in terms of template specializing, so in order to implement the example above I would have to use a string denoting a type as a parameter/attribute rather than a type by itself.

I am very sure MLIR as it is allows to model such concepts, but I couldn’t find a sufficient example. Thank you very much in advance.

It sounds like you want to create a custom type in tablegen. Have you looked at this tutorial?

I did, but then again, if we were to specify a Type1 which behaves differently based on what other type was specified - let’s say Type2 or Type3 or Type4, there is no way other than using attributes and operands to refer to any of these three types (I refer to something like C++ template instantiation Type1<Type2>). We cannot pass a type as a parameter directly in MLIR assembly format, as def-objects in TableGen, which are translated into C++ classes,

cannot be templated further or subclassed.

(found it here: DefiningDialects/Operations/#tablegen-syntax)

I think what you want to do is very similar to the ComplexType. The actual type itself is defined here. Basically you can define a type which takes as input a type. With this method, the parametrizable type is known statically at compile time. If you want it to be dynamic then yeah there’s no other option than to pass it as an operand/attribute.

1 Like

Seems to be exactly the thing I need. Thank you very much!