[llvm-branch-commits] [flang] [Flang][OpenMP] Derived type explicit allocatable member mapping (PR #96266)
Kareem Ergawy via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jul 14 22:56:35 PDT 2024
================
@@ -189,85 +295,60 @@ generateMemberPlacementIndices(const Object &object,
indices = llvm::SmallVector<int>{llvm::reverse(indices)};
}
-void addChildIndexAndMapToParent(
- const omp::Object &object,
- std::map<const semantics::Symbol *,
- llvm::SmallVector<OmpMapMemberIndicesData>> &parentMemberIndices,
- mlir::omp::MapInfoOp &mapOp, semantics::SemanticsContext &semaCtx) {
- std::optional<evaluate::DataRef> dataRef = ExtractDataRef(object.ref());
- assert(dataRef.has_value() &&
- "DataRef could not be extracted during mapping of derived type "
- "cannot proceed");
- const semantics::Symbol *parentSym = &dataRef->GetFirstSymbol();
- assert(parentSym && "Could not find parent symbol during lower of "
- "a component member in OpenMP map clause");
+void addChildIndexAndMapToParent(const omp::Object &object,
+ OmpMapMemberIndicesData &parentMemberIndices,
+ mlir::omp::MapInfoOp &mapOp,
+ semantics::SemanticsContext &semaCtx) {
llvm::SmallVector<int> indices;
generateMemberPlacementIndices(object, indices, semaCtx);
- parentMemberIndices[parentSym].push_back({indices, mapOp});
+ parentMemberIndices.memberPlacementIndices.push_back(indices);
+ parentMemberIndices.memberMap.push_back(mapOp);
}
-static void calculateShapeAndFillIndices(
- llvm::SmallVectorImpl<int64_t> &shape,
- llvm::SmallVectorImpl<OmpMapMemberIndicesData> &memberPlacementData) {
- shape.push_back(memberPlacementData.size());
- size_t largestIndicesSize =
- std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
- [](auto a, auto b) {
- return a.memberPlacementIndices.size() <
- b.memberPlacementIndices.size();
- })
- ->memberPlacementIndices.size();
- shape.push_back(largestIndicesSize);
-
- // DenseElementsAttr expects a rectangular shape for the data, so all
- // index lists have to be of the same length, this emplaces -1 as filler.
- for (auto &v : memberPlacementData) {
- if (v.memberPlacementIndices.size() < largestIndicesSize) {
- auto *prevEnd = v.memberPlacementIndices.end();
- v.memberPlacementIndices.resize(largestIndicesSize);
- std::fill(prevEnd, v.memberPlacementIndices.end(), -1);
- }
+llvm::SmallVector<int>
+generateMemberPlacementIndices(const Object &object,
+ Fortran::semantics::SemanticsContext &semaCtx) {
+ std::list<int> indices;
+ auto compObj = getComponentObject(object, semaCtx);
+ while (compObj) {
+ indices.push_front(getComponentPlacementInParent(compObj->sym()));
+ compObj =
+ getComponentObject(getBaseObject(compObj.value(), semaCtx), semaCtx);
}
+
+ return llvm::SmallVector<int>{std::begin(indices), std::end(indices)};
}
-static mlir::DenseIntElementsAttr createDenseElementsAttrFromIndices(
- llvm::SmallVectorImpl<OmpMapMemberIndicesData> &memberPlacementData,
- fir::FirOpBuilder &builder) {
- llvm::SmallVector<int64_t> shape;
- calculateShapeAndFillIndices(shape, memberPlacementData);
-
- llvm::SmallVector<int> indicesFlattened =
- std::accumulate(memberPlacementData.begin(), memberPlacementData.end(),
- llvm::SmallVector<int>(),
- [](llvm::SmallVector<int> &x, OmpMapMemberIndicesData y) {
- x.insert(x.end(), y.memberPlacementIndices.begin(),
- y.memberPlacementIndices.end());
- return x;
- });
-
- return mlir::DenseIntElementsAttr::get(
- mlir::VectorType::get(shape,
- mlir::IntegerType::get(builder.getContext(), 32)),
- indicesFlattened);
+bool memberHasAllocatableParent(const Object &object,
+ Fortran::semantics::SemanticsContext &semaCtx) {
----------------
ergawy wrote:
```suggestion
bool isMemberOrParentAllocatableOrPointer(const Object &object,
Fortran::semantics::SemanticsContext &semaCtx) {
if (Fortran::semantics::IsAllocatableOrObjectPoint(object.sym()))
return true;
```
https://github.com/llvm/llvm-project/pull/96266
More information about the llvm-branch-commits
mailing list