[PATCH] D158538: [MS-ABI] Remove comdat attribute for inheriting ctor.

2023-08-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 marked an inline comment as done.
jyu2 added a comment.

Thanks.  @rnk




Comment at: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp:41
+
+// CHECK-LABEL: define internal noundef ptr 
@"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, 
ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 align 2
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %p1, 
ptr noundef nonnull align 1 dereferenceable(1) %d) unnamed_addr #2 comdat align 
2

rnk wrote:
> jyu2 wrote:
> > rnk wrote:
> > > To make this less fragile, can you come up with a way to use `CHECK-NOT: 
> > > comdat` since that's the key thing we're testing for here? You will need 
> > > some subsequent anchor like `entry:` or something else.
> > Thanks.  I changed.
> This isn't quite what I was trying to suggest, I was thinking something more 
> like:
> 
> ```
> // CHECK-LABEL: define internal noundef ptr 
> @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"
> // CHECK-NOT: comdat
> // CHECK-SAME: {{\{$}}
> ```
> 
> So, it finds the class with the inheriting constructor, and then checks that 
> the word "comdat" does not appear  anywhere on that line. I haven't tested 
> the CHECK-SAME pattern, it may need some adjustment.
I see.  Thanks!!  I changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158538/new/

https://reviews.llvm.org/D158538

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158538: [MS-ABI] Remove comdat attribute for inheriting ctor.

2023-08-28 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d0bd8e51be2: [MSABI] Remove comdat attribute for inheriting 
ctor. (authored by jyu2).

Changed prior to commit:
  https://reviews.llvm.org/D158538?vs=554025&id=554075#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158538/new/

https://reviews.llvm.org/D158538

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/ms-inheriting-ctor.cpp


Index: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s 
-o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(&h, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage without comdat.
+
+// CHECK-LABEL: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"
+// CHECK-NOT:comdat
+// CHECK-SAME: {{\{$}}
+
+// non-inheriting ctro should has linkonce_odr with comdat attribute.
+
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"
+// CHECK:comdat
+// CHECK-SAME: {{\{$}}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,15 +1970,6 @@
   if (const auto *Dtor = dyn_cast(D))
 return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, 
GD.getDtorType());
 
-  if (isa(D) &&
-  cast(D)->isInheritingConstructor() &&
-  Context.getTargetInfo().getCXXABI().isMicrosoft()) {
-// Our approach to inheriting constructors is fundamentally different from
-// that used by the MS ABI, so keep our inheriting constructor thunks
-// internal rather than trying to pick an unambiguous mangling for them.
-return llvm::GlobalValue::InternalLinkage;
-  }
-
   return getLLVMLinkageForDeclarator(D, Linkage);
 }
 
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11688,6 +11688,14 @@
   if (FD->isMSExternInline())
 return GVA_StrongODR;
 
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+  isa(FD) &&
+  cast(FD)->isInheritingConstructor())
+// Our approach to inheriting constructors is fundamentally different from
+// that used by the MS ABI, so keep our inheriting constructor thunks
+// internal rather than trying to pick an unambiguous mangling for them.
+return GVA_Internal;
+
   return GVA_DiscardableODR;
 }
 


Index: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(&h, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage without comdat.
+
+// CHECK-LABEL: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"
+// CHECK-NOT:comdat
+// CHECK-SAME: {{\{$}}
+
+// non-inheriting ctro should has linkonce_odr with comdat attribute.
+
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr @"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"
+// CHECK:comdat
+// CHECK-SAME: {{\{$}}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,15 +1970,6 @@
   if (const auto *Dtor = dyn_cast(D))
 return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, GD.getDtorType());
 
-  if (isa(D) &&
-  cast(D)->isInheritingConstructor() &&
-  Context.getTargetInfo().getCXXABI().isMicrosoft()) {
-// Our approach to inheriting constructors is fundamentally different from
-// that used by the MS ABI, so keep our inheriting constructor thunks
-// internal rather than trying to pick an unambiguous mangling fo

[PATCH] D158538: [MS-ABI] Remove comdat attribute for inheriting ctor.

2023-08-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 554025.
jyu2 added a comment.

Thanks @rnk.  This is address his comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158538/new/

https://reviews.llvm.org/D158538

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/ms-inheriting-ctor.cpp


Index: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s 
-o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(&h, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage without comdat.
+
+// CHECK-LABEL: define internal noundef ptr 
@"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, 
ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 align 2
+// CHECK-NOT: define internal noundef ptr 
@"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, 
ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 comdata 
align 2
+
+// non-inheriting ctro should has linkonce_odr with comdat attribute.
+
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %p1, 
ptr noundef nonnull align 1 dereferenceable(1) %d) unnamed_addr #2 comdat align 
2
+// CHECK-NOT: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %p1, 
ptr noundef nonnull align 1 dereferenceable(1) %d) unnamed_addr #2 align 2
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,15 +1970,6 @@
   if (const auto *Dtor = dyn_cast(D))
 return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, 
GD.getDtorType());
 
-  if (isa(D) &&
-  cast(D)->isInheritingConstructor() &&
-  Context.getTargetInfo().getCXXABI().isMicrosoft()) {
-// Our approach to inheriting constructors is fundamentally different from
-// that used by the MS ABI, so keep our inheriting constructor thunks
-// internal rather than trying to pick an unambiguous mangling for them.
-return llvm::GlobalValue::InternalLinkage;
-  }
-
   return getLLVMLinkageForDeclarator(D, Linkage);
 }
 
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11688,6 +11688,14 @@
   if (FD->isMSExternInline())
 return GVA_StrongODR;
 
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+  isa(FD) &&
+  cast(FD)->isInheritingConstructor())
+// Our approach to inheriting constructors is fundamentally different from
+// that used by the MS ABI, so keep our inheriting constructor thunks
+// internal rather than trying to pick an unambiguous mangling for them.
+return GVA_Internal;
+
   return GVA_DiscardableODR;
 }
 


Index: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(&h, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage without comdat.
+
+// CHECK-LABEL: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 align 2
+// CHECK-NOT: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef 

[PATCH] D158538: [MS-ABI] Remove comdat attribute for inheriting ctor.

2023-08-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Hi @rnk,

Thank you so much for the suggestion.

>> Before we do that, you should be able to delete the logic in 
>> CodeGenModule::getFunctionLinkage to handle inheriting constructor thunks. 
>> Your change should have the same effect. Can you do that, and check that it 
>> passes tests? If we do that, we're don't have to accumulate extra special 
>> case code, we've just moved the special case code earlier, up from codegen 
>> into the earlier linkage calculation.

Yes, you are right.   I remove the code in CodeGenModule.cpp, the test passes 
for check-clang.




Comment at: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp:41
+
+// CHECK-LABEL: define internal noundef ptr 
@"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, 
ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 align 2
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %p1, 
ptr noundef nonnull align 1 dereferenceable(1) %d) unnamed_addr #2 comdat align 
2

rnk wrote:
> To make this less fragile, can you come up with a way to use `CHECK-NOT: 
> comdat` since that's the key thing we're testing for here? You will need some 
> subsequent anchor like `entry:` or something else.
Thanks.  I changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158538/new/

https://reviews.llvm.org/D158538

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158538: [MS-ABI] Remove comdat attribute for inheriting ctor.

2023-08-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Ping,

Our customer fond problem I submit bug: in 
https://github.com/llvm/llvm-project/issues/65045

This issue related with big change of 5179eb78210a2ad01a18c37b75048ccfe78414ac

Where internal linkage for inheriting ctor were set in change set at following 
code.  Could some one help to code review the change?  Or any suggestion on how 
to fix this in other ways?

Thank you so much for the help.
Jennifer

CodeGenModule.cpp
if (isa(D) &&

  cast(D)->isInheritingConstructor() &&
  Context.getTargetInfo().getCXXABI().isMicrosoft()) {
// Our approach to inheriting constructors is fundamentally different from
// that used by the MS ABI, so keep our inheriting constructor thunks
// internal rather than trying to pick an unambiguous mangling for them.
return llvm::GlobalValue::InternalLinkage;
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158538/new/

https://reviews.llvm.org/D158538

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158538: [MS-ABI] Remove comdat attribute for inheriting ctor.

2023-08-22 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: rnk, rsmith, majnemer, cfe-commits.
jyu2 added a project: clang.
Herald added a project: All.
jyu2 requested review of this revision.

Currently, for MS, the linkage for the inheriting constructors is set to
internal.  However, the comdat attribute is also set like:

define internal noundef ptr @"??0?$B@_N@@qeaa@AEBVF@@aebua@@@z"(ptr noundef 
nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 
dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) 
unnamed_addr comdat

This could cause linker to fail.

The change is to remove comdat attribute for the inheriting constructor
to make linker happy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158538

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGenCXX/ms-inheriting-ctor.cpp


Index: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s 
-o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(&h, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage, should not with comdat.
+
+// CHECK-LABEL: define internal noundef ptr 
@"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, 
ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 align 2
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 
dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %p1, 
ptr noundef nonnull align 1 dereferenceable(1) %d) unnamed_addr #2 comdat align 
2
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11688,6 +11688,14 @@
   if (FD->isMSExternInline())
 return GVA_StrongODR;
 
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+  isa(FD) &&
+  cast(FD)->isInheritingConstructor())
+// Our approach to inheriting constructors is fundamentally different from
+// that used by the MS ABI, so keep our inheriting constructor thunks
+// internal rather than trying to pick an unambiguous mangling for them.
+return GVA_Internal;
+
   return GVA_DiscardableODR;
 }
 


Index: clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(&h, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage, should not with comdat.
+
+// CHECK-LABEL: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr #2 align 2
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr @"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"(ptr noundef nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %p1, ptr noundef nonnull align 1 dereferenceable(1) %d) unnamed_addr #2 comdat align 2
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11688,6 +11688,14 @@
   if (FD->isMSExternInline())
 return GVA_StrongODR;
 
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+  isa(FD) &&
+  cast(FD)->isInheritingConstructor())
+// Our approach to inheriting constructors is fundamentally different from
+// that used by the MS ABI, so keep our inheriting constructor thunks
+// internal rather than trying to pick an unambiguous mangling for them.
+return GVA_Internal;
+
   return GVA_DiscardableODR;
 }
 
___
cfe-commits mailing 

[PATCH] D158233: [SEH] Fix wrong argument passes to the call of OutlinedFinally.

2023-08-21 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff08c8e57e39: [SEH] Fix wrong argument passes to the call of 
OutlinedFinally. (authored by jyu2).

Changed prior to commit:
  https://reviews.llvm.org/D158233?vs=552157&id=552170#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158233/new/

https://reviews.llvm.org/D158233

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/exceptions-seh-finally.c
  clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp


Index: clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions 
-fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S 
-emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}
Index: clang/test/CodeGen/exceptions-seh-finally.c
===
--- clang/test/CodeGen/exceptions-seh-finally.c
+++ clang/test/CodeGen/exceptions-seh-finally.c
@@ -154,8 +154,11 @@
   }
 }
 // CHECK-LABEL: define dso_local i32 @finally_with_return()
+// CHECK: store i32 1, ptr %cleanup.dest.slot
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: icmp ne i32 %cleanup.dest
 // CHECK: call void @"?fin$0@0@finally_with_return@@"({{.*}})
-// CHECK-NEXT: ret i32 42
+// CHECK: ret i32 42
 
 // CHECK: define internal void @"?fin$0@0@finally_with_return@@"({{.*}})
 // CHECK-SAME: [[finally_attrs]]
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -873,8 +873,13 @@
 
   // If there's exactly one branch-after and no other threads,
   // we can route it without a switch.
+  // Skip for SEH, since ExitSwitch is used to generate code to indicate
+  // abnormal termination. (SEH: Except _leave and fall-through at
+  // the end, all other exits in a _try (return/goto/continue/break)
+  // are considered as abnormal terminations, using NormalCleanupDestSlot
+  // to indicate abnormal termination)
   if (!Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
-  Scope.getNumBranchAfters() == 1) {
+  !currentFunctionUsesSEHTry() && Scope.getNumBranchAfters() == 1) {
 assert(!BranchThroughDest || !IsActive);
 
 // Clean up the possibly dead store to the cleanup dest slot.


Index: clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}
Index

[PATCH] D158233: [SEH] Fix wrong argument passes to the call of OutlinedFinally.

2023-08-21 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGCleanup.cpp:882
   if (!Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
-  Scope.getNumBranchAfters() == 1) {
+  !getLangOpts().EHAsynch && Scope.getNumBranchAfters() == 1) {
 assert(!BranchThroughDest || !IsActive);

rnk wrote:
> rnk wrote:
> > This seems like it's only necessary when exiting a `__try` scope, but this 
> > check affects all exits from C++ cleanup scopes. Is there a way to check if 
> > there is an active try scope? When do we need to signal abnormal 
> > termination via normal control flow?
> You can consider `usesSEHTry` , but it will require some type checking and 
> casting: 
> https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#a275d0f7f778c6ece58722aabde9b6d86
Thanks @rnk!  That is good point.  I was thinking I just turn off this 
optimization when EHa is used.  

Can I use currentFunctionUsesSEHTry() instead?
Thanks.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158233/new/

https://reviews.llvm.org/D158233

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158233: [SEH] Fix wrong argument passes to the call of OutlinedFinally.

2023-08-21 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 552157.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158233/new/

https://reviews.llvm.org/D158233

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/exceptions-seh-finally.c
  clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp


Index: clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions 
-fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S 
-emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}
Index: clang/test/CodeGen/exceptions-seh-finally.c
===
--- clang/test/CodeGen/exceptions-seh-finally.c
+++ clang/test/CodeGen/exceptions-seh-finally.c
@@ -154,8 +154,11 @@
   }
 }
 // CHECK-LABEL: define dso_local i32 @finally_with_return()
+// CHECK: store i32 1, ptr %cleanup.dest.slot
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: icmp ne i32 %cleanup.dest
 // CHECK: call void @"?fin$0@0@finally_with_return@@"({{.*}})
-// CHECK-NEXT: ret i32 42
+// CHECK: ret i32 42
 
 // CHECK: define internal void @"?fin$0@0@finally_with_return@@"({{.*}})
 // CHECK-SAME: [[finally_attrs]]
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -873,8 +873,14 @@
 
   // If there's exactly one branch-after and no other threads,
   // we can route it without a switch.
+  // Skip for SEH, since ExitSwitch is used to generate code to indicate
+  // abnormal termination. (SEH: Except _leave and fall-through at
+  // the end, all other exits in a _try (return/goto/continue/break)
+  // are considered as abnormal terminations, using NormalCleanupDestSlot
+  // to indicate abnormal termination)
+  const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl);
   if (!Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
-  Scope.getNumBranchAfters() == 1) {
+  !currentFunctionUsesSEHTry() && Scope.getNumBranchAfters() == 1) {
 assert(!BranchThroughDest || !IsActive);
 
 // Clean up the possibly dead store to the cleanup dest slot.


Index: clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}
Index: clang/test/CodeGen/exceptions-seh-finally.c
===
--- clang/test/CodeGen/exceptions-seh-finally.c
+++ clang/test/CodeGen/exceptions-seh-finally.c
@@ -154,8 +154,11

[PATCH] D158233: [SEH] Fix wrong argument passes to the call of OutlinedFinally.

2023-08-17 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: asmith, tentzen, rnk, efriedma, pengfei.
jyu2 added a project: clang.
Herald added a project: All.
jyu2 requested review of this revision.

When return out of __try block.  In this test case, currently "false" is
passed to the OutlinedFinally call,  "true" should be passed to indicate 
abnormal
terminations.

The rule: Except _leave and fall-through at the end, all other exits
in a _try (return/goto/continue/break) are considered as abnormal
terminations, NormalCleanupDestSlot is used to indicate abnormal
terminations.

The problem is, during the processing abnormal termination,
the ExitSwitch is used.  However, in this case, Existswitch is route out.

One way to fix is to skip route it without a switch. So proper
abnormal termination's code could be generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158233

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp


Index: clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions 
-fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S 
-emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -873,8 +873,13 @@
 
   // If there's exactly one branch-after and no other threads,
   // we can route it without a switch.
+  // Skip for SEH, since ExitSwitch is used to generate code to indicate
+  // abnormal termination. (SEH: Except _leave and fall-through at
+  // the end, all other exits in a _try (return/goto/continue/break)
+  // are considered as abnormal terminations, using NormalCleanupDestSlot
+  // to indicate abnormal termination)
   if (!Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
-  Scope.getNumBranchAfters() == 1) {
+  !getLangOpts().EHAsynch && Scope.getNumBranchAfters() == 1) {
 assert(!BranchThroughDest || !IsActive);
 
 // Clean up the possibly dead store to the cleanup dest slot.


Index: clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -873,8 +873,13 @@
 
   // If there's exactly one branch-after and no other threads,
   // we can route it without 

[PATCH] D157566: [SEH] fix assertion when -fasy-exceptions is used.

2023-08-10 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33e3b2c46084: Fix assertion when -fasy-exception is used. 
(authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157566/new/

https://reviews.llvm.org/D157566

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/windows-seh-async-exceptions.cpp


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+  PrintfArg();
+  PrintfArg(const char* s);
+
+  // compiler crash fixed if this destructor removed
+  ~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+  devif_Warning("");
+  return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+  PrintfArg();
+  PrintfArg(const char* s);
+
+  // compiler crash fixed if this destructor removed
+  ~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+  devif_Warning("");
+  return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157566: [SEH] fix assertion when -fasy-exceptions is used.

2023-08-10 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 549174.
jyu2 added a comment.

Thanks all for the review!  This is fix space problem.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157566/new/

https://reviews.llvm.org/D157566

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/windows-seh-async-exceptions.cpp


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+  PrintfArg();
+  PrintfArg(const char* s);
+
+  // compiler crash fixed if this destructor removed
+  ~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+  devif_Warning("");
+  return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+  PrintfArg();
+  PrintfArg(const char* s);
+
+  // compiler crash fixed if this destructor removed
+  ~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+  devif_Warning("");
+  return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157566: [SEH] fix assertion when -fasy-exceptions is used.

2023-08-09 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: asmith, tentzen, rnk, efriedma, pengfei.
jyu2 added a project: clang.
Herald added a project: All.
jyu2 requested review of this revision.

The assertion only happens with use of -fasy-exception without
-fexcessions.

The assertion appen during the call to generate SehScopeBegin(), where
assert with:
assert(CGF.Builder.GetInsertBlock() && InvokeDest);
InvokeDest is null. Because exceptions are disabled, and SEH is not
in use.
The fix is before call EmitSehCppScopeBegin check getInvokeDest(),
to avoid assert during the emit llvm.seh.scope.begin()


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157566

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/windows-seh-async-exceptions.cpp


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+PrintfArg();
+PrintfArg(const char* s);
+
+// compiler crash fixed if this destructor removed
+~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+devif_Warning("");
+return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+PrintfArg();
+PrintfArg(const char* s);
+
+// compiler crash fixed if this destructor removed
+~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+devif_Warning("");
+return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-14 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/JumpDiagnostics.cpp:794
+  // [-Wc++20-extensions]
+  LabelDecl *TL = TargetLabel;
+  // Is TargetLabel one of the targets of the JumpStmt? If not, then skip

Just wonder why not just use TargetLabel instead?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155342/new/

https://reviews.llvm.org/D155342

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-14 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 accepted this revision.
jyu2 added a comment.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155342/new/

https://reviews.llvm.org/D155342

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154672: [OPENMP52] Deprecation of 'depend' clause in ordered directive.

2023-07-07 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG852fe30b687e: [OPENMP52] Deprecation of 'depend' 
clause in ordered directive. (authored by jyu2).

Changed prior to commit:
  https://reviews.llvm.org/D154672?vs=538162&id=538240#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154672/new/

https://reviews.llvm.org/D154672

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp


Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -402,6 +402,7 @@
   for (int i = 0; i < 10; ++i) { // expected-error {{expected 2 for loops 
after '#pragma omp for', but found only 1}}
 #if _OPENMP >= 202111
 #pragma omp ordered doacross(sink : i)
+#pragma omp ordered depend(source) // expected-warning {{'depend' clause for 
'ordered' is deprecated; use 'doacross' instead}}
 int j;
 #pragma omp ordered doacross(sink : i, j) // omp52-error {{expected loop 
