Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLIR][TableGen] Add gen-attrdef-list #126332

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mlir/test/mlir-tblgen/attrdefs.td
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: mlir-tblgen -gen-attrdef-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL
// RUN: mlir-tblgen -gen-attrdef-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF
// RUN: mlir-tblgen -gen-attrdef-list -I %S/../../include %s | FileCheck %s --check-prefix=LIST

include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"
Expand All @@ -19,6 +20,12 @@ include "mlir/IR/OpBase.td"
// DEF: ::test::CompoundAAttr,
// DEF: ::test::SingleParameterAttr

// LIST: ATTRDEF(IndexAttr)
// LIST: ATTRDEF(SimpleAAttr)
// LIST: ATTRDEF(CompoundAAttr)
// LIST: ATTRDEF(SingleParameterAttr)

// LIST: #undef ATTRDEF
// DEF-LABEL: ::mlir::OptionalParseResult generatedAttributeParser(
// DEF-SAME: ::mlir::AsmParser &parser,
// DEF-SAME: ::llvm::StringRef *mnemonic, ::mlir::Type type,
Expand Down
25 changes: 24 additions & 1 deletion mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ class DefGenerator {
public:
bool emitDecls(StringRef selectedDialect);
bool emitDefs(StringRef selectedDialect);
bool emitList(StringRef selectedDialect);

protected:
DefGenerator(ArrayRef<const Record *> defs, raw_ostream &os,
Expand Down Expand Up @@ -1025,6 +1026,23 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
return false;
}

bool DefGenerator::emitList(StringRef selectedDialect) {
emitSourceFileHeader(("List of " + defType + "Def Definitions").str(), os);

SmallVector<AttrOrTypeDef, 16> defs;
collectAllDefs(selectedDialect, defRecords, defs);
if (defs.empty())
return false;

auto interleaveFn = [&](const AttrOrTypeDef &def) {
os << defType.upper() << "DEF(" << def.getCppClassName() << ")";
};
llvm::interleave(defs, os, interleaveFn, "\n");
os << "\n\n";
os << "#undef " << defType.upper() << "DEF" << "\n";
return false;
}

//===----------------------------------------------------------------------===//
// Type Constraints
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1099,7 +1117,12 @@ static mlir::GenRegistration
AttrDefGenerator generator(records, os);
return generator.emitDecls(attrDialect);
});

static mlir::GenRegistration
genAttrList("gen-attrdef-list", "Generate an AttrDef list",
[](const RecordKeeper &records, raw_ostream &os) {
AttrDefGenerator generator(records, os);
return generator.emitList(attrDialect);
});
//===----------------------------------------------------------------------===//
// TypeDef

Expand Down