[Mlir-commits] [mlir] [MLIR][TblGen] add AttrOrTypeCAPIGen (PR #172590)
Maksim Levental
llvmlistbot at llvm.org
Tue Dec 16 19:42:09 PST 2025
https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/172590
None
>From f9635e6d76f36a1938031bf5c4b5f72e31f36ded Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Tue, 16 Dec 2025 19:41:23 -0800
Subject: [PATCH] [MLIR][TblGen] add AttrOrTypeCAPIGen
---
mlir/tools/mlir-tblgen/AttrOrTypeCAPIGen.cpp | 50 ++++++++++++++++++++
mlir/tools/mlir-tblgen/CMakeLists.txt | 1 +
2 files changed, 51 insertions(+)
create mode 100644 mlir/tools/mlir-tblgen/AttrOrTypeCAPIGen.cpp
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeCAPIGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeCAPIGen.cpp
new file mode 100644
index 0000000000000..8fd0eeeeda31e
--- /dev/null
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeCAPIGen.cpp
@@ -0,0 +1,50 @@
+//===- AttrOrTypeCAPIGen.cpp - MLIR Attribute and Type CAPI generation ----===//
+//
+// 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 "mlir/TableGen/GenInfo.h"
+#include "mlir/TableGen/Pass.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+
+using namespace mlir;
+using namespace mlir::tblgen;
+using llvm::formatv;
+using llvm::RecordKeeper;
+
+static llvm::cl::OptionCategory
+ passGenCat("Options for -gen-attr-or-type-capi-header and "
+ "-gen-attr-or-type-capi-impl");
+
+const char *const gettorDecl = R"(
+MLIR_CAPI_EXPORTED MlirType mlir{0}TypeGet({1});
+
+)";
+
+const char *const gettorDefn = R"(
+MLIR_CAPI_EXPORTED MlirType mlir{0}TypeGet({1})
+{
+ return wrap({0}Type::get({2}));
+}
+
+)";
+
+static bool emitCAPIHeader(const RecordKeeper &records, raw_ostream &os) {}
+
+static bool emitCAPIImpl(const RecordKeeper &records, raw_ostream &os) {}
+
+static mlir::GenRegistration
+ genCAPIHeader("gen-attr-or-type-capi-header",
+ "Generate Attribute or Type C API header", &emitCAPIHeader);
+
+static mlir::GenRegistration
+ genCAPIImpl("gen-attr-or-type-capi-impl",
+ "Generate Attribute or Type C API implementation",
+ &emitCAPIImpl);
diff --git a/mlir/tools/mlir-tblgen/CMakeLists.txt b/mlir/tools/mlir-tblgen/CMakeLists.txt
index d7087cba3c874..4256613ce4848 100644
--- a/mlir/tools/mlir-tblgen/CMakeLists.txt
+++ b/mlir/tools/mlir-tblgen/CMakeLists.txt
@@ -8,6 +8,7 @@ set(LLVM_LINK_COMPONENTS
add_tablegen(mlir-tblgen MLIR
DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
EXPORT MLIR
+ AttrOrTypeCAPIGen.cpp
AttrOrTypeDefGen.cpp
AttrOrTypeFormatGen.cpp
BytecodeDialectGen.cpp
More information about the Mlir-commits
mailing list