diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td index a809611fd0aec..bd0c663228015 100644 --- a/mlir/test/mlir-tblgen/attrdefs.td +++ b/mlir/test/mlir-tblgen/attrdefs.td @@ -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 diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td index b9e3a7954e361..ebdb172e9aff3 100644 --- a/mlir/test/mlir-tblgen/typedefs.td +++ b/mlir/test/mlir-tblgen/typedefs.td @@ -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 diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp index 2a513c3b8cc9b..e51c776b905a8 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -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 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)