Skip to content

Commit 0517d64

Browse files
committed
replace comment by TODO. move declaration
1 parent 0f604c7 commit 0517d64

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ struct OpenACCMappableModel
5353
mlir::acc::VariableTypeCategory getTypeCategory(mlir::Type type,
5454
mlir::Value var) const;
5555

56-
bool generatePrivateDestroy(mlir::Type type, mlir::OpBuilder &builder,
57-
mlir::Location loc, mlir::Value privatized) const;
58-
5956
mlir::Value generatePrivateInit(mlir::Type type, mlir::OpBuilder &builder,
6057
mlir::Location loc,
6158
mlir::TypedValue<mlir::acc::MappableType> var,
6259
llvm::StringRef varName,
6360
mlir::ValueRange extents, mlir::Value initVal,
6461
bool &needsDestroy) const;
62+
63+
bool generatePrivateDestroy(mlir::Type type, mlir::OpBuilder &builder,
64+
mlir::Location loc, mlir::Value privatized) const;
6565
};
6666

6767
} // namespace fir::acc

flang/include/flang/Optimizer/Support/Utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ std::optional<llvm::ArrayRef<int64_t>> getComponentLowerBoundsIfNonDefault(
200200
fir::RecordType recordType, llvm::StringRef component,
201201
mlir::ModuleOp module, const mlir::SymbolTable *symbolTable = nullptr);
202202

203+
/// Indicate if a derived type has final routine. Returns std::nullopt if that
204+
/// information is not in the IR;
205+
std::optional<bool>
206+
isRecordWithFinalRoutine(fir::RecordType recordType, mlir::ModuleOp module,
207+
const mlir::SymbolTable *symbolTable = nullptr);
208+
203209
/// Generate a LLVM constant value of type `ity`, using the provided offset.
204210
mlir::LLVM::ConstantOp
205211
genConstantIndex(mlir::Location loc, mlir::Type ity,

flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "flang/Optimizer/Dialect/FIRType.h"
2222
#include "flang/Optimizer/Dialect/Support/FIRContext.h"
2323
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
24+
#include "flang/Optimizer/Support/Utils.h"
2425
#include "mlir/Dialect/Arith/IR/Arith.h"
2526
#include "mlir/Dialect/OpenACC/OpenACC.h"
2627
#include "mlir/IR/BuiltinOps.h"
@@ -555,8 +556,20 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
555556
mlir::ModuleOp mod = builder.getInsertionBlock()
556557
->getParent()
557558
->getParentOfType<mlir::ModuleOp>();
558-
fir::FirOpBuilder firBuilder(builder, mod);
559559

560+
if (auto recType = llvm::dyn_cast<fir::RecordType>(
561+
fir::getFortranElementType(unwrappedTy))) {
562+
// Need to make deep copies of allocatable components.
563+
if (fir::isRecordWithAllocatableMember(recType))
564+
TODO(loc,
565+
"OpenACC: privatizing derived type with allocatable components");
566+
// Need to decide if user assignment/final routine should be called.
567+
if (fir::isRecordWithFinalRoutine(recType, mod).value_or(false))
568+
TODO(loc, "OpenACC: privatizing derived type with user assignment or "
569+
"final routine ");
570+
}
571+
572+
fir::FirOpBuilder firBuilder(builder, mod);
560573
auto getDeclareOpForType = [&](mlir::Type ty) -> hlfir::DeclareOp {
561574
auto alloca = fir::AllocaOp::create(firBuilder, loc, ty);
562575
return hlfir::DeclareOp::create(firBuilder, loc, alloca, varName);
@@ -696,17 +709,9 @@ template <typename Ty>
696709
bool OpenACCMappableModel<Ty>::generatePrivateDestroy(
697710
mlir::Type type, mlir::OpBuilder &builder, mlir::Location loc,
698711
mlir::Value privatized) const {
699-
// TODO: This is only dealing with cleaning-up heap allocation of the
700-
// variable when any was made. Some Fortran types may have allocatable
701-
// components. Currently the init is not doing deep copies of such components,
702-
// so they are not freed here either. Likewise, the copies, when any, are not
703-
// made using Fortran user defined assignments, so the destructors are not
704-
// called either. This deserve a standard clarification, and in the meantime,
705-
// it would likely be better to reject the privatization of such types.
706712
mlir::Type unwrappedTy = fir::unwrapRefType(type);
707713
// For boxed scalars allocated with AllocMem during init, free the heap.
708714
if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(unwrappedTy)) {
709-
// Load the box, take the address and free target if it was heap allocated.
710715
mlir::Value boxVal = privatized;
711716
if (fir::isa_ref_type(boxVal.getType()))
712717
boxVal = fir::LoadOp::create(builder, loc, boxVal);

flang/lib/Optimizer/Support/Utils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ std::optional<llvm::ArrayRef<int64_t>> fir::getComponentLowerBoundsIfNonDefault(
5151
return std::nullopt;
5252
}
5353

54+
std::optional<bool>
55+
fir::isRecordWithFinalRoutine(fir::RecordType recordType, mlir::ModuleOp module,
56+
const mlir::SymbolTable *symbolTable) {
57+
fir::TypeInfoOp typeInfo =
58+
fir::lookupTypeInfoOp(recordType, module, symbolTable);
59+
if (!typeInfo)
60+
return std::nullopt;
61+
return !typeInfo.getNoFinal();
62+
}
63+
5464
mlir::LLVM::ConstantOp
5565
fir::genConstantIndex(mlir::Location loc, mlir::Type ity,
5666
mlir::ConversionPatternRewriter &rewriter,

flang/test/Lower/OpenACC/acc-firstprivate-derived-allocatable-component.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
55
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s --check-prefix=FIR-CHECK
66

7+
! TODO: This test hits a fatal TODO. Deal with allocatable component
8+
! destructions. For arrays, allocatable component allocation may also be
9+
! missing.
10+
! XFAIL: *
11+
712
module m_firstprivate_derived_alloc_comp
813
type point
914
real, allocatable :: x(:)

0 commit comments

Comments
 (0)