@@ -7151,11 +7151,13 @@ class MappableExprsHandler {
7151
7151
/// [ValueDecl *] --> {LE(FieldIndex, Pointer),
7152
7152
/// HE(FieldIndex, Pointer)}
7153
7153
struct StructRangeInfoTy {
7154
+ MapCombinedInfoTy PreliminaryMapData;
7154
7155
std::pair<unsigned /*FieldIndex*/, Address /*Pointer*/> LowestElem = {
7155
7156
0, Address::invalid()};
7156
7157
std::pair<unsigned /*FieldIndex*/, Address /*Pointer*/> HighestElem = {
7157
7158
0, Address::invalid()};
7158
7159
Address Base = Address::invalid();
7160
+ Address LB = Address::invalid();
7159
7161
bool IsArraySection = false;
7160
7162
bool HasCompleteRecord = false;
7161
7163
};
@@ -7754,11 +7756,9 @@ class MappableExprsHandler {
7754
7756
(IsPointer || ForDeviceAddr) && EncounteredME &&
7755
7757
(dyn_cast<MemberExpr>(I->getAssociatedExpression()) ==
7756
7758
EncounteredME);
7757
- if (!OverlappedElements.empty()) {
7759
+ if (!OverlappedElements.empty() && Next == CE ) {
7758
7760
// Handle base element with the info for overlapped elements.
7759
7761
assert(!PartialStruct.Base.isValid() && "The base element is set.");
7760
- assert(Next == CE &&
7761
- "Expected last element for the overlapped elements.");
7762
7762
assert(!IsPointer &&
7763
7763
"Unexpected base element with the pointer type.");
7764
7764
// Mark the whole struct as the struct that requires allocation on the
@@ -7775,13 +7775,17 @@ class MappableExprsHandler {
7775
7775
PartialStruct.HighestElem.first)>::max(),
7776
7776
HB};
7777
7777
PartialStruct.Base = BP;
7778
+ PartialStruct.LB = LB;
7779
+ assert(
7780
+ PartialStruct.PreliminaryMapData.BasePointers.empty() &&
7781
+ "Overlapped elements must be used only once for the variable.");
7782
+ std::swap(PartialStruct.PreliminaryMapData, CombinedInfo);
7778
7783
// Emit data for non-overlapped data.
7779
7784
OpenMPOffloadMappingFlags Flags =
7780
7785
OMP_MAP_MEMBER_OF |
7781
7786
getMapTypeBits(MapType, MapModifiers, MotionModifiers, IsImplicit,
7782
7787
/*AddPtrFlag=*/false,
7783
7788
/*AddIsTargetParamFlag=*/false, IsNonContiguous);
7784
- LB = BP;
7785
7789
llvm::Value *Size = nullptr;
7786
7790
// Do bitcopy of all non-overlapped structure elements.
7787
7791
for (OMPClauseMappableExprCommon::MappableExprComponentListRef
@@ -7890,6 +7894,7 @@ class MappableExprsHandler {
7890
7894
PartialStruct.HighestElem = {FieldIndex, LB};
7891
7895
}
7892
7896
PartialStruct.Base = BP;
7897
+ PartialStruct.LB = BP;
7893
7898
} else if (FieldIndex < PartialStruct.LowestElem.first) {
7894
7899
PartialStruct.LowestElem = {FieldIndex, LB};
7895
7900
} else if (FieldIndex > PartialStruct.HighestElem.first) {
@@ -8609,8 +8614,8 @@ class MappableExprsHandler {
8609
8614
Address LBAddr = PartialStruct.LowestElem.second;
8610
8615
Address HBAddr = PartialStruct.HighestElem.second;
8611
8616
if (PartialStruct.HasCompleteRecord) {
8612
- LBAddr = PartialStruct.Base ;
8613
- HBAddr = PartialStruct.Base ;
8617
+ LBAddr = PartialStruct.LB ;
8618
+ HBAddr = PartialStruct.LB ;
8614
8619
}
8615
8620
CombinedInfo.Exprs.push_back(VD);
8616
8621
// Base is the base of the struct
@@ -8909,11 +8914,17 @@ class MappableExprsHandler {
8909
8914
// Sort the overlapped elements for each item.
8910
8915
llvm::SmallVector<const FieldDecl *, 4> Layout;
8911
8916
if (!OverlappedData.empty()) {
8912
- if (const auto *CRD =
8913
- VD->getType().getCanonicalType()->getAsCXXRecordDecl())
8917
+ const Type *BaseType = VD->getType().getCanonicalType().getTypePtr();
8918
+ const Type *OrigType = BaseType->getPointeeOrArrayElementType();
8919
+ while (BaseType != OrigType) {
8920
+ BaseType = OrigType->getCanonicalTypeInternal().getTypePtr();
8921
+ OrigType = BaseType->getPointeeOrArrayElementType();
8922
+ }
8923
+
8924
+ if (const auto *CRD = BaseType->getAsCXXRecordDecl())
8914
8925
getPlainLayout(CRD, Layout, /*AsBase=*/false);
8915
8926
else {
8916
- const auto *RD = VD->getType().getCanonicalType() ->getAsRecordDecl();
8927
+ const auto *RD = BaseType ->getAsRecordDecl();
8917
8928
Layout.append(RD->field_begin(), RD->field_end());
8918
8929
}
8919
8930
}
@@ -9567,10 +9578,12 @@ getNestedDistributeDirective(ASTContext &Ctx, const OMPExecutableDirective &D) {
9567
9578
/// void *base, void *begin,
9568
9579
/// int64_t size, int64_t type,
9569
9580
/// void *name = nullptr) {
9570
- /// // Allocate space for an array section first.
9571
- /// if ((size > 1 || base != begin) && !maptype.IsDelete)
9581
+ /// // Allocate space for an array section first or add a base/begin for
9582
+ /// // pointer dereference.
9583
+ /// if ((size > 1 || (base != begin && maptype.IsPtrAndObj)) &&
9584
+ /// !maptype.IsDelete)
9572
9585
/// __tgt_push_mapper_component(rt_mapper_handle, base, begin,
9573
- /// size*sizeof(Ty), clearToFrom (type));
9586
+ /// size*sizeof(Ty), clearToFromMember (type));
9574
9587
/// // Map members.
9575
9588
/// for (unsigned i = 0; i < size; i++) {
9576
9589
/// // For each component specified by this mapper:
@@ -9585,9 +9598,9 @@ getNestedDistributeDirective(ASTContext &Ctx, const OMPExecutableDirective &D) {
9585
9598
/// }
9586
9599
/// }
9587
9600
/// // Delete the array section.
9588
- /// if (( size > 1 || base != begin) && maptype.IsDelete)
9601
+ /// if (size > 1 && maptype.IsDelete)
9589
9602
/// __tgt_push_mapper_component(rt_mapper_handle, base, begin,
9590
- /// size*sizeof(Ty), clearToFrom (type));
9603
+ /// size*sizeof(Ty), clearToFromMember (type));
9591
9604
/// }
9592
9605
/// \endcode
9593
9606
void CGOpenMPRuntime::emitUserDefinedMapper(const OMPDeclareMapperDecl *D,
@@ -9851,18 +9864,26 @@ void CGOpenMPRuntime::emitUDMapperArrayInitOrDel(
9851
9864
MapperCGF.createBasicBlock(getName({"omp.array", Prefix}));
9852
9865
llvm::Value *IsArray = MapperCGF.Builder.CreateICmpSGT(
9853
9866
Size, MapperCGF.Builder.getInt64(1), "omp.arrayinit.isarray");
9854
- // base != begin?
9855
- llvm::Value *BaseIsBegin = MapperCGF.Builder.CreateIsNotNull(
9856
- MapperCGF.Builder.CreatePtrDiff(Base, Begin));
9857
- llvm::Value *Cond = MapperCGF.Builder.CreateOr(IsArray, BaseIsBegin);
9858
9867
llvm::Value *DeleteBit = MapperCGF.Builder.CreateAnd(
9859
9868
MapType,
9860
9869
MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_DELETE));
9861
9870
llvm::Value *DeleteCond;
9871
+ llvm::Value *Cond;
9862
9872
if (IsInit) {
9873
+ // base != begin?
9874
+ llvm::Value *BaseIsBegin = MapperCGF.Builder.CreateIsNotNull(
9875
+ MapperCGF.Builder.CreatePtrDiff(Base, Begin));
9876
+ // IsPtrAndObj?
9877
+ llvm::Value *PtrAndObjBit = MapperCGF.Builder.CreateAnd(
9878
+ MapType,
9879
+ MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_PTR_AND_OBJ));
9880
+ PtrAndObjBit = MapperCGF.Builder.CreateIsNotNull(PtrAndObjBit);
9881
+ BaseIsBegin = MapperCGF.Builder.CreateAnd(BaseIsBegin, PtrAndObjBit);
9882
+ Cond = MapperCGF.Builder.CreateOr(IsArray, BaseIsBegin);
9863
9883
DeleteCond = MapperCGF.Builder.CreateIsNull(
9864
9884
DeleteBit, getName({"omp.array", Prefix, ".delete"}));
9865
9885
} else {
9886
+ Cond = IsArray;
9866
9887
DeleteCond = MapperCGF.Builder.CreateIsNotNull(
9867
9888
DeleteBit, getName({"omp.array", Prefix, ".delete"}));
9868
9889
}
@@ -9879,7 +9900,8 @@ void CGOpenMPRuntime::emitUDMapperArrayInitOrDel(
9879
9900
llvm::Value *MapTypeArg = MapperCGF.Builder.CreateAnd(
9880
9901
MapType,
9881
9902
MapperCGF.Builder.getInt64(~(MappableExprsHandler::OMP_MAP_TO |
9882
- MappableExprsHandler::OMP_MAP_FROM)));
9903
+ MappableExprsHandler::OMP_MAP_FROM |
9904
+ MappableExprsHandler::OMP_MAP_MEMBER_OF)));
9883
9905
llvm::Value *MapNameArg = llvm::ConstantPointerNull::get(CGM.VoidPtrTy);
9884
9906
9885
9907
// Call the runtime API __tgt_push_mapper_component to fill up the runtime
@@ -10171,9 +10193,12 @@ void CGOpenMPRuntime::emitTargetCall(
10171
10193
10172
10194
// If there is an entry in PartialStruct it means we have a struct with
10173
10195
// individual members mapped. Emit an extra combined entry.
10174
- if (PartialStruct.Base.isValid())
10175
- MEHandler.emitCombinedEntry(CombinedInfo, CurInfo.Types, PartialStruct,
10176
- nullptr, /*NoTargetParam=*/false);
10196
+ if (PartialStruct.Base.isValid()) {
10197
+ CombinedInfo.append(PartialStruct.PreliminaryMapData);
10198
+ MEHandler.emitCombinedEntry(
10199
+ CombinedInfo, CurInfo.Types, PartialStruct, nullptr,
10200
+ !PartialStruct.PreliminaryMapData.BasePointers.empty());
10201
+ }
10177
10202
10178
10203
// We need to append the results of this capture to what we already have.
10179
10204
CombinedInfo.append(CurInfo);
0 commit comments