[Mlir-commits] [mlir] 96c23eb - [mlir][EmitC] Use declarative assembly format for opaque types and attributes (#76066)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jan 4 06:43:38 PST 2024
Author: Simon Camphausen
Date: 2024-01-04T15:43:33+01:00
New Revision: 96c23ebd3b28f034784eab66393ea9a46e45c6ee
URL: https://github.com/llvm/llvm-project/commit/96c23ebd3b28f034784eab66393ea9a46e45c6ee
DIFF: https://github.com/llvm/llvm-project/commit/96c23ebd3b28f034784eab66393ea9a46e45c6ee.diff
LOG: [mlir][EmitC] Use declarative assembly format for opaque types and attributes (#76066)
The parser and printer of string attributes were changed to handle
escape sequences. Therefore, we no longer require a custom parser and
printer. Verification is moved from the parser to the verifier
accordingly.
Added:
Modified:
mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
index ae843e49c6c5ba..ea5e9efd5fa0b9 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
@@ -57,8 +57,7 @@ def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque"> {
}];
let parameters = (ins StringRefParameter<"the opaque value">:$value);
-
- let hasCustomAssemblyFormat = 1;
+ let assemblyFormat = "`<` $value `>`";
}
def EmitC_OpaqueOrTypedAttr : AnyAttrOf<[EmitC_OpaqueAttr, TypedAttrInterface]>;
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
index 7874aa2c9e3040..8818c049ed7713 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
@@ -42,7 +42,8 @@ def EmitC_OpaqueType : EmitC_Type<"Opaque", "opaque"> {
}];
let parameters = (ins StringRefParameter<"the opaque value">:$value);
- let hasCustomAssemblyFormat = 1;
+ let assemblyFormat = "`<` $value `>`";
+ let genVerifyDecl = 1;
}
def EmitC_PointerType : EmitC_Type<"Pointer", "ptr"> {
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 8508d29d2306a3..5f502f1f7a1714 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -621,27 +621,6 @@ LogicalResult emitc::YieldOp::verify() {
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/EmitC/IR/EmitCAttributes.cpp.inc"
-Attribute emitc::OpaqueAttr::parse(AsmParser &parser, Type type) {
- if (parser.parseLess())
- return Attribute();
- std::string value;
- SMLoc loc = parser.getCurrentLocation();
- if (parser.parseOptionalString(&value)) {
- parser.emitError(loc) << "expected string";
- return Attribute();
- }
- if (parser.parseGreater())
- return Attribute();
-
- return get(parser.getContext(), value);
-}
-
-void emitc::OpaqueAttr::print(AsmPrinter &printer) const {
- printer << "<\"";
- llvm::printEscapedString(getValue(), printer.getStream());
- printer << "\">";
-}
-
//===----------------------------------------------------------------------===//
// EmitC Types
//===----------------------------------------------------------------------===//
@@ -653,27 +632,15 @@ void emitc::OpaqueAttr::print(AsmPrinter &printer) const {
// OpaqueType
//===----------------------------------------------------------------------===//
-Type emitc::OpaqueType::parse(AsmParser &parser) {
- if (parser.parseLess())
- return Type();
- std::string value;
- SMLoc loc = parser.getCurrentLocation();
- if (parser.parseOptionalString(&value) || value.empty()) {
- parser.emitError(loc) << "expected non empty string in !emitc.opaque type";
- return Type();
+LogicalResult mlir::emitc::OpaqueType::verify(
+ llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
+ llvm::StringRef value) {
+ if (value.empty()) {
+ return emitError() << "expected non empty string in !emitc.opaque type";
}
if (value.back() == '*') {
- parser.emitError(loc) << "pointer not allowed as outer type with "
- "!emitc.opaque, use !emitc.ptr instead";
- return Type();
+ return emitError() << "pointer not allowed as outer type with "
+ "!emitc.opaque, use !emitc.ptr instead";
}
- if (parser.parseGreater())
- return Type();
- return get(parser.getContext(), value);
-}
-
-void emitc::OpaqueType::print(AsmPrinter &printer) const {
- printer << "<\"";
- llvm::printEscapedString(getValue(), printer.getStream());
- printer << "\">";
+ return success();
}
More information about the Mlir-commits
mailing list