[llvm-branch-commits] [OpenMP][MLIR] Extend explicit derived type member mapping support for OpenMP dialects lowering to LLVM-IR (PR #81510)

Kareem Ergawy via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 15 08:02:45 PST 2024


================
@@ -1783,6 +1783,98 @@ void collectMapDataFromMapOperands(MapInfoData &mapData,
   }
 }
 
+static int getMapDataMemberIdx(MapInfoData &mapData,
+                               mlir::omp::MapInfoOp memberOp) {
+  int memberDataIdx = -1;
+  for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
+    if (mapData.MapClause[i] == memberOp)
+      memberDataIdx = i;
+  }
+  return memberDataIdx;
+}
----------------
ergawy wrote:

`std::find_if(...)`, just like the other PR 😛.

Also it seems like all the uses of this function assume that `-1` will not be returned (there has to be an element matching the search key). So, I would suggest:
```suggestion
static int getMapDataMemberIdx(MapInfoData &mapData,
                               mlir::omp::MapInfoOp memberOp) {
  auto res = llvm::find(mapData.MapClause, memberOp);
  assert(res != mapData.MapClause.end());
  return std::distance(mapData.MapClause.begin(), res);
}
```

https://github.com/llvm/llvm-project/pull/81510


More information about the llvm-branch-commits mailing list