iteration variable}}
 #else
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,21 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
-// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 -DOMP52 | FileCheck %s 
--check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -DOMP52 -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-IRBUILDER
 
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o 
%t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -59,7 +59,7 @@
 // CHECK-NORMAL-NEXT: call 

[PATCH] D154672: [OPENMP52] Deprecation of 'depend' clause in ordered directive.

2023-07-07 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1532
   InGroup;
+def warn_omp_depend_in_ordered_deprecated : Warning<"denpend clause for 
ordered is deprecated; use doacross instaed">, InGroup;
 

aaron.ballman wrote:
> ABataev wrote:
> > denpend->depend
> > instaed->instead
> Also, wrap to 80 columns and put syntax elements in single quotes. e.g., 
> 'depend' clause for 'ordered'
Thanks Alexey and Aaron for the review!!!  Just a question, do you know why 
git-clang-format does not format .td file now.  It was working before.
Thanks.
Jennifer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154672/new/

https://reviews.llvm.org/D154672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154672: [OPENMP52] Deprecation of 'depend' clause in ordered directive.

2023-07-07 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 538162.
jyu2 added a comment.

Thanks @jdoerfert, @ABataev and @aaron.ballman for the code reviews.  This is 
addressing comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154672/new/

https://reviews.llvm.org/D154672

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp


Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -402,6 +402,7 @@
   for (int i = 0; i < 10; ++i) { // expected-error {{expected 2 for loops 
after '#pragma omp for', but found only 1}}
 #if _OPENMP >= 202111
 #pragma omp ordered doacross(sink : i)
+#pragma omp ordered depend(source) // expected-warning {{'depend' clause for 
'ordered' is deprecated; use doacross instead}}
 int j;
 #pragma omp ordered doacross(sink : i, j) // omp52-error {{expected loop 
iteration variable}}
 #else
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,21 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
-// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 -DOMP52 | FileCheck %s 
--check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -DOMP52 -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-IRBUILDER
 
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o 
%t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -59,7 +59,7 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 
[[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 
@__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 

[PATCH] D154672: [OPENMP52] Deprecation of 'depend' clause in ordered directive.

2023-07-06 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This is just add warning when using depend clause in ordered directive for 
openmp52 and up.

BTW, I need change test ordered_doacross_codegen.c since I can not use macro 
_OPENMP >= 202111 due to use of -fopenmp-simd.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154672

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp


Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -402,6 +402,7 @@
   for (int i = 0; i < 10; ++i) { // expected-error {{expected 2 for loops 
after '#pragma omp for', but found only 1}}
 #if _OPENMP >= 202111
 #pragma omp ordered doacross(sink : i)
+#pragma omp ordered depend(source) // expected-warning {{denpend clause for 
ordered is deprecated; use doacross instaed}}
 int j;
 #pragma omp ordered doacross(sink : i, j) // omp52-error {{expected loop 
iteration variable}}
 #else
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,21 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
-// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 -DOMP52 | FileCheck %s 
--check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -DOMP52 -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-IRBUILDER
 
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o 
%t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--ch

[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-06 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf70967fdc473: [OPENMP52] Support Support omp_cur_iteration 
modifier for doacross (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154556/new/

https://reviews.llvm.org/D154556

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp

Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -132,7 +132,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
@@ -155,6 +159,10 @@
 #pragma omp ordered doacross(sink : // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected expression}} omp52-error {{expected 'i' loop iteration variable}}
 #pragma omp ordered doacross(sink : i // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected 'j' loop iteration variable}}
 #pragma omp ordered doacross(sink : i) // omp52-error {{expected 'j' loop iteration variable}}
+#pragma omp ordered doacross(sink:omp_cur_iteration + 1) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration - 2) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(source:omp_cur_iteration - 1) // omp52-error {{'doacross source:' must be with 'omp_cur_iteration'}}
 #pragma omp ordered doacross(source:)
if (i == j)
 #pragma omp ordered doacross(source:) // omp52-error {{'#pragma omp ordered' with 'doacross' clause cannot be an immediate substatement}}
@@ -309,7 +317,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -84,6 +84,43 @@
 #pragma omp ordered depend(sink : i - 2)
 #endif
 d[i] = a[i - 2];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 1
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#ifdef OMP52
+#pragma omp ordered doacross(sink :omp_cur_iteration - 1)
+#else
+#pragma omp ordered depend(sink : i - 1)
+#endif
+d[i] = a[i - 1];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I:%.+]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if OMP52
+#pragma omp ordered doacross(source:omp_cur_iteration)

[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-06 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/AST/OpenMPClause.cpp:2516-2523
+  if (DepType == OMPC_DOACROSS_source)
+OS << "source:";
+  else if (DepType == OMPC_DOACROSS_sink)
+OS << "sink:";
+  else if (DepType == OMPC_DOACROSS_source_omp_cur_iteration)
+OS << "source: omp_cur_iteration";
+  else if (DepType == OMPC_DOACROSS_sink_omp_cur_iteration)

ABataev wrote:
> switch?
Thanks.  Changed!.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154556/new/

https://reviews.llvm.org/D154556

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-06 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 537749.
jyu2 added a comment.

Thanks Alexey for the review.  This is address his comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154556/new/

https://reviews.llvm.org/D154556

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp

Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -132,7 +132,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
@@ -155,6 +159,10 @@
 #pragma omp ordered doacross(sink : // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected expression}} omp52-error {{expected 'i' loop iteration variable}}
 #pragma omp ordered doacross(sink : i // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected 'j' loop iteration variable}}
 #pragma omp ordered doacross(sink : i) // omp52-error {{expected 'j' loop iteration variable}}
+#pragma omp ordered doacross(sink:omp_cur_iteration + 1) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration - 2) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(source:omp_cur_iteration - 1) // omp52-error {{'doacross source:' must be with 'omp_cur_iteration'}}
 #pragma omp ordered doacross(source:)
if (i == j)
 #pragma omp ordered doacross(source:) // omp52-error {{'#pragma omp ordered' with 'doacross' clause cannot be an immediate substatement}}
@@ -309,7 +317,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -84,6 +84,43 @@
 #pragma omp ordered depend(sink : i - 2)
 #endif
 d[i] = a[i - 2];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 1
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#ifdef OMP52
+#pragma omp ordered doacross(sink :omp_cur_iteration - 1)
+#else
+#pragma omp ordered depend(sink : i - 1)
+#endif
+d[i] = a[i - 1];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I:%.+]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if OMP52
+#pragma omp ordered doacross(source:omp_cur_iteration)
+#else
+#pragma omp ordered depend(source)
+#endif
+c[i] = c[i] + 1;
   }
   // CHECK: call void @__kmpc_for_static_fini

[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 537553.
jyu2 added a comment.

Fix typo.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154556/new/

https://reviews.llvm.org/D154556

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp

Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -132,7 +132,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
@@ -155,6 +159,10 @@
 #pragma omp ordered doacross(sink : // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected expression}} omp52-error {{expected 'i' loop iteration variable}}
 #pragma omp ordered doacross(sink : i // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected 'j' loop iteration variable}}
 #pragma omp ordered doacross(sink : i) // omp52-error {{expected 'j' loop iteration variable}}
+#pragma omp ordered doacross(sink:omp_cur_iteration + 1) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration - 2) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(source:omp_cur_iteration - 1) // omp52-error {{'doacross source:' must be with 'omp_cur_iteration'}}
 #pragma omp ordered doacross(source:)
if (i == j)
 #pragma omp ordered doacross(source:) // omp52-error {{'#pragma omp ordered' with 'doacross' clause cannot be an immediate substatement}}
@@ -309,7 +317,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -84,6 +84,43 @@
 #pragma omp ordered depend(sink : i - 2)
 #endif
 d[i] = a[i - 2];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 1
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#ifdef OMP52
+#pragma omp ordered doacross(sink :omp_cur_iteration - 1)
+#else
+#pragma omp ordered depend(sink : i - 1)
+#endif
+d[i] = a[i - 1];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I:%.+]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if OMP52
+#pragma omp ordered doacross(source:omp_cur_iteration)
+#else
+#pragma omp ordered depend(source)
+#endif
+c[i] = c[i] + 1;
   }
   // CHECK: call void @__kmpc_for_static_fini(
   // CHECK-NORMAL: call void @__kmpc_doacross_f

[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This is just syntax to make it easier for the user. It doesn't add any
new functionality.

for
doacross(sink: omp_cur_iteration - 1)
Equivalent to
doacross(sink: ConterVar - 1, ...)

doacross(source: omp_cur_iteration)
Equivalent to
doacross(source)

And restriction is:
OMP5.2 p.327

If vector is specified with the omp_cur_iteration keyword and with
sink as the dependence-type then it must be omp_cur_iteration - 1.

If vector is specified with source as the dependence-type then it must be
omp_cur_iteration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154556

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp

Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -132,7 +132,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
@@ -155,6 +159,10 @@
 #pragma omp ordered doacross(sink : // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected expression}} omp52-error {{expected 'i' loop iteration variable}}
 #pragma omp ordered doacross(sink : i // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected 'j' loop iteration variable}}
 #pragma omp ordered doacross(sink : i) // omp52-error {{expected 'j' loop iteration variable}}
+#pragma omp ordered doacross(sink:omp_cur_iteration + 1) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration - 2) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(source:omp_cur_iteration - 1) // omp52-error {{'doacross source:' must be with 'omp_cur_iteration'}}
 #pragma omp ordered doacross(source:)
if (i == j)
 #pragma omp ordered doacross(source:) // omp52-error {{'#pragma omp ordered' with 'doacross' clause cannot be an immediate substatement}}
@@ -309,7 +317,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -84,6 +84,43 @@
 #pragma omp ordered depend(sink : i - 2)
 #endif
 d[i] = a[i - 2];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 1
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#ifdef OMP52
+#pragma omp ordered doacross(sink :omp_cur_iteration - 1)
+#else
+#pragma omp ordered depend(sink : i - 1)
+#endif
+d[i] = a[i - 1];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I:%.+]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35041a435def: [OPENMP52] Codegen support for doacross 
clause. (authored by jyu2).

Changed prior to commit:
  https://reviews.llvm.org/D154180?vs=536838&id=536909#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,37 +5839,46 @@
   return Fn;
 }
 
+template 
+static void emitRestoreIP(CodeGenFunction &CGF, const T *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+
+  unsigned NumLoops = C->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < NumLoops; I++) {
+const Expr *CounterVal = C->getLoopData(I);
+assert(CounterVal);
+llvm::Value *StoreValue = CGF.EmitScalarConversion(
+CGF.EmitScalarExpr(CounterVal), CounterVal->getType(), Int64Ty,
+CounterVal->getExprLoc());

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D154180#4469417 , @ABataev wrote:

> LG with a nit

Thank you so much!
Jennifer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11410
   } else {
-assert(C->getDependencyKind() == OMPC_DEPEND_sink);
+assert(ODK.isSink(C));
 RTLFn = OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(),

ABataev wrote:
> Add a message, please
Added.  Thanks for the review.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:2279
+public:
+  bool isSink(const T *) { return false; }
+};

ABataev wrote:
> Add isSOurce 
Opps..  Sorry.  Added.  Thanks!!!  Jennifer



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5860-5862
+  bool IsDependSource = false;
+  if (ODK.isSource(C))
+IsDependSource = true;

ABataev wrote:
> bool IsDependSource = ODK.isSource(C);
Thanks.  Changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 536838.
jyu2 added a comment.

Thanks  Alexey for the review!!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,37 +5839,46 @@
   return Fn;
 }
 
