-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][EmitC] Use declarative assembly format for opaque types and attributes #76066
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4ca79ff
to
8daecef
Compare
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-emitc Author: Simon Camphausen (simon-camp) ChangesFull diff: https://github.com/llvm/llvm-project/pull/76066.diff 3 Files Affected:
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();
}
|
marbre
approved these changes
Jan 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
mgehre-amd
pushed a commit
to Xilinx/llvm-project
that referenced
this pull request
Mar 11, 2024
…tributes (llvm#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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.