diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -2088,15 +2088,19 @@ // Emits the opcode enum and op classes. static void emitOpClasses(const std::vector &defs, raw_ostream &os, bool emitDecl) { - IfDefScope scope("GET_OP_CLASSES", os); // First emit forward declaration for each class, this allows them to refer // to each others in traits for example. if (emitDecl) { + os << "#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES)\n"; + os << "#undef GET_OP_FWD_DEFINES\n"; for (auto *def : defs) { Operator op(*def); os << "class " << op.getCppClassName() << ";\n"; } + os << "#endif\n\n"; } + + IfDefScope scope("GET_OP_CLASSES", os); for (auto *def : defs) { Operator op(*def); if (emitDecl) { @@ -2113,14 +2117,14 @@ // Emits a comma-separated list of the ops. static void emitOpList(const std::vector &defs, raw_ostream &os) { - IfDefScope scope("GET_OP_LIST", os); - - interleave( - // TODO: We are constructing the Operator wrapper instance just for - // getting it's qualified class name here. Reduce the overhead by having a - // lightweight version of Operator class just for that purpose. - defs, [&os](Record *def) { os << Operator(def).getQualCppClassName(); }, - [&os]() { os << ",\n"; }); + IfDefScope scope("GET_OP_LIST", os); + + interleave( + // TODO: We are constructing the Operator wrapper instance just for + // getting it's qualified class name here. Reduce the overhead by having + // a lightweight version of Operator class just for that purpose. + defs, [&os](Record *def) { os << Operator(def).getQualCppClassName(); }, + [&os]() { os << ",\n"; }); } static std::string getOperationName(const Record &def) {