+template 
+static void emitRestoreIP(CodeGenFunction &CGF, const T *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+
+  unsigned NumLoops = C->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < NumLoops; I++) {
+const Expr *CounterVal = C->getLoopData(I);
+assert(CounterVal);
+llvm::Value *StoreValue = CGF.EmitScalarConversion(
+CGF.EmitScalarExpr(CounterVal), CounterVal->getType(), Int64Ty,
+CounterVal->getExprLoc());
+StoreValues.emplace_back(StoreValue);
+  }
+  OMPDoacrossKind ODK;
+  bool IsDependSource = ODK.isSource(C);
+  CGF.Builder.restoreIP(
+  OMPBuilder.createOrderedDepend(CGF.Builder, AllocaIP, NumLoops,
+  

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11405-11406
+  llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
+  const OMPDependClause *DepC = dyn_cast(C);
+  const OMPDoacrossClause *DoC = dyn_cast(C);
+  if ((DoC && DoC->getDependenceType() == OMPC_DOACROSS_source) ||

ABataev wrote:
> 1. const auto *
> 2. Can you try torework it to make it more C++-ish? Use template deduction to 
> avoid runtime dyn_casts.
> e.g. something like:
> ```
> namespace {
> template 
> class OMPDoacrossKind {
> public:
> bool isSink(const T *) {return false;}
> }
> }
> template <>
> class OMPDoacrossKInd {
> public:
> bool isSink(const OMPDependClause* C) {return C->getDependenceType();}
> }
> ...
> ```
> and use `if (OMPDoacrossKInd::isSink(C)) RTLFn = ...` and same for `Source`
Good idea!!!  Thank you so much.  Changed.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5859-5868
+  const auto DOC = dyn_cast(C);
+  const auto DC = dyn_cast(C);
+  bool IsDependSource = false;
+  if ((DC && DC->getDependencyKind() == OMPC_DEPEND_source) ||
+  (DOC && DOC->getDependenceType() == OMPC_DOACROSS_source))
+IsDependSource = true;
+  CGF.Builder.restoreIP(

ABataev wrote:
> Same, use template-based analysis instead of runtime-based.
Thanks.  Changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 536798.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,37 +5839,48 @@
   return Fn;
 }
 
+template 
+static void emitRestoreIP(CodeGenFunction &CGF, const T *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+
+  unsigned NumLoops = C->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < NumLoops; I++) {
+const Expr *CounterVal = C->getLoopData(I);
+assert(CounterVal);
+llvm::Value *StoreValue = CGF.EmitScalarConversion(
+CGF.EmitScalarExpr(CounterVal), CounterVal->getType(), Int64Ty,
+CounterVal->getExprLoc());
+StoreValues.emplace_back(StoreValue);
+  }
+  OMPDoacrossKind ODK;
+  bool IsDependSource = false;
+  if (ODK.isSource(C))
+IsDependSource = true;
+  CGF.Builder.restoreIP(
+  OMPBuilder.createOrderedDepend(CGF.Builder, AllocaIP, NumLoops,
+

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11401-11402
   llvm::Value *Args[] = {
-  emitUpdateLocation(CGF, C->getBeginLoc()),
-  getThreadID(CGF, C->getBeginLoc()),
+  RT.emitUpdateLocation(CGF, C->getBeginLoc()),
+  RT.getThreadID(CGF, C->getBeginLoc()),
   CGF.Builder.CreateConstArrayGEP(CntAddr, 0).getPointer()};

ABataev wrote:
> RT is needed only for loc and tid, you can preemit them in the member 
> functions and pass here instead of emitting them here and expose private 
> interfaces.
Yes,  Thanks.  Changed.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11422-11428
+  const OMPDependClause *CL) {
+  return EmitDoacrossOrdered(*this, CGF, CGM, CL);
+}
+
+void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction &CGF,
+  const OMPDoacrossClause *CL) {
+  return EmitDoacrossOrdered(*this, CGF, CGM, CL);

ABataev wrote:
> Use Cl or just C instead of CL.
Sorry.  Changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 536443.
jyu2 added a comment.

Thanks Alexey!!!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,37 +5839,50 @@
   return Fn;
 }
 
+template 
+static void emitRestoreIP(CodeGenFunction &CGF, const T *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+
+  unsigned NumLoops = C->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < NumLoops; I++) {
+const Expr *CounterVal = C->getLoopData(I);
+assert(CounterVal);
+llvm::Value *StoreValue = CGF.EmitScalarConversion(
+CGF.EmitScalarExpr(CounterVal), CounterVal->getType(), Int64Ty,
+CounterVal->getExprLoc());
+StoreValues.emplace_back(StoreValue);
+  }
+  const auto DOC = dyn_cast(C);
+  const auto DC = dyn_cast(C);
+  bool IsDependSource = false;
+  if ((DC && DC->getDependencyKind() == OMPC_DEPEND_source) ||
+  (DOC && DOC->getD

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11383
 void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction &CGF,
-  const OMPDependClause *C) {
+  const OMPClause *CL) {
+  const OMPDependClause *DC =

ABataev wrote:
> Just `C` is better, or `Cl`
Changed.  Thanks.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11384-11387
+  const OMPDependClause *DC =
+  isa(CL) ? dyn_cast(CL) : nullptr;
+  const OMPDoacrossClause *DoC =
+  isa(CL) ? dyn_cast(CL) : nullptr;

ABataev wrote:
> ```
> const auto *DepC = dyn_cast(CL);
> const auto *DoC = dyn_cast(CL);
> ```
Thanks Alexey.  Changed




Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11410-11429
+  if (DoC) {
+if (DoC->getDependenceType() == OMPC_DOACROSS_source) {
+  RTLFn = OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_doacross_post);
+} else {
+  assert(DoC->getDependenceType() == OMPC_DOACROSS_sink);
+  RTLFn = OMPBuilder.getOrCreateRuntimeFunction(

ABataev wrote:
> Try to unify this code, avoid duplications
Yes thanks.  Changed.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5845-5846
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+  auto DOC = dyn_cast(C);
+  auto DC = dyn_cast(C);
+

ABataev wrote:
> const auto *
Changed.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5874-5889
 if (S.hasClausesOfKind()) {
   // The ordered directive with depend clause.
   assert(!S.hasAssociatedStmt() &&
  "No associated statement must be in ordered depend construct.");
   InsertPointTy AllocaIP(AllocaInsertPt->getParent(),
  AllocaInsertPt->getIterator());
+  for (const auto *DC : S.getClausesOfKind())

ABataev wrote:
> Same, try to unify the code
Thanks.  Changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 536394.
jyu2 marked an inline comment as done.
jyu2 added a comment.

Thanks Alexey's review.  This address Alexey's comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154180/new/

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,37 +5839,50 @@
   return Fn;
 }
 
+template 
+static void emitRestoreIP(CodeGenFunction &CGF, const T *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+
+  unsigned NumLoops = C->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < NumLoops; I++) {
+const Expr *CounterVal = C->getLoopData(I);
+assert(CounterVal);
+llvm::Value *StoreValue = CGF.EmitScalarConversion(
+CGF.EmitScalarExpr(CounterVal), CounterVal->getType(), Int64Ty,
+CounterVal->getExprLoc());
+StoreValues.emplace_back(StoreValue);
+  }
+  const auto DOC = dyn_cast(C);
+  const auto DC = dyn_cast(C);
+  bool IsDependSource = false;
+  if ((D

[PATCH] D154180: [OPENMP52] Codegen support for doacross clause.

2023-06-29 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This is following the ordered depend clause.
1> Using  OMPClause instead OMPDependClause in emitDoacrossOrdered to hand both

  OMPDependClause and OMPDoacrossClause.

2> Add new utility function emitRestoreIP which used for both clause.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154180

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c

Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,13 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -51,7 +59,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:)
+#else
 #pragma omp ordered depend(source)
+#endif
 c[i] = c[i] + 1;
 foo();
 // CHECK: call void @foo()
@@ -66,7 +78,11 @@
 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(sink : i - 2)
+#else
 #pragma omp ordered depend(sink : i - 2)
+#endif
 d[i] = a[i - 2];
   }
   // CHECK: call void @__kmpc_for_static_fini(
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5839,6 +5839,33 @@
   return Fn;
 }
 
+static void emitRestoreIP(CodeGenFunction &CGF, const OMPClause *C,
+  llvm::OpenMPIRBuilder::InsertPointTy AllocaIP,
+  llvm::OpenMPIRBuilder &OMPBuilder) {
+  auto DOC = dyn_cast(C);
+  auto DC = dyn_cast(C);
+
+  unsigned NumLoops = DC ? DC->getNumLoops() : DOC->getNumLoops();
+  QualType Int64Ty = CGF.CGM.getContext().getIntTypeForBitwidth(
+  /*DestWidth=*/64, /*Signed=*/1);
+  llvm::SmallVector StoreValues;
+  for (unsigned I = 0; I < Num

[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-29 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 closed this revision.
jyu2 added a comment.

Checked in with rG085845a2acbe 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153556/new/

https://reviews.llvm.org/D153556

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-29 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 535794.
jyu2 added a comment.

Sorry, full diff.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153556/new/

https://reviews.llvm.org/D153556

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -444,6 +444,10 @@
   let flangClass = "ScalarIntExpr";
 }
 
+def OMPC_Doacross : Clause<"doacross"> {
+  let clangClass = "OMPDoacrossClause";
+}
+
 //===--===//
 // Definition of OpenMP directives
 //===--===//
@@ -604,7 +608,8 @@
 }
 def OMP_Ordered : Directive<"ordered"> {
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
   let allowedOnceClauses = [
 VersionedClause,
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1937,6 +1937,7 @@
 CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
 CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
 CHECK_SIMPLE_CLAUSE(CancellationConstructType, OMPC_cancellation_construct_type)
+CHECK_SIMPLE_CLAUSE(Doacross, OMPC_doacross)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2717,6 +2717,9 @@
   VisitOMPClauseWithPreInit(C);
   Visitor->AddStmt(C->getSize());
 }
+void OMPClauseEnqueue::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
+  VisitOMPClauseList(C);
+}
 
 } // namespace
 
Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
@@ -135,12 +136,48 @@
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#pragma omp ordered doacross(sink : i) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#else
 #pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
 #pragma omp ordered depend(sink : i) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
+#endif
   }
 #pragma omp parallel for ordered(2) // expected-note 3 {{'ordered' clause with specified parameter}}
   for (int i = 0; i < 10; ++i) {
 for (int j = 0; j < 10; ++j) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross // omp52-error {{expected '(' after 'doacross'}} omp52-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
+#pragma omp ordered doacross( // omp52-error {{expected ')'}} omp52-error {{expected 'source' or 'sink' in OpenMP clause 'doacross'}} omp52-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}} omp52-warning {{missing ':' or ')' aft

[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Thanks.




Comment at: clang/lib/Parse/ParseOpenMP.cpp:4415-4439
+  } else if (Kind == OMPC_doacross) {
+// Handle dependence type for the doacross clause.
+ColonProtectionRAIIObject ColonRAII(*this);
+Data.ExtraModifier = getOpenMPSimpleClauseType(
+Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "",
+getLangOpts());
+Data.ExtraModifierLoc = Tok.getLocation();

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > Can it be unified with depenbd clause parsing? (Maybe in a separate 
> > > template function)
> > I don't really has an idea on how to combine this two with template 
> > function.  Since depend clause in ordered is deprecated in 52, and will be 
> > removed, should we leave as this?
> Even ff it will be removed in 52, it will still stay for OpenMP < 52. Would 
> be good to try to unify it.
OKay thanks.  Changed



Comment at: clang/lib/Sema/SemaOpenMP.cpp:20694-20700
+auto *C = OMPDoacrossClause::Create(
+Context, StartLoc, LParenLoc, EndLoc,
+IsSource ? OMPC_DOACROSS_source : OMPC_DOACROSS_sink, DepLoc, ColonLoc,
+Vars, TotalDepCount.getZExtValue());
+if (DSAStack->isParentOrderedRegion())
+  DSAStack->addDoacrossDependClause(C, OpsOffs);
+return C;

ABataev wrote:
> Better to create clauses in ActOnDoAcross and ActOnDepend, this function 
> better to return required data as a struct/class/bolean, etc.
Okay I create static function instead.  Thanks.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11299-11344
   if (DC->getDependencyKind() == OMPC_DEPEND_source) {
 if (DependSourceClause) {
   Diag(C->getBeginLoc(), diag::err_omp_more_one_clause)
   << getOpenMPDirectiveName(OMPD_ordered)
   << getOpenMPClauseName(OMPC_depend) << 2;
   ErrorFound = true;
 } else {

jyu2 wrote:
> ABataev wrote:
> > Try to avoid copy-paste. Maybe introduce templated function?
> Not sure how to do this part.
I just merged code into OMPC_depend.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153556/new/

https://reviews.llvm.org/D153556

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 535601.
jyu2 added a comment.

Thanks Alexey's review.  This is address his comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153556/new/

https://reviews.llvm.org/D153556

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -444,6 +444,10 @@
   let flangClass = "ScalarIntExpr";
 }
 
+def OMPC_Doacross : Clause<"doacross"> {
+  let clangClass = "OMPDoacrossClause";
+}
+
 //===--===//
 // Definition of OpenMP directives
 //===--===//
@@ -604,7 +608,8 @@
 }
 def OMP_Ordered : Directive<"ordered"> {
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
   let allowedOnceClauses = [
 VersionedClause,
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1937,6 +1937,7 @@
 CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
 CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
 CHECK_SIMPLE_CLAUSE(CancellationConstructType, OMPC_cancellation_construct_type)
+CHECK_SIMPLE_CLAUSE(Doacross, OMPC_doacross)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2717,6 +2717,9 @@
   VisitOMPClauseWithPreInit(C);
   Visitor->AddStmt(C->getSize());
 }
+void OMPClauseEnqueue::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
+  VisitOMPClauseList(C);
+}
 
 } // namespace
 
Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
@@ -135,12 +136,48 @@
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#pragma omp ordered doacross(sink : i) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#else
 #pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
 #pragma omp ordered depend(sink : i) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
+#endif
   }
 #pragma omp parallel for ordered(2) // expected-note 3 {{'ordered' clause with specified parameter}}
   for (int i = 0; i < 10; ++i) {
 for (int j = 0; j < 10; ++j) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross // omp52-error {{expected '(' after 'doacross'}} omp52-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
+#pragma omp ordered doacross( // omp52-error {{expected ')'}} omp52-error {{expected 'source' or 'sink' in OpenMP clause 'doacross'}} omp52-error {{'ordered' directive without any clauses cannot be closely nested inside orde

[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Thanks Alexey for the review.




Comment at: clang/lib/Parse/ParseOpenMP.cpp:4415-4439
+  } else if (Kind == OMPC_doacross) {
+// Handle dependence type for the doacross clause.
+ColonProtectionRAIIObject ColonRAII(*this);
+Data.ExtraModifier = getOpenMPSimpleClauseType(
+Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "",
+getLangOpts());
+Data.ExtraModifierLoc = Tok.getLocation();

ABataev wrote:
> Can it be unified with depenbd clause parsing? (Maybe in a separate template 
> function)
I don't really has an idea on how to combine this two with template function.  
Since depend clause in ordered is deprecated in 52, and will be removed, should 
we leave as this?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:91
   llvm::SmallVector, 4>;
-  using DoacrossDependMapTy =
-  llvm::DenseMap;
+  using DoacrossDependMapTy = llvm::DenseMap;
   /// Kind of the declaration used in the uses_allocators clauses.

ABataev wrote:
> DoacrossClauseMapTy? Since it is intended to handle also doacross clauses.
Changed.  Thanks.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11299-11344
   if (DC->getDependencyKind() == OMPC_DEPEND_source) {
 if (DependSourceClause) {
   Diag(C->getBeginLoc(), diag::err_omp_more_one_clause)
   << getOpenMPDirectiveName(OMPD_ordered)
   << getOpenMPClauseName(OMPC_depend) << 2;
   ErrorFound = true;
 } else {

ABataev wrote:
> Try to avoid copy-paste. Maybe introduce templated function?
Not sure how to do this part.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11359-11371
+  } else if ((DependFound || DoacrossFound) && (TC || SC)) {
+SourceLocation Loc =
+DependFound ? DependFound->getBeginLoc() : 
DoacrossFound->getBeginLoc();
+Diag(Loc, diag::err_omp_depend_clause_thread_simd)
+<< getOpenMPClauseName(DependFound ? OMPC_depend : OMPC_doacross)
 << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind());
 ErrorFound = true;

ABataev wrote:
> Same, try to avoid copy-paste
The code is for both Depend and Doacross with is really try to avoid copy-paste.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:24002
+
+OMPClause *Sema::ActOnOpenMPDoacrossClause(
+OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc,

ABataev wrote:
> Same, if possible try to unify handling with the depend clause, if possible
ActOnOpenMPDoacrossClauseCommon is added which called in 
ActOnOpenMPDependClause
and
ActOnOpenMPDoacrossClause



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153556/new/

https://reviews.llvm.org/D153556

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-28 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 535289.
jyu2 added a comment.

Thanks Alex for the review.  This is to address his comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153556/new/

https://reviews.llvm.org/D153556

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -444,6 +444,10 @@
   let flangClass = "ScalarIntExpr";
 }
 
+def OMPC_Doacross : Clause<"doacross"> {
+  let clangClass = "OMPDoacrossClause";
+}
+
 //===--===//
 // Definition of OpenMP directives
 //===--===//
@@ -604,7 +608,8 @@
 }
 def OMP_Ordered : Directive<"ordered"> {
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
   let allowedOnceClauses = [
 VersionedClause,
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1937,6 +1937,7 @@
 CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
 CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
 CHECK_SIMPLE_CLAUSE(CancellationConstructType, OMPC_cancellation_construct_type)
+CHECK_SIMPLE_CLAUSE(Doacross, OMPC_doacross)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2717,6 +2717,9 @@
   VisitOMPClauseWithPreInit(C);
   Visitor->AddStmt(C->getSize());
 }
+void OMPClauseEnqueue::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
+  VisitOMPClauseList(C);
+}
 
 } // namespace
 
Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
@@ -135,12 +136,48 @@
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#pragma omp ordered doacross(sink : i) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#else
 #pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
 #pragma omp ordered depend(sink : i) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
+#endif
   }
 #pragma omp parallel for ordered(2) // expected-note 3 {{'ordered' clause with specified parameter}}
   for (int i = 0; i < 10; ++i) {
 for (int j = 0; j < 10; ++j) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross // omp52-error {{expected '(' after 'doacross'}} omp52-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
+#pragma omp ordered doacross( // omp52-error {{expected ')'}} omp52-error {{expected 'source' or 'sink' in OpenMP clause 'doacross'}} omp52-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parame

[PATCH] D153556: [OPENMP52] Initial support for doacross clause.

2023-06-22 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert, mikerice.
jyu2 added projects: OpenMP, clang.
Herald added subscribers: sunshaoce, arphaman, guansong, yaxunl.
Herald added a reviewer: kiranchandramohan.
Herald added projects: Flang, All.
jyu2 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added a project: LLVM.

Initial support for doacross clause in ordered directive. 
This is  intend to replace depend clause in ordered directive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153556

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -444,6 +444,10 @@
   let flangClass = "ScalarIntExpr";
 }
 
+def OMPC_Doacross : Clause<"doacross"> {
+  let clangClass = "OMPDoacrossClause";
+}
+
 //===--===//
 // Definition of OpenMP directives
 //===--===//
@@ -604,7 +608,8 @@
 }
 def OMP_Ordered : Directive<"ordered"> {
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
   let allowedOnceClauses = [
 VersionedClause,
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1937,6 +1937,7 @@
 CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
 CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
 CHECK_SIMPLE_CLAUSE(CancellationConstructType, OMPC_cancellation_construct_type)
+CHECK_SIMPLE_CLAUSE(Doacross, OMPC_doacross)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2717,6 +2717,9 @@
   VisitOMPClauseWithPreInit(C);
   Visitor->AddStmt(C->getSize());
 }
+void OMPClauseEnqueue::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
+  VisitOMPClauseList(C);
+}
 
 } // namespace
 
Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
@@ -135,12 +136,48 @@
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#pragma omp ordered doacross(sink : i) // omp52-error {{'ordered' directive with 'doacross' clause cannot be closely nested inside ordered region without specified parameter}}
+#else
 #pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
 #pragma omp ordered depend(sink : i) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
+#endif
   }
 #pragma omp parallel for ordered(2) // expected-note 3 {{'ordered' clause with specified parameter}}
   for (int i = 0; i < 10; ++i) {
 for (int j = 0; j < 10; ++j) {
+#if _OPENMP >= 202111
+#pragma omp ordered doacross // omp52-error {{expected '(' after 'doacross'}} omp52-error {{'or

[PATCH] D151743: [OMP] Fix compiler assert "DeclRefExpr for Decl not entered in LocalDeclMap?"

2023-05-30 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaaa33b6a98de: Fix assert "DeclRefExpr for Decl not 
entered in LocalDeclMap?" (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151743/new/

https://reviews.llvm.org/D151743

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_uses_allocators.c


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -64,6 +64,35 @@
   {}
 }
 
+typedef enum omp_memspace_handle_t {
+  omp_default_mem_space = 0,
+  omp_large_cap_mem_space = 1,
+  omp_const_mem_space = 2,
+  omp_high_bw_mem_space = 3,
+  omp_low_lat_mem_space = 4,
+  llvm_omp_target_host_mem_space = 100,
+  llvm_omp_target_shared_mem_space = 101,
+  llvm_omp_target_device_mem_space = 102,
+  KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
+} omp_memspace_handle_t;
+
+extern omp_allocator_handle_t
+omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
+   const omp_alloctrait_t traits[]);
+
+void *omp_aligned_alloc(unsigned long alignment, unsigned long size,
+omp_allocator_handle_t allocator);
+extern void * omp_alloc(int size, omp_allocator_handle_t a);
+#define N 1024
+
+void foo() {
+  int errors = 0;
+  omp_memspace_handle_t  memspace = omp_default_mem_space;
+  omp_alloctrait_t   traits[1] = {{omp_atk_alignment, 64}};
+  omp_allocator_handle_t alloc = omp_init_allocator(memspace,1,traits);
+  #pragma omp target map(tofrom: errors) uses_allocators(alloc(traits))
+  { }
+}
 #endif
 
 // CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
@@ -140,3 +169,15 @@
 // CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
 // CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
 // CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%alloc]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 1, ptr [[TRAITS_ADDR]])
+// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
+// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
+
+// Destroy allocator upon exit from the region.
+// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
+// CHECK: [[CONV1:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
+// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV1]])
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6041,7 +6041,7 @@
   CGM.getModule(), OMPRTL___kmpc_init_allocator),
   {ThreadId, MemSpaceHandle, NumTraits, Traits});
   // Store to allocator.
-  CGF.EmitVarDecl(*cast(
+  CGF.EmitAutoVarAlloca(*cast(
   cast(Allocator->IgnoreParenImpCasts())->getDecl()));
   LValue AllocatorLVal = CGF.EmitLValue(Allocator->IgnoreParenImpCasts());
   AllocatorVal =


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -64,6 +64,35 @@
   {}
 }
 
+typedef enum omp_memspace_handle_t {
+  omp_default_mem_space = 0,
+  omp_large_cap_mem_space = 1,
+  omp_const_mem_space = 2,
+  omp_high_bw_mem_space = 3,
+  omp_low_lat_mem_space = 4,
+  llvm_omp_target_host_mem_space = 100,
+  llvm_omp_target_shared_mem_space = 101,
+  llvm_omp_target_device_mem_space = 102,
+  KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
+} omp_memspace_handle_t;
+
+extern omp_allocator_handle_t
+omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
+   const omp_alloctrait_t traits[]);
+
+void *omp_aligned_alloc(unsigned long alignment, unsigned long size,
+omp_allocator_handle_t allocator);
+extern void * omp_alloc(int size, omp_allocator_handle_t a);
+#define N 1024
+
+void foo() {
+  int errors = 0;
+  omp_memspace_handle_t  memspace = omp_default_mem_space;
+  omp_alloctrait_t   traits[1] = {{omp_atk_alignment, 64}};
+  omp_allocator_handle_t alloc = omp_init_allocator(memspace,1,traits);
+  #pragma omp target map(tofrom: errors) uses_allocators(alloc(traits))
+  { }
+}
 #endif
 
 // CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
@@ -140,3 +169,15 @@
 // CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
 // CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
 // CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
+
+// CHECK: [[TRAITS_ADDR_REF:%.

[PATCH] D151743: [OMP] Fix compiler assert "DeclRefExpr for Decl not entered in LocalDeclMap?"

2023-05-30 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert.
jyu2 added projects: OpenMP, clang.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.

Currently compiler assert when passing variable "memspace" in
omp_init_allocator.

omp_allocator_handle_t alloc=omp_init_allocator(memspace,1,traits)

The problem is memspace is not mapping to the target region.  During
the call to emitAllocatorInit, calls to EmitVarDecl for "alloc", then
emit initialization of "alloc" that cause to assert.

If I understant correct, it is not necessary to emit variable
initialization, since "allocator" is private to target region.

To fix this call CGF.EmitAutoVarAlloca(allocator) instead
CGF.EmitVarDecl(allocator).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151743

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_uses_allocators.c


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -64,6 +64,35 @@
   {}
 }
 
