diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp index 6a39424bd463f..6aeaf3ae4780c 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "AttrOrTypeFormatGen.h" +#include "SharedCL.h" #include "mlir/TableGen/AttrOrTypeDef.h" #include "mlir/TableGen/Class.h" #include "mlir/TableGen/CodeGenHelpers.h" @@ -773,7 +774,7 @@ bool DefGenerator::emitDecls(StringRef selectedDialect) { // Emit the TypeID explicit specializations to have a single definition for // each of these. for (const AttrOrTypeDef &def : defs) - if (!def.getDialect().getCppNamespace().empty()) + if (!clUseFallbackTypeIDs && !def.getDialect().getCppNamespace().empty()) os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << def.getDialect().getCppNamespace() << "::" << def.getCppClassName() << ")\n"; @@ -986,7 +987,7 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) { gen.emitDef(os); } // Emit the TypeID explicit specializations to have a single symbol def. - if (!def.getDialect().getCppNamespace().empty()) + if (!clUseFallbackTypeIDs && !def.getDialect().getCppNamespace().empty()) os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << def.getDialect().getCppNamespace() << "::" << def.getCppClassName() << ")\n"; diff --git a/mlir/tools/mlir-tblgen/CMakeLists.txt b/mlir/tools/mlir-tblgen/CMakeLists.txt index fb507dc7f8c3c..6c6c74deb9938 100644 --- a/mlir/tools/mlir-tblgen/CMakeLists.txt +++ b/mlir/tools/mlir-tblgen/CMakeLists.txt @@ -31,6 +31,7 @@ add_tablegen(mlir-tblgen MLIR PassDocGen.cpp PassGen.cpp RewriterGen.cpp + SharedCL.cpp SPIRVUtilsGen.cpp ) diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp index 414cad5e1dcc2..e230100f34d0d 100644 --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include "SharedCL.h" #include "DialectGenUtilities.h" #include "mlir/TableGen/Class.h" #include "mlir/TableGen/CodeGenHelpers.h" @@ -293,7 +294,7 @@ static void emitDialectDecl(Dialect &dialect, raw_ostream &os) { // End the dialect decl. os << "};\n"; } - if (!dialect.getCppNamespace().empty()) + if (!clUseFallbackTypeIDs && !dialect.getCppNamespace().empty()) os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace() << "::" << dialect.getCppClassName() << ")\n"; } @@ -347,7 +348,7 @@ static void emitDialectDef(Dialect &dialect, const RecordKeeper &records, std::string cppClassName = dialect.getCppClassName(); // Emit the TypeID explicit specializations to have a single symbol def. - if (!dialect.getCppNamespace().empty()) + if (!clUseFallbackTypeIDs && !dialect.getCppNamespace().empty()) os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace() << "::" << cppClassName << ")\n"; diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index a970cbc5caceb..eaa26e545eec6 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -14,6 +14,7 @@ #include "OpClass.h" #include "OpFormatGen.h" #include "OpGenHelpers.h" +#include "SharedCL.h" #include "mlir/TableGen/Argument.h" #include "mlir/TableGen/Attribute.h" #include "mlir/TableGen/Class.h" @@ -31,6 +32,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Signals.h" @@ -4625,7 +4627,7 @@ emitOpClasses(const RecordKeeper &records, OpEmitter::emitDecl(op, os, staticVerifierEmitter); } // Emit the TypeID explicit specialization to have a single definition. - if (!op.getCppNamespace().empty()) + if (!clUseFallbackTypeIDs && !op.getCppNamespace().empty()) os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << op.getCppNamespace() << "::" << op.getCppClassName() << ")\n\n"; } else { @@ -4636,7 +4638,7 @@ emitOpClasses(const RecordKeeper &records, OpEmitter::emitDef(op, os, staticVerifierEmitter); } // Emit the TypeID explicit specialization to have a single definition. - if (!op.getCppNamespace().empty()) + if (!clUseFallbackTypeIDs && !op.getCppNamespace().empty()) os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << op.getCppNamespace() << "::" << op.getCppClassName() << ")\n\n"; } diff --git a/mlir/tools/mlir-tblgen/SharedCL.cpp b/mlir/tools/mlir-tblgen/SharedCL.cpp new file mode 100644 index 0000000000000..733fc3a34f164 --- /dev/null +++ b/mlir/tools/mlir-tblgen/SharedCL.cpp @@ -0,0 +1,21 @@ +//===- SharedCL.cpp - tblgen command line arguments -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SharedCL.h" + +using namespace mlir; +using namespace mlir::tblgen; +namespace cl = llvm::cl; + +static llvm::cl::OptionCategory clShared("Options for all -gen-*"); + +cl::opt mlir::tblgen::clUseFallbackTypeIDs = cl::opt( + "use-fallback-type-ids", + cl::desc( + "Don't generate static TypeID decls; fall back to string comparison."), + cl::init(false), cl::cat(clShared)); diff --git a/mlir/tools/mlir-tblgen/SharedCL.h b/mlir/tools/mlir-tblgen/SharedCL.h new file mode 100644 index 0000000000000..a4610822f91f0 --- /dev/null +++ b/mlir/tools/mlir-tblgen/SharedCL.h @@ -0,0 +1,22 @@ +//===- SharedCL.h - tblgen command line arguments -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TOOLS_MLIRTBLGEN_SHARED_CL_H_ +#define MLIR_TOOLS_MLIRTBLGEN_SHARED_CL_H_ + +#include "llvm/Support/CommandLine.h" + +namespace mlir { +namespace tblgen { + +extern llvm::cl::opt clUseFallbackTypeIDs; + +} // namespace tblgen +} // namespace mlir + +#endif // MLIR_TOOLS_MLIRTBLGEN_SHARED_CL_H_