Skip to content

Commit 605c732

Browse files
committed
Remove dead deferred-entry codegen. All non-mathing use_device_ptr translations happen at the end.
1 parent ea97bd6 commit 605c732

File tree

1 file changed

+19
-114
lines changed

1 file changed

+19
-114
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 19 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -7185,19 +7185,6 @@ class MappableExprsHandler {
71857185
Mapper(Mapper), VarRef(VarRef), ForDeviceAddr(ForDeviceAddr) {}
71867186
};
71877187

7188-
/// If use_device_ptr or use_device_addr is used on a decl which is a struct
7189-
/// member and there is no map information about it, then emission of that
7190-
/// entry is deferred until the whole struct has been processed.
7191-
struct DeferredDevicePtrEntryTy {
7192-
const Expr *IE = nullptr;
7193-
const ValueDecl *VD = nullptr;
7194-
bool ForDeviceAddr = false;
7195-
7196-
DeferredDevicePtrEntryTy(const Expr *IE, const ValueDecl *VD,
7197-
bool ForDeviceAddr)
7198-
: IE(IE), VD(VD), ForDeviceAddr(ForDeviceAddr) {}
7199-
};
7200-
72017188
/// The target directive from where the mappable clauses were extracted. It
72027189
/// is either a executable directive or a user-defined mapper directive.
72037190
llvm::PointerUnion<const OMPExecutableDirective *,
@@ -8775,13 +8762,10 @@ class MappableExprsHandler {
87758762
// Look at the use_device_ptr and use_device_addr clauses information and
87768763
// mark the existing map entries as such. If there is no map information for
87778764
// an entry in the use_device_ptr and use_device_addr list, we create one
8778-
// with map type 'alloc' and zero size section. It is the user fault if that
8779-
// was not mapped before. If there is no map information and the pointer is
8780-
// a struct member, then we defer the emission of that entry until the whole
8781-
// struct has been processed.
8782-
llvm::MapVector<CanonicalDeclPtr<const Decl>,
8783-
SmallVector<DeferredDevicePtrEntryTy, 4>>
8784-
DeferredInfo;
8765+
// with map type 'return_param' and zero size section. It is the user's
8766+
// fault if that was not mapped before. If there is no map information, then
8767+
// we defer the emission of that entry until all the maps for the same VD
8768+
// have been handled.
87858769
MapCombinedInfoTy UseDeviceDataCombinedInfo;
87868770

87878771
auto &&UseDeviceDataCombinedInfoGen =
@@ -8805,13 +8789,10 @@ class MappableExprsHandler {
88058789
CodeGenFunction &CGF, const Expr *IE, const ValueDecl *VD,
88068790
OMPClauseMappableExprCommon::MappableExprComponentListRef
88078791
Components,
8808-
bool IsImplicit, bool IsDevAddr,
8809-
bool IEIsAttachPtrForDevAddr = false) {
8792+
bool IsDevAddr, bool IEIsAttachPtrForDevAddr = false) {
88108793
// We didn't find any match in our map information - generate a zero
88118794
// size array section - if the pointer is a struct member we defer
88128795
// this action until the whole struct has been processed.
8813-
// TODO: Check for any reason to still add a map for member fields.
8814-
// The following seems to be working fine.
88158796
llvm::Value *Ptr;
88168797
if (IsDevAddr && !IEIsAttachPtrForDevAddr) {
88178798
if (IE->isGLValue())
@@ -8925,8 +8906,7 @@ class MappableExprsHandler {
89258906
/*DesiredAttachPtrExpr=*/UDPOperandExpr,
89268907
/*IsDevAddr=*/false))
89278908
continue;
8928-
MapInfoGen(CGF, IE, VD, Components, C->isImplicit(),
8929-
/*IsDevAddr=*/false);
8909+
MapInfoGen(CGF, IE, VD, Components, /*IsDevAddr=*/false);
89308910
}
89318911
}
89328912

@@ -8971,7 +8951,7 @@ class MappableExprsHandler {
89718951
/*DesiredAttachPtrExpr=*/UDAAttachPtrExpr,
89728952
/*IsDevAddr=*/true))
89738953
continue;
8974-
MapInfoGen(CGF, IE, VD, Components, C->isImplicit(),
8954+
MapInfoGen(CGF, IE, VD, Components,
89758955
/*IsDevAddr=*/true,
89768956
/*IEIsAttachPtrForDevAddr=*/UDAAttachPtrExpr != nullptr);
89778957
}
@@ -9006,9 +8986,6 @@ class MappableExprsHandler {
90068986
return AttachPtrComparator(LHS.first, RHS.first);
90078987
});
90088988