+typedef enum omp_memspace_handle_t {
+  omp_default_mem_space = 0,
+  omp_large_cap_mem_space = 1,
+  omp_const_mem_space = 2,
+  omp_high_bw_mem_space = 3,
+  omp_low_lat_mem_space = 4,
+  llvm_omp_target_host_mem_space = 100,
+  llvm_omp_target_shared_mem_space = 101,
+  llvm_omp_target_device_mem_space = 102,
+  KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
+} omp_memspace_handle_t;
+
+extern omp_allocator_handle_t
+omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
+   const omp_alloctrait_t traits[]);
+
+void *omp_aligned_alloc(unsigned long alignment, unsigned long size,
+omp_allocator_handle_t allocator);
+extern void * omp_alloc(int size, omp_allocator_handle_t a);
+#define N 1024
+
+void foo() {
+  int errors = 0;
+  omp_memspace_handle_t  memspace = omp_default_mem_space;
+  omp_alloctrait_t   traits[1] = {{omp_atk_alignment, 64}};
+  omp_allocator_handle_t alloc = omp_init_allocator(memspace,1,traits);
+  #pragma omp target map(tofrom: errors) uses_allocators(alloc(traits))
+  { }
+}
 #endif
 
 // CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
@@ -140,3 +169,15 @@
 // CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
 // CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
 // CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%alloc]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 1, ptr [[TRAITS_ADDR]])
+// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
+// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
+
+// Destroy allocator upon exit from the region.
+// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
+// CHECK: [[CONV1:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
+// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV1]])
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6041,7 +6041,7 @@
   CGM.getModule(), OMPRTL___kmpc_init_allocator),
   {ThreadId, MemSpaceHandle, NumTraits, Traits});
   // Store to allocator.
-  CGF.EmitVarDecl(*cast(
+  CGF.EmitAutoVarAlloca(*cast(
   cast(Allocator->IgnoreParenImpCasts())->getDecl()));
   LValue AllocatorLVal = CGF.EmitLValue(Allocator->IgnoreParenImpCasts());
   AllocatorVal =


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -64,6 +64,35 @@
   {}
 }
 
+typedef enum omp_memspace_handle_t {
+  omp_default_mem_space = 0,
+  omp_large_cap_mem_space = 1,
+  omp_const_mem_space = 2,
+  omp_high_bw_mem_space = 3,
+  omp_low_lat_mem_space = 4,
+  llvm_omp_target_host_mem_space = 100,
+  llvm_omp_target_shared_mem_space = 101,
+  llvm_omp_target_device_mem_space = 102,
+  KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
+} omp_memspace_handle_t;
+
+extern omp_allocator_handle_t
+omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
+   const omp_alloctrait_t traits[]);
+
+void *omp_aligned_alloc(unsigned long alignment, unsigned long size,
+omp_allocator_handle_t allocator);
+extern void * omp_alloc(int size, omp_allocator_handle_t a);
+#define N 1024
+
+void foo() {
+  int errors = 0;
+  omp_memspace_handle_t  memspace = omp_default_mem_space;
+  omp_alloctrait_t   traits[1] = {{omp_atk_alignment, 64}};
+  omp_alloc

[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa419ec4f256d: Fix runtime crash inside __kmpc_init_allocator 
(authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151576/new/

https://reviews.llvm.org/D151576

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_uses_allocators.c
  clang/test/OpenMP/target_uses_allocators_codegen.cpp
  openmp/libomptarget/test/mapping/target_uses_allocator.c

Index: openmp/libomptarget/test/mapping/target_uses_allocator.c
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_uses_allocator.c
@@ -0,0 +1,56 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+
+#include 
+#include 
+
+#define N 1024
+
+int test_omp_aligned_alloc_on_device() {
+  int errors = 0;
+
+  omp_memspace_handle_t memspace = omp_default_mem_space;
+  omp_alloctrait_t traits[2] = {{omp_atk_alignment, 64}, {omp_atk_access, 64}};
+  omp_allocator_handle_t alloc =
+  omp_init_allocator(omp_default_mem_space, 1, traits);
+
+#pragma omp target map(tofrom : errors) uses_allocators(alloc(traits))
+  {
+int *x;
+int not_correct_array_values = 0;
+
+x = (int *)omp_aligned_alloc(64, N * sizeof(int), alloc);
+if (x == NULL) {
+  errors++;
+} else {
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+x[i] = i;
+  }
+
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+if (x[i] != i) {
+#pragma omp atomic write
+  not_correct_array_values = 1;
+}
+  }
+  if (not_correct_array_values) {
+errors++;
+  }
+  omp_free(x, alloc);
+}
+  }
+
+  omp_destroy_allocator(alloc);
+
+  return errors;
+}
+
+int main() {
+  int errors = 0;
+  if (test_omp_aligned_alloc_on_device())
+printf("FAILE\n");
+  else
+// CHECK: PASSED
+printf("PASSED\n");
+}
Index: clang/test/OpenMP/target_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -132,8 +132,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[

[PATCH] D148723: [clang] Restrict Inline Builtin to non-static, non-odr linkage

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D148723#4376946 , 
@serge-sans-paille wrote:

> @jyu2 : could you test that patch in your setup ? Also I can't find the bug 
> id associated with your original bug anymore...

I just submit bug in https://github.com/llvm/llvm-project/issues/62958 and 
assign that to you.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148723/new/

https://reviews.llvm.org/D148723

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151576: Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert.
jyu2 added projects: OpenMP, clang.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, jplehr, sstefan1.

It seems load of traits.addr should be passed in runtime call.  Currently
the load of load traits.addr gets passed cause runtime to fail.

To fix this, skip the call to EmitLoadOfScalar for extra load.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151576

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_uses_allocators.c
  clang/test/OpenMP/target_uses_allocators_codegen.cpp
  openmp/libomptarget/test/mapping/target_uses_allocator.c

Index: openmp/libomptarget/test/mapping/target_uses_allocator.c
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_uses_allocator.c
@@ -0,0 +1,56 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+
+#include 
+#include 
+
+#define N 1024
+
+int test_omp_aligned_alloc_on_device() {
+  int errors = 0;
+
+  omp_memspace_handle_t memspace = omp_default_mem_space;
+  omp_alloctrait_t traits[2] = {{omp_atk_alignment, 64}, {omp_atk_access, 64}};
+  omp_allocator_handle_t alloc =
+  omp_init_allocator(omp_default_mem_space, 1, traits);
+
+#pragma omp target map(tofrom : errors) uses_allocators(alloc(traits))
+  {
+int *x;
+int not_correct_array_values = 0;
+
+x = (int *)omp_aligned_alloc(64, N * sizeof(int), alloc);
+if (x == NULL) {
+  errors++;
+} else {
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+x[i] = i;
+  }
+
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+if (x[i] != i) {
+#pragma omp atomic write
+  not_correct_array_values = 1;
+}
+  }
+  if (not_correct_array_values) {
+errors++;
+  }
+  omp_free(x, alloc);
+}
+  }
+
+  omp_destroy_allocator(alloc);
+
+  return errors;
+}
+
+int main() {
+  int errors = 0;
+  if (test_omp_aligned_alloc_on_device())
+printf("FAILE\n");
+  else
+// CHECK: PASSED
+printf("PASSED\n");
+}
Index: clang/test/OpenMP/target_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -132,8 +132,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// C

[PATCH] D151517: Fix wrong error message when compiling C souce code

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGacb1b4fbb793: Fix wrong error message when compiling C souce 
code: (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151517/new/

https://reviews.llvm.org/D151517

Files:
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/target_uses_allocators.c


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
@@ -19,9 +21,27 @@
   KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
 } omp_allocator_handle_t;
 
+typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
+omp_atk_alignment = 2,
+omp_atk_access = 3,
+omp_atk_pool_size = 4,
+omp_atk_fallback = 5,
+omp_atk_fb_data = 6,
+omp_atk_pinned = 7,
+omp_atk_partition = 8
+} omp_alloctrait_key_t;
+
+typedef struct omp_alloctrait_t {
+  omp_alloctrait_key_t key;
+  __UINTPTR_TYPE__ value;
+} omp_alloctrait_t;
+
+
 // CHECK: define {{.*}}[[FIE:@.+]]()
 void fie(void) {
   int x;
+  omp_allocator_handle_t my_allocator;
+  omp_alloctrait_t traits[10];
   #pragma omp target uses_allocators(omp_null_allocator) 
allocate(omp_null_allocator: x) firstprivate(x)
   {}
   #pragma omp target uses_allocators(omp_default_mem_alloc) 
allocate(omp_default_mem_alloc: x) firstprivate(x)
@@ -40,6 +60,8 @@
   {}
   #pragma omp target uses_allocators(omp_thread_mem_alloc) 
allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning 
{{allocator with the 'thread' trait access has unspecified behavior on 'target' 
directive}}
   {}
+#pragma omp target uses_allocators(omp_null_allocator, omp_thread_mem_alloc, 
my_allocator(traits))
+  {}
 }
 
 #endif
@@ -106,3 +128,16 @@
 // CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
 // CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
 // CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
+// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
+
+// Destroy allocator upon exit from the region.
+// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
+// CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
+// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -3103,8 +3103,13 @@
 return nullptr;
   SmallVector Data;
   do {
+CXXScopeSpec SS;
+Token Replacement;
 ExprResult Allocator =
-getLangOpts().CPlusPlus ? ParseCXXIdExpression() : ParseExpression();
+getLangOpts().CPlusPlus
+? ParseCXXIdExpression()
+: tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false,
+  Replacement);
 if (Allocator.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
 StopBeforeMatch);


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fop

[PATCH] D151517: Fix wrong error message when compiling C souce code

2023-05-26 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D151517#4374583 , @ABataev wrote:

> Could you split it into 3 separate patch

Thanks Alexey!  Sure I am split into three.  Here is first one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151517/new/

https://reviews.llvm.org/D151517

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151517: Fix wrong error message when compiling C souce code

2023-05-25 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 525894.
jyu2 retitled this revision from "Fix couple of problems in uses_allocators 
clause." to "Fix wrong error message when compiling C souce code".
jyu2 edited the summary of this revision.
jyu2 added a comment.

Thanks Alexey,  sure I am separate the patch.  This is first oen.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151517/new/

https://reviews.llvm.org/D151517

Files:
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/target_uses_allocators.c


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
@@ -19,9 +21,27 @@
   KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
 } omp_allocator_handle_t;
 
+typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
+omp_atk_alignment = 2,
+omp_atk_access = 3,
+omp_atk_pool_size = 4,
+omp_atk_fallback = 5,
+omp_atk_fb_data = 6,
+omp_atk_pinned = 7,
+omp_atk_partition = 8
+} omp_alloctrait_key_t;
+
+typedef struct omp_alloctrait_t {
+  omp_alloctrait_key_t key;
+  __UINTPTR_TYPE__ value;
+} omp_alloctrait_t;
+
+
 // CHECK: define {{.*}}[[FIE:@.+]]()
 void fie(void) {
   int x;
+  omp_allocator_handle_t my_allocator;
+  omp_alloctrait_t traits[10];
   #pragma omp target uses_allocators(omp_null_allocator) 
allocate(omp_null_allocator: x) firstprivate(x)
   {}
   #pragma omp target uses_allocators(omp_default_mem_alloc) 
allocate(omp_default_mem_alloc: x) firstprivate(x)
@@ -40,6 +60,8 @@
   {}
   #pragma omp target uses_allocators(omp_thread_mem_alloc) 
allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning 
{{allocator with the 'thread' trait access has unspecified behavior on 'target' 
directive}}
   {}
+#pragma omp target uses_allocators(omp_null_allocator, omp_thread_mem_alloc, 
my_allocator(traits))
+  {}
 }
 
 #endif
@@ -106,3 +128,16 @@
 // CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
 // CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
 // CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
+// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
+
+// Destroy allocator upon exit from the region.
+// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
+// CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
+// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -3103,8 +3103,13 @@
 return nullptr;
   SmallVector Data;
   do {
+CXXScopeSpec SS;
+Token Replacement;
 ExprResult Allocator =
-getLangOpts().CPlusPlus ? ParseCXXIdExpression() : ParseExpression();
+getLangOpts().CPlusPlus
+? ParseCXXIdExpression()
+: tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false,
+  Replacement);
 if (Allocator.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
 StopBeforeMatch);


Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/tes

[PATCH] D151517: Fix couple of problems in uses_allocators clause.

2023-05-25 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert.
jyu2 added projects: OpenMP, clang.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, jplehr, sstefan1.

1> Fix wrong error message when compiling C souce code:
Currently emit error as following for uses_allocators(alloc(traits)):

called object type 'omp_allocator_handle_t' (aka
'enum omp_allocator_handle_t') is not a function or function pointer

To fix this, since "alloc" is Id expresison(spce 5.2), during the parser
(in ParseOpenMP.cpp), using tryParseCXXIdExpression instead of
ParseExpression for C.

2> Fix runtime problem when call to __kmpc_init_allocator
It seem load of traits.addr should be passed in rumtime call.  Curently
the load of load traits.addr gets passed cause runtime to fail.

3> change to use CGF.EmitAutoVarAlloca(allocator) instead
CGF.EmitVarDecl(allocator).
If I understant correct, it is not necessary to emit variable init,
since "allocator" is private to target region.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151517

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_uses_allocators.c
  clang/test/OpenMP/target_uses_allocators_codegen.cpp
  openmp/libomptarget/test/mapping/target_uses_allocator.c

Index: openmp/libomptarget/test/mapping/target_uses_allocator.c
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_uses_allocator.c
@@ -0,0 +1,56 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+
+#include 
+#include 
+
+#define N 1024
+
+int test_omp_aligned_alloc_on_device() {
+  int errors = 0;
+
+  omp_memspace_handle_t memspace = omp_default_mem_space;
+  omp_alloctrait_t traits[2] = {{omp_atk_alignment, 64}, {omp_atk_access, 64}};
+  omp_allocator_handle_t alloc =
+  omp_init_allocator(omp_default_mem_space, 1, traits);
+
+#pragma omp target map(tofrom : errors) uses_allocators(alloc(traits))
+  {
+int *x;
+int not_correct_array_values = 0;
+
+x = (int *)omp_aligned_alloc(64, N * sizeof(int), alloc);
+if (x == NULL) {
+  errors++;
+} else {
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+x[i] = i;
+  }
+
+#pragma omp parallel for simd simdlen(16) aligned(x : 64)
+  for (int i = 0; i < N; i++) {
+if (x[i] != i) {
+#pragma omp atomic write
+  not_correct_array_values = 1;
+}
+  }
+  if (not_correct_array_values) {
+errors++;
+  }
+  omp_free(x, alloc);
+}
+  }
+
+  omp_destroy_allocator(alloc);
+
+  return errors;
+}
+
+int main() {
+  int errors = 0;
+  if (test_omp_aligned_alloc_on_device())
+printf("FAILE\n");
+  else
+// CHECK: PASSED
+printf("PASSED\n");
+}
Index: clang/test/OpenMP/target_uses_allocators_codegen.cpp
===
--- clang/test/OpenMP/target_uses_allocators_codegen.cpp
+++ clang/test/OpenMP/target_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 
Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -tri

[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-05-25 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 accepted this revision.
jyu2 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141627/new/

https://reviews.llvm.org/D141627

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-17 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG691927c904ed: Fix assertion when try is used inside 
catch(...) block (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150340/new/

https://reviews.llvm.org/D150340

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr 
null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // 
*
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // *
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-16 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D150340#4343915 , @efriedma wrote:

> LGTM... but I don't think the IR we're generating is really correct overall; 
> see https://github.com/llvm/llvm-project/issues/62723
>
> On a side-note, other open issues related to -EHa/__try:
>
> https://github.com/llvm/llvm-project/issues/62606
> D124642 

Thanks Eli for the code review!!  I will take look about missing seh.try.end in 
c++ try/catch part later.  In term of D124642 
, I'd really want to look at IR for return 
inside __try/__finally, but for some reason, I an not build compiler with your 
patch: no member named 'setHasAddressTaken' in 'llvm::MachineBasicBlock'; did 
you mean 'hasAddressTaken'.  I may missing some  thing in my environment.




Comment at: clang/lib/CodeGen/CGException.cpp:650
+llvm::FunctionCallee SehCppScope = getSehTryBeginFn(CGM);
+EmitSehScope(SehCppScope);
+  }

efriedma wrote:
> jyu2 wrote:
> > efriedma wrote:
> > > Do we need to make the same change in EmitSEHTryStmt/ExitSEHTryStmt?
> > > 
> > > Is there some reason not to just call EmitSehTryScopeBegin here?
> > EmitSehTryScopeBegin:  it is emit seh.scope.begin
> > 
> > In here we want to emit seh.try.begin.  call EmitSehSCope with different 
> > function.
> > 
> > For EmitSEHTryStmt/ExitSEHTryStmt if is for __try /__except/__finally and 
> > it is for C code.  I thought about that.  And tried some test(BTW, try and 
> > __try can not be in same construct), I don't see the problem.  So I did not 
> > add that. 
> Not sure I understand what you're saying about EmitSehTryScopeBegin.  
> CGException.cpp:45 refers to "llvm.seh.try.begin".  CGCleanup.cpp:1370 also 
> refers to "llvm.seh.try.begin"
> 
> For EmitSEHTryStmt/ExitSEHTryStmt, I guess __try codegen can't generate a 
> construct quite like the given testcase, so thta's fine.
:-(  Sorry, You are right!!  It is seems EmitSehTryScopeBegin is not called 
anywhere.
  
Changed.  Thanks for the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150340/new/

https://reviews.llvm.org/D150340

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 521465.
jyu2 added a comment.

Address Eli's comment.  Thanks for review!.

:-( Sorry, You are right!! It is seems EmitSehTryScopeBegin is not called 
anywhere.

Changed. Thanks for the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150340/new/

https://reviews.llvm.org/D150340

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr 
null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // 
*
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // *
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGException.cpp:650
+llvm::FunctionCallee SehCppScope = getSehTryBeginFn(CGM);
+EmitSehScope(SehCppScope);
+  }

efriedma wrote:
> Do we need to make the same change in EmitSEHTryStmt/ExitSEHTryStmt?
> 
> Is there some reason not to just call EmitSehTryScopeBegin here?
EmitSehTryScopeBegin:  it is emit seh.scope.begin

In here we want to emit seh.try.begin.  call EmitSehSCope with different 
function.

For EmitSEHTryStmt/ExitSEHTryStmt if is for __try /__except/__finally and it is 
for C code.  I thought about that.  And tried some test(BTW, try and __try can 
not be in same construct), I don't see the problem.  So I did not add that. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150340/new/

https://reviews.llvm.org/D150340

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150340: [SEH]:Fix assertion when try is used inside catch(...) block with /EHa

2023-05-10 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: asmith, efriedma, tentzen, pengfei.
jyu2 added a project: clang.
Herald added subscribers: kbarton, nemanjai.
Herald added a project: All.
jyu2 requested review of this revision.

Current assert wiht /EHa with
A single unwind edge may only enter one EH pad

  invoke void @llvm.seh.try.begin()
  to label %invoke.cont1 unwind label %catch.dispatch2

IR:
%1 = catchpad within %0 [ptr null, i32 0, ptr null]

  invoke void @llvm.seh.try.begin()
  to label %invoke.cont5 unwind label %catch.dispatch2

The problem is the invoke to llvm.seh.try.begin() missing "funclet"

Accodring: https://llvm.org/docs/LangRef.html#ob-funclet
If any "funclet" EH pads have been entered but not exited (per the
description in the EH doc), it is undefined behavior to execute a
call or invoke.

To fix the problem, when emit seh_try_begin,  call EmitSehScope,
instead of calling EmitRuntimeCallOrInvoke for proper "funclet"
gerenration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150340

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp

Index: clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
===
--- clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // *
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -2933,6 +2933,7 @@
   void EmitSehCppScopeEnd();
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
+  void EmitSehScope(llvm::FunctionCallee &SehCppScope);
 
   llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -645,8 +645,10 @@
   CatchScope->setHandler(I, CGM.getCXXABI().getCatchAllTypeInfo(), Handler);
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
-  if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+  if (getLangOpts().EHAsynch) {
+llvm::FunctionCallee SehCppScope = getSehTryBeginFn(CGM);
+EmitSehScope(SehCppScope);
+  }
 }
   }
 }
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -1328,18 +1328,16 @@
 
 // Need to set "funclet" in OperandBundle properly for noThrow
 //   intrinsic (see CGCall.cpp)
