[Mlir-commits] [mlir] [mlir][vector] Linearization: push 'bit width' logic out of patterns (PR #136581)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Wed Apr 30 09:51:17 PDT 2025
================
@@ -508,82 +412,111 @@ struct LinearizeVectorBitCast final
const TypeConverter &typeConverter, MLIRContext *context,
unsigned targetVectBitWidth = std::numeric_limits<unsigned>::max(),
PatternBenefit benefit = 1)
- : OpConversionPattern(typeConverter, context, benefit),
- targetVectorBitWidth(targetVectBitWidth) {}
+ : OpConversionPattern(typeConverter, context, benefit) {}
LogicalResult
matchAndRewrite(vector::BitCastOp castOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
- Location loc = castOp.getLoc();
auto resType = getTypeConverter()->convertType(castOp.getType());
- if (!resType)
- return rewriter.notifyMatchFailure(loc, "can't convert return type.");
-
- if (!isLessThanTargetBitWidth(castOp, targetVectorBitWidth))
- return rewriter.notifyMatchFailure(
- loc, "Can't flatten since targetBitWidth <= OpSize");
-
+ assert(resType && "expected 1-D vector type");
rewriter.replaceOpWithNewOp<vector::BitCastOp>(castOp, resType,
adaptor.getSource());
return mlir::success();
}
-
-private:
- unsigned targetVectorBitWidth;
};
} // namespace
-void mlir::vector::populateVectorLinearizeTypeConversionsAndLegality(
- TypeConverter &typeConverter, RewritePatternSet &patterns,
- ConversionTarget &target, unsigned targetBitWidth) {
+/// Return true if the operation `op` does not support scalable vectors and
+/// has at least 1 scalable vector result. These ops should all eventually
+/// support scalable vectors, and this function should be removed.
+static bool isNotLinearizableBecauseScalable(Operation *op) {
+
+ bool unsupported =
+ isa<vector::ExtractStridedSliceOp, vector::ExtractOp, vector::InsertOp>(
+ op);
+ if (!unsupported)
+ return false;
+
+ // Check if any of the results is a scalable vector type.
+ auto types = op->getResultTypes();
+ bool containsScalableResult =
+ std::any_of(types.begin(), types.end(), [](Type type) {
+ auto vecType = dyn_cast<VectorType>(type);
+ return vecType && vecType.isScalable();
+ });
+
+ return containsScalableResult;
+}
+
+static bool isNotLinearizable(Operation *op) {
----------------
banach-space wrote:
Could this method be documented? What does it mean to be "non-linearizable"?
Also, I'm confused about `isNotLinearizableBecauseScalable`. Is linearization disabled in the presence of scalable vectors?
https://github.com/llvm/llvm-project/pull/136581
More information about the Mlir-commits
mailing list