[llvm-branch-commits] [flang] [Flang][OpenMP] Derived type explicit allocatable member mapping (PR #96266)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jul 15 08:37:09 PDT 2024
================
@@ -141,6 +143,110 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
return op;
}
+omp::ObjectList gatherObjects(omp::Object obj,
+ semantics::SemanticsContext &semaCtx) {
+ omp::ObjectList objList;
+ std::optional<omp::Object> baseObj = getBaseObject(obj, semaCtx);
+ while (baseObj.has_value()) {
+ objList.push_back(baseObj.value());
+ baseObj = getBaseObject(baseObj.value(), semaCtx);
+ }
+ return omp::ObjectList{llvm::reverse(objList)};
+}
+
+bool duplicateMemberMapInfo(OmpMapMemberIndicesData &parentMembers,
+ llvm::SmallVectorImpl<int> &memberIndices) {
+ // A variation of std:equal that supports non-equal length index lists for our
+ // specific use-case, if one is larger than the other, we use -1, the default
+ // filler element in place of the smaller vector, this prevents UB from over
+ // indexing and removes the need for us to do any filling of intermediate
+ // index lists we'll discard.
+ auto isEqual = [](auto first1, auto last1, auto first2, auto last2) {
+ int v1, v2;
+ for (; first1 != last1; ++first1, ++first2) {
+ v1 = (first1 == last1) ? -1 : *first1;
+ v2 = (first2 == last2) ? -1 : *first2;
+
+ if (!(v1 == v2))
+ return false;
+ }
+ return true;
+ };
+
+ for (auto memberData : parentMembers.memberPlacementIndices)
+ if (isEqual(memberData.begin(), memberData.end(), memberIndices.begin(),
+ memberIndices.end()))
+ return true;
+ return false;
+}
----------------
agozillon wrote:
Happy to change the name, but unfortunately std::equal will not work and will result in the previously stated UB, I had this previously :-) The implementation is effectively the exact same (provided I am looking at the correct overload at least) as the above implementation, minus line 168 which supplements -1's when we over index, without this in the original implementation of std::equal we over index the 2nd range in certain cases and end up accessing random values which yields incorrect results. So I'll try to do what I stated in the previous comment and see how that goes!
https://github.com/llvm/llvm-project/pull/96266
More information about the llvm-branch-commits
mailing list