9009-
std::optional<size_t> MemberOfValueForFirstCombinedEntry = std::nullopt;
9010-
bool IsFirstGroup = true;
9011-
90128989
// And finally, process them all in order, grouping those with
90138990
// equivalent attach-ptr exprs together.
90148991
auto *It = AttachPtrMapInfoPairs.begin();
@@ -9096,93 +9073,24 @@ class MappableExprsHandler {
90969073
// individual members mapped. Emit an extra combined entry.
90979074
if (PartialStruct.Base.isValid()) {
90989075
GroupUnionCurInfo.NonContigInfo.Dims.push_back(0);
9099-
std::optional<size_t> CombinedEntryIndex = emitCombinedEntry(
9076+
emitCombinedEntry(
91009077
CurInfo, GroupUnionCurInfo.Types, PartialStruct, AttachInfo,
91019078
/*IsMapThis*/ !VD, OMPBuilder, VD,
91029079
/*OffsetForMemberOfFlag=*/CombinedInfo.BasePointers.size(),
91039080
/*NotTargetParam=*/true);
9104-
// Track the first group's combined entry's final-index for deferred
9105-
// entries to reference.
9106-
if (IsFirstGroup && CombinedEntryIndex.has_value())
9107-
MemberOfValueForFirstCombinedEntry =
9108-
CombinedInfo.BasePointers.size() + *CombinedEntryIndex;
91099081
}
91109082

91119083
// Append this group's results to the overall CurInfo in the correct
91129084
// order: combined-entry -> original-field-entries -> attach-entry
91139085
CurInfo.append(GroupUnionCurInfo);
91149086
if (AttachInfo.isValid())
91159087
emitAttachEntry(CGF, CurInfo, AttachInfo);
9116-
9117-
IsFirstGroup = false;
9118-
}
9119-
9120-
// Append any pending zero-length pointers which are struct members and
9121-
// used with use_device_ptr or use_device_addr.
9122-
// FIXME: This is now redundant as we are not populating DeferredInfo
9123-
// anymore. Remove unless we find a legitimate need of populating
9124-
// using DefferedInfo during the review process.
9125-
auto CI = DeferredInfo.find(Data.first);
9126-
if (CI != DeferredInfo.end()) {
9127-
size_t DeferredStartIdx = CurInfo.Types.size();
9128-
for (const DeferredDevicePtrEntryTy &L : CI->second) {
9129-
llvm::Value *BasePtr;
9130-
llvm::Value *Ptr;
9131-
if (L.ForDeviceAddr) {
9132-
if (L.IE->isGLValue())
9133-
Ptr = this->CGF.EmitLValue(L.IE).getPointer(CGF);
9134-
else
9135-
Ptr = this->CGF.EmitScalarExpr(L.IE);
9136-
BasePtr = Ptr;
9137-
// Entry is RETURN_PARAM. Also, set the placeholder value
9138-
// MEMBER_OF=FFFF so that the entry is later updated with the
9139-
// correct value of MEMBER_OF.
9140-
CurInfo.Types.push_back(
9141-
OpenMPOffloadMappingFlags::OMP_MAP_RETURN_PARAM |
9142-
OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF);
9143-
} else {
9144-
BasePtr = this->CGF.EmitLValue(L.IE).getPointer(CGF);
9145-
Ptr = this->CGF.EmitLoadOfScalar(this->CGF.EmitLValue(L.IE),
9146-
L.IE->getExprLoc());
9147-
// Entry is PTR_AND_OBJ and RETURN_PARAM. Also, set the
9148-
// placeholder value MEMBER_OF=FFFF so that the entry is later
9149-
// updated with the correct value of MEMBER_OF.
9150-
CurInfo.Types.push_back(
9151-
OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ |
9152-
OpenMPOffloadMappingFlags::OMP_MAP_RETURN_PARAM |
9153-
OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF);
9154-
}
9155-
CurInfo.Exprs.push_back(L.VD);
9156-
CurInfo.BasePointers.emplace_back(BasePtr);
9157-
CurInfo.DevicePtrDecls.emplace_back(L.VD);
9158-
CurInfo.DevicePointers.emplace_back(
9159-
L.ForDeviceAddr ? DeviceInfoTy::Address : DeviceInfoTy::Pointer);
9160-
CurInfo.Pointers.push_back(Ptr);
9161-
CurInfo.Sizes.push_back(
9162-
llvm::Constant::getNullValue(this->CGF.Int64Ty));
9163-
CurInfo.Mappers.push_back(nullptr);
9164-
}
9165-
9166-
// Correct the MEMBER_OF flags for the deferred entries we just added.
9167-
if (MemberOfValueForFirstCombinedEntry.has_value() &&
9168-
DeferredStartIdx < CurInfo.Types.size()) {
9169-
// Use the tracked combined entry index from the first group
9170-
// Note that this assumes that the entries for use_device_ptr/addr
9171-
// should belong to the CombinedEntry emitted when handling the first
9172-
// "group". e.g. Even if we have `map(this->sp->a, this->sp->b)`, the
9173-
// CombinedEntry created for those, with `this->sp` as the attach-ptr,
9174-
// would not be the first attach-entry.
9175-
OpenMPOffloadMappingFlags MemberOfFlag =
9176-
OMPBuilder.getMemberOfFlag(*MemberOfValueForFirstCombinedEntry);
9177-
for (size_t I = DeferredStartIdx; I < CurInfo.Types.size(); ++I)
9178-
OMPBuilder.setCorrectMemberOfFlag(CurInfo.Types[I], MemberOfFlag);
9179-
}
91809088
}
91819089

91829090
// We need to append the results of this capture to what we already have.
91839091
CombinedInfo.append(CurInfo);
91849092
}
9185-
// Append data for use_device_ptr clauses.
9093+
// Append data for use_device_ptr/addr clauses.
91869094
CombinedInfo.append(UseDeviceDataCombinedInfo);
91879095
}
91889096

