[clang] [OpenMP] Clang Codegen Interop : Accept multiple use & destroy clauses (PR #83398)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 29 01:53:46 PST 2024


https://github.com/SunilKuravinakop created https://github.com/llvm/llvm-project/pull/83398

Modified clang/lib/CodeGen/CGStmtOpenMP.cpp to accept multiple use & destroy clauses with interop directive.
Modified clang/test/OpenMP/interop_codegen.cpp to check for the changes.

>From d3db4821ad4f6c93057df5130ecc67f8aa69ca63 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop <kuravina at pe28vega.us.cray.com>
Date: Thu, 29 Feb 2024 03:38:27 -0600
Subject: [PATCH] Adding code for multiple occurences of "use" and "destroy"
 clause.

  Changes to be committed:
 	modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
 	modified:   clang/test/OpenMP/interop_codegen.cpp
---
 clang/lib/CodeGen/CGStmtOpenMP.cpp    | 34 +++++++++++++++++----------
 clang/test/OpenMP/interop_codegen.cpp | 22 ++++++++++++-----
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index ffcd3ae2711e34..3fbd2e03eb61df 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -7042,18 +7042,28 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) {
                                       Device, NumDependences, DependenceList,
                                       Data.HasNowaitClause);
     }
-  } else if (const auto *C = S.getSingleClause<OMPDestroyClause>()) {
-    llvm::Value *InteropvarPtr =
-        EmitLValue(C->getInteropVar()).getPointer(*this);
-    OMPBuilder.createOMPInteropDestroy(Builder, InteropvarPtr, Device,
-                                       NumDependences, DependenceList,
-                                       Data.HasNowaitClause);
-  } else if (const auto *C = S.getSingleClause<OMPUseClause>()) {
-    llvm::Value *InteropvarPtr =
-        EmitLValue(C->getInteropVar()).getPointer(*this);
-    OMPBuilder.createOMPInteropUse(Builder, InteropvarPtr, Device,
-                                   NumDependences, DependenceList,
-                                   Data.HasNowaitClause);
+  }
+  auto ItOMPDestroyClause = S.getClausesOfKind<OMPDestroyClause>();
+  if (!ItOMPDestroyClause.empty()) {
+    // Look at the multiple destroy clauses
+    for (const OMPDestroyClause *C : ItOMPDestroyClause) {
+      llvm::Value *InteropvarPtr =
+          EmitLValue(C->getInteropVar()).getPointer(*this);
+      OMPBuilder.createOMPInteropDestroy(Builder, InteropvarPtr, Device,
+                                         NumDependences, DependenceList,
+                                         Data.HasNowaitClause);
+    }
+  }
+  auto ItOMPUseClause = S.getClausesOfKind<OMPUseClause>();
+  if (!ItOMPUseClause.empty()) {
+    // Look at the multiple use clauses
+    for (const OMPUseClause *C : ItOMPUseClause) {
+      llvm::Value *InteropvarPtr =
+          EmitLValue(C->getInteropVar()).getPointer(*this);
+      OMPBuilder.createOMPInteropUse(Builder, InteropvarPtr, Device,
+                                     NumDependences, DependenceList,
+                                     Data.HasNowaitClause);
+    }
   }
 }
 
diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp
index ea83ef8ed4909f..31df2f1ba58c5f 100644
--- a/clang/test/OpenMP/interop_codegen.cpp
+++ b/clang/test/OpenMP/interop_codegen.cpp
@@ -15,21 +15,31 @@ typedef long omp_intptr_t;
 extern omp_intptr_t omp_get_interop_int(const omp_interop_t, int, int *);
 
 int main() {
-  omp_interop_t obj = omp_interop_none;
+  omp_interop_t obj1 = omp_interop_none;
+  omp_interop_t obj2 = omp_interop_none;
   omp_interop_t i1 = omp_interop_none;
   omp_interop_t i2 = omp_interop_none;
   omp_interop_t i3 = omp_interop_none;
   omp_interop_t i4 = omp_interop_none;
   omp_interop_t i5 = omp_interop_none;
 
-  #pragma omp interop init(targetsync: i1) init(targetsync: obj)
-  int id = (int )omp_get_interop_int(obj, omp_ipr_fr_id, NULL);
-  int id1 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL);
+  #pragma omp interop init(targetsync: obj1) init(targetsync: obj2)
+  int id = (int )omp_get_interop_int(obj1, omp_ipr_fr_id, NULL);
+  int id1 = (int )omp_get_interop_int(obj2, omp_ipr_fr_id, NULL);
+
+  #pragma omp interop init(target,targetsync: i1) use(i2) use(i3) destroy(i4) destroy(i5)
+  int id2 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL);
+  int id3 = (int )omp_get_interop_int(i2, omp_ipr_fr_id, NULL);
 
 
 }
 #endif
 
-// CHECK-LABEL: define {{.+}}main{{.+}} 
+// CHECK-LABEL: define {{.+}}main{{.+}}
+// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj1{{.*}})
+// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj2{{.*}})
 // CHECK: call {{.+}}__tgt_interop_init({{.+}}i1{{.*}})
-// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj{{.*}})
+// CHECK: call {{.+}}__tgt_interop_destroy({{.+}}i4{{.*}})
+// CHECK: call {{.+}}__tgt_interop_destroy({{.+}}i5{{.*}})
+// CHECK: call {{.+}}__tgt_interop_use({{.+}}i2{{.*}})
+// CHECK: call {{.+}}__tgt_interop_use({{.+}}i3{{.*}})



More information about the cfe-commits mailing list