From 97a8476068bad449c0340021398b0356a44857aa Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 18 Jul 2025 13:44:25 -0700 Subject: [PATCH] [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. --- flang-rt/lib/runtime/assign.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flang-rt/lib/runtime/assign.cpp b/flang-rt/lib/runtime/assign.cpp index d642ed578b06..7cf4147a94a9 100644 --- a/flang-rt/lib/runtime/assign.cpp +++ b/flang-rt/lib/runtime/assign.cpp @@ -279,13 +279,15 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) { if (mustDeallocateLHS) { // Convert the LHS into a temporary, then make it look deallocated. toDeallocate_ = &tempDescriptor_.descriptor(); - persist_ = true; // tempDescriptor_ state must outlive child tickets std::memcpy( reinterpret_cast(toDeallocate_), &to_, to_.SizeInBytes()); to_.set_base_addr(nullptr); if (toDerived_ && (flags_ & NeedFinalization)) { - if (int status{workQueue.BeginFinalize(*toDeallocate_, *toDerived_)}; - status != StatOk && status != StatContinue) { + int status{workQueue.BeginFinalize(*toDeallocate_, *toDerived_)}; + if (status == StatContinue) { + // tempDescriptor_ state must outlive pending child ticket + persist_ = true; + } else if (status != StatOk) { return status; } flags_ &= ~NeedFinalization; @@ -304,6 +306,9 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) { if (int stat{ReturnError( workQueue.terminator(), newFrom.Allocate(kNoAsyncObject))}; stat != StatOk) { + if (stat == StatContinue) { + persist_ = true; + } return stat; } if (HasDynamicComponent(*from_)) { @@ -507,6 +512,7 @@ RT_API_ATTRS int AssignTicket::Continue(WorkQueue &workQueue) { } } if (persist_) { + // tempDescriptor_ must outlive pending child ticket(s) done_ = true; return StatContinue; } else {