Skip to content

Commit 41971f7

Browse files
committed
unify with the attribute elision
1 parent 9afde67 commit 41971f7

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,18 +2008,25 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
20082008
<< "() != " << propElement.getVar()->prop.getDefaultValue();
20092009
}
20102010

2011+
/// Elide the variadic segment size properties if necessary.
2012+
/// 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.
20122025
static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
20132026
MethodBody &body) {
20142027
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedProps;\n";
20152028

2016-
// Elide the variadic segment size properties if necessary.
2017-
if (!fmt.allOperands &&
2018-
op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
2019-
body << " elidedProps.push_back(\"operandSegmentSizes\");\n";
2020-
if (!fmt.allResultTypes &&
2021-
op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
2022-
body << " elidedProps.push_back(\"resultSegmentSizes\");\n";
2029+
genVariadicSegmentElision(fmt, op, body, "elidedProps");
20232030

20242031
for (const NamedProperty *namedProperty : fmt.usedProperties)
20252032
body << " elidedProps.push_back(\"" << namedProperty->name << "\");\n";
@@ -2066,13 +2073,9 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
20662073
static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
20672074
MethodBody &body, bool withKeyword) {
20682075
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;\n";
2069-
// Elide the variadic segment size attributes if necessary.
2070-
if (!fmt.allOperands &&
2071-
op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
2072-
body << " elidedAttrs.push_back(\"operandSegmentSizes\");\n";
2073-
if (!fmt.allResultTypes &&
2074-
op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
2075-
body << " elidedAttrs.push_back(\"resultSegmentSizes\");\n";
2076+
2077+
genVariadicSegmentElision(fmt, op, body, "elidedAttrs");
2078+
20762079
for (const StringRef key : fmt.inferredAttributes.keys())
20772080
body << " elidedAttrs.push_back(\"" << key << "\");\n";
20782081
for (const NamedAttribute *attr : fmt.usedAttributes)

0 commit comments

Comments
 (0)