Compilation errors at TableGen descriptions

Hello, colleagues.

I’m new at MLIR and I need to improve a MLIR-based IR for our DSL called HIL (High-level Intermediate Language). This DSL is aimed at calculation graph describing. Every graph has a number of nodes that are interconnected by channels. Nodes can be of different types (switch, merge, operation, source, sink).

The previous developer of our MLIR-based IR has left our team and he used TableGen-based descriptions for IR structures. To be more specific, here is a channel description:

def HIL_Chan : HIL_Op<"chan", [HasParent<"Chans">]> {
  let summary = "Channel.";
  let description = [{
    The `hil.nodetype` operation for defining types of nodes
  }];

  let arguments = (ins
    StrAttr:$typeName,
    StrAttr:$varName,
    OptionalAttr<StrAttr>:$nodeFrom,
    OptionalAttr<StrAttr>:$nodeTo);
  let assemblyFormat = [{
    $typeName $varName (`(` $nodeFrom^ `=``>` $nodeTo `)`)? attr-dict
  }];
}

In nodeFrom and nodeTo names of the source and destination nodes are stored. I want to add more information here. For that purpose, I’ve implemented the following attributes:

def InputPortAttr : HIL_Attr<"InputPort"> {
  let mnemonic = "input-port";

  let summary = "Input port";

  let description = [{
    Input port arg type
  }];

  let parameters = (ins
    "std::string":$typeName,
    "double*":$flow,
    "std::string":$name);

  let hasCustomAssemblyFormat = 1;
}

def OutputPortAttr : HIL_Attr<"OutputPort"> {
  let mnemonic = "output-port";

  let summary = "Output port";

  let description = [{
    Output port arg type
  }];

  let parameters = (ins
    "std::string":$typeName,
    "double*":$flow,
    "unsigned":$latency,
    "std::string":$name,
    "std::string":$value);

  let hasCustomAssemblyFormat = 1;
}

def InputBndAttr : HIL_Attr<"InputBnd"> {

  let mnemonic = "input-binding";

  let summary = "Input port binding";

  let description = [{
    Input binding attr type
  }];

  let parameters = (ins
    "std::string":$nodeName,
    InputPortAttr:$port);

  let hasCustomAssemblyFormat = 1;
}

def OutputBndAttr : HIL_Attr<"OutputBnd"> {

  let mnemonic = "output-binding";

  let summary = "Output port binding";

  let description = [{
    Output binding attr type
  }];

  let parameters = (ins
    "std::string":$nodeName,
    OutputPortAttr:$port);

  let hasCustomAssemblyFormat = 1;
}

and now channel looks like:

def HIL_Chan : HIL_Op<"chan", [HasParent<"Chans">]> {
  let summary = "Channel.";
  let description = [{
    The `hil.nodetype` operation for defining types of nodes
  }];

  let arguments = (ins
    StrAttr:$typeName,
    StrAttr:$varName,
    OptionalAttr<InputBndAttr>:$nodeFrom,
    OptionalAttr<OutputBndAttr>:$nodeTo);
  let assemblyFormat = [{
    $typeName $varName (`(` $nodeFrom^ `=``>` $nodeTo `)`)? attr-dict
  }];
}

When I build this code, I get the following compilation error:

Ops.h.inc:82:16: error: ‘InputBndAttr’ in namespace ‘mlir::hil’ does not name a type

I’ve “includes” for attributes in my *.td. What should I do to debug such error?
I’d like to attach the code of MLIR-based IR here, but the forum engine does not allow me to upload *.td-files.

Here is the packed MLIR-based IR from our project: https://drive.google.com/file/d/1jTFRwv07a-sEko-RyzDom_tsHFkg-WGY/view?usp=sharing

It doesn’t look like you are including your Dialect.h in the Ops.h file, so the c++ definition of InputBndAttr doesn’t exist when Ops.h.inc is included.

Looking at the include files for Ops.h:

#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
3 Likes