Skip to content

[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
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -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]>;
Expand Down
3 changes: 2 additions & 1 deletion mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -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"> {
Expand Down
49 changes: 8 additions & 41 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand All @@ -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();
}