[Mlir-commits] [mlir] [tblgen] Add command line flags for using fallback TypeIDs in generation (PR #125767)
Stef Lindall
llvmlistbot at llvm.org
Tue Feb 4 13:38:59 PST 2025
https://github.com/bethebunny updated https://github.com/llvm/llvm-project/pull/125767
>From dfc4c69dd7eb151162f21abeb24a4f1b3e412bee Mon Sep 17 00:00:00 2001
From: Stef <stef at modular.com>
Date: Tue, 4 Feb 2025 21:26:16 +0000
Subject: [PATCH 1/2] [tblgen] Add command line flags for using fallback
TypeIDs in generation
---
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp | 15 +++++++++++++--
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 15 +++++++++++++--
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 6a39424bd463fd7..5134ccac8671446 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -4,6 +4,7 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
+//
//===----------------------------------------------------------------------===//
#include "AttrOrTypeFormatGen.h"
@@ -25,6 +26,16 @@ using namespace mlir::tblgen;
using llvm::Record;
using llvm::RecordKeeper;
+//===----------------------------------------------------------------------===//
+// Utility structs and functions
+//===----------------------------------------------------------------------===//
+
+static llvm::cl::OptionCategory clAttrOrTypeDefs("Options for -gen-*def-*");
+
+static llvm::cl::opt<bool> clUseFallbackTypeIDs(
+ "gen-attr-or-type-use-fallback-type-ids", llvm::cl::desc("Don't generate static TypeID decls; fall back to string comparison."),
+ llvm::cl::init(false), llvm::cl::cat(clAttrOrTypeDefs));
+
//===----------------------------------------------------------------------===//
// Utility Functions
//===----------------------------------------------------------------------===//
@@ -773,7 +784,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 +997,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/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index a970cbc5cacebe3..e3c87e1e578ebdc 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -31,6 +31,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"
@@ -233,6 +234,16 @@ static const char *const opCommentHeader = R"(
// Utility structs and functions
//===----------------------------------------------------------------------===//
+static llvm::cl::OptionCategory clOpDefs("Options for op definitions");
+
+static llvm::cl::opt<bool> clUseFallbackTypeIDs(
+ "gen-op-use-fallback-type-ids", llvm::cl::desc("Don't generate static TypeID decls; fall back to string comparison."),
+ llvm::cl::init(false), llvm::cl::cat(clOpDefs));
+
+//===----------------------------------------------------------------------===//
+// Utility structs and functions
+//===----------------------------------------------------------------------===//
+
// Replaces all occurrences of `match` in `str` with `substitute`.
static std::string replaceAllSubstrs(std::string str, const std::string &match,
const std::string &substitute) {
@@ -4625,7 +4636,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 +4647,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";
}
>From bda3e2429e3ddf81109659ba27f207d5870d2a73 Mon Sep 17 00:00:00 2001
From: Stef <stef at modular.com>
Date: Tue, 4 Feb 2025 21:38:28 +0000
Subject: [PATCH 2/2] update comment blocks
---
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp | 2 +-
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 5134ccac8671446..5ebd0b654744e0e 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -27,7 +27,7 @@ using llvm::Record;
using llvm::RecordKeeper;
//===----------------------------------------------------------------------===//
-// Utility structs and functions
+// CL Options
//===----------------------------------------------------------------------===//
static llvm::cl::OptionCategory clAttrOrTypeDefs("Options for -gen-*def-*");
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index e3c87e1e578ebdc..1e37ec2f9f86201 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -231,7 +231,7 @@ static const char *const opCommentHeader = R"(
)";
//===----------------------------------------------------------------------===//
-// Utility structs and functions
+// CL Options
//===----------------------------------------------------------------------===//
static llvm::cl::OptionCategory clOpDefs("Options for op definitions");
More information about the Mlir-commits
mailing list