[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-20 Thread Xiang Li via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
python3kgae marked an inline comment as done.
Closed by commit rG7e04c0ad6325: [HLSL] Add groupshare address space. (authored 
by python3kgae).

Changed prior to commit:
  https://reviews.llvm.org/D135060?vs=469048=469259#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/Parser/opencl-cxx-keywords.cl
  clang/test/ParserHLSL/group_shared.hlsl
  clang/test/ParserHLSL/group_shared_202x.hlsl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared_202x.hlsl
  clang/test/SemaOpenCL/address-spaces.cl
  clang/test/SemaOpenCL/invalid-kernel.cl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaOpenCL/invalid-kernel.cl
===
--- clang/test/SemaOpenCL/invalid-kernel.cl
+++ clang/test/SemaOpenCL/invalid-kernel.cl
@@ -13,14 +13,14 @@
   return 0;
 }
 
-int* global x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* global x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* local x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* local x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* constant x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* constant x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -231,12 +231,12 @@
 }
 #endif
 
-__private int func_return_priv(void);   //expected-error {{return value cannot be qualified with address space}}
-__global int func_return_global(void);  //expected-error {{return value cannot be qualified with address space}}
-__local int func_return_local(void);//expected-error {{return value cannot be qualified with address space}}
-__constant int func_return_constant(void);  //expected-error {{return value cannot be qualified with address space}}
+__private int func_return_priv(void);   //expected-error {{return type cannot be qualified with address space}}
+__global int func_return_global(void);  //expected-error {{return type cannot be qualified with address space}}
+__local int func_return_local(void);//expected-error {{return type cannot be qualified with address space}}
+__constant int func_return_constant(void);  //expected-error {{return type cannot be qualified with address space}}
 #if __OPENCL_C_VERSION__ >= 200
-__generic int func_return_generic(void);//expected-error {{return value cannot be qualified with address space}}
+__generic int func_return_generic(void);//expected-error {{return type cannot be qualified with address space}}
 #endif
 
 void func_multiple_addr(void) {
Index: clang/test/SemaHLSL/group_shared_202x.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared_202x.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -std=hlsl202x  -o - -fsyntax-only %s -verify
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+auto func() 

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/ParserHLSL/group_shared_202x.hlsl:5-6
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+auto l = []() -> groupshared void {};
+// expected-error@+1 {{expected a type}}

python3kgae wrote:
> aaron.ballman wrote:
> > One test I think we need in SemaCXX for this is what happens when the 
> > lambda return type (or function return type) is deduced. e.g.,
> > ```
> > extern groupshared float f;
> > 
> > auto func() {
> >   return f;
> > }
> > 
> > void other() {
> >   [&]() { return f; };
> > }
> > ```
> > Does use of `return f` cause us to deduce a return type that's annotated 
> > with `groupshared` or does that get stripped off thanks to lvalue to rvalue 
> > conversions and so we deduce `float`?
> groupshared is stripped because of lvalue to rvalue conversions.
> 
> And even hlsl202x not enable CXX14 :( .
Excellent, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-19 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked 3 inline comments as done.
python3kgae added inline comments.



Comment at: clang/test/ParserHLSL/group_shared_202x.hlsl:5-6
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+auto l = []() -> groupshared void {};
+// expected-error@+1 {{expected a type}}

aaron.ballman wrote:
> One test I think we need in SemaCXX for this is what happens when the lambda 
> return type (or function return type) is deduced. e.g.,
> ```
> extern groupshared float f;
> 
> auto func() {
>   return f;
> }
> 
> void other() {
>   [&]() { return f; };
> }
> ```
> Does use of `return f` cause us to deduce a return type that's annotated with 
> `groupshared` or does that get stripped off thanks to lvalue to rvalue 
> conversions and so we deduce `float`?
groupshared is stripped because of lvalue to rvalue conversions.

And even hlsl202x not enable CXX14 :( .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-19 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 469048.
python3kgae added a comment.

Update comments and add more test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/Parser/opencl-cxx-keywords.cl
  clang/test/ParserHLSL/group_shared.hlsl
  clang/test/ParserHLSL/group_shared_202x.hlsl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared_202x.hlsl
  clang/test/SemaOpenCL/address-spaces.cl
  clang/test/SemaOpenCL/invalid-kernel.cl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaOpenCL/invalid-kernel.cl
===
--- clang/test/SemaOpenCL/invalid-kernel.cl
+++ clang/test/SemaOpenCL/invalid-kernel.cl
@@ -13,14 +13,14 @@
   return 0;
 }
 
-int* global x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* global x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* local x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* local x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* constant x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* constant x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -231,12 +231,12 @@
 }
 #endif
 
-__private int func_return_priv(void);   //expected-error {{return value cannot be qualified with address space}}
-__global int func_return_global(void);  //expected-error {{return value cannot be qualified with address space}}
-__local int func_return_local(void);//expected-error {{return value cannot be qualified with address space}}
-__constant int func_return_constant(void);  //expected-error {{return value cannot be qualified with address space}}
+__private int func_return_priv(void);   //expected-error {{return type cannot be qualified with address space}}
+__global int func_return_global(void);  //expected-error {{return type cannot be qualified with address space}}
+__local int func_return_local(void);//expected-error {{return type cannot be qualified with address space}}
+__constant int func_return_constant(void);  //expected-error {{return type cannot be qualified with address space}}
 #if __OPENCL_C_VERSION__ >= 200
-__generic int func_return_generic(void);//expected-error {{return value cannot be qualified with address space}}
+__generic int func_return_generic(void);//expected-error {{return type cannot be qualified with address space}}
 #endif
 
 void func_multiple_addr(void) {
Index: clang/test/SemaHLSL/group_shared_202x.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared_202x.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -std=hlsl202x  -o - -fsyntax-only %s -verify
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+auto func() -> groupshared void;
+
+// expected-error@+1 {{parameter may not be qualified with an address space}}
+auto func(float groupshared) -> void;
+
+// expected-error@+1 {{parameter 

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:10083
 }
+// HLSL not support address space on a function return type declaration.
+LangAS AddressSpace = NewFD->getReturnType().getAddressSpace();





Comment at: clang/lib/Sema/SemaLambda.cpp:977
+  if (!RetTy.isNull()) {
+// HLSL not support address space on a lambda return type declaration.
+LangAS AddressSpace = RetTy.getAddressSpace();





Comment at: clang/test/ParserHLSL/group_shared_202x.hlsl:5-6
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+auto l = []() -> groupshared void {};
+// expected-error@+1 {{expected a type}}

One test I think we need in SemaCXX for this is what happens when the lambda 
return type (or function return type) is deduced. e.g.,
```
extern groupshared float f;

auto func() {
  return f;
}

void other() {
  [&]() { return f; };
}
```
Does use of `return f` cause us to deduce a return type that's annotated with 
`groupshared` or does that get stripped off thanks to lvalue to rvalue 
conversions and so we deduce `float`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-13 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 467383.
python3kgae marked an inline comment as done.
python3kgae added a comment.

Add hlsl202x test for C++ 11 features like lambda.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/Parser/opencl-cxx-keywords.cl
  clang/test/ParserHLSL/group_shared.hlsl
  clang/test/ParserHLSL/group_shared_202x.hlsl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared_202x.hlsl
  clang/test/SemaOpenCL/address-spaces.cl
  clang/test/SemaOpenCL/invalid-kernel.cl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaOpenCL/invalid-kernel.cl
===
--- clang/test/SemaOpenCL/invalid-kernel.cl
+++ clang/test/SemaOpenCL/invalid-kernel.cl
@@ -13,14 +13,14 @@
   return 0;
 }
 
-int* global x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* global x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* local x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* local x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* constant x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* constant x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -231,12 +231,12 @@
 }
 #endif
 
-__private int func_return_priv(void);   //expected-error {{return value cannot be qualified with address space}}
-__global int func_return_global(void);  //expected-error {{return value cannot be qualified with address space}}
-__local int func_return_local(void);//expected-error {{return value cannot be qualified with address space}}
-__constant int func_return_constant(void);  //expected-error {{return value cannot be qualified with address space}}
+__private int func_return_priv(void);   //expected-error {{return type cannot be qualified with address space}}
+__global int func_return_global(void);  //expected-error {{return type cannot be qualified with address space}}
+__local int func_return_local(void);//expected-error {{return type cannot be qualified with address space}}
+__constant int func_return_constant(void);  //expected-error {{return type cannot be qualified with address space}}
 #if __OPENCL_C_VERSION__ >= 200
-__generic int func_return_generic(void);//expected-error {{return value cannot be qualified with address space}}
+__generic int func_return_generic(void);//expected-error {{return type cannot be qualified with address space}}
 #endif
 
 void func_multiple_addr(void) {
Index: clang/test/SemaHLSL/group_shared_202x.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared_202x.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -std=hlsl202x  -o - -fsyntax-only %s -verify
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+auto func() -> groupshared void;
+
+// expected-error@+1 {{parameter may not be qualified with an address space}}
+auto func(float 

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-13 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked 2 inline comments as done.
python3kgae added inline comments.



Comment at: clang/test/ParserHLSL/group_shared.hlsl:11
+// expected-warning@+1 {{'auto' type specifier is a C++11 extension}}
+auto l = []() groupshared  {};
+

beanz wrote:
> What happens to this if you set the language standard to hlsl 202x? I setup 
> 202x in Clang to be C++11-based since I think that is the direction 202x will 
> take (still a lot unsure about the exact features).
hlsl 202x works!
I'll need to add more tests for hlsl 202x since lambda compiles.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-12 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/ParserHLSL/group_shared.hlsl:11
+// expected-warning@+1 {{'auto' type specifier is a C++11 extension}}
+auto l = []() groupshared  {};
+

What happens to this if you set the language standard to hlsl 202x? I setup 
202x in Clang to be C++11-based since I think that is the direction 202x will 
take (still a lot unsure about the exact features).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-12 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked 2 inline comments as done.
python3kgae added inline comments.



Comment at: clang/test/SemaHLSL/group_shared.hlsl:57
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);

aaron.ballman wrote:
> Some other Sema test cases that would be useful:
> ```
> // Do we reject it on a return type in a function pointer?
> groupshared void (*fp)();
> // What about on parameters in a function pointer?
> void (*fp2)(groupshared float);
> // Trailing return types?
> auto func() -> groupshared void;
> // What about in a novel qualifier order?
> void groupshared f();
> 
> struct S {
>   // Do we reject it as a function qualifier on a member function?
>   void f() groupshared;
> };
> 
> // Does it impact size or alignment?
> static_assert(sizeof(float) == sizeof(groupshared float));
> static_assert(alignof(double) == alignof(groupshared double));
> 
> // Does it impact type identity for templates?
> template 
> struct S {
>   static constexpr bool value = false;
> };
> 
> template <>
> struct S {
>   static constexpr bool value = true;
> };
> static_assert(!S::value);
> static_assert(S::value);
> 
> // Can you overload based on the qualifier?
> void func(float f) {}
> void func(groupshared float f) {} // Error on redefinition?
> ```
> (Note, I'm taking guesses on some of these test cases; if I've guessed wrong, 
> feel free to correct me!)
> 
> I'd also expect tests to show up in ParserHLSL testing the parsing behavior:
> ```
> // Do we accept novel qualifier orders?
> extern groupshared float f;
> extern float groupshared f; // Ok, redeclaration?
> 
> // Can we parse it on a lambda? Note, be sure to add more lambda tests with 
> // more complex parsing situations to make sure you're happy with the parsing
> // behavior.
> []() groupshared {};
> 
> // Can we still parse attributes written on the type?
> float groupshared [[]] i = 12;
> ```
Unfortunately, things like pointer and lambda are not supported in HLSL yet.
So some tests will not work.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-12 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 467285.
python3kgae marked 2 inline comments as done.
python3kgae added a comment.

Add SubjectList<[Var]> and add tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/Parser/opencl-cxx-keywords.cl
  clang/test/ParserHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaOpenCL/address-spaces.cl
  clang/test/SemaOpenCL/invalid-kernel.cl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaOpenCL/invalid-kernel.cl
===
--- clang/test/SemaOpenCL/invalid-kernel.cl
+++ clang/test/SemaOpenCL/invalid-kernel.cl
@@ -13,14 +13,14 @@
   return 0;
 }
 
-int* global x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* global x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* local x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* local x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* constant x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* constant x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -231,12 +231,12 @@
 }
 #endif
 
-__private int func_return_priv(void);   //expected-error {{return value cannot be qualified with address space}}
-__global int func_return_global(void);  //expected-error {{return value cannot be qualified with address space}}
-__local int func_return_local(void);//expected-error {{return value cannot be qualified with address space}}
-__constant int func_return_constant(void);  //expected-error {{return value cannot be qualified with address space}}
+__private int func_return_priv(void);   //expected-error {{return type cannot be qualified with address space}}
+__global int func_return_global(void);  //expected-error {{return type cannot be qualified with address space}}
+__local int func_return_local(void);//expected-error {{return type cannot be qualified with address space}}
+__constant int func_return_constant(void);  //expected-error {{return type cannot be qualified with address space}}
 #if __OPENCL_C_VERSION__ >= 200
-__generic int func_return_generic(void);//expected-error {{return value cannot be qualified with address space}}
+__generic int func_return_generic(void);//expected-error {{return type cannot be qualified with address space}}
 #endif
 
 void func_multiple_addr(void) {
Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,107 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-warning@+2 {{'groupshared' attribute only applies to variables}}
+// expected-error@+1 {{return type cannot be qualified with address space}}
+ groupshared float foo() {

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-12 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:4063
+  let Spellings = [Keyword<"groupshared">];
+  let Documentation = [HLSLGroupSharedAddressSpaceDocs];
+}

Shouldn't this have `let Subjects = SubjectList<[Var]>;`?

I don't think we support `groupshared` on anything except variable declarations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:10299
   Error<"attribute %0 can only be applied to an OpenCL kernel function">;
-def err_opencl_return_value_with_address_space : Error<
-  "return value cannot be qualified with address space">;
+def err_opencl_hlsl_return_value_with_address_space : Error<
+  "return type cannot be qualified with address space">;

I think we can drop the opencl and hlsl from the name at this point.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11710
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
-
 // Layout randomization diagnostics.

Looks like this change can be reverted out.



Comment at: clang/lib/Parse/ParseDecl.cpp:4344
+case tok::kw_groupshared:
+  ParseHLSLQualifiers(DS.getAttributes());
+  break;

It took me a while to convince myself that this was correct -- the token is 
consumed at the end of the `while` loop.



Comment at: clang/lib/Parse/ParseDecl.cpp:5841
+case tok::kw_groupshared:
+  ParseHLSLQualifiers(DS.getAttributes());
+  break;

Same thing here -- the end of the `while` loop is what consumes the token, so 
this is also correct.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1410
+  ParseHLSLQualifiers(DS.getAttributes());
+  ConsumeToken();
+}

And this consume is correct because the parse function doesn't consume any 
tokens.



Comment at: clang/test/SemaHLSL/group_shared.hlsl:57
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);

Some other Sema test cases that would be useful:
```
// Do we reject it on a return type in a function pointer?
groupshared void (*fp)();
// What about on parameters in a function pointer?
void (*fp2)(groupshared float);
// Trailing return types?
auto func() -> groupshared void;
// What about in a novel qualifier order?
void groupshared f();

struct S {
  // Do we reject it as a function qualifier on a member function?
  void f() groupshared;
};

// Does it impact size or alignment?
static_assert(sizeof(float) == sizeof(groupshared float));
static_assert(alignof(double) == alignof(groupshared double));

// Does it impact type identity for templates?
template 
struct S {
  static constexpr bool value = false;
};

template <>
struct S {
  static constexpr bool value = true;
};
static_assert(!S::value);
static_assert(S::value);

// Can you overload based on the qualifier?
void func(float f) {}
void func(groupshared float f) {} // Error on redefinition?
```
(Note, I'm taking guesses on some of these test cases; if I've guessed wrong, 
feel free to correct me!)

I'd also expect tests to show up in ParserHLSL testing the parsing behavior:
```
// Do we accept novel qualifier orders?
extern groupshared float f;
extern float groupshared f; // Ok, redeclaration?

// Can we parse it on a lambda? Note, be sure to add more lambda tests with 
// more complex parsing situations to make sure you're happy with the parsing
// behavior.
[]() groupshared {};

// Can we still parse attributes written on the type?
float groupshared [[]] i = 12;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-11 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:4045
+def HLSLGroupSharedAddressSpace : TypeAttr {
+  let Spellings = [Keyword<"groupshared">, Clang<"groupshared">];
+  let Documentation = [HLSLGroupSharedAddressSpaceDocs];

aaron.ballman wrote:
> So this is being exposed as both a keyword and an attribute? Why? (No tests 
> are using it as an attribute.)
It should be only keyword. I misunderstood what the Clang<> means here :(



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1408
+// Parse HLSL addr space attribute.
+if (Tok.is(tok::kw_groupshared)) {
+  ParseHLSLQualifiers(DS.getAttributes());

aaron.ballman wrote:
> Do you expect to add more address spaces for HLSL? Do we want a helper 
> function here for `isHLSLQualifier()` instead?
> 
> Also, there's no test coverage for this change.
Added isHLSLQualifier.
Maybe not other address space in a short term but will need other qualifiers 
for sure. :)

HLSL doesn't support lambda at this moment.
Should I just remove this and add it back when lambda is supported?



Comment at: clang/lib/Sema/SemaDecl.cpp:14927-14931
+  if (ResultType.getAddressSpace() != LangAS::Default && getLangOpts().HLSL) {
+Diag(FD->getLocation(),
+ diag::err_hlsl_attribute_address_function_return_type);
+FD->setInvalidDecl();
+  }

aaron.ballman wrote:
> Why is this being done from `ActOnStartOfFunctionDef()` instead of 
> `CheckFunctionReturnType()`?
> 
> We're missing test coverage for specifying this on a function declaration, a 
> friend function declaration, or a member function (declaration or definition).
> 
> What about non-function situations like conversion operators? Can you write 
> `operator groupshared int() const;` ?
Moved to ActOnFunctionDeclarator following 
err_opencl_return_value_with_address_space.
Also added tests.
operator overload is not supported in current version of hlsl though.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-11 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 466925.
python3kgae marked 12 inline comments as done.
python3kgae added a comment.

Code cleanup to match comments.
Reuse opencl error.
Fix typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/Parser/opencl-cxx-keywords.cl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaOpenCL/address-spaces.cl
  clang/test/SemaOpenCL/invalid-kernel.cl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaOpenCL/invalid-kernel.cl
===
--- clang/test/SemaOpenCL/invalid-kernel.cl
+++ clang/test/SemaOpenCL/invalid-kernel.cl
@@ -13,14 +13,14 @@
   return 0;
 }
 
-int* global x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* global x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* local x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* local x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
 
-int* constant x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+int* constant x(int* x) { // expected-error {{return type cannot be qualified with address space}}
   return x + 1;
 }
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -231,12 +231,12 @@
 }
 #endif
 
-__private int func_return_priv(void);   //expected-error {{return value cannot be qualified with address space}}
-__global int func_return_global(void);  //expected-error {{return value cannot be qualified with address space}}
-__local int func_return_local(void);//expected-error {{return value cannot be qualified with address space}}
-__constant int func_return_constant(void);  //expected-error {{return value cannot be qualified with address space}}
+__private int func_return_priv(void);   //expected-error {{return type cannot be qualified with address space}}
+__global int func_return_global(void);  //expected-error {{return type cannot be qualified with address space}}
+__local int func_return_local(void);//expected-error {{return type cannot be qualified with address space}}
+__constant int func_return_constant(void);  //expected-error {{return type cannot be qualified with address space}}
 #if __OPENCL_C_VERSION__ >= 200
-__generic int func_return_generic(void);//expected-error {{return value cannot be qualified with address space}}
+__generic int func_return_generic(void);//expected-error {{return type cannot be qualified with address space}}
 #endif
 
 void func_multiple_addr(void) {
Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-error@+1 {{return type cannot be qualified with address space}}
+ groupshared float foo() {
+  static groupshared float foo0;
+return 1;
+ }
+// expected-error@+1 {{return type cannot 

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

At a high-level: can you make sure that functional changes all have 
corresponding test coverage?




Comment at: clang/include/clang/Basic/Attr.td:4045
+def HLSLGroupSharedAddressSpace : TypeAttr {
+  let Spellings = [Keyword<"groupshared">, Clang<"groupshared">];
+  let Documentation = [HLSLGroupSharedAddressSpaceDocs];

So this is being exposed as both a keyword and an attribute? Why? (No tests are 
using it as an attribute.)



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11703-11704
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
-
+def err_hlsl_attribute_address_function_return_type : Error<
+  "function return type may not be qualified with an address space">;
 // Layout randomization diagnostics.

It looks like `err_opencl_return_value_with_address_space` could be modified to 
make this work. (The existing phrasing of 'return value' is strange and I'd be 
fine changing that to 'return type' instead.)



Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:59
+Generic,  // ptr64
+Generic,  // hlsl_gourpshared
 };





Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:83
+Generic, // ptr64
+Generic, // hlsl_gourpshared
 





Comment at: clang/lib/Basic/Targets/DirectX.h:44
+0, // ptr64
+3, // hlsl_gourpshared
 };





Comment at: clang/lib/Basic/Targets/NVPTX.h:46
+0, // ptr64
+0, // hlsl_gourpshared
 };





Comment at: clang/lib/Basic/Targets/SPIR.h:46
+0, // ptr64
+0, // hlsl_gourpshared
 };





Comment at: clang/lib/Basic/Targets/SPIR.h:76
+0, // ptr64
+0, // hlsl_gourpshared
 };





Comment at: clang/lib/Basic/Targets/TCE.h:53
 0, // ptr64
+0, // hlsl_gourpshared
 };





Comment at: clang/lib/Basic/Targets/X86.h:47
+272, // ptr64
+0,   // hlsl_gourpshared
 };





Comment at: clang/lib/Parse/ParseExprCXX.cpp:1408
+// Parse HLSL addr space attribute.
+if (Tok.is(tok::kw_groupshared)) {
+  ParseHLSLQualifiers(DS.getAttributes());

Do you expect to add more address spaces for HLSL? Do we want a helper function 
here for `isHLSLQualifier()` instead?

Also, there's no test coverage for this change.



Comment at: clang/lib/Sema/SemaDecl.cpp:14927-14931
+  if (ResultType.getAddressSpace() != LangAS::Default && getLangOpts().HLSL) {
+Diag(FD->getLocation(),
+ diag::err_hlsl_attribute_address_function_return_type);
+FD->setInvalidDecl();
+  }

Why is this being done from `ActOnStartOfFunctionDef()` instead of 
`CheckFunctionReturnType()`?

We're missing test coverage for specifying this on a function declaration, a 
friend function declaration, or a member function (declaration or definition).

What about non-function situations like conversion operators? Can you write 
`operator groupshared int() const;` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

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


[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-09 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 466382.
python3kgae added a comment.

Change Category to DocCatVariable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+ groupshared float foo() {
+  static groupshared float foo0;
+return 1;
+ }
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+  groupshared void bar() {
+extern groupshared float bar0;
+  }
+ 
+  struct S {
+// expected-error@+1 {{field may not be qualified with an address space}}
+groupshared float f;
+static groupshared float g;
+  };
+
+  // expected-error@+1 {{parameter may not be qualified with an address space}}
+  float foo2(groupshared float a) {
+return a;
+  }
+
+// expected-note@+2 {{parameter may not be qualified with an address space}}
+template
+  T tfoo(T t) {
+ return t;
+  }
+  // expected-warning@+1 {{alias declarations are a C++11 extension}}
+ using GSF = groupshared float;
+ GSF gs;
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);
Index: clang/test/CodeGenHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/group_shared.hlsl
@@ -0,0 +1,15 @@
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// Make sure groupshared translated into address space 3.
+// CHECK:@"?a@@3PAMA" = addrspace(3) global [10 x float]
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+ }
+
Index: clang/test/AST/HLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/group_shared.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s | FileCheck %s
+
+//CHECK:VarDecl 0x[[A:[0-9a-f]+]] <{{.*}} col:24> col:20 used a 'groupshared float[10]'
+ groupshared float a[10];
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> line:[[@LINE+2]]:7 main 'void ()'
+ [numthreads(8,8,1)]
+ void main() {
+// CHECK:BinaryOperator 0x{{[0-9a-f]+}} <{{.*}}> 'groupshared float' lvalue '='
+// CHECK:ArraySubscriptExpr 0x{{[0-9a-f]+}}  'groupshared float' lvalue
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'groupshared float *' 
+// CHECK:DeclRefExpr 0x{{[0-9a-f]+}}  'groupshared float[10]' lvalue Var 0x[[A]] 'a' 'groupshared float[10]'
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 0
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 1
+   a[0] = 1;
+ }
+
+
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 8 1
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ 

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-06 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 465661.
python3kgae added a comment.

Fix test fail caused by max address space change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared.hlsl
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
 }
 
 template 
Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+ groupshared float foo() {
+  static groupshared float foo0;
+return 1;
+ }
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+  groupshared void bar() {
+extern groupshared float bar0;
+  }
+ 
+  struct S {
+// expected-error@+1 {{field may not be qualified with an address space}}
+groupshared float f;
+static groupshared float g;
+  };
+
+  // expected-error@+1 {{parameter may not be qualified with an address space}}
+  float foo2(groupshared float a) {
+return a;
+  }
+
+// expected-note@+2 {{parameter may not be qualified with an address space}}
+template
+  T tfoo(T t) {
+ return t;
+  }
+  // expected-warning@+1 {{alias declarations are a C++11 extension}}
+ using GSF = groupshared float;
+ GSF gs;
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);
Index: clang/test/CodeGenHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/group_shared.hlsl
@@ -0,0 +1,15 @@
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// Make sure groupshared translated into address space 3.
+// CHECK:@"?a@@3PAMA" = addrspace(3) global [10 x float]
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+ }
+ 
\ No newline at end of file
Index: clang/test/AST/HLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/group_shared.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s | FileCheck %s
+
+//CHECK:VarDecl 0x[[A:[0-9a-f]+]] <{{.*}} col:24> col:20 used a 'groupshared float[10]'
+ groupshared float a[10];
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> line:[[@LINE+2]]:7 main 'void ()'
+ [numthreads(8,8,1)]
+ void main() {
+// CHECK:BinaryOperator 0x{{[0-9a-f]+}} <{{.*}}> 'groupshared float' lvalue '='
+// CHECK:ArraySubscriptExpr 0x{{[0-9a-f]+}}  'groupshared float' lvalue
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'groupshared float *' 
+// CHECK:DeclRefExpr 0x{{[0-9a-f]+}}  'groupshared float[10]' lvalue Var 0x[[A]] 'a' 'groupshared float[10]'
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 0
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 1
+   a[0] = 1;
+ }
+
+
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 8 1
Index: clang/lib/Sema/SemaType.cpp

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-05 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 465628.
python3kgae added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared.hlsl

Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+ groupshared float foo() {
+  static groupshared float foo0;
+return 1;
+ }
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+  groupshared void bar() {
+extern groupshared float bar0;
+  }
+ 
+  struct S {
+// expected-error@+1 {{field may not be qualified with an address space}}
+groupshared float f;
+static groupshared float g;
+  };
+
+  // expected-error@+1 {{parameter may not be qualified with an address space}}
+  float foo2(groupshared float a) {
+return a;
+  }
+
+// expected-note@+2 {{parameter may not be qualified with an address space}}
+template
+  T tfoo(T t) {
+ return t;
+  }
+  // expected-warning@+1 {{alias declarations are a C++11 extension}}
+ using GSF = groupshared float;
+ GSF gs;
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);
Index: clang/test/CodeGenHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/group_shared.hlsl
@@ -0,0 +1,15 @@
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// Make sure groupshared translated into address space 3.
+// CHECK:@"?a@@3PAMA" = addrspace(3) global [10 x float]
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+ }
+ 
\ No newline at end of file
Index: clang/test/AST/HLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/group_shared.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s | FileCheck %s
+
+//CHECK:VarDecl 0x[[A:[0-9a-f]+]] <{{.*}} col:24> col:20 used a 'groupshared float[10]'
+ groupshared float a[10];
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> line:[[@LINE+2]]:7 main 'void ()'
+ [numthreads(8,8,1)]
+ void main() {
+// CHECK:BinaryOperator 0x{{[0-9a-f]+}} <{{.*}}> 'groupshared float' lvalue '='
+// CHECK:ArraySubscriptExpr 0x{{[0-9a-f]+}}  'groupshared float' lvalue
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'groupshared float *' 
+// CHECK:DeclRefExpr 0x{{[0-9a-f]+}}  'groupshared float[10]' lvalue Var 0x[[A]] 'a' 'groupshared float[10]'
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 0
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 1
+   a[0] = 1;
+ }
+
+
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 8 1
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2898,6 +2898,8 @@
   if (T.isVolatileQualified() && getLangOpts().CPlusPlus20)
 Diag(Loc, diag::warn_deprecated_volatile_return) << T;
 
+  if (T.getAddressSpace() != LangAS::Default && getLangOpts().HLSL)
+return true;
   return false;
 }
 
@@ -6775,6 +6777,8 @@
 // The keyword-based type attributes imply which address space to use.
 ASIdx = S.getLangOpts().SYCLIsDevice ? Attr.asSYCLLangAS()
  : Attr.asOpenCLLangAS();
+if (S.getLangOpts().HLSL)
+  ASIdx = Attr.asHLSLLangAS();
 
 if (ASIdx == LangAS::Default)
   

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-03 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: pow2clk, beanz, bogner.
Herald added subscribers: kosarev, Anastasia, mattd, gchakrabarti, asavonic, 
kerbowa, jvesely.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added subscribers: cfe-commits, jholewinski.
Herald added a project: clang.

Added keyword, LangAS and TypeAttrbute for groupshared.

Tanslate it to LangAS with asHLSLLangAS.

Make sure it translated into address space 3 for DirectX target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared.hlsl

Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+ groupshared float foo() {
+  static groupshared float foo0;
+return 1;
+ }
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+  groupshared void bar() {
+extern groupshared float bar0;
+  }
+ 
+  struct S {
+// expected-error@+1 {{field may not be qualified with an address space}}
+groupshared float f;
+static groupshared float g;
+  };
+
+  // expected-error@+1 {{parameter may not be qualified with an address space}}
+  float foo2(groupshared float a) {
+return a;
+  }
+
+// expected-note@+2 {{parameter may not be qualified with an address space}}
+template
+  T tfoo(T t) {
+ return t;
+  }
+  // expected-warning@+1 {{alias declarations are a C++11 extension}}
+ using GSF = groupshared float;
+ GSF gs;
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);
Index: clang/test/CodeGenHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/group_shared.hlsl
@@ -0,0 +1,15 @@
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// Make sure groupshared translated into address space 3.
+// CHECK:@"?a@@3PAMA" = addrspace(3) global [10 x float]
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+ }
+ 
\ No newline at end of file
Index: clang/test/AST/HLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/group_shared.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s | FileCheck %s
+
+//CHECK:VarDecl 0x[[A:[0-9a-f]+]] <{{.*}} col:24> col:20 used a 'groupshared float[10]'
+ groupshared float a[10];
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> line:[[@LINE+2]]:7 main 'void ()'
+ [numthreads(8,8,1)]
+ void main() {
+// CHECK:BinaryOperator 0x{{[0-9a-f]+}} <{{.*}}> 'groupshared float' lvalue '='
+// CHECK:ArraySubscriptExpr 0x{{[0-9a-f]+}}  'groupshared float' lvalue
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'groupshared float *' 
+// CHECK:DeclRefExpr 0x{{[0-9a-f]+}}  'groupshared float[10]' lvalue Var 0x[[A]] 'a' 'groupshared float[10]'
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 0
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 1
+   a[0] = 1;
+ }
+
+
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 8 1
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2898,6 +2898,8 @@
   if (T.isVolatileQualified() && getLangOpts().CPlusPlus20)
 Diag(Loc, diag::warn_deprecated_volatile_return) << T;
 
+  if (T.getAddressSpace() != LangAS::Default &&