Skip to content

Commit 97a8476

Browse files
authored
[flang][runtime] Further work on speeding up work queue operations (#149189)
This patch avoids a trip through the work queue engine for cases on a CPU where finalization and destruction actions during assignment were handled without enqueueing another task.
1 parent 9878ef3 commit 97a8476

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

flang-rt/lib/runtime/assign.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,15 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) {
279279
if (mustDeallocateLHS) {
280280
// Convert the LHS into a temporary, then make it look deallocated.
281281
toDeallocate_ = &tempDescriptor_.descriptor();
282-
persist_ = true; // tempDescriptor_ state must outlive child tickets
283282
std::memcpy(
284283
reinterpret_cast<void *>(toDeallocate_), &to_, to_.SizeInBytes());
285284
to_.set_base_addr(nullptr);
286285
if (toDerived_ && (flags_ & NeedFinalization)) {
287-
if (int status{workQueue.BeginFinalize(*toDeallocate_, *toDerived_)};
288-
status != StatOk && status != StatContinue) {
286+
int status{workQueue.BeginFinalize(*toDeallocate_, *toDerived_)};
287+
if (status == StatContinue) {
288+
// tempDescriptor_ state must outlive pending child ticket
289+
persist_ = true;
290+
} else if (status != StatOk) {
289291
return status;
290292
}
291293
flags_ &= ~NeedFinalization;
@@ -304,6 +306,9 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) {
304306
if (int stat{ReturnError(
305307
workQueue.terminator(), newFrom.Allocate(kNoAsyncObject))};
306308
stat != StatOk) {
309+
if (stat == StatContinue) {
310+
persist_ = true;
311+
}
307312
return stat;
308313
}
309314
if (HasDynamicComponent(*from_)) {
@@ -507,6 +512,7 @@ RT_API_ATTRS int AssignTicket::Continue(WorkQueue &workQueue) {
507512
}
508513
}
509514
if (persist_) {
515+
// tempDescriptor_ must outlive pending child ticket(s)
510516
done_ = true;
511517
return StatContinue;
512518
} else {

0 commit comments

Comments
 (0)