[Mlir-commits] [mlir] [MLIR][ODS] Print prop-dict fields with custom printers (PR #217589)
Mehdi Amini
llvmlistbot at llvm.org
Fri Aug 21 05:03:44 PDT 2026
================
@@ -2348,6 +2348,129 @@ static void genVariadicSegmentElision(OperationFormat &fmt, Operator &op,
body << " " << elidedStorage << ".push_back(\"resultSegmentSizes\");\n";
}
+static void genEnumAttrPrinter(const NamedAttribute *var, const Operator &op,
+ MethodBody &body, StringRef valueExpression);
+
+/// Generate the key-value printer used by the default `prop-dict` printer.
+static void genKeyValuePropDictPrinter(OperationFormat &fmt, Operator &op,
+ OpClass &opClass) {
+ if (!fmt.hasPropDict || !fmt.useProperties || op.hasCustomPropertiesPrinter())
+ return;
+
+ bool hasPrintableField =
+ !op.getProperties().empty() ||
+ llvm::any_of(
+ op.getAttributes(),
+ [](const auto &attr) { return !attr.attr.isDerivedAttr(); }) ||
+ (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments") &&
+ fmt.allOperands) ||
+ (op.getTrait("::mlir::OpTrait::AttrSizedResultSegments") &&
+ fmt.allResultTypes);
+ if (!hasPrintableField)
+ return;
+
+ SmallVector<MethodParameter> paramList;
+ paramList.emplace_back("::mlir::MLIRContext *", "_odsContext");
+ paramList.emplace_back("::mlir::OpAsmPrinter &", "_odsPrinter");
+ paramList.emplace_back("const Properties &", "prop");
+ paramList.emplace_back("::mlir::ArrayRef<::llvm::StringRef>", "elidedProps");
+ Method *method = opClass.addStaticMethod(
+ "void", "_odsPrintPropertiesAsKeyValueList", std::move(paramList));
+ MethodBody &body = method->body().indent();
+
+ body << R"decl(
+bool first = true;
+auto printKey = [&](::llvm::StringRef name) {
+ _odsPrinter << (first ? "<" : ", ") << name << " = ";
----------------
joker-eph wrote:
Done
https://github.com/llvm/llvm-project/pull/217589
More information about the Mlir-commits
mailing list