Using LLVM dialect types on other dialects


I’m trying to build dialect types on top of LLVM types. For example:

!a = type !llvm.struct<"a", (fields)>
!mut_a = type !verona.mut<a>
func @function(%arg : !mut_a) : !mut_b { ... }

So, a verona.class type is just an LLVM StructType and the reference capability (mutable) is a wrapper type on top of the class.

My table-gen file looks like:

include "mlir/Dialect/LLVMIR/"
def Verona_ClassType : LLVM_AnyStruct;
def Verona_MutType : Verona_TypeDef<"mut"> {
  let parameters = (ins Verona_ClassType : $object);

However, I get an error from table-gen:

error: Couldn't find class 'LLVM_AnyStruct'

I could only see two dialects using LLVM types that way: AMX and X86Vector, both using a table-gen flag -gen-llvmir-conversions, which basically defines the LLVMOpBase symbols by hand via emitBuilders.

Does that mean including isn’t doing what I expect it should, ie. include the definitions like mlir/IR/ does? Or am I missing something obvious from the LLVM definitions?

The dag element type in parameters is expected to derive the TypeParameter tablegen class (or, in rare cases, it’s just a string with the C++ type name) - see Operation Definition Specification (ODS) - MLIR. Type parameters are not necessarily other types, so you can’t just use a def deriving Type there.

Right, that’s slightly different than I did some months ago, but that’s not where the error is coming from.

The error line is:

def Verona_ClassType : LLVM_AnyStruct;

Once I’m past defining Verona_ClassType I’ll look into the others and correct all the remaining mistakes.

LLVM_AnyStruct is a def, not a class. Generally, it’s part of the ODS concepts I refer to as “type constraints”. They are just names and verification rules for what gets accepted as op operand and have no relation to type definitions in ODS.

Ah, right! I need to get my head around the whole ODS again, I’ll read the docs all over again.

For now I’m just declaring it as a Type<CPred<...llvm...>> and will see if there’s a better way forward.


Syntactically in tablegen you could write it as defvar Verona_ClassType = LLVM_AnyStruct.

1 Like

Hi Sean, that works too, this is just an alias, right?

Yes, it is just an alias.