@@ -2008,10 +2008,26 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
2008
2008
<< " () != " << propElement.getVar ()->prop .getDefaultValue ();
2009
2009
}
2010
2010
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
+
2011
2024
// / Generate the printer for the 'prop-dict' directive.
2012
2025
static void genPropDictPrinter (OperationFormat &fmt, Operator &op,
2013
2026
MethodBody &body) {
2014
2027
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedProps;\n " ;
2028
+
2029
+ genVariadicSegmentElision (fmt, op, body, " elidedProps" );
2030
+
2015
2031
for (const NamedProperty *namedProperty : fmt.usedProperties )
2016
2032
body << " elidedProps.push_back(\" " << namedProperty->name << " \" );\n " ;
2017
2033
for (const NamedAttribute *namedAttr : fmt.usedAttributes )
@@ -2057,13 +2073,9 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
2057
2073
static void genAttrDictPrinter (OperationFormat &fmt, Operator &op,
2058
2074
MethodBody &body, bool withKeyword) {
2059
2075
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
+
2067
2079
for (const StringRef key : fmt.inferredAttributes .keys ())
2068
2080
body << " elidedAttrs.push_back(\" " << key << " \" );\n " ;
2069
2081
for (const NamedAttribute *attr : fmt.usedAttributes )
0 commit comments