[llvm-branch-commits] [Flang][OpenMP] Derived type explicit allocatable member mapping (PR #111192)
Kareem Ergawy via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Oct 8 04:21:16 PDT 2024
================
@@ -183,99 +347,69 @@ getComponentObject(std::optional<Object> object,
return getComponentObject(baseObj.value(), semaCtx);
}
-static void
-generateMemberPlacementIndices(const Object &object,
- llvm::SmallVectorImpl<int> &indices,
- semantics::SemanticsContext &semaCtx) {
+void generateMemberPlacementIndices(const Object &object,
+ llvm::SmallVectorImpl<int64_t> &indices,
+ semantics::SemanticsContext &semaCtx) {
+ indices.clear();
auto compObj = getComponentObject(object, semaCtx);
+
while (compObj) {
- indices.push_back(getComponentPlacementInParent(compObj->sym()));
+ int64_t index = getComponentPlacementInParent(compObj->sym());
+ assert(index >= 0);
+ indices.push_back(index);
compObj =
getComponentObject(getBaseObject(compObj.value(), semaCtx), semaCtx);
}
- indices = llvm::SmallVector<int>{llvm::reverse(indices)};
+ indices = llvm::SmallVector<int64_t>{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");
- llvm::SmallVector<int> indices;
+void addChildIndexAndMapToParent(const omp::Object &object,
+ OmpMapParentAndMemberData &parentMemberIndices,
+ mlir::omp::MapInfoOp &mapOp,
+ semantics::SemanticsContext &semaCtx) {
+ llvm::SmallVector<int64_t> 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);
- }
+bool isMemberOrParentAllocatableOrPointer(
+ const Object &object, semantics::SemanticsContext &semaCtx) {
+ if (semantics::IsAllocatableOrObjectPointer(object.sym()))
+ return true;
+
+ auto compObj = getBaseObject(object, semaCtx);
+ while (compObj) {
+ if (compObj.has_value() &&
+ semantics::IsAllocatableOrObjectPointer(compObj.value().sym()))
----------------
ergawy wrote:
```suggestion
if (semantics::IsAllocatableOrObjectPointer(compObj.value().sym()))
```
https://github.com/llvm/llvm-project/pull/111192
More information about the llvm-branch-commits
mailing list