@@ -9270,25 +9178,24 @@ class MappableExprsHandler {
92709178
/// \p PartialStruct contains attach base-pointer information.
92719179
/// \returns The index of the combined entry if one was added, std::nullopt
92729180
/// otherwise.
9273-
std::optional<size_t> emitCombinedEntry(
9274-
MapCombinedInfoTy &CombinedInfo, MapFlagsArrayTy &CurTypes,
9275-
const StructRangeInfoTy &PartialStruct, AttachInfoTy &AttachInfo,
9276-
bool IsMapThis, llvm::OpenMPIRBuilder &OMPBuilder, const ValueDecl *VD,
9277-
unsigned OffsetForMemberOfFlag, bool NotTargetParams) const {
9181+
void emitCombinedEntry(MapCombinedInfoTy &CombinedInfo,
9182+
MapFlagsArrayTy &CurTypes,
9183+
const StructRangeInfoTy &PartialStruct,
9184+
AttachInfoTy &AttachInfo, bool IsMapThis,
9185+
llvm::OpenMPIRBuilder &OMPBuilder, const ValueDecl *VD,
9186+
unsigned OffsetForMemberOfFlag,
9187+
bool NotTargetParams) const {
92789188
if (CurTypes.size() == 1 &&
92799189
((CurTypes.back() & OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF) !=
92809190
OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF) &&
92819191
!PartialStruct.IsArraySection)
9282-
return std::nullopt;
9283-
9192+
return;
92849193
Address LBAddr = PartialStruct.LowestElem.second;
92859194
Address HBAddr = PartialStruct.HighestElem.second;
92869195
if (PartialStruct.HasCompleteRecord) {
92879196
LBAddr = PartialStruct.LB;
92889197
HBAddr = PartialStruct.LB;
92899198
}
9290-
// Capture the index where the combined entry will be inserted
9291-
size_t CombinedEntryIndex = CombinedInfo.BasePointers.size();
92929199
CombinedInfo.Exprs.push_back(VD);
92939200
// Base is the base of the struct
92949201
CombinedInfo.BasePointers.push_back(PartialStruct.Base.emitRawPointer(CGF));
@@ -9387,8 +9294,6 @@ class MappableExprsHandler {
93879294
// &ps, &ps->a, sizeof(void*), ATTACH // Use combined-entry's LB
93889295
if (AttachInfo.isValid())
93899296
AttachInfo.AttachPteeAddr = LBAddr;
9390-
9391-
return CombinedEntryIndex;
93929297
}
93939298

93949299
/// Generate all the base pointers, section pointers, sizes, map types, and
@@ -9807,10 +9712,10 @@ class MappableExprsHandler {
98079712
// entry.
98089713
if (PartialStruct.Base.isValid()) {
98099714
CurCaptureVarInfo.append(PartialStruct.PreliminaryMapData);
9810-
(void)emitCombinedEntry(
9715+
emitCombinedEntry(
98119716
CurCaptureVarInfo, CurInfoForComponentLists.Types,
98129717
PartialStruct, AttachInfo, Cap->capturesThis(), OMPBuilder,
9813-
nullptr, OffsetForMemberOfFlag,
9718+
/*VD=*/nullptr, OffsetForMemberOfFlag,
98149719
/*NotTargetParams*/ !IsEligibleForTargetParamFlag);
98159720
}
98169721

0 commit comments

Comments
 (0)