diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h @@ -248,6 +248,20 @@ /// execution engine. Type getOpaquePointerType(OpBuilder &builder); +/// Generates an uninitialized temporary buffer of the given size and +/// type, but returns it as type `memref` (rather than as type +/// `memref<$sz x $tp>`). +Value genAlloca(OpBuilder &builder, Location loc, Value sz, Type tp); + +/// Generates an uninitialized temporary buffer of the given size and +/// type, but returns it as type `memref` (rather than as type +/// `memref<$sz x $tp>`). +Value genAlloca(OpBuilder &builder, Location loc, unsigned sz, Type tp); + +/// Generates an uninitialized temporary buffer with room for one value +/// of the given type, and returns the `memref<$tp>`. +Value genAllocaScalar(OpBuilder &builder, Location loc, Type tp); + //===----------------------------------------------------------------------===// // Inlined constant generators. // diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp @@ -583,3 +583,20 @@ Type mlir::sparse_tensor::getOpaquePointerType(OpBuilder &builder) { return LLVM::LLVMPointerType::get(builder.getI8Type()); } + +Value mlir::sparse_tensor::genAlloca(OpBuilder &builder, Location loc, + unsigned sz, Type tp) { + return genAlloca(builder, loc, constantIndex(builder, loc, sz), tp); +} + +Value mlir::sparse_tensor::genAlloca(OpBuilder &builder, Location loc, Value sz, + Type tp) { + auto memTp = MemRefType::get({ShapedType::kDynamicSize}, tp); + return builder.create(loc, memTp, ValueRange{sz}); +} + +Value mlir::sparse_tensor::genAllocaScalar(OpBuilder &builder, Location loc, + Type tp) { + return builder.create(loc, MemRefType::get({}, tp)); +} + diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp @@ -155,14 +155,6 @@ } } -/// Generates an uninitialized temporary buffer of the given size and -/// type, but returns it as type `memref` (rather than as type -/// `memref<$sz x $tp>`). -static Value genAlloca(OpBuilder &builder, Location loc, Value sz, Type tp) { - auto memTp = MemRefType::get({ShapedType::kDynamicSize}, tp); - return builder.create(loc, memTp, ValueRange{sz}); -} - /// Generates an uninitialized buffer of the given size and type, /// but returns it as type `memref` (rather than as type /// `memref<$sz x $tp>`). Unlike temporary buffers on the stack, @@ -172,19 +164,6 @@ return rewriter.create(loc, memTp, ValueRange{sz}); } -/// Generates an uninitialized temporary buffer of the given size and -/// type, but returns it as type `memref` (rather than as type -/// `memref<$sz x $tp>`). -static Value genAlloca(OpBuilder &builder, Location loc, unsigned sz, Type tp) { - return genAlloca(builder, loc, constantIndex(builder, loc, sz), tp); -} - -/// Generates an uninitialized temporary buffer with room for one value -/// of the given type, and returns the `memref<$tp>`. -static Value genAllocaScalar(OpBuilder &builder, Location loc, Type tp) { - return builder.create(loc, MemRefType::get({}, tp)); -} - /// Generates a temporary buffer of the given type and given contents. static Value genBuffer(OpBuilder &builder, Location loc, ValueRange values) { unsigned sz = values.size();