Skip to content

Commit 85aa991

Browse files
committed
[offload] Remove redundant checks in MappingInfoTy::lookupMapping
Also add some comments while I was at it.
1 parent 5fbb6d9 commit 85aa991

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

offload/libomptarget/OpenMP/Mapping.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,47 +141,44 @@ 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 a mapped
160+
// region, but it's contained in the extended mapped region, which
161+
// 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;
173171
// Does it extend beyond the mapped region?
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);
182179
// Does it extend into an already mapped region?
183-
LR.Flags.ExtendsBefore = HP < LR.TPR.getEntry()->HstPtrBegin &&
184-
(HP + Size) > LR.TPR.getEntry()->HstPtrBegin;
180+
// We know that HP < LR.TPR.getEntry()->HstPtrBegin
181+
LR.Flags.ExtendsBefore = (HP + Size) > LR.TPR.getEntry()->HstPtrBegin;
185182
// Does it extend beyond the mapped region?
186183
LR.Flags.ExtendsAfter = HP < LR.TPR.getEntry()->HstPtrEnd &&
187184
(HP + Size) > LR.TPR.getEntry()->HstPtrEnd;

0 commit comments

Comments
 (0)