@@ -2008,10 +2008,26 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
20082008 << " () != " << propElement.getVar ()->prop .getDefaultValue ();
20092009}
20102010
2011+ // / Elide the variadic segment size attributes if necessary.
2012+ // / This pushes elided attribute names in `elidedStorage`.
2013+ static void genVariadicSegmentElision (OperationFormat &fmt, Operator &op,
2014+ MethodBody &body,
2015+ const char *elidedStorage) {
2016+ if (!fmt.allOperands &&
2017+ op.getTrait (" ::mlir::OpTrait::AttrSizedOperandSegments" ))
2018+ body << " " << elidedStorage << " .push_back(\" operandSegmentSizes\" );\n " ;
2019+ if (!fmt.allResultTypes &&
2020+ op.getTrait (" ::mlir::OpTrait::AttrSizedResultSegments" ))
2021+ body << " " << elidedStorage << " .push_back(\" resultSegmentSizes\" );\n " ;
2022+ }
2023+
20112024// / Generate the printer for the 'prop-dict' directive.
20122025static void genPropDictPrinter (OperationFormat &fmt, Operator &op,
20132026 MethodBody &body) {
20142027 body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedProps;\n " ;
2028+
2029+ genVariadicSegmentElision (fmt, op, body, " elidedProps" );
2030+
20152031 for (const NamedProperty *namedProperty : fmt.usedProperties )
20162032 body << " elidedProps.push_back(\" " << namedProperty->name << " \" );\n " ;
20172033 for (const NamedAttribute *namedAttr : fmt.usedAttributes )
@@ -2057,13 +2073,9 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
20572073static void genAttrDictPrinter (OperationFormat &fmt, Operator &op,
20582074 MethodBody &body, bool withKeyword) {
20592075 body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;\n " ;
2060- // Elide the variadic segment size attributes if necessary.
2061- if (!fmt.allOperands &&
2062- op.getTrait (" ::mlir::OpTrait::AttrSizedOperandSegments" ))
2063- body << " elidedAttrs.push_back(\" operandSegmentSizes\" );\n " ;
2064- if (!fmt.allResultTypes &&
2065- op.getTrait (" ::mlir::OpTrait::AttrSizedResultSegments" ))
2066- body << " elidedAttrs.push_back(\" resultSegmentSizes\" );\n " ;
2076+
2077+ genVariadicSegmentElision (fmt, op, body, " elidedAttrs" );
2078+
20672079 for (const StringRef key : fmt.inferredAttributes .keys ())
20682080 body << " elidedAttrs.push_back(\" " << key << " \" );\n " ;
20692081 for (const NamedAttribute *attr : fmt.usedAttributes )
0 commit comments