[flang-commits] [flang] [flang][acc] Implement PointerLikeType API gen[Allocate/Free/Copy] (PR #163660)
Razvan Lupusoru via flang-commits
flang-commits at lists.llvm.org
Thu Oct 16 11:21:41 PDT 2025
================
@@ -751,4 +751,226 @@ template bool OpenACCMappableModel<fir::PointerType>::generatePrivateDestroy(
mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
mlir::Value privatized) const;
+template <typename Ty>
+mlir::Value OpenACCPointerLikeModel<Ty>::genAllocate(
+ mlir::Type pointer, mlir::OpBuilder &builder, mlir::Location loc,
+ llvm::StringRef varName, mlir::Type varType, mlir::Value originalVar,
+ bool &needsFree) const {
+
+ // Get the element type from the pointer type
+ mlir::Type eleTy = mlir::cast<Ty>(pointer).getElementType();
+
+ // Unlimited polymorphic (class(*)) cannot be handled - size unknown
+ if (fir::isUnlimitedPolymorphicType(eleTy))
+ return {};
+
+ // Character types with dynamic length cannot be handled without a descriptor.
+ if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy))
+ if (charTy.hasDynamicLen())
+ return {};
+
+ // Return null for dynamic or unknown shape arrays because the size of the
+ // allocation cannot be determined simply from the type.
+ if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (seqTy.hasDynamicExtents() || seqTy.hasUnknownShape())
+ return {};
----------------
razvanlupusoru wrote:
> fir::hasDynamicSize(eleTy) should be equivalent
Thank you for the suggestion to use hasDynamicSize - I will use that instead.
> Which leads me to another question, what is the expected behavior of fir.ref<fir.box/class<T>>? Is it to allocate/free/copy descriptors or to also allocate/free/copy the target data of the descriptor?
I think that `genAllocate` should allow for simple shallow allocations - so allocated descriptor storage is enough. `generatePrivateInit` from MappableType (which is accessible through both `fir.ref<fir.box>` and `fir.box` should handle the complexity of allocating both descriptor and data.
However, I have decided in the current PR, I will reject boxes in this API and we can revisit if we need shallow allocations of it.
https://github.com/llvm/llvm-project/pull/163660
More information about the flang-commits
mailing list