Skip to content

Commit 9afde67

Browse files
committed
add variadic segment size elision to properties
1 parent b336310 commit 9afde67

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

mlir/test/IR/properties.mlir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// # RUN: mlir-opt %s -split-input-file | mlir-opt |FileCheck %s
1+
// # RUN: mlir-opt %s -split-input-file | mlir-opt | FileCheck %s
22
// # RUN: mlir-opt %s -mlir-print-op-generic -split-input-file | mlir-opt -mlir-print-op-generic | FileCheck %s --check-prefix=GENERIC
33

44
// CHECK: test.with_properties
@@ -38,6 +38,14 @@ test.using_property_in_custom [1, 4, 20]
3838
// GENERIC-SAME: }>
3939
test.using_property_ref_in_custom 1 + 4 = 5
4040

41+
// Tests that the variadic segment size properties are elided.
42+
// CHECK: %[[CI64:.*]] = arith.constant
43+
// CHECK-NEXT: test.variadic_segment_prop %[[CI64]], %[[CI64]] : %[[CI64]] : i64, i64 : i64 end
44+
// GENERIC: %[[CI64:.*]] = "arith.constant"()
45+
// GENERIC-NEXT: "test.variadic_segment_prop"(%[[CI64]], %[[CI64]], %[[CI64]]) <{operandSegmentSizes = array<i32: 2, 1>, resultSegmentSizes = array<i32: 2, 1>}> : (i64, i64, i64) -> (i64, i64, i64)
46+
%ci64 = arith.constant 0 : i64
47+
test.variadic_segment_prop %ci64, %ci64 : %ci64 : i64, i64 : i64 end
48+
4149
// CHECK: test.with_default_valued_properties na{{$}}
4250
// GENERIC: "test.with_default_valued_properties"()
4351
// GENERIC-SAME: <{a = 0 : i32, b = "", c = -1 : i32, unit = false}> : () -> ()

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,6 +3047,15 @@ def TestOpUsingPropertyInCustomAndOther
30473047
);
30483048
}
30493049

3050+
def TestOpWithVariadicSegmentProperties : TEST_Op<"variadic_segment_prop",
3051+
[AttrSizedOperandSegments, AttrSizedResultSegments]> {
3052+
let arguments = (ins Variadic<I64>:$a1, Variadic<I64>:$a2);
3053+
let results = (outs Variadic<I64>:$b1, Variadic<I64>:$b2);
3054+
let assemblyFormat = [{
3055+
$a1 `:` $a2 `:` type($b1) `:` type($b2) prop-dict attr-dict `end`
3056+
}];
3057+
}
3058+
30503059
def TestOpUsingPropertyRefInCustom : TEST_Op<"using_property_ref_in_custom"> {
30513060
let assemblyFormat = "custom<IntProperty>($first) `+` custom<SumProperty>($second, ref($first)) attr-dict";
30523061
let arguments = (ins IntProperty<"int64_t">:$first, IntProperty<"int64_t">:$second);

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,15 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
20122012
static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
20132013
MethodBody &body) {
20142014
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedProps;\n";
2015+
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";
2023+
20152024
for (const NamedProperty *namedProperty : fmt.usedProperties)
20162025
body << " elidedProps.push_back(\"" << namedProperty->name << "\");\n";
20172026
for (const NamedAttribute *namedAttr : fmt.usedAttributes)

0 commit comments

Comments
 (0)