[Mlir-commits] [mlir] c98cff5 - [mlir] Automatically populate `operand_segment_sizes` in the auto-generated build methods.
River Riddle
llvmlistbot at llvm.org
Thu Mar 5 12:58:54 PST 2020
Author: River Riddle
Date: 2020-03-05T12:52:22-08:00
New Revision: c98cff5ae4325875c416a395073a3830b52df894
URL: https://github.com/llvm/llvm-project/commit/c98cff5ae4325875c416a395073a3830b52df894
DIFF: https://github.com/llvm/llvm-project/commit/c98cff5ae4325875c416a395073a3830b52df894.diff
LOG: [mlir] Automatically populate `operand_segment_sizes` in the auto-generated build methods.
This greatly simplifies the requirements for builders using this mechanism for managing variadic operands.
Differential Revision: https://reviews.llvm.org/D75317
Added:
Modified:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/include/mlir/Dialect/VectorOps/VectorOps.td
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/mlir-tblgen/op-result.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
index 899c54d4bbae..1d312202f7b6 100644
--- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -1713,14 +1713,11 @@ def SubViewOp : Std_Op<"subview", [AttrSizedOperandSegments, NoSideEffect]> {
}
}];
- // TODO(b/144779634, ravishankarm) : Use
diff erent arguments for
- // offsets, sizes and strides.
let arguments = (ins
AnyMemRef:$source,
Variadic<Index>:$offsets,
Variadic<Index>:$sizes,
- Variadic<Index>:$strides,
- I32ElementsAttr:$operand_segment_sizes
+ Variadic<Index>:$strides
);
let results = (outs AnyMemRef:$result);
diff --git a/mlir/include/mlir/Dialect/VectorOps/VectorOps.td b/mlir/include/mlir/Dialect/VectorOps/VectorOps.td
index 39bf89c48640..7ab4ac17045a 100644
--- a/mlir/include/mlir/Dialect/VectorOps/VectorOps.td
+++ b/mlir/include/mlir/Dialect/VectorOps/VectorOps.td
@@ -713,8 +713,7 @@ def Vector_ReshapeOp :
Vector_Op<"reshape", [AttrSizedOperandSegments, NoSideEffect]>,
Arguments<(ins AnyVector:$vector, Variadic<Index>:$input_shape,
Variadic<Index>:$output_shape,
- I64ArrayAttr:$fixed_vector_sizes,
- I32ElementsAttr:$operand_segment_sizes)>,
+ I64ArrayAttr:$fixed_vector_sizes)>,
Results<(outs AnyVector:$result)> {
let summary = "vector reshape operation";
let description = [{
diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
index 9f3954581efe..0560a0f19526 100644
--- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -1825,10 +1825,7 @@ void mlir::SubViewOp::build(Builder *b, OperationState &result, Value source,
ArrayRef<NamedAttribute> attrs) {
if (!resultType)
resultType = inferSubViewResultType(source.getType().cast<MemRefType>());
- auto segmentAttr = b->getI32VectorAttr(
- {1, static_cast<int>(offsets.size()), static_cast<int32_t>(sizes.size()),
- static_cast<int32_t>(strides.size())});
- build(b, result, resultType, source, offsets, sizes, strides, segmentAttr);
+ build(b, result, resultType, source, offsets, sizes, strides);
result.addAttributes(attrs);
}
diff --git a/mlir/test/mlir-tblgen/op-result.td b/mlir/test/mlir-tblgen/op-result.td
index af88e0b95404..76484c8c7fb5 100644
--- a/mlir/test/mlir-tblgen/op-result.td
+++ b/mlir/test/mlir-tblgen/op-result.td
@@ -45,7 +45,7 @@ def OpD : NS_Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> {
}
// CHECK-LABEL: OpD definitions
-// CHECK: void OpD::build(Builder *, OperationState &odsState, ValueRange operands, ArrayRef<NamedAttribute> attributes)
+// CHECK: void OpD::build(Builder *odsBuilder, OperationState &odsState, ValueRange operands, ArrayRef<NamedAttribute> attributes)
// CHECK: odsState.addTypes({attr.second.cast<TypeAttr>().getValue()});
def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
@@ -54,7 +54,7 @@ def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
}
// CHECK-LABEL: OpE definitions
-// CHECK: void OpE::build(Builder *, OperationState &odsState, ValueRange operands, ArrayRef<NamedAttribute> attributes)
+// CHECK: void OpE::build(Builder *odsBuilder, OperationState &odsState, ValueRange operands, ArrayRef<NamedAttribute> attributes)
// CHECK: odsState.addTypes({attr.second.getType()});
def OpF : NS_Op<"one_variadic_result_op", []> {
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 7aa51bdbf1cf..f4db32a3315c 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -20,6 +20,7 @@
#include "mlir/TableGen/OpInterfaces.h"
#include "mlir/TableGen/OpTrait.h"
#include "mlir/TableGen/Operator.h"
+#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Signals.h"
#include "llvm/TableGen/Error.h"
@@ -737,7 +738,7 @@ void OpEmitter::genUseOperandAsResultTypeCollectiveParamBuilder() {
// Signature
std::string params =
- std::string("Builder *, OperationState &") + builderOpState +
+ std::string("Builder *odsBuilder, OperationState &") + builderOpState +
", ValueRange operands, ArrayRef<NamedAttribute> attributes";
auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static);
auto &body = m.body();
@@ -804,7 +805,7 @@ void OpEmitter::genUseOperandAsResultTypeSeparateParamBuilder() {
void OpEmitter::genUseAttrAsResultTypeBuilder() {
std::string params =
- std::string("Builder *, OperationState &") + builderOpState +
+ std::string("Builder *odsBuilder, OperationState &") + builderOpState +
", ValueRange operands, ArrayRef<NamedAttribute> attributes";
auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static);
auto &body = m.body();
@@ -1062,6 +1063,20 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(OpMethodBody &body,
<< ");\n";
}
+ // If the operation has the operand segment size attribute, add it here.
+ if (op.getTrait("OpTrait::AttrSizedOperandSegments")) {
+ body << " " << builderOpState
+ << ".addAttribute(\"operand_segment_sizes\", "
+ "odsBuilder->getI32VectorAttr({";
+ interleaveComma(llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
+ if (op.getOperand(i).isVariadic())
+ body << "static_cast<int32_t>(" << getArgumentName(op, i) << ".size())";
+ else
+ body << "1";
+ });
+ body << "}));\n";
+ }
+
// Push all attributes to the result.
for (const auto &namedAttr : op.getAttributes()) {
auto &attr = namedAttr.attr;
More information about the Mlir-commits
mailing list