Skip to content
Open
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
Expand Up @@ -4,6 +4,13 @@
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"

// DECL: namespace test {
// DECL: class IndexAttr;
// DECL: class SimpleAAttr;
// DECL: class CompoundAAttr;
// DECL: class SingleParameterAttr;
// DECL: } // namespace test

// DECL: #ifdef GET_ATTRDEF_CLASSES
// DECL: #undef GET_ATTRDEF_CLASSES

Expand Down
8 changes: 8 additions & 0 deletions mlir/test/mlir-tblgen/typedefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"

// DECL: namespace test {
// DECL: class SimpleAType;
// DECL: class CompoundAType;
// DECL: class IndexType;
// DECL: class SingleParameterType;
// DECL: class IntegerType;
// DECL: } // namespace test

// DECL: #ifdef GET_TYPEDEF_CLASSES
// DECL: #undef GET_TYPEDEF_CLASSES

Expand Down
18 changes: 12 additions & 6 deletions mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,29 +869,35 @@ class AsmPrinter;

bool DefGenerator::emitDecls(StringRef selectedDialect) {
emitSourceFileHeader((defType + "Def Declarations").str(), os);
llvm::IfDefEmitter scope(os, "GET_" + defType.upper() + "DEF_CLASSES");

// Output the common "header".
os << typeDefDeclHeader;

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

{
DialectNamespaceEmitter nsEmitter(os, defs.front().getDialect());

// Declare all the def classes first (in case they reference each other).
// Declare all the def classes first (in case they reference each other and
// for forward declarations).
for (const AttrOrTypeDef &def : defs) {
tblgen::emitSummaryAndDescComments(os, def.getSummary(),
def.getDescription());
os << "class " << def.getCppClassName() << ";\n";
}
}

llvm::IfDefEmitter scope(os, "GET_" + defType.upper() + "DEF_CLASSES");

// Output the common "header".
os << typeDefDeclHeader;

{
DialectNamespaceEmitter nsEmitter(os, defs.front().getDialect());
// Emit the declarations.
for (const AttrOrTypeDef &def : defs)
DefGen(def).emitDecl(os);
}

// Emit the TypeID explicit specializations to have a single definition for
// each of these.
for (const AttrOrTypeDef &def : defs)
Expand Down