Skip to content

Commit 5f91b69

Browse files
authored
[MLIR] Always emit setPropertiesFromParsedAttr() when hasCustomAssemblyFormat is set (#145973)
This allows people writing custom C++ assembly functions to reuse the "prop-dict" parser. Fix #145028
1 parent 4662871 commit 5f91b69

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

mlir/test/mlir-tblgen/op-decl-and-defs.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
125125
// CHECK: ::llvm::LogicalResult verifyInvariants();
126126
// CHECK: static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context);
127127
// CHECK: ::llvm::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results);
128+
// CHECK: static ::llvm::LogicalResult setPropertiesFromParsedAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
128129
// CHECK: // Display a graph for debugging purposes.
129130
// CHECK: void displayGraph();
130131
// CHECK: };

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,8 @@ if (!dict) {
13021302
}
13031303
// keep track of used keys in the input dictionary to be able to error out
13041304
// if there are some unknown ones.
1305-
DenseSet<StringAttr> usedKeys;
1306-
MLIRContext *ctx = dict.getContext();
1305+
::mlir::DenseSet<::mlir::StringAttr> usedKeys;
1306+
::mlir::MLIRContext *ctx = dict.getContext();
13071307
(void)ctx;
13081308
)decl";
13091309

@@ -1315,7 +1315,7 @@ auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr,
13151315
::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult {{
13161316
{0};
13171317
};
1318-
auto {1}AttrName = StringAttr::get(ctx, "{1}");
1318+
auto {1}AttrName = ::mlir::StringAttr::get(ctx, "{1}");
13191319
usedKeys.insert({1}AttrName);
13201320
auto attr = dict.get({1}AttrName);
13211321
if (!attr && {2}) {{
@@ -1363,7 +1363,7 @@ if (attr && ::mlir::failed(setFromAttr(prop.{1}, attr, emitError)))
13631363
bool isRequired = !attr.isOptional() && !attr.hasDefaultValue();
13641364
body << formatv(R"decl(
13651365
auto &propStorage = prop.{0};
1366-
auto {0}AttrName = StringAttr::get(ctx, "{0}");
1366+
auto {0}AttrName = ::mlir::StringAttr::get(ctx, "{0}");
13671367
auto attr = dict.get({0}AttrName);
13681368
usedKeys.insert({0}AttrName);
13691369
if (attr || /*isRequired=*/{1}) {{
@@ -1384,7 +1384,7 @@ if (attr || /*isRequired=*/{1}) {{
13841384
namedAttr.name, isRequired);
13851385
}
13861386
body << R"decl(
1387-
for (NamedAttribute attr : dict) {
1387+
for (::mlir::NamedAttribute attr : dict) {
13881388
if (!usedKeys.contains(attr.getName()))
13891389
return emitError() << "unknown key '" << attr.getName() <<
13901390
"' when parsing properties dictionary";
@@ -3848,8 +3848,14 @@ void mlir::tblgen::generateOpFormat(const Operator &constOp, OpClass &opClass,
38483848
// TODO: Operator doesn't expose all necessary functionality via
38493849
// the const interface.
38503850
Operator &op = const_cast<Operator &>(constOp);
3851-
if (!op.hasAssemblyFormat())
3851+
if (!op.hasAssemblyFormat()) {
3852+
// We still need to generate the parsed attribute properties setter for
3853+
// allowing it to be reused in custom assembly implementations.
3854+
OperationFormat format(op, hasProperties);
3855+
format.hasPropDict = true;
3856+
genParsedAttrPropertiesSetter(format, op, opClass);
38523857
return;
3858+
}
38533859

38543860
// Parse the format description.
38553861
llvm::SourceMgr mgr;

0 commit comments

Comments
 (0)