template <typename NamedStructuredOpType>
static void printNamedStructuredOp(OpAsmPrinter &p, NamedStructuredOpType op);
+/// Helper function to dispatch an OpFoldResult into either the `dynamicVec` if
+/// it is a Value or into `staticVec` if it is an IntegerAttr.
+/// In the case of a Value, a copy of the `sentinel` value is also pushed to
+/// `staticVec`. This is useful to extract mixed static and dynamic entries that
+/// come from an AttrSizedOperandSegments trait.
+static void dispatchIndexOpFoldResult(OpFoldResult ofr,
+ SmallVectorImpl<Value> &dynamicVec,
+ SmallVectorImpl<int64_t> &staticVec,
+ int64_t sentinel) {
+ if (auto v = ofr.dyn_cast<Value>()) {
+ dynamicVec.push_back(v);
+ staticVec.push_back(sentinel);
+ return;
+ }
+ APInt apInt = ofr.dyn_cast<Attribute>().cast<IntegerAttr>().getValue();
+ staticVec.push_back(apInt.getSExtValue());
+}
+
/// This is a common class used for patterns of the form
/// ```
/// someop(memrefcast) -> someop
//===----------------------------------------------------------------------===//
// InitTensorOp
//===----------------------------------------------------------------------===//
+void InitTensorOp::build(OpBuilder &b, OperationState &result,
+ ArrayRef<OpFoldResult> sizes, Type elementType,
+ ArrayRef<NamedAttribute> attrs) {
+ unsigned rank = sizes.size();
+ SmallVector<Value, 4> dynamicSizes;
+ SmallVector<int64_t, 4> staticSizes;
+ for (unsigned i = 0; i < rank; ++i) {
+ // staticLow and staticHigh have full information of the padding config.
+ // This will grow staticLow and staticHigh with 1 value. If the config is
+ // dynamic (ie not a constant), dynamicLow and dynamicHigh will grow with 1
+ // value as well.
+ dispatchIndexOpFoldResult(sizes[i], dynamicSizes, staticSizes,
+ ShapedType::kDynamicSize);
+ }
+ auto resultType = RankedTensorType ::get(staticSizes, elementType);
+ build(b, result, resultType, dynamicSizes, b.getI64ArrayAttr(staticSizes));
+ result.addAttributes(attrs);
+}
static LogicalResult verify(InitTensorOp op) {
RankedTensorType resultType = op.getType();
return RankedTensorType::get(resultShape, sourceType.getElementType());
}
-/// Helper function to dispatch an OpFoldResult into either the `dynamicVec` if
-/// it is a Value or into `staticVec` if it is an IntegerAttr.
-/// In the case of a Value, a copy of the `sentinel` value is also pushed to
-/// `staticVec`. This is useful to extract mixed static and dynamic entries that
-/// come from an AttrSizedOperandSegments trait.
-static void dispatchIndexOpFoldResult(OpFoldResult ofr,
- SmallVectorImpl<Value> &dynamicVec,
- SmallVectorImpl<int64_t> &staticVec,
- int64_t sentinel) {
- if (auto v = ofr.dyn_cast<Value>()) {
- dynamicVec.push_back(v);
- staticVec.push_back(sentinel);
- return;
- }
- APInt apInt = ofr.dyn_cast<Attribute>().cast<IntegerAttr>().getValue();
- staticVec.push_back(apInt.getSExtValue());
-}
-
void PadTensorOp::build(OpBuilder &b, OperationState &result, Value source,
ArrayRef<int64_t> staticLow,
ArrayRef<int64_t> staticHigh, ValueRange low,