HomePhabricator

[MLIR] Attribute and type formats in ODS

Authored by Mogball on Oct 15 2021, 2:39 PM.

Description

[MLIR] Attribute and type formats in ODS

Declarative attribute and type formats with assembly formats. Define an
assemblyFormat field in attribute and type defs with a mnemonic to
generate a parser and printer.

tablegen
def MyAttr : AttrDef<MyDialect, "MyAttr"> {
  let parameters = (ins "int64_t":$count, "AffineMap":$map);
  let mnemonic = "my_attr";
  let assemblyFormat = "`<` $count `,` $map `>`";
}

Use struct to define a comma-separated list of key-value pairs:

tablegen
def MyType : TypeDef<MyDialect, "MyType"> {
  let parameters = (ins "int":$one, "int":$two, "int":$three);
  let mnemonic = "my_attr";
  let assemblyFormat = "`<` $three `:` struct($one, $two) `>`";
}

Use struct(*) to capture all parameters.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D111594

Details

Committed
MogballNov 8 2021, 9:38 AM
Reviewer
rriddle
Differential Revision
D111594: [MLIR] Attribute and type formats in ODS
Parents
rG56ada0f80df2: [mlir][vector] Use dyn_cast instead of cast in patterns
Branches
Unknown
Tags
Unknown