Skip to content

[tblgen] Add command line flag for using fallback TypeIDs in generation #125767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
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
5 changes: 3 additions & 2 deletions mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions mlir/tools/mlir-tblgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_tablegen(mlir-tblgen MLIR
PassDocGen.cpp
PassGen.cpp
RewriterGen.cpp
SharedCL.cpp
SPIRVUtilsGen.cpp
)

Expand Down
5 changes: 3 additions & 2 deletions mlir/tools/mlir-tblgen/DialectGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include "SharedCL.h"
#include "DialectGenUtilities.h"
#include "mlir/TableGen/Class.h"
#include "mlir/TableGen/CodeGenHelpers.h"
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";

Expand Down
6 changes: 4 additions & 2 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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";
}
Expand Down
21 changes: 21 additions & 0 deletions mlir/tools/mlir-tblgen/SharedCL.cpp
Original file line number Diff line number Diff line change
@@ -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<bool> mlir::tblgen::clUseFallbackTypeIDs = cl::opt<bool>(
"use-fallback-type-ids",
cl::desc(
"Don't generate static TypeID decls; fall back to string comparison."),
cl::init(false), cl::cat(clShared));
22 changes: 22 additions & 0 deletions mlir/tools/mlir-tblgen/SharedCL.h
Original file line number Diff line number Diff line change
@@ -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<bool> clUseFallbackTypeIDs;

} // namespace tblgen
} // namespace mlir

#endif // MLIR_TOOLS_MLIRTBLGEN_SHARED_CL_H_
Loading