[Mlir-commits] [mlir] Revert "[MLIR][IRDL] Added IRDL to C++ Translation" (PR #138285)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri May 2 07:26:32 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Théo Degioanni (Moxinilian)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->133982
---
Patch is 78.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/138285.diff
39 Files Affected:
- (modified) mlir/CMakeLists.txt (-2)
- (modified) mlir/cmake/modules/CMakeLists.txt (-3)
- (removed) mlir/cmake/modules/IRDLToCpp.cmake (-12)
- (modified) mlir/cmake/modules/MLIRConfig.cmake.in (-1)
- (modified) mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td (-4)
- (modified) mlir/include/mlir/InitAllTranslations.h (-3)
- (removed) mlir/include/mlir/Target/IRDLToCpp/IRDLToCpp.h (-38)
- (removed) mlir/include/mlir/Target/IRDLToCpp/TranslationRegistration.h (-22)
- (modified) mlir/lib/Dialect/IRDL/IR/IRDL.cpp (+12-53)
- (modified) mlir/lib/Target/CMakeLists.txt (-1)
- (removed) mlir/lib/Target/IRDLToCpp/CMakeLists.txt (-18)
- (removed) mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp (-585)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/DialectDecl.txt (-28)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/DialectDef.txt (-27)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/Header.txt (-10)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/PerOperationDecl.txt (-185)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/PerOperationDef.txt (-28)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/TypeDecl.txt (-26)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/TypeDef.txt (-35)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/TypeHeaderDecl.txt (-14)
- (removed) mlir/lib/Target/IRDLToCpp/Templates/TypeHeaderDef.txt (-9)
- (removed) mlir/lib/Target/IRDLToCpp/TemplatingUtils.h (-89)
- (removed) mlir/lib/Target/IRDLToCpp/TranslationRegistration.cpp (-49)
- (modified) mlir/test/Dialect/IRDL/invalid.irdl.mlir (+3-3)
- (removed) mlir/test/Dialect/IRDL/invalid_names.irdl.mlir (-94)
- (modified) mlir/test/Dialect/IRDL/regions-ops.irdl.mlir (+6-6)
- (modified) mlir/test/lib/Dialect/CMakeLists.txt (-1)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/CMakeLists.txt (-15)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/TestIRDLToCppDialect.cpp (-88)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/TestIRDLToCppDialect.h (-23)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/test.testd.mlir (-6)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/test_conversion.testd.mlir (-17)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir (-35)
- (removed) mlir/test/lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp_invalid_unsupported_types.irdl.mlir (-79)
- (modified) mlir/test/tblgen-to-irdl/TestDialect.td (+2-2)
- (removed) mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt (-28)
- (removed) mlir/tools/mlir-irdl-to-cpp/mlir-irdl-to-cpp.cpp (-143)
- (modified) mlir/tools/mlir-opt/CMakeLists.txt (-1)
- (modified) mlir/tools/mlir-opt/mlir-opt.cpp (-4)
``````````diff
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 56e756d4ae55c..9e786154a2b40 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -63,7 +63,6 @@ list(INSERT CMAKE_MODULE_PATH 0
)
include(AddMLIR)
-include(IRDLToCpp)
# -BSymbolic is incompatible with TypeID
if("${CMAKE_SHARED_LINKER_FLAGS}" MATCHES "-Bsymbolic[^-]")
@@ -207,7 +206,6 @@ include_directories(BEFORE
# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
# from another directory like tools
-add_subdirectory(tools/mlir-irdl-to-cpp)
add_subdirectory(tools/mlir-linalg-ods-gen)
add_subdirectory(tools/mlir-pdll)
add_subdirectory(tools/mlir-tblgen)
diff --git a/mlir/cmake/modules/CMakeLists.txt b/mlir/cmake/modules/CMakeLists.txt
index 47349f0c7eb62..96c27044c4e8d 100644
--- a/mlir/cmake/modules/CMakeLists.txt
+++ b/mlir/cmake/modules/CMakeLists.txt
@@ -112,8 +112,6 @@ set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)
set(MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE mlir-src-sharder)
-set(MLIR_CONFIG_IRDL_TO_CPP_EXE mlir-irdl-to-cpp)
-
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
@@ -137,7 +135,6 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
- ${CMAKE_CURRENT_SOURCE_DIR}/IRDLToCpp.cmake
${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
COMPONENT mlir-cmake-exports)
diff --git a/mlir/cmake/modules/IRDLToCpp.cmake b/mlir/cmake/modules/IRDLToCpp.cmake
deleted file mode 100644
index 8470ccdf55166..0000000000000
--- a/mlir/cmake/modules/IRDLToCpp.cmake
+++ /dev/null
@@ -1,12 +0,0 @@
-function(add_irdl_to_cpp_target target irdl_file)
- add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
- COMMAND ${MLIR_IRDL_TO_CPP_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
-
- # The command output depends on the executable to ensure IRDL sources are properly rebuilt
- # if the tool changes.
- DEPENDS ${MLIR_IRDL_TO_CPP_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file}
- COMMENT "Building ${irdl_file}..."
- )
- add_custom_target(${target} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc)
-endfunction()
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index 71f3e028b1e88..c695b5787af66 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -12,7 +12,6 @@ set(MLIR_INCLUDE_DIRS "@MLIR_CONFIG_INCLUDE_DIRS@")
set(MLIR_TABLEGEN_EXE "@MLIR_CONFIG_TABLEGEN_EXE@")
set(MLIR_PDLL_TABLEGEN_EXE "@MLIR_CONFIG_PDLL_TABLEGEN_EXE@")
set(MLIR_SRC_SHARDER_TABLEGEN_EXE "@MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE@")
-set(MLIR_IRDL_TO_CPP_EXE "@MLIR_CONFIG_IRDL_TO_CPP_EXE@")
set(MLIR_INSTALL_AGGREGATE_OBJECTS "@MLIR_INSTALL_AGGREGATE_OBJECTS@")
set(MLIR_ENABLE_BINDINGS_PYTHON "@MLIR_ENABLE_BINDINGS_PYTHON@")
set(MLIR_ENABLE_EXECUTION_ENGINE "@MLIR_ENABLE_EXECUTION_ENGINE@")
diff --git a/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td b/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
index 40b13167a973d..f3bc3497500e7 100644
--- a/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
+++ b/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
@@ -91,7 +91,6 @@ def IRDL_TypeOp : IRDL_Op<"type",
let regions = (region SizedRegion<1>:$body);
let assemblyFormat =
"$sym_name attr-dict-with-keyword custom<SingleBlockRegion>($body)";
- let hasVerifier = 1;
}
def IRDL_AttributeOp : IRDL_Op<"attribute",
@@ -127,8 +126,6 @@ def IRDL_AttributeOp : IRDL_Op<"attribute",
let regions = (region SizedRegion<1>:$body);
let assemblyFormat =
"$sym_name attr-dict-with-keyword custom<SingleBlockRegion>($body)";
-
- let hasVerifier = 1;
}
def IRDL_ParametersOp : IRDL_Op<"parameters",
@@ -205,7 +202,6 @@ def IRDL_OperationOp : IRDL_Op<"operation",
let assemblyFormat =
"$sym_name attr-dict-with-keyword custom<SingleBlockRegion>($body)";
let hasRegionVerifier = true;
- let hasVerifier = 1;
}
def IRDL_OperandsOp : IRDL_Op<"operands", [HasParent<"OperationOp">]> {
diff --git a/mlir/include/mlir/InitAllTranslations.h b/mlir/include/mlir/InitAllTranslations.h
index 1ab80fb27fa9a..3de3e02ff3f81 100644
--- a/mlir/include/mlir/InitAllTranslations.h
+++ b/mlir/include/mlir/InitAllTranslations.h
@@ -14,8 +14,6 @@
#ifndef MLIR_INITALLTRANSLATIONS_H
#define MLIR_INITALLTRANSLATIONS_H
-#include "mlir/Target/IRDLToCpp/TranslationRegistration.h"
-
namespace mlir {
void registerFromLLVMIRTranslation();
@@ -35,7 +33,6 @@ inline void registerAllTranslations() {
static bool initOnce = []() {
registerFromLLVMIRTranslation();
registerFromSPIRVTranslation();
- registerIRDLToCppTranslation();
registerToCppTranslation();
registerToLLVMIRTranslation();
registerToSPIRVTranslation();
diff --git a/mlir/include/mlir/Target/IRDLToCpp/IRDLToCpp.h b/mlir/include/mlir/Target/IRDLToCpp/IRDLToCpp.h
deleted file mode 100644
index 940ce5632cb41..0000000000000
--- a/mlir/include/mlir/Target/IRDLToCpp/IRDLToCpp.h
+++ /dev/null
@@ -1,38 +0,0 @@
-//===- IRDLToCpp.h - Register translation -----------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the registration function for the IRDL to C++ translation.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_TARGET_IRDLTOCPP_IRDLTOCPP_H
-#define MLIR_TARGET_IRDLTOCPP_IRDLTOCPP_H
-
-#include "mlir/Dialect/IRDL/IR/IRDL.h"
-
-namespace mlir {
-namespace irdl {
-
-/// Translates an IRDL dialect definition to a C++ definition that can be used
-/// with MLIR.
-///
-/// The following preprocessor macros will generate the following code:
-///
-/// // This define generates code for the dialect's class declarations
-/// #define GEN_DIALECT_DECL_HEADER
-///
-/// // This define generates code for the dialect's class definitions
-/// #define GEN_DIALECT_DEF
-LogicalResult
-translateIRDLDialectToCpp(llvm::ArrayRef<irdl::DialectOp> dialects,
- raw_ostream &output);
-
-} // namespace irdl
-} // namespace mlir
-
-#endif // MLIR_TARGET_IRDLTOCPP_IRDLTOCPP_H
diff --git a/mlir/include/mlir/Target/IRDLToCpp/TranslationRegistration.h b/mlir/include/mlir/Target/IRDLToCpp/TranslationRegistration.h
deleted file mode 100644
index 430c519570862..0000000000000
--- a/mlir/include/mlir/Target/IRDLToCpp/TranslationRegistration.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- TranslationRegistration.h - Register translation ---------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the registration function for the IRDL to C++ translation.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_TARGET_IRDLTOCPP_TRANSLATIONREGISTRATION_H
-#define MLIR_TARGET_IRDLTOCPP_TRANSLATIONREGISTRATION_H
-
-namespace mlir {
-
-void registerIRDLToCppTranslation();
-
-} // namespace mlir
-
-#endif // MLIR_TARGET_IRDLTOCPP_TRANSLATIONREGISTRATION_H
diff --git a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
index bcc9f0b109ac2..c0778d478619a 100644
--- a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
+++ b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
@@ -74,62 +74,13 @@ static void printSingleBlockRegion(OpAsmPrinter &p, Operation *op,
if (!region.getBlocks().front().empty())
p.printRegion(region);
}
-static llvm::LogicalResult isValidName(llvm::StringRef in, mlir::Operation *loc,
- const Twine &label) {
- if (in.empty())
- return loc->emitError("name of ") << label << " is empty";
-
- bool allowUnderscore = false;
- for (auto &elem : in) {
- if (elem == '_') {
- if (!allowUnderscore)
- return loc->emitError("name of ")
- << label << " should not contain leading or double underscores";
- } else {
- if (!isalnum(elem))
- return loc->emitError("name of ")
- << label
- << " must contain only lowercase letters, digits and "
- "underscores";
-
- if (llvm::isUpper(elem))
- return loc->emitError("name of ")
- << label << " should not contain uppercase letters";
- }
-
- allowUnderscore = elem != '_';
- }
-
- return success();
-}
LogicalResult DialectOp::verify() {
if (!Dialect::isValidNamespace(getName()))
return emitOpError("invalid dialect name");
- if (failed(isValidName(getSymName(), getOperation(), "dialect")))
- return failure();
-
return success();
}
-LogicalResult OperationOp::verify() {
- return isValidName(getSymName(), getOperation(), "operation");
-}
-
-LogicalResult TypeOp::verify() {
- auto symName = getSymName();
- if (symName.front() == '!')
- symName = symName.substr(1);
- return isValidName(symName, getOperation(), "type");
-}
-
-LogicalResult AttributeOp::verify() {
- auto symName = getSymName();
- if (symName.front() == '#')
- symName = symName.substr(1);
- return isValidName(symName, getOperation(), "attribute");
-}
-
LogicalResult OperationOp::verifyRegions() {
// Stores pairs of value kinds and the list of names of values of this kind in
// the operation.
@@ -182,10 +133,18 @@ static LogicalResult verifyNames(Operation *op, StringRef kindName,
DenseMap<StringRef, size_t> nameMap;
for (auto [i, name] : llvm::enumerate(names)) {
StringRef nameRef = llvm::cast<StringAttr>(name).getValue();
-
- if (failed(isValidName(nameRef, op, Twine(kindName) + " #" + Twine(i))))
- return failure();
-
+ if (nameRef.empty())
+ return op->emitOpError()
+ << "name of " << kindName << " #" << i << " is empty";
+ if (!llvm::isAlpha(nameRef[0]) && nameRef[0] != '_')
+ return op->emitOpError()
+ << "name of " << kindName << " #" << i
+ << " must start with either a letter or an underscore";
+ if (llvm::any_of(nameRef,
+ [](char c) { return !llvm::isAlnum(c) && c != '_'; }))
+ return op->emitOpError()
+ << "name of " << kindName << " #" << i
+ << " must contain only letters, digits and underscores";
if (nameMap.contains(nameRef))
return op->emitOpError() << "name of " << kindName << " #" << i
<< " is a duplicate of the name of " << kindName
diff --git a/mlir/lib/Target/CMakeLists.txt b/mlir/lib/Target/CMakeLists.txt
index 6eb0abc214d38..f14ec49b5a0c2 100644
--- a/mlir/lib/Target/CMakeLists.txt
+++ b/mlir/lib/Target/CMakeLists.txt
@@ -1,5 +1,4 @@
add_subdirectory(Cpp)
-add_subdirectory(IRDLToCpp)
add_subdirectory(SPIRV)
add_subdirectory(LLVMIR)
add_subdirectory(LLVM)
diff --git a/mlir/lib/Target/IRDLToCpp/CMakeLists.txt b/mlir/lib/Target/IRDLToCpp/CMakeLists.txt
deleted file mode 100644
index 731f3fea37451..0000000000000
--- a/mlir/lib/Target/IRDLToCpp/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-add_mlir_translation_library(MLIRTargetIRDLToCpp
- TranslationRegistration.cpp
- IRDLToCpp.cpp
- Templates/DialectDecl.txt
- Templates/DialectDef.txt
- Templates/Header.txt
- Templates/PerOperationDecl.txt
- Templates/PerOperationDef.txt
- Templates/TypeDecl.txt
- Templates/TypeDef.txt
- Templates/TypeHeaderDecl.txt
- Templates/TypeHeaderDef.txt
-
- LINK_LIBS PUBLIC
- MLIRIR
- MLIRIRDL
- MLIRTranslateLib
-)
diff --git a/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp b/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp
deleted file mode 100644
index 538ea4f450b29..0000000000000
--- a/mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp
+++ /dev/null
@@ -1,585 +0,0 @@
-//===- IRDLToCpp.cpp - Converts IRDL definitions to C++ -------------------===//
-//
-// Part of the LLVM Project, under the A0ache 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/Target/IRDLToCpp/IRDLToCpp.h"
-#include "mlir/Dialect/IRDL/IR/IRDL.h"
-#include "mlir/Support/LLVM.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/TypeSwitch.h"
-#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/raw_ostream.h"
-
-#include "TemplatingUtils.h"
-
-using namespace mlir;
-
-constexpr char headerTemplateText[] =
-#include "Templates/Header.txt"
- ;
-
-constexpr char declarationMacroFlag[] = "GEN_DIALECT_DECL_HEADER";
-constexpr char definitionMacroFlag[] = "GEN_DIALECT_DEF";
-
-namespace {
-
-/// The set of strings that can be generated from a Dialect declaraiton
-struct DialectStrings {
- std::string dialectName;
- std::string dialectCppName;
- std::string dialectCppShortName;
- std::string dialectBaseTypeName;
-
- std::string namespaceOpen;
- std::string namespaceClose;
- std::string namespacePath;
-};
-
-/// The set of strings that can be generated from a Type declaraiton
-struct TypeStrings {
- StringRef typeName;
- std::string typeCppName;
-};
-
-/// The set of strings that can be generated from an Operation declaraiton
-struct OpStrings {
- StringRef opName;
- std::string opCppName;
- SmallVector<std::string> opResultNames;
- SmallVector<std::string> opOperandNames;
-};
-
-static std::string joinNameList(llvm::ArrayRef<std::string> names) {
- std::string nameArray;
- llvm::raw_string_ostream nameArrayStream(nameArray);
- nameArrayStream << "{\"" << llvm::join(names, "\", \"") << "\"}";
-
- return nameArray;
-}
-
-/// Generates the C++ type name for a TypeOp
-static std::string typeToCppName(irdl::TypeOp type) {
- return llvm::formatv("{0}Type",
- convertToCamelFromSnakeCase(type.getSymName(), true));
-}
-
-/// Generates the C++ class name for an OperationOp
-static std::string opToCppName(irdl::OperationOp op) {
- return llvm::formatv("{0}Op",
- convertToCamelFromSnakeCase(op.getSymName(), true));
-}
-
-/// Generates TypeStrings from a TypeOp
-static TypeStrings getStrings(irdl::TypeOp type) {
- TypeStrings strings;
- strings.typeName = type.getSymName();
- strings.typeCppName = typeToCppName(type);
- return strings;
-}
-
-/// Generates OpStrings from an OperatioOp
-static OpStrings getStrings(irdl::OperationOp op) {
- auto operandOp = op.getOp<irdl::OperandsOp>();
-
- auto resultOp = op.getOp<irdl::ResultsOp>();
-
- OpStrings strings;
- strings.opName = op.getSymName();
- strings.opCppName = opToCppName(op);
-
- if (operandOp) {
- strings.opOperandNames = SmallVector<std::string>(
- llvm::map_range(operandOp->getNames(), [](Attribute attr) {
- return llvm::formatv("{0}", cast<StringAttr>(attr));
- }));
- }
-
- if (resultOp) {
- strings.opResultNames = SmallVector<std::string>(
- llvm::map_range(resultOp->getNames(), [](Attribute attr) {
- return llvm::formatv("{0}", cast<StringAttr>(attr));
- }));
- }
-
- return strings;
-}
-
-/// Fills a dictionary with values from TypeStrings
-static void fillDict(irdl::detail::dictionary &dict,
- const TypeStrings &strings) {
- dict["TYPE_NAME"] = strings.typeName;
- dict["TYPE_CPP_NAME"] = strings.typeCppName;
-}
-
-/// Fills a dictionary with values from OpStrings
-static void fillDict(irdl::detail::dictionary &dict, const OpStrings &strings) {
- const auto operandCount = strings.opOperandNames.size();
- const auto resultCount = strings.opResultNames.size();
-
- dict["OP_NAME"] = strings.opName;
- dict["OP_CPP_NAME"] = strings.opCppName;
- dict["OP_OPERAND_COUNT"] = std::to_string(strings.opOperandNames.size());
- dict["OP_RESULT_COUNT"] = std::to_string(strings.opResultNames.size());
- dict["OP_OPERAND_INITIALIZER_LIST"] =
- operandCount ? joinNameList(strings.opOperandNames) : "{\"\"}";
- dict["OP_RESULT_INITIALIZER_LIST"] =
- resultCount ? joinNameList(strings.opResultNames) : "{\"\"}";
-}
-
-/// Fills a dictionary with values from DialectStrings
-static void fillDict(irdl::detail::dictionary &dict,
- const DialectStrings &strings) {
- dict["DIALECT_NAME"] = strings.dialectName;
- dict["DIALECT_BASE_TYPE_NAME"] = strings.dialectBaseTypeName;
- dict["DIALECT_CPP_NAME"] = strings.dialectCppName;
- dict["DIALECT_CPP_SHORT_NAME"] = strings.dialectCppShortName;
- dict["NAMESPACE_OPEN"] = strings.namespaceOpen;
- dict["NAMESPACE_CLOSE"] = strings.namespaceClose;
- dict["NAMESPACE_PATH"] = strings.namespacePath;
-}
-
-static LogicalResult generateTypedefList(irdl::DialectOp &dialect,
- SmallVector<std::string> &typeNames) {
- auto typeOps = dialect.getOps<irdl::TypeOp>();
- auto range = llvm::map_range(typeOps, typeToCppName);
- typeNames = SmallVector<std::string>(range);
- return success();
-}
-
-static LogicalResult generateOpList(irdl::DialectOp &dialect,
- SmallVector<std::string> &opNames) {
- auto operationOps = dialect.getOps<irdl::OperationOp>();
- auto range = llvm::map_range(operationOps, opToCppName);
- opNames = SmallVector<std::string>(range);
- return success();
-}
-
-} // namespace
-
-static LogicalResult generateTypeInclude(irdl::TypeOp type, raw_ostream &output,
- irdl::detail::dictionary &dict) {
- static const auto typeDeclTemplate = irdl::detail::Template(
-#include "Templates/TypeDecl.txt"
- );
-
- fillDict(dict, getStrings(type));
- typeDeclTemplate.render(output, dict);
-
- return success();
-}
-
-static void generateOpGetterDeclarations(irdl::detail::dictionary &dict,
- const OpStrings &opStrings) {
- auto opGetters = std::string{};
- auto resGetters = std::string{};
-
- for (size_t i = 0, end = opStrings.opOperandNames.size(); i < end; ++i) {
- const auto op =
- llvm::convertToCamelFromSnakeCase(opStrings.opOperandNames[i], true);
- opGetters += llvm::formatv("::mlir::Value get{0}() { return "
- "getStructuredOperands({1}).front(); }\n ",
- op, i);
- }
- for (size_t i = 0, end = opStrings.opResultNames.size(); i < end; ++i) {
- const auto op =
- llvm::convertToCamelFromSnakeCase(opStrings.opResultNames[i], true);
- resGetters += llvm::formatv(
- R"(::mlir::Value get{0}() { return ::llvm::cast<::mlir::Value>(getStructuredResults({1}).front()); }
- )",
- op, i);
- }
-
- dict["OP_OPERAND_GETTER_DECLS"] = opGetters;
- dict["OP_RESULT_GETTER_DECLS"] = resGetters;
-}
-
-static void generateOpBuilderDeclarations(irdl::detail::dictionary &dict,
- const OpStrings &opStrings) {
- std::string buildDecls;
- llvm::raw_string_ostream stream{buildDecls};
-
- auto resultParams =
- llvm::join(llvm::map_range(opStrings.opResultNames,
- [](StringRef name) -> std::string {
- return llvm::formatv(
- "::mlir::Type {0}, ",
- llvm::convertToCamelFromSnakeCase(name));
- }),
- "");
-
- auto operandParams =
- llvm::join(llvm::map_range(opStrings.opOperandNames,
- [](StringRef name) -> std::string {
- return llvm::formatv(
- "::mlir::Value {0}, ",
- llvm::convertToCamelFromSnakeCase(name));
- ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/138285
More information about the Mlir-commits
mailing list