[Openmp-commits] [openmp] Fix mapping of struct to device (PR #70821)

Gheorghe-Teodor Bercea via Openmp-commits openmp-commits at lists.llvm.org
Tue Oct 31 11:39:51 PDT 2023


================
@@ -573,11 +573,38 @@ int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
                     void **ArgMappers, AsyncInfoTy &AsyncInfo,
                     bool FromMapper) {
   TIMESCOPE_WITH_IDENT(Loc);
+
+  // Initialize new map type with old type:
+  SmallVector<int64_t> NewArgTypes = SmallVector<int64_t>(ArgNum);
+  for (int32_t I = 0; I < ArgNum; ++I) {
+    NewArgTypes[I] = ArgTypes[I];
+  }
+
+  // Try to prevent mapping a struct multiple times in the same construct.
+  // Mapping the struct more than once will potentially overwrite previously
+  // mapped information.
+  for (int32_t I = 0; I < ArgNum; ++I) {
+    if (NewArgTypes[I] < 0)
+      continue;
+    for (int32_t J = I + 1; J < ArgNum; ++J) {
+      if (Args[I] == ArgsBase[I] && Args[I] == Args[J] &&
+          ArgsBase[I] == ArgsBase[J] && ArgSizes[I] == ArgSizes[J] &&
+          NewArgTypes[J] >= 0) {
+        NewArgTypes[I] |= ArgTypes[J];
+        NewArgTypes[J] = -1;
+      }
+    }
+  }
+
   // process each input.
   for (int32_t I = 0; I < ArgNum; ++I) {
+    int64_t ArgType = NewArgTypes[I];
+    if (ArgType < 0)
----------------
doru1004 wrote:

That's right!

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


More information about the Openmp-commits mailing list