/// Matches a ConstantIndexOp.
detail::op_matcher<arith::ConstantIndexOp> matchConstantIndex();
-/// Detects the `values` produced by a ConstantIndexOp and places the new
-/// constant in place of the corresponding sentinel value.
-/// TODO(pifon2a): Remove this function and use foldDynamicIndexList.
-void canonicalizeSubViewPart(SmallVectorImpl<OpFoldResult> &values,
- function_ref<bool(int64_t)> isDynamic);
-
/// Returns `success` when any of the elements in `ofrs` was produced by
/// arith::ConstantIndexOp. In that case the constant attribute replaces the
/// Value. Returns `failure` when no folding happened.
LogicalResult matchAndRewrite(OpType op,
PatternRewriter &rewriter) const override {
- // No constant operand, just return;
- if (llvm::none_of(op.getOperands(), [](Value operand) {
- return matchPattern(operand, matchConstantIndex());
- }))
- return failure();
-
- // At least one of offsets/sizes/strides is a new constant.
- // Form the new list of operands and constant attributes from the existing.
SmallVector<OpFoldResult> mixedOffsets(op.getMixedOffsets());
SmallVector<OpFoldResult> mixedSizes(op.getMixedSizes());
SmallVector<OpFoldResult> mixedStrides(op.getMixedStrides());
- canonicalizeSubViewPart(mixedOffsets, ShapedType::isDynamic);
- canonicalizeSubViewPart(mixedSizes, ShapedType::isDynamic);
- canonicalizeSubViewPart(mixedStrides, ShapedType::isDynamic);
+
+ // No constant operands were folded, just return;
+ if (failed(foldDynamicIndexList(rewriter, mixedOffsets)) &&
+ failed(foldDynamicIndexList(rewriter, mixedSizes)) &&
+ failed(foldDynamicIndexList(rewriter, mixedStrides)))
+ return failure();
// Create the new op in canonical form.
ResultTypeFunc resultTypeFunc;
return detail::op_matcher<arith::ConstantIndexOp>();
}
-// Detects the `values` produced by a ConstantIndexOp and places the new
-// constant in place of the corresponding sentinel value.
-void mlir::canonicalizeSubViewPart(
- SmallVectorImpl<OpFoldResult> &values,
- llvm::function_ref<bool(int64_t)> isDynamic) {
- for (OpFoldResult &ofr : values) {
- if (ofr.is<Attribute>())
- continue;
- // Newly static, move from Value to constant.
- if (auto cstOp =
- ofr.dyn_cast<Value>().getDefiningOp<arith::ConstantIndexOp>())
- ofr = OpBuilder(cstOp).getIndexAttr(cstOp.value());
- }
-}
-
// Returns `success` when any of the elements in `ofrs` was produced by
// arith::ConstantIndexOp. In that case the constant attribute replaces the
// Value. Returns `failure` when no folding happened.
LogicalResult matchAndRewrite(InsertOpTy insertSliceOp,
PatternRewriter &rewriter) const override {
- // No constant operand, just return.
- if (llvm::none_of(insertSliceOp.getOperands(), [](Value operand) {
- return matchPattern(operand, matchConstantIndex());
- }))
- return failure();
-
- // At least one of offsets/sizes/strides is a new constant.
- // Form the new list of operands and constant attributes from the
- // existing.
SmallVector<OpFoldResult> mixedOffsets(insertSliceOp.getMixedOffsets());
SmallVector<OpFoldResult> mixedSizes(insertSliceOp.getMixedSizes());
SmallVector<OpFoldResult> mixedStrides(insertSliceOp.getMixedStrides());
- canonicalizeSubViewPart(mixedOffsets, ShapedType::isDynamic);
- canonicalizeSubViewPart(mixedSizes, ShapedType::isDynamic);
- canonicalizeSubViewPart(mixedStrides, ShapedType::isDynamic);
+
+ // No constant operands were folded, just return;
+ if (failed(foldDynamicIndexList(rewriter, mixedOffsets)) &&
+ failed(foldDynamicIndexList(rewriter, mixedSizes)) &&
+ failed(foldDynamicIndexList(rewriter, mixedStrides)))
+ return failure();
// Create the new op in canonical form.
auto sourceType = ExtractSliceOp::inferCanonicalRankReducedResultType(