[Mlir-commits] [mlir] [mlir][core|ptr] Add `PtrLikeTypeInterface` and casting ops to the `ptr` dialect (PR #137469)
Fabian Mora
llvmlistbot at llvm.org
Sun Apr 27 04:44:37 PDT 2025
================
@@ -376,6 +376,20 @@ BaseMemRefType BaseMemRefType::cloneWith(std::optional<ArrayRef<int64_t>> shape,
return builder;
}
+FailureOr<PtrLikeTypeInterface>
+BaseMemRefType::clonePtrWith(Attribute memorySpace,
+ std::optional<Type> elementType) const {
+ Type eTy = elementType ? *elementType : getElementType();
+ if (llvm::dyn_cast<UnrankedMemRefType>(*this))
+ return cast<PtrLikeTypeInterface>(
+ UnrankedMemRefType::get(eTy, memorySpace));
+
+ MemRefType::Builder builder(llvm::cast<MemRefType>(*this));
+ builder.setElementType(eTy);
+ builder.setMemorySpace(memorySpace);
+ return cast<PtrLikeTypeInterface>(static_cast<MemRefType>(builder));
+}
----------------
fabianmcg wrote:
`MemRefType::Builder builder(llvm::cast<MemRefType>(*this))` populates the builder with the existing info in the `memref` type, see: https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/BuiltinTypes.h#L169-L171 . Therefore it's only needed to set the element type and memory space.
https://github.com/llvm/llvm-project/pull/137469
More information about the Mlir-commits
mailing list