[Mlir-commits] [mlir] [mlir][sparse] remove most bufferization.alloc_tensor ops from sparse (PR #66847)
Aart Bik
llvmlistbot at llvm.org
Wed Sep 20 09:34:50 PDT 2023
================
@@ -764,6 +765,46 @@ class SparseTensorAllocConverter
bool enableBufferInitialization;
};
+/// Sparse codegen rule for the empty tensor operator.
+/// TODO(springerm): remove when bufferization.alloc_tensor is gone
+class SparseTensorEmptyConverter : public OpConversionPattern<tensor::EmptyOp> {
+public:
+ using OpConversionPattern::OpConversionPattern;
+ SparseTensorEmptyConverter(TypeConverter &typeConverter, MLIRContext *context,
+ bool enableInit)
+ : OpConversionPattern(typeConverter, context),
+ enableBufferInitialization(enableInit) {}
+
+ LogicalResult
+ matchAndRewrite(tensor::EmptyOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ const auto resType = getSparseTensorType(op);
+ if (!resType.hasEncoding())
+ return failure();
+
+ // Construct allocation for each field.
+ const Location loc = op.getLoc();
+ const Value sizeHint; // none
+ const ValueRange dynSizes = adaptor.getDynamicSizes();
+ const size_t found = dynSizes.size();
+ const int64_t expected = resType.getNumDynamicDims();
+ if (found != static_cast<size_t>(expected))
+ return rewriter.notifyMatchFailure(
----------------
aartbik wrote:
Yeah, this was borrowed from the allocation code but it seems overly protective.
https://github.com/llvm/llvm-project/pull/66847
More information about the Mlir-commits
mailing list