[llvm] [Offload] Introduce ATTACH map-type support for pointer attachment. (PR #149036)
Abhinav Gaba via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 05:21:48 PDT 2025
================
@@ -821,19 +821,22 @@ int processAttachEntries(DeviceTy &Device, AttachInfoTy &AttachInfo,
return TPR;
};
- // Get device version of the pointer (e.g., &p)
+ // Get device version of the pointee (e.g., &p[10]) first, as we can
+ // release its TPR after extracting the pointer value.
+ void *TgtPteeBegin;
+ if (auto PteeTPROpt = LookupTargetPointer(HstPteeBegin, 0, "pointee"))
+ TgtPteeBegin = PteeTPROpt->TargetPointer;
+ else
+ continue;
----------------
abhinavgaba wrote:
It's written this way to make sure that the scope of `PteeTPROpt` is limited to the `if` statement. That way the TPR gets destroyed as soon as we get out of the `if`, and releases the lock it had acquired on the map-entry.
Another alternative would be:
```cpp
void *TgtPteeBegin;
{
auto PteeTPROpt = LookupTargetPointer(HstPteeBegin, 0, "pointee");
if (!PteeTPROpt)
TgtPteeBegin = PteeTPROpt->TargetPointer;
}
```
Otherwise, if we want to keep the original way it was written, as you suggested, we would need to explicitly call `PteeTPROpt->reset()` to release the lock.
```cpp
auto PteeTPROpt = LookupTargetPointer(HstPteeBegin, 0, "pointee");
if (!PteeTPROpt)
continue;
void *TgtPteeBegin = PteeTPROpt->TargetPointer;
PteeTPROpt->reset();
```
https://github.com/llvm/llvm-project/pull/149036
More information about the llvm-commits
mailing list