Skip to content

Commit 7b89c41

Browse files
authored
[offload] Remove redundant checks in MappingInfoTy::lookupMapping (#127638)
Also add some clarifying comments.
1 parent 1fd0600 commit 7b89c41

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

offload/libomptarget/OpenMP/Mapping.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,48 +141,45 @@ LookupResult MappingInfoTy::lookupMapping(HDTTMapAccessorTy &HDTTMap,
141141
if (HDTTMap->empty())
142142
return LR;
143143

144+
// HDTTMap is std::set, ordered by HstPtrBegin.
145+
// Upper is the first element whose HstPtrBegin > HP.
144146
auto Upper = HDTTMap->upper_bound(HP);
145147

146148
if (Size == 0) {
147-
// specification v5.1 Pointer Initialization for Device Data Environments
148-
// upper_bound satisfies
149-
// std::prev(upper)->HDTT.HstPtrBegin <= hp < upper->HDTT.HstPtrBegin
149+
// HP satisfies
150+
// std::prev(Upper)->HDTT.HstPtrBegin <= HP < Upper->HDTT.HstPtrBegin
150151
if (Upper != HDTTMap->begin()) {
151152
LR.TPR.setEntry(std::prev(Upper)->HDTT, OwnedTPR);
152-
// the left side of extended address range is satisfied.
153-
// hp >= LR.TPR.getEntry()->HstPtrBegin || hp >=
154-
// LR.TPR.getEntry()->HstPtrBase
155-
LR.Flags.IsContained = HP < LR.TPR.getEntry()->HstPtrEnd ||
156-
HP < LR.TPR.getEntry()->HstPtrBase;
153+
// We know that HP >= LR.TPR.getEntry()->HstPtrBegin
154+
LR.Flags.IsContained = HP < LR.TPR.getEntry()->HstPtrEnd;
157155
}
158156

159157
if (!LR.Flags.IsContained && Upper != HDTTMap->end()) {
160158
LR.TPR.setEntry(Upper->HDTT, OwnedTPR);
161-
// the right side of extended address range is satisfied.
162-
// hp < LR.TPR.getEntry()->HstPtrEnd || hp < LR.TPR.getEntry()->HstPtrBase
159+
// This is a special case: HP is not really contained in the mapped
160+
// address range, but it's contained in the extended address range,
161+
// which suffices to get the mapping of the base pointer.
162+
// We know that HP < LR.TPR.getEntry()->HstPtrBegin
163163
LR.Flags.IsContained = HP >= LR.TPR.getEntry()->HstPtrBase;
164164
}
165165
} else {
166-
// check the left bin
167166
if (Upper != HDTTMap->begin()) {
168167
LR.TPR.setEntry(std::prev(Upper)->HDTT, OwnedTPR);
169-
// Is it contained?
170-
LR.Flags.IsContained = HP >= LR.TPR.getEntry()->HstPtrBegin &&
171-
HP < LR.TPR.getEntry()->HstPtrEnd &&
168+
// We know that HP >= LR.TPR.getEntry()->HstPtrBegin
169+
LR.Flags.IsContained = HP < LR.TPR.getEntry()->HstPtrEnd &&
172170
(HP + Size) <= LR.TPR.getEntry()->HstPtrEnd;
173-
// Does it extend beyond the mapped region?
171+
// Does it extend beyond the mapped address range?
174172
LR.Flags.ExtendsAfter = HP < LR.TPR.getEntry()->HstPtrEnd &&
175173
(HP + Size) > LR.TPR.getEntry()->HstPtrEnd;
176174
}
177175

178-
// check the right bin
179176
if (!(LR.Flags.IsContained || LR.Flags.ExtendsAfter) &&
180177
Upper != HDTTMap->end()) {
181178
LR.TPR.setEntry(Upper->HDTT, OwnedTPR);
182-
// Does it extend into an already mapped region?
183-
LR.Flags.ExtendsBefore = HP < LR.TPR.getEntry()->HstPtrBegin &&
184-
(HP + Size) > LR.TPR.getEntry()->HstPtrBegin;
185-
// Does it extend beyond the mapped region?
179+
// Does it extend into an already mapped address range?
180+
// We know that HP < LR.TPR.getEntry()->HstPtrBegin
181+
LR.Flags.ExtendsBefore = (HP + Size) > LR.TPR.getEntry()->HstPtrBegin;
182+
// Does it extend beyond the mapped address range?
186183
LR.Flags.ExtendsAfter = HP < LR.TPR.getEntry()->HstPtrEnd &&
187184
(HP + Size) > LR.TPR.getEntry()->HstPtrEnd;
188185
}

0 commit comments

Comments
 (0)