[llvm-branch-commits] [flang] [mlir] [flang][OpenACC] generate Destroy region to free memory of private and firstprivate if needed (PR #162702)

Razvan Lupusoru via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 9 13:16:51 PDT 2025


================
@@ -667,23 +673,69 @@ template mlir::Value
 OpenACCMappableModel<fir::BaseBoxType>::generatePrivateInit(
     mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
     mlir::TypedValue<mlir::acc::MappableType> var, llvm::StringRef varName,
-    mlir::ValueRange extents, mlir::Value initVal) const;
+    mlir::ValueRange extents, mlir::Value initVal, bool &needsDestroy) const;
 
 template mlir::Value
 OpenACCMappableModel<fir::ReferenceType>::generatePrivateInit(
     mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
     mlir::TypedValue<mlir::acc::MappableType> var, llvm::StringRef varName,
-    mlir::ValueRange extents, mlir::Value initVal) const;
+    mlir::ValueRange extents, mlir::Value initVal, bool &needsDestroy) const;
 
 template mlir::Value OpenACCMappableModel<fir::HeapType>::generatePrivateInit(
     mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
     mlir::TypedValue<mlir::acc::MappableType> var, llvm::StringRef varName,
-    mlir::ValueRange extents, mlir::Value initVal) const;
+    mlir::ValueRange extents, mlir::Value initVal, bool &needsDestroy) const;
 
 template mlir::Value
 OpenACCMappableModel<fir::PointerType>::generatePrivateInit(
     mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
     mlir::TypedValue<mlir::acc::MappableType> var, llvm::StringRef varName,
-    mlir::ValueRange extents, mlir::Value initVal) const;
+    mlir::ValueRange extents, mlir::Value initVal, bool &needsDestroy) const;
+
+template <typename Ty>
+bool OpenACCMappableModel<Ty>::generatePrivateDestroy(
+    mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
+    mlir::Value privatized) const {
+  // TODO: This is only dealing with cleaning-up heap allocation of the
+  // variable when any was made. Some Fortran types may have allocatable
+  // components. Currently the init is not doing deep copies of such components,
+  // so they are not freed here either. Likewise, the copies, when any, are not
+  // made using Fortran user defined assignments, so the destructors are not
----------------
razvanlupusoru wrote:

This is an implementation limitation. Any chance you can add a TODO in lowering for such a case?

https://github.com/llvm/llvm-project/pull/162702


More information about the llvm-branch-commits mailing list