-static void EmitSehScope(CodeGenFunction &CGF,
- llvm::FunctionCallee &SehCppScope) {
-  llvm::BasicBlock *InvokeDest = CGF.getInvokeDest();
-  assert(CGF.Builder.GetInsertBlock() && InvokeDest);
-  llvm::BasicBlock *Cont = CGF.createBasicBlock("invoke.cont");
+void CodeGenFunction::EmitSehScope(llvm::FunctionCallee &SehCppScope) {
+  llvm::BasicBlock *InvokeDest = getInvokeDest();
+  assert(Builder.GetInsertBlock() && InvokeDest);
+  llvm::BasicBlock *Cont = createBasicBlock("invoke.cont");
   SmallVector BundleList =
-  CGF.getBundlesForFunclet(SehCppScope.getCallee());
-  if (CGF.CurrentFuncletPad)
-BundleList.emplac

[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-04-27 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

If it is okay with is_divece_ptr.  I am okay with it.
Please add a lit test for this?

Thanks.
Jennifer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141627/new/

https://reviews.llvm.org/D141627

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

2023-04-20 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

I think something like

#ifdef RINZOCORE_SHARED
#define RINZO_LIB __declspec(dllexport)
#else
#define RINZO_LIB __declspec(dllimport)
#endif

RINZO_LIB inline func() {}


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148723/new/

https://reviews.llvm.org/D148723

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

2023-04-19 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Hi @serge-sans-paille, thanks for the fix.  Could you please also try some test 
with dllimport/dllexport with inline function?  Jennifer




Comment at: clang/lib/AST/ASTContext.cpp:11538
  const FunctionDecl *FD) {
-  if (!FD->isExternallyVisible())
+  if (!FD->isExternallyVisible() || FD->isInlineBuiltinDeclaration())
 return GVA_Internal;

How about __declspec(dllimpor/dllexprort) __forceinline fexprl?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148723/new/

https://reviews.llvm.org/D148723

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147307: [clang] Do not require GNUInlineAttr for inline builtins

2023-04-18 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

This change seems cause assert:

https://godbolt.org/z/z9G87Wr37


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147307/new/

https://reviews.llvm.org/D147307

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146000: [OpenMP]Skip generating this[:1] map info for non-member variable.

2023-03-14 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d9880ebbcb7: [OpenMP]Skip generating this[:1] map info for 
non-member variable. (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146000/new/

https://reviews.llvm.org/D146000

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -68,11 +68,13 @@
 auto Asize = 4;
 auto Csize = 4;
 
-#pragma omp target data map(to : d.A) map(from : d.C)
+#pragma omp target data map(from : d.C)
 {
 #pragma omp target teams firstprivate(Csize)
   d.C = 1;
 }
+#pragma omp target map(from : d.A)
+d.A = 3;
   }
 };
 
@@ -91,4 +93,6 @@
   z.bar(d);
   // CHECK 1
   printf("%d\n", d.C);
+  // CHECK 3
+  printf("%d\n", d.A);
 }
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -56,6 +56,9 @@
for (int i = 0; i < Csize; ++i)
   d.C[i] = 1;
  }
+ #pragma omp target map(from:d.C[0:Csize])
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
}
 };
 
@@ -66,9 +69,11 @@
   descriptor d;
   c.bar(d);
 }
+
 // CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
 // CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
-
+// CHECK: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, i64 0, i64 0]
+// CHECK-NOT: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, i64 1, i64 0]
 // CHECK-LABEL: define {{[^@]+}}@_Z3foov
 // CHECK-SAME: () #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
@@ -189,6 +194,12 @@
 // CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS9:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_PTRS10:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_MAPPERS11:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[_TMP12:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[CSIZE_CASTED13:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS18:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS19:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS20:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_SIZES21:%.*]] = alloca [3 x i64], align 8
 // CHECK-NEXT:store ptr [[THIS]], ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:store ptr [[D]], ptr [[D_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
@@ -323,6 +334,87 @@
 // CHECK-NEXT:[[TMP71:%.*]] = getelementptr inbounds [3 x ptr], ptr [[DOTOFFLOAD_PTRS]], i32 0, i32 0
 // CHECK-NEXT:[[TMP72:%.*]] = getelementptr inbounds [3 x i64], ptr [[DOTOFFLOAD_SIZES]], i32 0, i32 0
 // CHECK-NEXT:call void @__tgt_target_data_end_mapper(ptr @[[GLOB1]], i64 -1, i32 3, ptr [[TMP70]], ptr [[TMP71]], ptr [[TMP72]], ptr @.offload_maptypes.1, ptr null, ptr null)
+// CHECK-NEXT:[[TMP73:%.*]] = load ptr, ptr [[D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[TMP73]], ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP74:%.*]] = load i32, ptr [[CSIZE]], align 4
+// CHECK-NEXT:store i32 [[TMP74]], ptr [[CSIZE_CASTED13]], align 4
+// CHECK-NEXT:[[TMP75:%.*]] = load i64, ptr [[CSIZE_CASTED13]], align 8
+// CHECK-NEXT:[[TMP76:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP77:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP78:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[C14:%.*]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], ptr [[TMP78]], i32 0, i32 1
+// CHECK-NEXT:[[TMP79:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[C15:%.*]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], ptr [[TMP79]], i32 0, i32 1
+// CHECK-NEXT:[[TMP80:%.*]] = load ptr, ptr [[C15]], align 8
+// CHECK-NEXT:[[ARRAYIDX16:%.*]] = getelementptr inbounds float, ptr [[TMP80]], i64 0
+// CHECK-NEXT:[[TMP81:%.*]] = load i32, ptr [[CSIZE]], align 4
+// CHECK-NEXT:[[CONV17:%.*]] = zext i32 [[TMP81]] to i64
+// CHECK-NEXT:[[TMP82:%.*]] = mul nuw i64 [[CONV17]], 4
+// CHECK-NEXT:[[TMP83:%.*]] = getelementptr ptr, ptr [[C14]], i32 1
+// CHECK-NEXT:[[TMP84:%.*]] = ptrtoint ptr [[TMP83]] to i64
+// CHECK-NEXT:[[TMP85:%.*]] = ptrtoint ptr [[C14]] to i64
+// CHECK-NEXT:[[TMP86:%.*]] = sub i64 [[TMP84]], [[TMP85]]
+// CHECK-NEXT:[[TMP87:%.*]] = sdiv exact i64 [[TMP86]], ptrtoint (p

[PATCH] D146000: [OpenMP]Skip generating this[:1] map info for non-member variable.

2023-03-13 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 504907.
jyu2 added a comment.

Fix clang format problem


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146000/new/

https://reviews.llvm.org/D146000

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -68,11 +68,13 @@
 auto Asize = 4;
 auto Csize = 4;
 
-#pragma omp target data map(to : d.A) map(from : d.C)
+#pragma omp target data map(from : d.C)
 {
 #pragma omp target teams firstprivate(Csize)
   d.C = 1;
 }
+#pragma omp target map(from : d.A)
+d.A = 3;
   }
 };
 
@@ -91,4 +93,6 @@
   z.bar(d);
   // CHECK 1
   printf("%d\n", d.C);
+  // CHECK 3
+  printf("%d\n", d.A);
 }
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -56,6 +56,9 @@
for (int i = 0; i < Csize; ++i)
   d.C[i] = 1;
  }
+ #pragma omp target map(from:d.C[0:Csize])
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
}
 };
 
@@ -66,9 +69,11 @@
   descriptor d;
   c.bar(d);
 }
+
 // CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
 // CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
-
+// CHECK: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, i64 0, i64 0]
+// CHECK-NOT: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, i64 1, i64 0]
 // CHECK-LABEL: define {{[^@]+}}@_Z3foov
 // CHECK-SAME: () #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
@@ -189,6 +194,12 @@
 // CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS9:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_PTRS10:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_MAPPERS11:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[_TMP12:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[CSIZE_CASTED13:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS18:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS19:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS20:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_SIZES21:%.*]] = alloca [3 x i64], align 8
 // CHECK-NEXT:store ptr [[THIS]], ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:store ptr [[D]], ptr [[D_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
@@ -323,6 +334,87 @@
 // CHECK-NEXT:[[TMP71:%.*]] = getelementptr inbounds [3 x ptr], ptr [[DOTOFFLOAD_PTRS]], i32 0, i32 0
 // CHECK-NEXT:[[TMP72:%.*]] = getelementptr inbounds [3 x i64], ptr [[DOTOFFLOAD_SIZES]], i32 0, i32 0
 // CHECK-NEXT:call void @__tgt_target_data_end_mapper(ptr @[[GLOB1]], i64 -1, i32 3, ptr [[TMP70]], ptr [[TMP71]], ptr [[TMP72]], ptr @.offload_maptypes.1, ptr null, ptr null)
+// CHECK-NEXT:[[TMP73:%.*]] = load ptr, ptr [[D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[TMP73]], ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP74:%.*]] = load i32, ptr [[CSIZE]], align 4
+// CHECK-NEXT:store i32 [[TMP74]], ptr [[CSIZE_CASTED13]], align 4
+// CHECK-NEXT:[[TMP75:%.*]] = load i64, ptr [[CSIZE_CASTED13]], align 8
+// CHECK-NEXT:[[TMP76:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP77:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP78:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[C14:%.*]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], ptr [[TMP78]], i32 0, i32 1
+// CHECK-NEXT:[[TMP79:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[C15:%.*]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], ptr [[TMP79]], i32 0, i32 1
+// CHECK-NEXT:[[TMP80:%.*]] = load ptr, ptr [[C15]], align 8
+// CHECK-NEXT:[[ARRAYIDX16:%.*]] = getelementptr inbounds float, ptr [[TMP80]], i64 0
+// CHECK-NEXT:[[TMP81:%.*]] = load i32, ptr [[CSIZE]], align 4
+// CHECK-NEXT:[[CONV17:%.*]] = zext i32 [[TMP81]] to i64
+// CHECK-NEXT:[[TMP82:%.*]] = mul nuw i64 [[CONV17]], 4
+// CHECK-NEXT:[[TMP83:%.*]] = getelementptr ptr, ptr [[C14]], i32 1
+// CHECK-NEXT:[[TMP84:%.*]] = ptrtoint ptr [[TMP83]] to i64
+// CHECK-NEXT:[[TMP85:%.*]] = ptrtoint ptr [[C14]] to i64
+// CHECK-NEXT:[[TMP86:%.*]] = sub i64 [[TMP84]], [[TMP85]]
+// CHECK-NEXT:[[TMP87:%.*]] = sdiv exact i64 [[TMP86]], ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64)
+// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr 

[PATCH] D146000: [OpenMP]Skip generating this[:1] map info for non-member variable.

2023-03-13 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

My change of D14093  is only fixed problem for 
"pragma target data".

The problem still here for "pragma target"
what I am missing is:
When processing "pragma target data", the VD is passed when call to
emitCombinedEntry, so check VD is null as map for this pointer.

But when processing "pragma target" the VD is passed as nullptr, so
check VD is null is not working.

To fix this I add a new parameter IsMapThis. During the call to
emitCombinedEntry passes true if it is capturing this pointer and use
that instead check of "!VD".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146000

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -68,11 +68,13 @@
 auto Asize = 4;
 auto Csize = 4;
 
-#pragma omp target data map(to : d.A) map(from : d.C)
+#pragma omp target data map(from : d.C)
 {
 #pragma omp target teams firstprivate(Csize)
   d.C = 1;
 }
+#pragma omp target map(from : d.A)
+d.A = 3;
   }
 };
 
@@ -91,4 +93,6 @@
   z.bar(d);
   // CHECK 1
   printf("%d\n", d.C);
+  // CHECK 3
+  printf("%d\n", d.A);
 }
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -56,6 +56,9 @@
for (int i = 0; i < Csize; ++i)
   d.C[i] = 1;
  }
+ #pragma omp target map(from:d.C[0:Csize])
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
}
 };
 
@@ -66,9 +69,11 @@
   descriptor d;
   c.bar(d);
 }
+
 // CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
 // CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
-
+// CHECK: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, i64 0, i64 0]
+// CHECK-NOT: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, i64 1, i64 0]
 // CHECK-LABEL: define {{[^@]+}}@_Z3foov
 // CHECK-SAME: () #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
@@ -189,6 +194,12 @@
 // CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS9:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_PTRS10:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_MAPPERS11:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[_TMP12:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[CSIZE_CASTED13:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS18:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS19:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS20:%.*]] = alloca [3 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_SIZES21:%.*]] = alloca [3 x i64], align 8
 // CHECK-NEXT:store ptr [[THIS]], ptr [[THIS_ADDR]], align 8
 // CHECK-NEXT:store ptr [[D]], ptr [[D_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
@@ -323,6 +334,87 @@
 // CHECK-NEXT:[[TMP71:%.*]] = getelementptr inbounds [3 x ptr], ptr [[DOTOFFLOAD_PTRS]], i32 0, i32 0
 // CHECK-NEXT:[[TMP72:%.*]] = getelementptr inbounds [3 x i64], ptr [[DOTOFFLOAD_SIZES]], i32 0, i32 0
 // CHECK-NEXT:call void @__tgt_target_data_end_mapper(ptr @[[GLOB1]], i64 -1, i32 3, ptr [[TMP70]], ptr [[TMP71]], ptr [[TMP72]], ptr @.offload_maptypes.1, ptr null, ptr null)
+// CHECK-NEXT:[[TMP73:%.*]] = load ptr, ptr [[D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[TMP73]], ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP74:%.*]] = load i32, ptr [[CSIZE]], align 4
+// CHECK-NEXT:store i32 [[TMP74]], ptr [[CSIZE_CASTED13]], align 4
+// CHECK-NEXT:[[TMP75:%.*]] = load i64, ptr [[CSIZE_CASTED13]], align 8
+// CHECK-NEXT:[[TMP76:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP77:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[TMP78:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[C14:%.*]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], ptr [[TMP78]], i32 0, i32 1
+// CHECK-NEXT:[[TMP79:%.*]] = load ptr, ptr [[_TMP12]], align 8
+// CHECK-NEXT:[[C15:%.*]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], ptr [[TMP79]], i32 0, i32 1
+// CHECK-NEXT:[[TMP80:%.*]] = load ptr, ptr [[C15]], align 8
+// C

[PATCH] D145093: [OpenMP] Add map info for dereference pointer.

2023-03-09 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D145093#4179927 , @ronlieb wrote:

> seems to fail amdgpu buildbot 
> https://lab.llvm.org/buildbot/#/builders/193/builds/27692

I turn off the test run to amdgpu.  And rechecked in with
c5b060900e98 


In D145093#4180143 , @ronlieb wrote:

> had not heard back , so reverted it for now 
> commit 8cf85a0cadb033fed3d96aa5283deb4bfbbaf2c8 
>  (HEAD 
> -> main, origin/main, origin/HEAD)
> Author: Ron Lieberman 
> Date:   Wed Mar 8 22:01:22 2023 -0600
>
>   Revert "Add map info for dereference pointer."
>   
>   breaks amdgpu buildbot




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: [OpenMP] Add map info for dereference pointer.

2023-03-08 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f2f37842582: Add map info for dereference pointer. 
(authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  clang/test/OpenMP/target_update_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,105 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j, a = 0, b = 0;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+#pragma omp target map(tofrom : (**t1d))
+  { (*t1d)[0] = 4; }
+  // CHECK: 4
+  printf("%d\n", (*t1d)[0]);
+#pragma omp target map(tofrom : (*(*(t1d + a) + b)))
+  { *(*(t1d + a) + b) = 5; }
+  // CHECK: 5
+  printf("%d\n", *(*(t1d + a) + b));
+}
+
+typedef int(T)[3];
+void bar() {
+  T **a;
+  int b[2][3];
+  int(*p)[3] = b;
+  a = &p;
+  for (int i = 0; i < 3; i++) {
+(**a)[1] = i;
+  }
+#pragma omp target map((**a)[ : 3])
+  {
+(**a)[1] = 6;
+// CHECK: 6
+printf("%d\n", (**a)[1]);
+  }
+}
+
+struct SSA {
+  int i;
+  SSA *sa;
+  SSA() {
+i = 1;
+sa = this;
+  }
+};
+
+void zoo(int **f, SSA *sa) {
+  int *t = *f;
+  f = (int **)malloc(sa->i * 4 * sizeof(int));
+  t = (int *)malloc(sa->i * sizeof(int));
+  *(f + sa->i + 1) = t;
+  *(sa->sa->i + *(f + sa->i + 1)) = 4;
+  printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
+#pragma omp target map(sa, *(sa->sa->i + *(1 + sa->i + f)))
+  { *(sa->sa->i + *(1 + sa->i + f)) = 7; }
+  // CHECK: 7
+  printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
+}
+
+void xoo() {
+  int *x = 0;
+  SSA *sa = new SSA();
+  zoo(&x, sa);
+}
+
+void yoo(int **x) {
+  *x = (int *)malloc(2 * sizeof(int));
+#pragma omp target map(**x)
+  {
+**x = 8;
+// CHECK: 8
+printf("%d\n", **x);
+  }
+#pragma omp target map(*(*x + 1))
+  {
+*(*x + 1) = 9;
+// CHECK: 9
+printf("%d\n", *(*x + 1));
+  }
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+  bar();
+  xoo();
+  yoo(&data);
+}
Index: clang/test/OpenMP/target_update_codegen.cpp
===
--- clang/test/OpenMP/target_update_codegen.cpp
+++ clang/test/OpenMP/target_update_codegen.cpp
@@ -748,18 +748,18 @@
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 #ifdef CK13
 
-// CK13: [[SIZE00:@.+]] = {{.+}}constant [1 x i64] [i64 4]
-// CK13: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 1]
+// CK13: [[SIZE00:@.+]] = {{.+}}constant [2 x i64] [i64 {{4|8}}, i64 4]
+// CK13: [[MTYPE00:@.+]] = {{.+}}constant [2 x i64] [i64 1, i64 17]
 
 // CK13-LABEL: lvalue
 void lvalue(int **BB, int a, int b) {
 
-  // CK13-DAG: call void @__tgt_target_data_update_mapper(%struct.ident_t* @{{.+}}, i64 -1, i32 1, i8** [[GEPBP:%.+]], i8** [[GEPP:%.+]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[SIZE00]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[MTYPE00]]{{.+}}, i8** null)
+  // CK13-DAG: call void @__tgt_target_data_update_mapper(%struct.ident_t* @{{.+}}, i64 -1, i32 2, i8** [[GEPBP:%.+]], i8** [[GEPP:%.+]], {{.+}}getelementptr {{.+}}[2 x i{{.+}}]* [[SIZE00]], {{.+}}getelementptr {{.+}}[2 x i{{.+}}]* [[MTYPE00]]{{.+}}, i8** null)
   // CK13-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
   // CK13-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
-  // CK13-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
-  // CK13-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
+  // CK13-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1
+  // CK13-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1
   // CK13-DAG: [[BPC0:%.+]] = bitcast i8** [[BP0]] to i32***
   // CK13-DAG: [[PC0:%.+]] = bitcast i8** [[P0]] to i32**
   // CK13-DAG: store i32** [[B_VAL1:%.+]], i32*** [[BPC0]]
@@ -772,7 +772,6 @@
   // CK13-32-DAG: [[ADD_PTR]] = getelementptr inbounds i32*, i32** [[B_VAL:%.+]], i32 [[A_ADDR:%.+]]
   // CK13-64-DAG: [[IDX_EXT]] = sext i

[PATCH] D145093: [OpenMP] Add map info for dereference pointer.

2023-03-08 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 503413.
jyu2 added a comment.

Okay, I add code to get **a to work.  Thanks Alexey for the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  clang/test/OpenMP/target_update_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,105 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j, a = 0, b = 0;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+#pragma omp target map(tofrom : (**t1d))
+  { (*t1d)[0] = 4; }
+  // CHECK: 4
+  printf("%d\n", (*t1d)[0]);
+#pragma omp target map(tofrom : (*(*(t1d + a) + b)))
+  { *(*(t1d + a) + b) = 5; }
+  // CHECK: 5
+  printf("%d\n", *(*(t1d + a) + b));
+}
+
+typedef int(T)[3];
+void bar() {
+  T **a;
+  int b[2][3];
+  int(*p)[3] = b;
+  a = &p;
+  for (int i = 0; i < 3; i++) {
+(**a)[1] = i;
+  }
+#pragma omp target map((**a)[ : 3])
+  {
+(**a)[1] = 6;
+// CHECK: 6
+printf("%d\n", (**a)[1]);
+  }
+}
+
+struct SSA {
+  int i;
+  SSA *sa;
+  SSA() {
+i = 1;
+sa = this;
+  }
+};
+
+void zoo(int **f, SSA *sa) {
+  int *t = *f;
+  f = (int **)malloc(sa->i * 4 * sizeof(int));
+  t = (int *)malloc(sa->i * sizeof(int));
+  *(f + sa->i + 1) = t;
+  *(sa->sa->i + *(f + sa->i + 1)) = 4;
+  printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
+#pragma omp target map(sa, *(sa->sa->i + *(1 + sa->i + f)))
+  { *(sa->sa->i + *(1 + sa->i + f)) = 7; }
+  // CHECK: 7
+  printf("%d\n", *(sa->sa->i + *(1 + sa->i + f)));
+}
+
+void xoo() {
+  int *x = 0;
+  SSA *sa = new SSA();
+  zoo(&x, sa);
+}
+
+void yoo(int **x) {
+  *x = (int *)malloc(2 * sizeof(int));
+#pragma omp target map(**x)
+  {
+**x = 8;
+// CHECK: 8
+printf("%d\n", **x);
+  }
+#pragma omp target map(*(*x + 1))
+  {
+*(*x + 1) = 9;
+// CHECK: 9
+printf("%d\n", *(*x + 1));
+  }
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+  bar();
+  xoo();
+  yoo(&data);
+}
Index: clang/test/OpenMP/target_update_codegen.cpp
===
--- clang/test/OpenMP/target_update_codegen.cpp
+++ clang/test/OpenMP/target_update_codegen.cpp
@@ -748,18 +748,18 @@
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 #ifdef CK13
 
-// CK13: [[SIZE00:@.+]] = {{.+}}constant [1 x i64] [i64 4]
-// CK13: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 1]
+// CK13: [[SIZE00:@.+]] = {{.+}}constant [2 x i64] [i64 {{4|8}}, i64 4]
+// CK13: [[MTYPE00:@.+]] = {{.+}}constant [2 x i64] [i64 1, i64 17]
 
 // CK13-LABEL: lvalue
 void lvalue(int **BB, int a, int b) {
 
-  // CK13-DAG: call void @__tgt_target_data_update_mapper(%struct.ident_t* @{{.+}}, i64 -1, i32 1, i8** [[GEPBP:%.+]], i8** [[GEPP:%.+]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[SIZE00]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[MTYPE00]]{{.+}}, i8** null)
+  // CK13-DAG: call void @__tgt_target_data_update_mapper(%struct.ident_t* @{{.+}}, i64 -1, i32 2, i8** [[GEPBP:%.+]], i8** [[GEPP:%.+]], {{.+}}getelementptr {{.+}}[2 x i{{.+}}]* [[SIZE00]], {{.+}}getelementptr {{.+}}[2 x i{{.+}}]* [[MTYPE00]]{{.+}}, i8** null)
   // CK13-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
   // CK13-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
-  // CK13-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
-  // CK13-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
+  // CK13-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1
+  // CK13-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1
   // CK13-DAG: [[BPC0:%.+]] = bitcast i8** [[BP0]] to i32***
   // CK13-DAG: [[PC0:%.+]] = bitcast i8** [[P0]] to i32**
   // CK13-DAG: store i32** [[B_VAL1:%.+]], i32*** [[BPC0]]
@@ -772,7 +772,6 @@
   // CK13-32-DAG: [[ADD_PTR]] = getelementptr inbounds i32*, i32** [[B_VAL:%.+]], i32 [[A_ADDR:%.+]]
   // CK13-64-DAG: [[IDX_EXT]] = sext i32 [[TWO:%.+]] to i64
   // CK13-DAG: [[B_VAL]] = load i32**, i32*** [[BB_ADDR:%.+]]
- 

[PATCH] D145093: Add map info for dereference pointer.

2023-03-07 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7489-7493
+  if (UO && UO->getOpcode() == UO_Deref)
+if (isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()))
+  IsVarDerefAssoWithArray = true;

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > jyu2 wrote:
> > > > ABataev wrote:
> > > > > What if we have something like:
> > > > > ```
> > > > > typedef int (T)[3];
> > > > > 
> > > > > T** p;
> > > > > map(**p)
> > > > > ```
> > > > > ? Shall it work? I.e. mapping of the whole array by dereferening the 
> > > > > pointer to the array.
> > > > No, it is not work currently.  What about *(*(p+a)+b)...
> > > My question - shall it work? Mapping  (**a)[:3] should result in the same 
> > > in the same code for **a if a is
> > > ```
> > > typedef int(T)[3];
> > > T** a;
> > > ```
> > Oh, that should work.  I add additional test for that.
> > 
> > ```
> > typedef int(T)[3];
> > void bar()
> > {
> > 
> > T** a;
> > int b[2][3];
> > int (*p)[3] = b;
> > a =  &p;
> > printf("%p %p p %p\n", &a, b, *p);
> > for (int i = 0; i< 3; i++) {
> >   (**a)[1] = i;
> > }
> > #pragma omp target map((**a)[:3])
> > {
> >  (**a)[1]=5;
> >   // CHECK: 5
> >   printf("a = %d\n", (**a)[1]);
> > }
> > }
> > ```
> > 
> No, I meant different thing:
> ```
> T **a;
> .. map (**a)
> ```
Yes, that is not working currently.  That is something need to be fixed include 
*(*(a+i)+j)  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-06 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7489-7493
+  if (UO && UO->getOpcode() == UO_Deref)
+if (isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()))
+  IsVarDerefAssoWithArray = true;

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > What if we have something like:
> > > ```
> > > typedef int (T)[3];
> > > 
> > > T** p;
> > > map(**p)
> > > ```
> > > ? Shall it work? I.e. mapping of the whole array by dereferening the 
> > > pointer to the array.
> > No, it is not work currently.  What about *(*(p+a)+b)...
> My question - shall it work? Mapping  (**a)[:3] should result in the same in 
> the same code for **a if a is
> ```
> typedef int(T)[3];
> T** a;
> ```
Oh, that should work.  I add additional test for that.

```
typedef int(T)[3];
void bar()
{

T** a;
int b[2][3];
int (*p)[3] = b;
a =  &p;
printf("%p %p p %p\n", &a, b, *p);
for (int i = 0; i< 3; i++) {
  (**a)[1] = i;
}
#pragma omp target map((**a)[:3])
{
 (**a)[1]=5;
  // CHECK: 5
  printf("a = %d\n", (**a)[1]);
}
}
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-06 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 502842.
jyu2 added a comment.

Add additional test as Alexey asked.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,51 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+}
+typedef int(T)[3];
+void bar()
+{
+  T** a;
+  int b[2][3];
+  int (*p)[3] = b;
+  a =  &p;
+  for (int i = 0; i< 3; i++) {
+(**a)[1] = i;
+  }
+  #pragma omp target map((**a)[:3])
+  {
+   (**a)[1] = 4;
+// CHECK: 4
+printf("%d\n", (**a)[1]);
+  }
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+  bar();
+}
Index: clang/test/OpenMP/target_map_deref_array_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,131 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern void *malloc (int __size) throw () __attribute__ ((__malloc__));
+
+void foo(int **t1d)
+{
+  *t1d = (int *) malloc(3 * sizeof(int));
+  for (int j=0; j < 3; j++)
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;
+}
+
+#endif
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 8, i64 12]
+// CHECK: @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 33, i64 17]
+// CHECK-LABEL: define {{[^@]+}}@_Z3fooPPi
+// CHECK-SAME: (ptr noundef [[T1D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T1D_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[J:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:store ptr [[T1D]], ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noalias noundef ptr @_Z6malloci(i32 noundef signext 12) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[CALL]], ptr [[TMP0]], align 8
+// CHECK-NEXT:store i32 0, ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND:%.*]]
+// CHECK:   for.cond:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 3
+// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// CHECK:   for.body:
+// CHECK-NEXT:[[TMP2:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]]
+// CHECK-NEXT:store i32 1, ptr [[ARRAYIDX]], align 4
+// CHECK-NEXT:br label [[FOR_INC:%.*]]
+// CHECK:   for.inc:
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[INC:%.*]] = add nsw i32 [[TMP5]], 1
+// CHECK-NEXT:store i32 [[INC]], ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR

[PATCH] D145093: Add map info for dereference pointer.

2023-03-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 marked an inline comment as done.
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7489-7493
+  if (UO && UO->getOpcode() == UO_Deref)
+if (isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()) ||
+isa(Last->getAssociatedExpression()))
+  IsVarDerefAssoWithArray = true;

ABataev wrote:
> What if we have something like:
> ```
> typedef int (T)[3];
> 
> T** p;
> map(**p)
> ```
> ? Shall it work? I.e. mapping of the whole array by dereferening the pointer 
> to the array.
No, it is not work currently.  What about *(*(p+a)+b)...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 marked an inline comment as done.
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7487-7497
+  auto TNext = Next;
+  bool IsVarDerefAssoWithArray = false;
+  if (UO && UO->getOpcode() == UO_Deref)
+for (; TNext != CE; TNext = std::next(TNext))
+  if (isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > jyu2 wrote:
> > > > ABataev wrote:
> > > > > Why need a loop here? Can you somehow merge analysis for (*p) 
> > > > > expression with the pointer subscript analysis?
> > > > What about if you have three dereference pointers like (***a)[0:3]  or 
> > > > four pointers...
> > > Why you can't iterate through the required components just like for the 
> > > array subscrit expression?
> > Because currently, for unarray operator the map info is skipped following 
> > the rule:
> > 
> > bool IsNonDerefPointer = IsPointer && !UO && !BO && !IsNonContiguous;
> > 
> > So I need to check if it is dereference to array some how to not skip it.
> 1. Same problem in Sema too.
> 2. Can you try to fix it to avoid those loops?
Thanks.  I removed loop.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-03 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 502144.
jyu2 added a comment.

Thanks Alexey for the code review.  I removed loop by using last expression in 
the component for checking.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,33 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+}
Index: clang/test/OpenMP/target_map_deref_array_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,131 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern void *malloc (int __size) throw () __attribute__ ((__malloc__));
+
+void foo(int **t1d)
+{
+  *t1d = (int *) malloc(3 * sizeof(int));
+  for (int j=0; j < 3; j++)
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;
+}
+
+#endif
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 8, i64 12]
+// CHECK: @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 33, i64 17]
+// CHECK-LABEL: define {{[^@]+}}@_Z3fooPPi
+// CHECK-SAME: (ptr noundef [[T1D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T1D_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[J:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:store ptr [[T1D]], ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noalias noundef ptr @_Z6malloci(i32 noundef signext 12) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[CALL]], ptr [[TMP0]], align 8
+// CHECK-NEXT:store i32 0, ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND:%.*]]
+// CHECK:   for.cond:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 3
+// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// CHECK:   for.body:
+// CHECK-NEXT:[[TMP2:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]]
+// CHECK-NEXT:store i32 1, ptr [[ARRAYIDX]], align 4
+// CHECK-NEXT:br label [[FOR_INC:%.*]]
+// CHECK:   for.inc:
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[INC:%.*]] = add nsw i32 [[TMP5]], 1
+// CHECK-NEXT:store i32 [[INC]], ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND]], !llvm.loop [[LOOP4:![0-9]+]]
+// CHECK:   for.end:
+// CHECK-NEXT:[[TMP6:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP7:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8

[PATCH] D145093: Add map info for dereference pointer.

2023-03-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7487-7497
+  auto TNext = Next;
+  bool IsVarDerefAssoWithArray = false;
+  if (UO && UO->getOpcode() == UO_Deref)
+for (; TNext != CE; TNext = std::next(TNext))
+  if (isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > Why need a loop here? Can you somehow merge analysis for (*p) expression 
> > > with the pointer subscript analysis?
> > What about if you have three dereference pointers like (***a)[0:3]  or four 
> > pointers...
> Why you can't iterate through the required components just like for the array 
> subscrit expression?
Because currently, for unarray operator the map info is skipped following the 
rule:

bool IsNonDerefPointer = IsPointer && !UO && !BO && !IsNonContiguous;

So I need to check if it is dereference to array some how to not skip it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:7487-7497
+  auto TNext = Next;
+  bool IsVarDerefAssoWithArray = false;
+  if (UO && UO->getOpcode() == UO_Deref)
+for (; TNext != CE; TNext = std::next(TNext))
+  if (isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||
+  isa(TNext->getAssociatedExpression()) ||

ABataev wrote:
> Why need a loop here? Can you somehow merge analysis for (*p) expression with 
> the pointer subscript analysis?
What about if you have three dereference pointers like (***a)[0:3]  or four 
pointers...



Comment at: clang/lib/Sema/SemaOpenMP.cpp:2206-2207
 return false;
-
-  if (isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression())) {
-IsVariableAssociatedWithSection = true;
-// There is nothing more we need to know about this variable.
-return true;
+  auto Next = EI;
+  for (; Next != EE; Next = std::next(Next)) {
+if (isa(Next->getAssociatedExpression()) ||

ABataev wrote:
> Why do you need a loop here?
What about if you have three dereference pointers like (***a)[0:3]  or four 
pointers...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

> Yes, I understand. And did not ask for it. I just mean that a[0][:3] emits 
> different mapping data - TARGET_PAPARM|TO|FROM, PTR_AND_OBJ|TO|FROM

Oh I see.  I was think alloc for adding pointer.  But I now think I should just 
orignal maptype.  Changed thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 501921.
jyu2 added a comment.

Thanks Alexey for the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,33 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+}
Index: clang/test/OpenMP/target_map_deref_array_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,131 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern void *malloc (int __size) throw () __attribute__ ((__malloc__));
+
+void foo(int **t1d)
+{
+  *t1d = (int *) malloc(3 * sizeof(int));
+  for (int j=0; j < 3; j++)
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;
+}
+
+#endif
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 8, i64 12]
+// CHECK: @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 33, i64 17]
+// CHECK-LABEL: define {{[^@]+}}@_Z3fooPPi
+// CHECK-SAME: (ptr noundef [[T1D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T1D_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[J:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:store ptr [[T1D]], ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noalias noundef ptr @_Z6malloci(i32 noundef signext 12) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[CALL]], ptr [[TMP0]], align 8
+// CHECK-NEXT:store i32 0, ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND:%.*]]
+// CHECK:   for.cond:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 3
+// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// CHECK:   for.body:
+// CHECK-NEXT:[[TMP2:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]]
+// CHECK-NEXT:store i32 1, ptr [[ARRAYIDX]], align 4
+// CHECK-NEXT:br label [[FOR_INC:%.*]]
+// CHECK:   for.inc:
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[INC:%.*]] = add nsw i32 [[TMP5]], 1
+// CHECK-NEXT:store i32 [[INC]], ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND]], !llvm.loop [[LOOP4:![0-9]+]]
+// CHECK:   for.end:
+// CHECK-NEXT:[[TMP6:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP7:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP8:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHEC

[PATCH] D145093: Add map info for dereference pointer.

2023-03-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

> I mean we shall emit the same mapping for `(*a)[:3]` and for `a[0][:3]`

Yes I mean emit (*a)[:3] as a[0][:3]

The difficulty is during the process array section of 
OMPArraySectionExpr 0x12aa37e0 '' lvalue

| -ImplicitCastExpr 0x12a8a918 'int *'  |
| `-ArraySubscriptExpr 0x12a8a8d8 'int[3]':'int[3]' lvalue   |
|| 
-ImplicitCastExpr 0x12a8a8c0 'int (*)[3]'   
 |
|| `-DeclRefExpr 
0x12a8a880 'int (*)[3]' lvalue ParmVar 0x12a8a000 'a' 'int (*)[3]' |
| `-IntegerLiteral 0x12a8a8a0 'int' 0|
| -<<>>|
| -IntegerLiteral 0x12a8a8f8 'int' 3 |
|

`-<<>>

It is not easy to set section base as a[0].


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D145093#4164528 , @ABataev wrote:

> What result produces `map(a[0][:3]`?

Yes, that would be another way to fix the runtime problem.  However the 
difficulty is when process array section, section base is different.
with a[0][:3]
the section base is a[0]
with (*a)[:3], the section base is (*a);  It is hard to set a[0] as section 
base during processing the array section.

That is why I am adding dereference pointer not a[0].


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-01 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/test/OpenMP/target_map_deref_array_codegen.cpp:17
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;

ABataev wrote:
> Is this correct at all? This is not a pointer to the array, it is an array of 
> pointers, IIRC.
I am confuse about those two(pointer to array or array of pointer).  I thinks 
   int **tid ===  int (*t1d)[3], 
it is pointer to array.  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145093/new/

https://reviews.llvm.org/D145093

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145093: Add map info for dereference pointer.

2023-03-01 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added a project: OpenMP.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added a project: clang.

This is to fix run time problem when use:

int *a[3];
map((*a)[:3]) or (*a)[1].

current we skip generate map info for dereference pointer:
&(*a), &(*a)[0], 3*sizeof(int), TARGET_PARAM | TO | FROM

One way to fix runtime problem is to generate map info for dereference
pointer.

&(*a), &(*a), sizeof(pointer), ALLOC | TARGET_PARAM
&(*a), &(*a)[0], 3*sizeof(int),  PTR_AND_OBJ | TO | FROM

The change in CGOpenMPRuntime.cpp add that.

The change in SemaOpenMP is to fix variable of dereference array captured
by reference.  That is wrong. That cause run time to fail.

The rule is:
If variable is identified in a map clause it is always captured by
reference except if it is a pointer that is dereferenced somehow.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145093

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_deref_array_codegen.cpp
  openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Index: openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp
@@ -0,0 +1,33 @@
+// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+#include 
+#include 
+
+void foo(int **t1d) {
+  int ***t2d = &t1d;
+  int t3d = &t2d;
+  *t1d = (int *)malloc(3 * sizeof(int));
+  int j;
+
+  for (j = 0; j < 3; j++)
+(*t1d)[j] = 0;
+#pragma omp target map(tofrom : (*t1d)[0 : 3])
+  { (*t1d)[1] = 1; }
+  // CHECK: 1
+  printf("%d\n", (*t1d)[1]);
+#pragma omp target map(tofrom : (**t2d)[0 : 3])
+  { (**t2d)[1] = 2; }
+  // CHECK: 2
+  printf("%d\n", (**t2d)[1]);
+#pragma omp target map(tofrom : (***t3d)[0 : 3])
+  { (***t3d)[1] = 3; }
+  // CHECK: 3
+  printf("%d\n", (***t3d)[1]);
+}
+
+int main() {
+  int *data = 0;
+  foo(&data);
+}
Index: clang/test/OpenMP/target_map_deref_array_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,131 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern void *malloc (int __size) throw () __attribute__ ((__malloc__));
+
+void foo(int **t1d)
+{
+  *t1d = (int *) malloc(3 * sizeof(int));
+  for (int j=0; j < 3; j++)
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;
+}
+
+#endif
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 8, i64 12]
+// CHECK: @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 32, i64 17]
+// CHECK-LABEL: define {{[^@]+}}@_Z3fooPPi
+// CHECK-SAME: (ptr noundef [[T1D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T1D_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[J:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:store ptr [[T1D]], ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noalias noundef ptr @_Z6malloci(i32 noundef signext 12) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:store ptr [[CALL]], ptr [[TMP0]], align 8
+// CHECK-NEXT:store i32 0, ptr [[J]], align 4
+// CHECK-NEXT:br label [[FOR_COND:%.*]]
+// CHECK:   for.cond:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[J]], align 4
+// CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 3
+// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// CHECK:   for.body:
+// CHECK-NEXT:[[TMP2:%.*]] = load ptr, ptr [[T1D_ADDR]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8
+// CHECK-NEXT

[PATCH] D144616: Skip generating this[:1] map info for non-member variable.

2023-02-23 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b72a3276243: Skip using this[:1] map info for non-member 
variable. (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144616/new/

https://reviews.llvm.org/D144616

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -55,6 +55,26 @@
 { res = A + B; }
   }
 };
+struct descriptor {
+  int A;
+  int C;
+};
+
+class BASE {};
+
+class C : public BASE {
+public:
+  void bar(descriptor &d) {
+auto Asize = 4;
+auto Csize = 4;
+
+#pragma omp target data map(to : d.A) map(from : d.C)
+{
+#pragma omp target teams firstprivate(Csize)
+  d.C = 1;
+}
+  }
+};
 
 int main(int argc, char *argv[]) {
   B b(2, 3);
@@ -65,4 +85,10 @@
   c.run();
   // CHECK: 5
   printf("c.res = %d \n", c.res);
+
+  descriptor d;
+  C z;
+  z.bar(d);
+  // CHECK 1
+  printf("%d\n", d.C);
 }
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -1,20 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
 // RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
 // RUN:   | FileCheck %s
 
 // expected-no-diagnostics
 
-// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
-// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
 
-// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
-// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
-// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
-// CHECK-NEXT:ret void
-//
 class A {
 protected:
   int X;
@@ -29,28 +20,91 @@
   using A::Y;
 public:
   int res;
-// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+  B (int x, int y) : A(x,y), res{0} {}
+  void run (void) {
+  #pragma omp target
+ res = X + Y;
+  }
+};
+
+template
+struct descriptor
+{
+  T *A;
+  T *C;
+  T *C_ref;
+  unsigned M;
+  unsigned K;
+  unsigned N;
+};
+
+class BASE
+{
+};
+
+//template
+class C : public BASE
+{
+public:
+  void bar (descriptor &d)
+  {
+ auto Asize = d.M * d.K;
+ auto Csize = d.M * d.N;
+ #pragma omp target data map(to:d.A[0:Asize]) map(from:d.C[0:Csize])
+ {
+   #pragma omp target teams firstprivate(Csize)
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
+ }
+   }
+};
+
+void foo() {
+  B b(2, 3);
+  b.run();
+  C c;
+  descriptor d;
+  c.bar(d);
+}
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:[[C:%.*]] = alloca [[CLASS_C:%.*]], align 1
+// CHECK-NEXT:[[D:%.*]] = alloca [[STRUCT_DESCRIPTOR:%.*]], align 8
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:call void @_ZN1C3barER10descriptorIfE(ptr noundef nonnull align 1 dereferenceable(1) [[C]], ptr noundef nonnull align 8 dereferenceable(40) [[D]])
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(12) [[THIS:%.*]], i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) unnamed_addr #[[ATTR1:[0-9]+]] comdat align 2 {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
-// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
-// CHECK-NEXT:

[PATCH] D144616: Skip generating this[:1] map info for non-member variable.

2023-02-22 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added a project: OpenMP.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added a project: clang.

This fix runtime problem due to generate this[:1] map info for non member 
variable.

To fix this check VD, if VD is not null, it is not member from current or base 
classes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144616

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -55,6 +55,26 @@
 { res = A + B; }
   }
 };
+struct descriptor {
+  int A;
+  int C;
+};
+
+class BASE {};
+
+class C : public BASE {
+public:
+  void bar(descriptor &d) {
+auto Asize = 4;
+auto Csize = 4;
+
+#pragma omp target data map(to : d.A) map(from : d.C)
+{
+#pragma omp target teams firstprivate(Csize)
+  d.C = 1;
+}
+  }
+};
 
 int main(int argc, char *argv[]) {
   B b(2, 3);
@@ -65,4 +85,10 @@
   c.run();
   // CHECK: 5
   printf("c.res = %d \n", c.res);
+
+  descriptor d;
+  C z;
+  z.bar(d);
+  // CHECK 1
+  printf("%d\n", d.C);
 }
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -1,20 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
 // RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
 // RUN:   | FileCheck %s
 
 // expected-no-diagnostics
 
-// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
-// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
 
-// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
-// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
-// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
-// CHECK-NEXT:ret void
-//
 class A {
 protected:
   int X;
@@ -29,28 +20,91 @@
   using A::Y;
 public:
   int res;
-// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+  B (int x, int y) : A(x,y), res{0} {}
+  void run (void) {
+  #pragma omp target
+ res = X + Y;
+  }
+};
+
+template
+struct descriptor
+{
+  T *A;
+  T *C;
+  T *C_ref;
+  unsigned M;
+  unsigned K;
+  unsigned N;
+};
+
+class BASE
+{
+};
+
+//template
+class C : public BASE
+{
+public:
+  void bar (descriptor &d)
+  {
+ auto Asize = d.M * d.K;
+ auto Csize = d.M * d.N;
+ #pragma omp target data map(to:d.A[0:Asize]) map(from:d.C[0:Csize])
+ {
+   #pragma omp target teams firstprivate(Csize)
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
+ }
+   }
+};
+
+void foo() {
+  B b(2, 3);
+  b.run();
+  C c;
+  descriptor d;
+  c.bar(d);
+}
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:[[C:%.*]] = alloca [[CLASS_C:%.*]], align 1
+// CHECK-NEXT:[[D:%.*]] = alloca [[STRUCT_DESCRIPTOR:%.*]], align 8
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:call void @_ZN1C3barER10descriptorIfE(ptr noundef nonnull align 1 dereferenceable(1) [[C]], ptr noundef nonnull align 8 dereferenceable(40) [[D]])
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(12) [[THIS:%.*]], i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) unnamed_addr #[[ATTR1:[0-9]+]] comdat align 2 {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, al

[PATCH] D127855: [OpenMP] Basic parse and sema support for modifiers in order clause

2023-01-17 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Hi @sandeepkosuri, do you plan to fix this?  Thanks.  Jennifer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127855/new/

https://reviews.llvm.org/D127855

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-01-13 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

That part of code is original add for is_device_address, so I just wonder, if 
the change could break is_device_address?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141627/new/

https://reviews.llvm.org/D141627

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127855: [OpenMP] Basic parse and sema support for modifiers in order clause

2023-01-12 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D127855#3956014 , @sandeepkosuri 
wrote:

> As I do not have commit access, can someone commit this patch, now that it 
> passes the pre-merge tests ?

I see some tests failed after this patch.  Failed only with -fopenmp-vesion=51

https://www.godbolt.org/z/3oxWTcxn7


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127855/new/

https://reviews.llvm.org/D127855

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-10 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfe29a1695a6c: This is to fix runtime problem for member data 
used in target region. (authored by jyu2).

Changed prior to commit:
  https://reviews.llvm.org/D141350?vs=487845&id=488041#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141350/new/

https://reviews.llvm.org/D141350

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -0,0 +1,68 @@
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+extern "C" int printf(const char *, ...);
+template  class A {
+protected:
+  T X;
+  T Y;
+
+public:
+  A(T x, T y) : X{x}, Y{y} {};
+};
+
+template  class B : public A {
+  using A::X;
+  using A::Y;
+
+public:
+  T res;
+
+  B(T x, T y) : A(x, y), res{0} {};
+
+  void run(void) {
+#pragma omp target map(res)
+{ res = X + Y; }
+  }
+};
+
+class X {
+protected:
+  int A;
+
+public:
+  X(int a) : A{a} {};
+};
+class Y : public X {
+  using X::A;
+
+protected:
+  int B;
+
+public:
+  Y(int a, int b) : X(a), B{b} {};
+};
+class Z : public Y {
+  using X::A;
+  using Y::B;
+
+public:
+  int res;
+  Z(int a, int b) : Y(a, b), res{0} {};
+  void run(void) {
+#pragma omp target map(res)
+{ res = A + B; }
+  }
+};
+
+int main(int argc, char *argv[]) {
+  B b(2, 3);
+  b.run();
+  // CHECK: 5
+  printf("b.res = %d \n", b.res);
+  Z c(2, 3);
+  c.run();
+  // CHECK: 5
+  printf("c.res = %d \n", c.res);
+}
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -0,0 +1,122 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
+// RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+
+// expected-no-diagnostics
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:ret void
+//
+class A {
+protected:
+  int X;
+  int Y;
+
+public:
+  A (int x, int y) : X { x }, Y { y } { };
+};
+
+class B : public A {
+  using A::X;
+  using A::Y;
+public:
+  int res;
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:store i32 [[X:%.*]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT:store i32 [[Y:%.*]], ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:call void @_ZN1BC2Eii(ptr noundef nonnull align 4 dereferenceable(12) [[THIS1]], i32 noundef [[TMP0]], i32 noundef [[TMP1]])
+// CHECK-NEXT:ret void
+//
+  B (int x, int y) : A(x,y), res{0} {}
+// CHECK-LABEL: define {{[^@]+}}@_ZN1B3runEv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NOT: sdiv exact i64 {{.*}}, ptrtoint
+// CHECK-NEXT:[[RES:%.*]] = getelementptr inbounds [[CLASS_B:%.*]], ptr [[THIS1]], i32 0, i32 1
+// CHECK-NEXT:[[X:%.*]] = getelementptr inbounds [[CLASS_A:%.*]], ptr [[THIS1]], i32 0, i32 0
+// CHECK-NEXT:[[Y:%.*]] = getelementptr inbounds [[CLASS_A]], ptr [[THIS1]], i32 0, i32 1
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [4 x ptr], ptr [[DOTOFFLOAD_BASEPTRS]]

[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-10 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8490
+if (MD)
+  if (const CXXRecordDecl *RD = dyn_cast(MD->getParent()))
+HasBaseClass = RD->getNumBases() > 0;

ABataev wrote:
> `const auto *RD = dyn_cast(MD->getParent())`. Also, can we use 
> `MD->getParent()->getAsCXXRecordDecl()`?
Thank!  Changed.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8493
 // There should not be a mapper for a combined entry.
+if (MD && HasBaseClass) {
+  // OpenMP 5.2 148:21:

ABataev wrote:
> MD is true if HasBaseClass is true
Sorry, changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141350/new/

https://reviews.llvm.org/D141350

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-10 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 487845.
jyu2 added a comment.

Thanks Alexey for code review.  This is to address his comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141350/new/

https://reviews.llvm.org/D141350

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -0,0 +1,64 @@
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+extern "C" int printf(const char *, ...);
+template  class A {
+protected:
+  T X;
+  T Y;
+
+public:
+  A(T x, T y) : X{x}, Y{y} {};
+};
+
+template  class B : public A {
+  using A::X;
+  using A::Y;
+
+public:
+  T res;
+
+  B(T x, T y) : A(x, y), res{0} {};
+
+  void run(void) {
+#pragma omp target map(res)
+{ res = X + Y; }
+  }
+};
+
+class X {
+protected:
+  int A;
+public:
+  X (int a) : A {a} {};
+};
+class Y : public X {
+  using X::A;
+protected:
+  int B;
+public:
+  Y (int a, int b) : X(a), B{b} {};
+};
+class Z : public Y {
+  using X::A;
+  using Y::B;
+public:
+  int res;
+  Z(int a, int b): Y(a,b), res{0} {};
+  void run(void) {
+#pragma omp target map(res)
+{ res = A + B; }
+  }
+};
+
+int main(int argc, char *argv[]) {
+  B b(2, 3);
+  b.run();
+  // CHECK: 5
+  printf("b.res = %d \n", b.res);
+  Z c(2,3);
+  c.run();
+  // CHECK: 5
+  printf("c.res = %d \n", c.res);
+}
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -0,0 +1,122 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
+// RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+
+// expected-no-diagnostics
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:ret void
+//
+class A {
+protected:
+  int X;
+  int Y;
+
+public:
+  A (int x, int y) : X { x }, Y { y } { };
+};
+
+class B : public A {
+  using A::X;
+  using A::Y;
+public:
+  int res;
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:store i32 [[X:%.*]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT:store i32 [[Y:%.*]], ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:call void @_ZN1BC2Eii(ptr noundef nonnull align 4 dereferenceable(12) [[THIS1]], i32 noundef [[TMP0]], i32 noundef [[TMP1]])
+// CHECK-NEXT:ret void
+//
+  B (int x, int y) : A(x,y), res{0} {}
+// CHECK-LABEL: define {{[^@]+}}@_ZN1B3runEv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NOT: sdiv exact i64 {{.*}}, ptrtoint
+// CHECK-NEXT:[[RES:%.*]] = getelementptr inbounds [[CLASS_B:%.*]], ptr [[THIS1]], i32 0, i32 1
+// CHECK-NEXT:[[X:%.*]] = getelementptr inbounds [[CLASS_A:%.*]], ptr [[THIS1]], i32 0, i32 0
+// CHECK-NEXT:[[Y:%.*]] = getelementptr inbounds [[CLASS_A]], ptr [[THIS1]], i32 0, i32 1
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [4 x ptr], ptr [[DOTOFFLOAD_BASEPTRS]], i32 0, i32 0
+// CHECK-NEXT:store ptr [[THIS1]], ptr [[TMP0]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds [4 x ptr], ptr [[DOTOFFLOAD_PTRS]], i32 0, i32 0
+// CHECK-NEXT:store ptr [[T

[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-09 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D141350#4038619 , @ye-luo wrote:

> Does this patch work when there are more than one level of inheritance? For 
> example `class B: public A; class C: public B`

Yes, that works.  For that we emit this[:1] instead.   I can add more test that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141350/new/

https://reviews.llvm.org/D141350

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141350: Fix runtime problem for base class member data used in target region.

2023-01-09 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert, mikerice.
jyu2 added a project: OpenMP.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added a project: clang.

The problem is happened when base class member field is used in target
region , the size is wrong, cause runtime to fail. Currently the size of
calculation is depended on index of field, since field is in base class,
the calculation is wrong.

According OpenMP 5.2 148:21:
If the target construct is within a class non-static member function,
and a variable is an accessible data member of the object for which the
non-static data member function is invoked, the variable is treated as
if the this[:1] expression had appeared in a map clause with a map-type
of tofrom.

One way to fix this is emitting code to generate this[:1] instead only
when class has any base class.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141350

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -0,0 +1,35 @@
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 \
+// RUN: | %fcheck-generic
+
+extern "C" int printf(const char *, ...);
+template  class A {
+protected:
+  T X;
+  T Y;
+
+public:
+  A(T x, T y) : X{x}, Y{y} {};
+};
+
+template  class B : public A {
+  using A::X;
+  using A::Y;
+
+public:
+  T res;
+
+  B(T x, T y) : A(x, y), res{0} {};
+
+  void run(void) {
+#pragma omp target map(res)
+{ res = X + Y; }
+  }
+};
+
+int main(int argc, char *argv[]) {
+  B b(2, 3);
+  b.run();
+  // CHECK: 5
+  printf("b.res = %d \n", b.res);
+}
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -0,0 +1,122 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
+// RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+
+// expected-no-diagnostics
+
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:ret void
+//
+class A {
+protected:
+  int X;
+  int Y;
+
+public:
+  A (int x, int y) : X { x }, Y { y } { };
+};
+
+class B : public A {
+  using A::X;
+  using A::Y;
+public:
+  int res;
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:store i32 [[X:%.*]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT:store i32 [[Y:%.*]], ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:call void @_ZN1BC2Eii(ptr noundef nonnull align 4 dereferenceable(12) [[THIS1]], i32 noundef [[TMP0]], i32 noundef [[TMP1]])
+// CHECK-NEXT:ret void
+//
+  B (int x, int y) : A(x,y), res{0} {}
+// CHECK-LABEL: define {{[^@]+}}@_ZN1B3runEv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [4 x ptr], align 8
+// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
+// CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK-NOT: sdiv exact i64 {{.*}}, ptrtoint
+// CHECK-NEXT:[[RES:%.*]] = getelementptr inbounds [[CLASS_B:%.*]], ptr [[THIS1]], i32 0, i32 1
+// CHECK-NEXT:[[X:%.*]] = getelementptr inbounds [[CLASS_A:%.*]], ptr [[THIS1]], i32 0, i32 0
+// CHECK-NEXT:[[Y:%.*]] = getelementptr inbounds [[CLASS_A]], ptr [[THIS1]], i32 0, i32 1
+// CHECK

[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-08 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf781f704239: [OPENMP51]Codegen for error directive. 
(authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139166/new/

https://reviews.llvm.org/D139166

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/error_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -198,6 +198,7 @@
 __OMP_RTL(__kmpc_barrier, false, Void, IdentPtr, Int32)
 __OMP_RTL(__kmpc_cancel, false, Int32, IdentPtr, Int32, Int32)
 __OMP_RTL(__kmpc_cancel_barrier, false, Int32, IdentPtr, Int32)
+__OMP_RTL(__kmpc_error, false, Void, IdentPtr, Int32, Int8Ptr)
 __OMP_RTL(__kmpc_flush, false, Void, IdentPtr)
 __OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr)
 __OMP_RTL(__kmpc_get_hardware_thread_id_in_block, false, Int32, )
Index: clang/test/OpenMP/error_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/error_codegen.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fopenmp -fopenmp-version=51 -triple x86_64 \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -std=c++11 -fopenmp-simd -fopenmp-version=51 \
+// RUN:  -debug-info-kind=limited -triple x86_64 -emit-llvm -o - %s |  \
+// RUN:  FileCheck  --check-prefix SIMD %s
+
+//CHECK: @.str = private unnamed_addr constant [23 x i8] c"GPU compiler required.\00", align 1
+//CHECK: @0 = private unnamed_addr constant {{.*}}error_codegen.cpp;main;52;1;;\00", align 1
+//CHECK: @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @0 }, align 8
+//CHECK: @.str.1 = private unnamed_addr constant [27 x i8] c"Note this is functioncall.\00", align 1
+//CHECK: @2 = private unnamed_addr constant {{.*}}error_codegen.cpp;main;54;1;;\00", align 1
+//CHECK: @3 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @2 }, align 8
+//CHECK: @.str.2 = private unnamed_addr constant [23 x i8] c"GNU compiler required.\00", align 1
+//CHECK: @4 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;29;1;;\00", align 1
+//CHECK: @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @4 }, align 8
+//CHECK: @.str.3 = private unnamed_addr constant [22 x i8] c"Notice: add for loop.\00", align 1
+//CHECK: @6 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;32;1;;\00", align 1
+//CHECK: @7 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @6 }, align 8
+//CHECK: @8 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;38;1;;\00", align 1
+//CHECK: @9 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @8 }, align 8
+
+void foo() {}
+
+template 
+int tmain(T argc, char **argv) {
+  T b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp error at(execution) severity(fatal) message("GNU compiler required.")
+  a = argv[0][0];
+  ++a;
+#pragma omp error at(execution) severity(warning) message("Notice: add for loop.")
+  {
+int b = 10;
+T c = 100;
+a = b + c;
+  }
+#pragma omp  error at(execution) severity(fatal) message("GPU compiler required.")
+  foo();
+return N;
+}
+// CHECK-LABEL: @main(
+// SIMD-LABEL: @main(
+// CHECK:call void @__kmpc_error(ptr @1, i32 2, ptr @.str)
+// SIMD-NOT:call void @__kmpc_error(ptr @1, i32 2, ptr @.str)
+// CHECK:call void @__kmpc_error(ptr @3, i32 1, ptr @.str.1)
+// SIMD-NOT:call void @__kmpc_error(ptr @3, i32 1, ptr @.str.1)
+//
+int main (int argc, char **argv) {
+  int b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp error at(execution) severity(fatal) message("GPU compiler required.")
+   a=2;
+#pragma omp error at(execution) severity(warning) message("Note this is functioncall.")
+  foo();
+  tmain(argc, argv);
+}
+
+//CHECK-LABEL: @_Z5tmainIiLi10EEiT_PPc(
+//SIMD-LABEL: @_Z5tmainIiLi10EEiT_PPc(
+//CHECK: call void @__kmpc_error(ptr @5, i32 2, ptr @.str.2)
+//CHECK: call void @__kmpc_error(ptr @7, i32 1, ptr @.str.3)
+//CHECK: call void @__kmpc_error(ptr @9, i32 2, ptr @.str)
+//SIMD-NOT: call void @__kmpc_error(ptr @5, i32 2, ptr @.str.2)
+//SIMD-NOT: call void @__kmpc_error(ptr @7, i32 1, ptr @.str.3)
+//SIMD-NOT: call void @__kmpc_error(ptr @9, i32 2, ptr @.str)
+//CHECK: ret i32 10
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5246,7 +5246,13 @@
 }
 
 void CodeGenFunction::EmitOMPErrorDire

[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-08 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:334
   llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
-  unsigned Flags = 0);
+  unsigned Flags = 0, bool EmitLoc = false);
 

ABataev wrote:
> Why do you need this location? To output it for the user in the runtime 
> library call?
Thanks Alexey!
Yes.  When run time emit error, the location will be presented like:

OMP: Warning #283: test_error_directive.cpp:6:1: Encountered user-directed 
warning: 2 or more procs required..

...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139166/new/

https://reviews.llvm.org/D139166

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-08 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 481319.
jyu2 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139166/new/

https://reviews.llvm.org/D139166

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/error_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -198,6 +198,7 @@
 __OMP_RTL(__kmpc_barrier, false, Void, IdentPtr, Int32)
 __OMP_RTL(__kmpc_cancel, false, Int32, IdentPtr, Int32, Int32)
 __OMP_RTL(__kmpc_cancel_barrier, false, Int32, IdentPtr, Int32)
+__OMP_RTL(__kmpc_error, false, Void, IdentPtr, Int32, Int8Ptr)
 __OMP_RTL(__kmpc_flush, false, Void, IdentPtr)
 __OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr)
 __OMP_RTL(__kmpc_get_hardware_thread_id_in_block, false, Int32, )
Index: clang/test/OpenMP/error_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/error_codegen.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fopenmp -fopenmp-version=51 -triple x86_64 \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -std=c++11 -fopenmp-simd -fopenmp-version=51 \
+// RUN:  -debug-info-kind=limited -triple x86_64 -emit-llvm -o - %s |  \
+// RUN:  FileCheck  --check-prefix SIMD %s
+
+//CHECK: @.str = private unnamed_addr constant [23 x i8] c"GPU compiler required.\00", align 1
+//CHECK: @0 = private unnamed_addr constant {{.*}}error_codegen.cpp;main;52;1;;\00", align 1
+//CHECK: @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @0 }, align 8
+//CHECK: @.str.1 = private unnamed_addr constant [27 x i8] c"Note this is functioncall.\00", align 1
+//CHECK: @2 = private unnamed_addr constant {{.*}}error_codegen.cpp;main;54;1;;\00", align 1
+//CHECK: @3 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @2 }, align 8
+//CHECK: @.str.2 = private unnamed_addr constant [23 x i8] c"GNU compiler required.\00", align 1
+//CHECK: @4 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;29;1;;\00", align 1
+//CHECK: @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @4 }, align 8
+//CHECK: @.str.3 = private unnamed_addr constant [22 x i8] c"Notice: add for loop.\00", align 1
+//CHECK: @6 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;32;1;;\00", align 1
+//CHECK: @7 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @6 }, align 8
+//CHECK: @8 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;38;1;;\00", align 1
+//CHECK: @9 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @8 }, align 8
+
+void foo() {}
+
+template 
+int tmain(T argc, char **argv) {
+  T b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp error at(execution) severity(fatal) message("GNU compiler required.")
+  a = argv[0][0];
+  ++a;
+#pragma omp error at(execution) severity(warning) message("Notice: add for loop.")
+  {
+int b = 10;
+T c = 100;
+a = b + c;
+  }
+#pragma omp  error at(execution) severity(fatal) message("GPU compiler required.")
+  foo();
+return N;
+}
+// CHECK-LABEL: @main(
+// SIMD-LABEL: @main(
+// CHECK:call void @__kmpc_error(ptr @1, i32 2, ptr @.str)
+// SIMD-NOT:call void @__kmpc_error(ptr @1, i32 2, ptr @.str)
+// CHECK:call void @__kmpc_error(ptr @3, i32 1, ptr @.str.1)
+// SIMD-NOT:call void @__kmpc_error(ptr @3, i32 1, ptr @.str.1)
+//
+int main (int argc, char **argv) {
+  int b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp error at(execution) severity(fatal) message("GPU compiler required.")
+   a=2;
+#pragma omp error at(execution) severity(warning) message("Note this is functioncall.")
+  foo();
+  tmain(argc, argv);
+}
+
+//CHECK-LABEL: @_Z5tmainIiLi10EEiT_PPc(
+//SIMD-LABEL: @_Z5tmainIiLi10EEiT_PPc(
+//CHECK: call void @__kmpc_error(ptr @5, i32 2, ptr @.str.2)
+//CHECK: call void @__kmpc_error(ptr @7, i32 1, ptr @.str.3)
+//CHECK: call void @__kmpc_error(ptr @9, i32 2, ptr @.str)
+//SIMD-NOT: call void @__kmpc_error(ptr @5, i32 2, ptr @.str.2)
+//SIMD-NOT: call void @__kmpc_error(ptr @7, i32 1, ptr @.str.3)
+//SIMD-NOT: call void @__kmpc_error(ptr @9, i32 2, ptr @.str)
+//CHECK: ret i32 10
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5246,7 +5246,13 @@
 }
 
 void CodeGenFunction::EmitOMPErrorDirective(const OMPErrorDirective &S) {
-  llvm_unreachable("CodeGen for 'omp error' is not supported yet.");
+  const OMPMessageClause *MC = S.getSingle

[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:334
   llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
-  unsigned Flags = 0);
+  unsigned Flags = 0, bool EmitLoc = false);
 

jyu2 wrote:
> jdoerfert wrote:
> > Why the new argument?
> Emit error without -g (debug info turn on.)
Hi @jdoerfert, 
Thanks for your review.  I added comment on what meaning of  EmitLoc as:

/// \param EmitLoc emit source location with debug-info is off.

Do you mean that is not clear to you?  Any suggestion?

Thanks.
Jennifer



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139166/new/

https://reviews.llvm.org/D139166

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:334
   llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
-  unsigned Flags = 0);
+  unsigned Flags = 0, bool EmitLoc = false);
 

jdoerfert wrote:
> Why the new argument?
Emit error without -g (debug info turn on.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139166/new/

https://reviews.llvm.org/D139166

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139166: [OPENMP51] Codegen support for error directive.

2022-12-01 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert, mikerice.
jyu2 added projects: OpenMP, clang.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added a project: LLVM.

Added codegen for `error` directive.
Generate IR to call: void __kmpc_error(ident_t *loc, int severity, const char 
*message);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139166

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/error_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -198,6 +198,7 @@
 __OMP_RTL(__kmpc_barrier, false, Void, IdentPtr, Int32)
 __OMP_RTL(__kmpc_cancel, false, Int32, IdentPtr, Int32, Int32)
 __OMP_RTL(__kmpc_cancel_barrier, false, Int32, IdentPtr, Int32)
+__OMP_RTL(__kmpc_error, false, Void, IdentPtr, Int32, Int8Ptr)
 __OMP_RTL(__kmpc_flush, false, Void, IdentPtr)
 __OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr)
 __OMP_RTL(__kmpc_get_hardware_thread_id_in_block, false, Int32, )
Index: clang/test/OpenMP/error_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/error_codegen.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fopenmp -fopenmp-version=51 -triple x86_64 \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -std=c++11 -fopenmp-simd -fopenmp-version=51 \
+// RUN:  -debug-info-kind=limited -triple x86_64 -emit-llvm -o - %s |  \
+// RUN:  FileCheck  --check-prefix SIMD %s
+
+//CHECK: @.str = private unnamed_addr constant [23 x i8] c"GPU compiler required.\00", align 1
+//CHECK: @0 = private unnamed_addr constant {{.*}}error_codegen.cpp;main;52;1;;\00", align 1
+//CHECK: @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @0 }, align 8
+//CHECK: @.str.1 = private unnamed_addr constant [27 x i8] c"Note this is functioncall.\00", align 1
+//CHECK: @2 = private unnamed_addr constant {{.*}}error_codegen.cpp;main;54;1;;\00", align 1
+//CHECK: @3 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @2 }, align 8
+//CHECK: @.str.2 = private unnamed_addr constant [23 x i8] c"GNU compiler required.\00", align 1
+//CHECK: @4 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;29;1;;\00", align 1
+//CHECK: @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @4 }, align 8
+//CHECK: @.str.3 = private unnamed_addr constant [22 x i8] c"Notice: add for loop.\00", align 1
+//CHECK: @6 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;32;1;;\00", align 1
+//CHECK: @7 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @6 }, align 8
+//CHECK: @8 = private unnamed_addr constant {{.*}}error_codegen.cpp;tmain;38;1;;\00", align 1
+//CHECK: @9 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr @8 }, align 8
+
+void foo() {}
+
+template 
+int tmain(T argc, char **argv) {
+  T b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp error at(execution) severity(fatal) message("GNU compiler required.")
+  a = argv[0][0];
+  ++a;
+#pragma omp error at(execution) severity(warning) message("Notice: add for loop.")
+  {
+int b = 10;
+T c = 100;
+a = b + c;
+  }
+#pragma omp  error at(execution) severity(fatal) message("GPU compiler required.")
+  foo();
+return N;
+}
+// CHECK-LABEL: @main(
+// SIMD-LABEL: @main(
+// CHECK:call void @__kmpc_error(ptr @1, i32 2, ptr @.str)
+// SIMD-NOT:call void @__kmpc_error(ptr @1, i32 2, ptr @.str)
+// CHECK:call void @__kmpc_error(ptr @3, i32 1, ptr @.str.1)
+// SIMD-NOT:call void @__kmpc_error(ptr @3, i32 1, ptr @.str.1)
+//
+int main (int argc, char **argv) {
+  int b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp error at(execution) severity(fatal) message("GPU compiler required.")
+   a=2;
+#pragma omp error at(execution) severity(warning) message("Note this is functioncall.")
+  foo();
+  tmain(argc, argv);
+}
+
+//CHECK-LABEL: @_Z5tmainIiLi10EEiT_PPc(
+//SIMD-LABEL: @_Z5tmainIiLi10EEiT_PPc(
+//CHECK: call void @__kmpc_error(ptr @5, i32 2, ptr @.str.2)
+//CHECK: call void @__kmpc_error(ptr @7, i32 1, ptr @.str.3)
+//CHECK: call void @__kmpc_error(ptr @9, i32 2, ptr @.str)
+//SIMD-NOT: call void @__kmpc_error(ptr @5, i32 2, ptr @.str.2)
+//SIMD-NOT: call void @__kmpc_error(ptr @7, i32 1, ptr @.str.3)
+//SIMD-NOT: call void @__kmpc_error(ptr @9, i32 2, ptr @.str)
+//CHECK: ret i32 10
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp

[PATCH] D138312: [OPENMP5.1] Initial support for message clause.

2022-11-18 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 closed this revision.
jyu2 added a comment.

checked with 9d90cf2fca44 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138312/new/

https://reviews.llvm.org/D138312

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138312: [OPENMP5.1] Initial support for message clause.

2022-11-18 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11048
   SeverityClauses.empty() ? nullptr : (*SeverityClauses.begin());
+  auto MessageClauses =
+  OMPExecutableDirective::getClausesOfKind(Clauses);

ABataev wrote:
> Use real type instead of auto
Thanks.  How about using getSingleClause.  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138312/new/

https://reviews.llvm.org/D138312

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138312: [OPENMP5.1] Initial support for message clause.

2022-11-18 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 476534.
jyu2 added a comment.

Thanks Alexey for the review.  Address his comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138312/new/

https://reviews.llvm.org/D138312

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/error_ast_print.cpp
  clang/test/OpenMP/error_message.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -307,6 +307,9 @@
 def OMPC_Severity : Clause<"severity"> {
   let clangClass = "OMPSeverityClause";
 }
+def OMPC_Message : Clause<"message"> {
+  let clangClass = "OMPMessageClause";
+}
 def OMPC_Allocate : Clause<"allocate"> {
   let clangClass = "OMPAllocateClause";
   let flangClass = "OmpAllocateClause";
@@ -536,7 +539,8 @@
 def OMP_Error : Directive<"error"> {
   let allowedClauses = [
 VersionedClause,
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_TaskWait : Directive<"taskwait"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1870,6 +1870,7 @@
 CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
 CHECK_SIMPLE_CLAUSE(At, OMPC_at)
 CHECK_SIMPLE_CLAUSE(Severity, OMPC_severity)
+CHECK_SIMPLE_CLAUSE(Message, OMPC_message)
 CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
 CHECK_SIMPLE_CLAUSE(When, OMPC_when)
 CHECK_SIMPLE_CLAUSE(AdjustArgs, OMPC_adjust_args)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2447,6 +2447,8 @@
 
 void OMPClauseEnqueue::VisitOMPSeverityClause(const OMPSeverityClause *) {}
 
+void OMPClauseEnqueue::VisitOMPMessageClause(const OMPMessageClause *) {}
+
 void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
   Visitor->AddStmt(C->getDevice());
 }
Index: clang/test/OpenMP/error_message.cpp
===
--- clang/test/OpenMP/error_message.cpp
+++ clang/test/OpenMP/error_message.cpp
@@ -94,6 +94,26 @@
 #pragma omp error at(execution) severity(warning) // no error, diagnosic at runtime
 #pragma omp error at(compilation) severity(fatal) // expected-error {{ERROR}}
 #pragma omp error at(execution) severity(fatal) // no error, error at runtime
+
+#pragma omp error message("GPU compiler is needed.") // expected-error {{GPU compiler is needed}}
+#pragma omp error at(compilation) message("GPU compiler is needed.") // expected-error {{GPU compiler is needed}}
+#pragma omp error at(execution) message("GPU compiler is needed.") // no error
+// expected-warning@+1 {{GPU compiler is needed.}}
+#pragma omp error severity(warning) message("GPU compiler is needed.") // expected-warning {{GPU compiler is needed.}}
+#pragma omp error severity(fatal) message("GPU compiler is needed.") // expected-error {{GPU compiler is needed}}
+// expected-warning@+1 {{GPU compiler is needed.}}
+#pragma omp error at(compilation) severity(warning) message("GPU compiler is needed.") // expected-warning {{GPU compiler is needed.}}
+#pragma omp error at(compilation) severity(fatal) message("GPU compiler is needed.") // expected-error {{GPU compiler is needed.}}
+#pragma omp error at(execution) severity(warning) message("GPU compiler is needed.") // no warning warning will emit at runtime.
+#pragma omp error at(execution) severity(fatal) message("GPU compiler is needed.") // no warning warning will emit at runtime.
+
+// expected-error@+1 {{GPU compiler is needed.}}
+#pragma omp error message("GPU compiler is needed.") message("GPU compiler is needed.") // expected-error {{directive '#pragma omp error' cannot contain more than one 'message' clause}}
+  int a;
+// expected-warning@+1 {{expected string literal in 'clause message' - ignoring}}
+#pragma omp error message(a) // expected-error {{ERROR}}
+// expected-error@+1 {{ERROR}}
+#pragma omp error message() // expected-error {{expected expression}}
   return T();
 }
 
Index: clang/test/OpenMP/error_ast_print.cpp
===
--- clang/test/OpenMP/error_ast_print.cpp
+++ clang/test/OpenMP/error_ast_print.

  1   2   3   4   >