Skip to content

Commit 1cd1143

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents f873fc3 + 7d56f36 commit 1cd1143

File tree

52 files changed

+3232
-471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3232
-471
lines changed

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
215215
llvm::ArrayRef<mlir::Value> lenParams,
216216
bool asTarget = false);
217217

218+
/// Create a two dimensional ArrayAttr containing integer data as
219+
/// IntegerAttrs, effectively: ArrayAttr<ArrayAttr<IntegerAttr>>>.
220+
mlir::ArrayAttr create2DI64ArrayAttr(
221+
llvm::SmallVectorImpl<llvm::SmallVector<int64_t>> &intData);
222+
218223
/// Create a temporary using `fir.alloca`. This function does not hoist.
219224
/// It is the callers responsibility to set the insertion point if
220225
/// hoisting is required.

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,17 @@ void ClauseProcessor::processMapObjects(
889889
lower::StatementContext &stmtCtx, mlir::Location clauseLocation,
890890
const omp::ObjectList &objects,
891891
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
892-
std::map<const semantics::Symbol *,
893-
llvm::SmallVector<OmpMapMemberIndicesData>> &parentMemberIndices,
892+
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
894893
llvm::SmallVectorImpl<mlir::Value> &mapVars,
895894
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms,
896895
llvm::SmallVectorImpl<mlir::Location> *mapSymLocs,
897896
llvm::SmallVectorImpl<mlir::Type> *mapSymTypes) const {
898897
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
898+
899899
for (const omp::Object &object : objects) {
900900
llvm::SmallVector<mlir::Value> bounds;
901901
std::stringstream asFortran;
902+
std::optional<omp::Object> parentObj;
902903

903904
lower::AddrAndBoundsInfo info =
904905
lower::gatherDataOperandAddrAndBounds<mlir::omp::MapBoundsOp,
@@ -907,28 +908,46 @@ void ClauseProcessor::processMapObjects(
907908
object.ref(), clauseLocation, asFortran, bounds,
908909
treatIndexAsSection);
909910

911+
mlir::Value baseOp = info.rawInput;
912+
if (object.sym()->owner().IsDerivedType()) {
913+
omp::ObjectList objectList = gatherObjects(object, semaCtx);
914+
assert(!objectList.empty() &&
915+
"could not find parent objects of derived type member");
916+
parentObj = objectList[0];
917+
parentMemberIndices.emplace(parentObj.value(),
918+
OmpMapParentAndMemberData{});
919+
920+
if (isMemberOrParentAllocatableOrPointer(object, semaCtx)) {
921+
llvm::SmallVector<int64_t> indices;
922+
generateMemberPlacementIndices(object, indices, semaCtx);
923+
baseOp = createParentSymAndGenIntermediateMaps(
924+
clauseLocation, converter, semaCtx, stmtCtx, objectList, indices,
925+
parentMemberIndices[parentObj.value()], asFortran.str(),
926+
mapTypeBits);
927+
}
928+
}
929+
910930
// Explicit map captures are captured ByRef by default,
911931
// optimisation passes may alter this to ByCopy or other capture
912932
// types to optimise
913-
mlir::Value baseOp = info.rawInput;
914933
auto location = mlir::NameLoc::get(
915934
mlir::StringAttr::get(firOpBuilder.getContext(), asFortran.str()),
916935
baseOp.getLoc());
917936
mlir::omp::MapInfoOp mapOp = createMapInfoOp(
918937
firOpBuilder, location, baseOp,
919938
/*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds,
920-
/*members=*/{}, /*membersIndex=*/mlir::DenseIntElementsAttr{},
939+
/*members=*/{}, /*membersIndex=*/mlir::ArrayAttr{},
921940
static_cast<
922941
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
923942
mapTypeBits),
924943
mlir::omp::VariableCaptureKind::ByRef, baseOp.getType());
925944

926-
if (object.sym()->owner().IsDerivedType()) {
927-
addChildIndexAndMapToParent(object, parentMemberIndices, mapOp, semaCtx);
945+
if (parentObj.has_value()) {
946+
addChildIndexAndMapToParent(
947+
object, parentMemberIndices[parentObj.value()], mapOp, semaCtx);
928948
} else {
929949
mapVars.push_back(mapOp);
930-
if (mapSyms)
931-
mapSyms->push_back(object.sym());
950+
mapSyms->push_back(object.sym());
932951
if (mapSymTypes)
933952
mapSymTypes->push_back(baseOp.getType());
934953
if (mapSymLocs)
@@ -949,9 +968,7 @@ bool ClauseProcessor::processMap(
949968
llvm::SmallVector<const semantics::Symbol *> localMapSyms;
950969
llvm::SmallVectorImpl<const semantics::Symbol *> *ptrMapSyms =
951970
mapSyms ? mapSyms : &localMapSyms;
952-
std::map<const semantics::Symbol *,
953-
llvm::SmallVector<OmpMapMemberIndicesData>>
954-
parentMemberIndices;
971+
std::map<Object, OmpMapParentAndMemberData> parentMemberIndices;
955972

956973
bool clauseFound = findRepeatableClause<omp::clause::Map>(
957974
[&](const omp::clause::Map &clause, const parser::CharBlock &source) {
@@ -1003,17 +1020,15 @@ bool ClauseProcessor::processMap(
10031020
mapSymLocs, mapSymTypes);
10041021
});
10051022

1006-
insertChildMapInfoIntoParent(converter, parentMemberIndices, result.mapVars,
1007-
*ptrMapSyms, mapSymTypes, mapSymLocs);
1008-
1023+
insertChildMapInfoIntoParent(converter, semaCtx, stmtCtx, parentMemberIndices,
1024+
result.mapVars, mapSymTypes, mapSymLocs,
1025+
ptrMapSyms);
10091026
return clauseFound;
10101027
}
10111028

10121029
bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
10131030
mlir::omp::MapClauseOps &result) {
1014-
std::map<const semantics::Symbol *,
1015-
llvm::SmallVector<OmpMapMemberIndicesData>>
1016-
parentMemberIndices;
1031+
std::map<Object, OmpMapParentAndMemberData> parentMemberIndices;
10171032
llvm::SmallVector<const semantics::Symbol *> mapSymbols;
10181033

10191034
auto callbackFn = [&](const auto &clause, const parser::CharBlock &source) {
@@ -1034,9 +1049,9 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
10341049
clauseFound =
10351050
findRepeatableClause<omp::clause::From>(callbackFn) || clauseFound;
10361051

1037-
insertChildMapInfoIntoParent(converter, parentMemberIndices, result.mapVars,
1038-
mapSymbols,
1039-
/*mapSymTypes=*/nullptr, /*mapSymLocs=*/nullptr);
1052+
insertChildMapInfoIntoParent(
1053+
converter, semaCtx, stmtCtx, parentMemberIndices, result.mapVars,
1054+
/*mapSymTypes=*/nullptr, /*mapSymLocs=*/nullptr, &mapSymbols);
10401055
return clauseFound;
10411056
}
10421057

@@ -1110,9 +1125,7 @@ bool ClauseProcessor::processUseDeviceAddr(
11101125
llvm::SmallVectorImpl<mlir::Type> &useDeviceTypes,
11111126
llvm::SmallVectorImpl<mlir::Location> &useDeviceLocs,
11121127
llvm::SmallVectorImpl<const semantics::Symbol *> &useDeviceSyms) const {
1113-
std::map<const semantics::Symbol *,
1114-
llvm::SmallVector<OmpMapMemberIndicesData>>
1115-
parentMemberIndices;
1128+
std::map<Object, OmpMapParentAndMemberData> parentMemberIndices;
11161129
bool clauseFound = findRepeatableClause<omp::clause::UseDeviceAddr>(
11171130
[&](const omp::clause::UseDeviceAddr &clause,
11181131
const parser::CharBlock &source) {
@@ -1125,9 +1138,9 @@ bool ClauseProcessor::processUseDeviceAddr(
11251138
&useDeviceSyms, &useDeviceLocs, &useDeviceTypes);
11261139
});
11271140

1128-
insertChildMapInfoIntoParent(converter, parentMemberIndices,
1129-
result.useDeviceAddrVars, useDeviceSyms,
1130-
&useDeviceTypes, &useDeviceLocs);
1141+
insertChildMapInfoIntoParent(converter, semaCtx, stmtCtx, parentMemberIndices,
1142+
result.useDeviceAddrVars, &useDeviceTypes,
1143+
&useDeviceLocs, &useDeviceSyms);
11311144
return clauseFound;
11321145
}
11331146

@@ -1136,9 +1149,8 @@ bool ClauseProcessor::processUseDevicePtr(
11361149
llvm::SmallVectorImpl<mlir::Type> &useDeviceTypes,
11371150
llvm::SmallVectorImpl<mlir::Location> &useDeviceLocs,
11381151
llvm::SmallVectorImpl<const semantics::Symbol *> &useDeviceSyms) const {
1139-
std::map<const semantics::Symbol *,
1140-
llvm::SmallVector<OmpMapMemberIndicesData>>
1141-
parentMemberIndices;
1152+
std::map<Object, OmpMapParentAndMemberData> parentMemberIndices;
1153+
11421154
bool clauseFound = findRepeatableClause<omp::clause::UseDevicePtr>(
11431155
[&](const omp::clause::UseDevicePtr &clause,
11441156
const parser::CharBlock &source) {
@@ -1151,9 +1163,9 @@ bool ClauseProcessor::processUseDevicePtr(
11511163
&useDeviceSyms, &useDeviceLocs, &useDeviceTypes);
11521164
});
11531165

1154-
insertChildMapInfoIntoParent(converter, parentMemberIndices,
1155-
result.useDevicePtrVars, useDeviceSyms,
1156-
&useDeviceTypes, &useDeviceLocs);
1166+
insertChildMapInfoIntoParent(converter, semaCtx, stmtCtx, parentMemberIndices,
1167+
result.useDevicePtrVars, &useDeviceTypes,
1168+
&useDeviceLocs, &useDeviceSyms);
11571169
return clauseFound;
11581170
}
11591171

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ class ClauseProcessor {
178178
lower::StatementContext &stmtCtx, mlir::Location clauseLocation,
179179
const omp::ObjectList &objects,
180180
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
181-
std::map<const semantics::Symbol *,
182-
llvm::SmallVector<OmpMapMemberIndicesData>> &parentMemberIndices,
181+
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
183182
llvm::SmallVectorImpl<mlir::Value> &mapVars,
184183
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms,
185184
llvm::SmallVectorImpl<mlir::Location> *mapSymLocs = nullptr,

flang/lib/Lower/OpenMP/Clauses.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ struct IdTyTemplate {
5555
return designator == other.designator;
5656
}
5757

58+
// Defining an "ordering" which allows types derived from this to be
59+
// utilised in maps and other containers that require comparison
60+
// operators for ordering
61+
bool operator<(const IdTyTemplate &other) const {
62+
return symbol < other.symbol;
63+
}
64+
5865
operator bool() const { return symbol != nullptr; }
5966
};
6067

@@ -76,6 +83,10 @@ struct ObjectT<Fortran::lower::omp::IdTyTemplate<Fortran::lower::omp::ExprTy>,
7683
Fortran::semantics::Symbol *sym() const { return identity.symbol; }
7784
const std::optional<ExprTy> &ref() const { return identity.designator; }
7885

86+
bool operator<(const ObjectT<IdTy, ExprTy> &other) const {
87+
return identity < other.identity;
88+
}
89+
7990
IdTy identity;
8091
};
8192
} // namespace tomp::type

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ static void genBodyOfTargetOp(
935935
firOpBuilder, copyVal.getLoc(), copyVal,
936936
/*varPtrPtr=*/mlir::Value{}, name.str(), bounds,
937937
/*members=*/llvm::SmallVector<mlir::Value>{},
938-
/*membersIndex=*/mlir::DenseIntElementsAttr{},
938+
/*membersIndex=*/mlir::ArrayAttr{},
939939
static_cast<
940940
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
941941
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT),
@@ -1792,7 +1792,7 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
17921792
mlir::Value mapOp = createMapInfoOp(
17931793
firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{},
17941794
name.str(), bounds, /*members=*/{},
1795-
/*membersIndex=*/mlir::DenseIntElementsAttr{},
1795+
/*membersIndex=*/mlir::ArrayAttr{},
17961796
static_cast<
17971797
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
17981798
mapFlag),

0 commit comments

Comments
 (0)