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) {