Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenMP] Clang Codegen Interop : Accept multiple init #82604

Merged
merged 12 commits into from
Feb 29, 2024

Conversation

SunilKuravinakop
Copy link
Contributor

Modifying clang/lib/CodeGen/CGStmtOpenMP.cpp to accept multiple init clauses with interop directive.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Feb 22, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 22, 2024

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: None (SunilKuravinakop)

Changes

Modifying clang/lib/CodeGen/CGStmtOpenMP.cpp to accept multiple init clauses with interop directive.


Full diff: https://github.com/llvm/llvm-project/pull/82604.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+18-12)
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 8fd74697de3c0f..c512b0bd851f7a 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) {
                                      S.getSingleClause<OMPUseClause>())) &&
          "OMPNowaitClause clause is used separately in OMPInteropDirective.");
 
-  if (const auto *C = S.getSingleClause<OMPInitClause>()) {
-    llvm::Value *InteropvarPtr =
-        EmitLValue(C->getInteropVar()).getPointer(*this);
-    llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown;
-    if (C->getIsTarget()) {
-      InteropType = llvm::omp::OMPInteropType::Target;
-    } else {
-      assert(C->getIsTargetSync() && "Expected interop-type target/targetsync");
-      InteropType = llvm::omp::OMPInteropType::TargetSync;
+  auto It = S.getClausesOfKind<OMPInitClause>();
+  if (!It.empty()) {
+    // Look at the multiple init clauses
+    for (auto C : It) {
+      llvm::Value *InteropvarPtr =
+          EmitLValue(C->getInteropVar()).getPointer(*this);
+      llvm::omp::OMPInteropType InteropType =
+          llvm::omp::OMPInteropType::Unknown;
+      if (C->getIsTarget()) {
+        InteropType = llvm::omp::OMPInteropType::Target;
+      } else {
+        assert(C->getIsTargetSync() &&
+               "Expected interop-type target/targetsync");
+        InteropType = llvm::omp::OMPInteropType::TargetSync;
+      }
+      OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType,
+                                      Device, NumDependences, DependenceList,
+                                      Data.HasNowaitClause);
     }
-    OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, Device,
-                                    NumDependences, DependenceList,
-                                    Data.HasNowaitClause);
   } else if (const auto *C = S.getSingleClause<OMPDestroyClause>()) {
     llvm::Value *InteropvarPtr =
         EmitLValue(C->getInteropVar()).getPointer(*this);

@alexey-bataev
Copy link
Member

The test is required

Sunil Kuravinakop added 3 commits February 24, 2024 00:41
provided twice.
This check is being done only for AMD GPU.

  Changes to be committed:
 	new file:   clang/test/OpenMP/interop_codegen.cpp
-fopenmp-targets=powerpc64le-ibm-linux-gnu.
  Changes to be committed:
 	modified:   clang/test/OpenMP/interop_codegen.cpp
@llvmbot llvmbot added the clang:openmp OpenMP related changes to Clang label Feb 24, 2024
auto It = S.getClausesOfKind<OMPInitClause>();
if (!It.empty()) {
// Look at the multiple init clauses
for (auto C : It) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand 'auto' here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Iterator variable It auto It is preferable rather than
llvm::iterator_range<clang::OMPExecutableDirective::specific_clause_iterator<clang::OMPInitClause> > It

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C is just OMPClause * here, not an iterator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asking about auto for C, not for It.

Sunil Kuravinakop added 2 commits February 24, 2024 12:46
…*C : It)".

  Changes to be committed:
 	modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
  Changes to be committed:
 	modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
auto It = S.getClausesOfKind<OMPInitClause>();
if (!It.empty()) {
// Look at the multiple init clauses
for (const class OMPInitClause *C : It) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop 'class', it won't compile

  Changes to be committed:
 	modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
 	modified:   clang/test/OpenMP/interop_codegen.cpp
@SunilKuravinakop
Copy link
Contributor Author

The recent commit also takes care of the feedback provided by Alexey.

Comment on lines 7046 to 7066
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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split it to a separate patch

merge.
  Changes to be committed:
 	modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
 	modified:   clang/test/OpenMP/interop_codegen.cpp
Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@sandeepkosuri sandeepkosuri merged commit 230b06b into llvm:main Feb 29, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants