Skip to content

Commit 90f301e

Browse files
committed
[flang][Lower][OpenMP] Allocate private boxed vars on stack
1 parent 245788a commit 90f301e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

flang/lib/Lower/OpenMP/PrivateReductionUtils.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,23 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
451451
return;
452452
}
453453

454-
// Allocating on the heap in case the whole reduction/privatization is nested
454+
// TODO: Allocate on the heap if the whole reduction/privatization is nested
455455
// inside of a loop
456-
auto [temp, needsDealloc] = createTempFromMold(loc, builder, source);
456+
mlir::Value tempValue;
457+
std::optional<int64_t> cstNeedsDealloc;
458+
if (isAllocatableOrPointer) {
459+
auto [heapTemp, needsDealloc] = createTempFromMold(loc, builder, source);
460+
tempValue = heapTemp;
461+
cstNeedsDealloc = fir::getIntIfConstant(needsDealloc);
462+
} else {
463+
tempValue = hlfir::createStackTempFromMold(loc, builder, source);
464+
cstNeedsDealloc = false;
465+
}
466+
hlfir::Entity temp{tempValue};
467+
457468
// if needsDealloc isn't statically false, add cleanup region. Always
458469
// do this for allocatable boxes because they might have been re-allocated
459470
// in the body of the loop/parallel region
460-
461-
std::optional<int64_t> cstNeedsDealloc = fir::getIntIfConstant(needsDealloc);
462471
assert(cstNeedsDealloc.has_value() &&
463472
"createTempFromMold decides this statically");
464473
if (cstNeedsDealloc.has_value() && *cstNeedsDealloc != false) {

0 commit comments

Comments
 (0)