[clang] [NFC][HLSL][DX] Update invalid environment tests (PR #81052)

2024-02-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota approved this pull request.


https://github.com/llvm/llvm-project/pull/81052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Prevent null pointer dereference in DiagnoseDeclAvailability() (PR #97095)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota approved this pull request.


https://github.com/llvm/llvm-project/pull/97095
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Prevent null pointer dereference in DiagnoseDeclAvailability() (PR #97095)

2024-07-01 Thread Helena Kotas via cfe-commits

hekota wrote:

Thanks!

https://github.com/llvm/llvm-project/pull/97095
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Implement `export` keyword (PR #96823)

2024-07-01 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - %s 
-verify
+
+export void f1();
+
+export void f1() {}
+
+namespace { // expected-note {{anonymous namespace begins here}}
+export void f2(); // expected-error {{export declaration appears within 
anonymous namespace}}
+}
+
+export void f3();
+
+export { // expected-note {{export block begins here}}
+void f4() {}
+export void f5() {} // expected-error {{export declaration appears within 
another export declaration}}

hekota wrote:

Each export creates a new ExportDecl node in the AST three and limiting it to 
just one make it cleaner. I am not aware of any specific reason other than 
maybe this and to keep the syntax and parsing code identical to C++ modules 
export.

https://github.com/llvm/llvm-project/pull/96823
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Implement `export` keyword (PR #96823)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed https://github.com/llvm/llvm-project/pull/96823
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/97352

Implements availability diagnostic on `export` functions. 

For shader libraries the HLSL availability diagnostic should run on all entry 
points and export functions. Now that the `export` keyword is implemented, we 
can detect which functions are exported and run the diagnostic on them.

Exported functions can be nested in namespaces and in export declarations so we 
need to scan not just the current translation unit but also namespace and 
export declarations contexts.

Fixes #92073

>From b67ecd20cc2c11f4f99c2d90c95fdbd988659947 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 26 Jun 2024 12:31:39 -0700
Subject: [PATCH 1/4] [HLSL] Implement `export` keyword

Fixes #92812
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  8 +++
 clang/lib/Parse/Parser.cpp|  2 +-
 clang/lib/Sema/SemaModule.cpp | 32 
 clang/test/AST/HLSL/export.hlsl   | 23 +
 clang/test/CodeGenHLSL/export.hlsl| 20 
 clang/test/SemaHLSL/export.hlsl   | 50 +++
 7 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/HLSL/export.hlsl
 create mode 100644 clang/test/CodeGenHLSL/export.hlsl
 create mode 100644 clang/test/SemaHLSL/export.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 25a87078a5709..a2465ecc936e0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12265,6 +12265,9 @@ def warn_hlsl_availability_unavailable :
   Warning,
   InGroup, DefaultError;
 
+def err_hlsl_export_not_on_function : Error<
+  "export declaration can only be used on functions">;
+
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
   "a randomized struct can only be initialized with a designated initializer">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 5e3ee5f0579aa..226377e93fe56 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -445,6 +445,14 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
 /// 'export' declaration
 /// 'export' '{' declaration-seq[opt] '}'
 ///
+/// HLSL: Parse export function declaration.
+///
+///  export-function-declaration: 
+/// 'export' function-declaration
+/// 
+///  export-declaration-group:
+/// 'export' '{' function-declaration-seq[opt] '}'
+///
 Decl *Parser::ParseExportDeclaration() {
   assert(Tok.is(tok::kw_export));
   SourceLocation ExportLoc = ConsumeToken();
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 6d0cf7b174e50..ddc8aa9b49e64 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -970,7 +970,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
 SingleDecl = ParseModuleImport(SourceLocation(), IS);
   } break;
   case tok::kw_export:
-if (getLangOpts().CPlusPlusModules) {
+if (getLangOpts().CPlusPlusModules || getLangOpts().HLSL) {
   ProhibitAttributes(Attrs);
   SingleDecl = ParseExportDeclaration();
   break;
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index ad118ac90e4aa..e920b880ecb4d 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -851,6 +851,21 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation 
ExportLoc,
   CurContext->addDecl(D);
   PushDeclContext(S, D);
 
+  if (getLangOpts().HLSL) {
+// exported functions cannot be in an unnamed namespace
+for (const DeclContext *DC = CurContext; DC; DC = DC->getLexicalParent()) {
+  if (const auto *ND = dyn_cast(DC)) {
+if (ND->isAnonymousNamespace()) {
+  Diag(ExportLoc, diag::err_export_within_anonymous_namespace);
+  Diag(ND->getLocation(), diag::note_anonymous_namespace);
+  D->setInvalidDecl();
+  return D;
+}
+  }
+}
+return D;
+  }
+
   // C++2a [module.interface]p1:
   //   An export-declaration shall appear only [...] in the purview of a module
   //   interface unit. An export-declaration shall not appear directly or
@@ -924,6 +939,23 @@ static bool checkExportedDeclContext(Sema &S, DeclContext 
*DC,
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
 
+  // HLSL: export declaration is valid only on functions
+  if (S.getLangOpts().HLSL) {
+auto *FD = dyn_cast(D);
+if (!FD) {
+  if (auto *ED2 = dyn_cast(D)) {
+S.Diag(ED2->getBeginLoc(), diag::err_export_within_export);
+if (auto *ED1 = dyn_cast(D->getDeclContext()))
+  S.Diag(ED1->getBeginLoc(), diag::note_export);
+  }
+  else {
+S.Diag(D->getBegin

[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97352

>From b67ecd20cc2c11f4f99c2d90c95fdbd988659947 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 26 Jun 2024 12:31:39 -0700
Subject: [PATCH 1/5] [HLSL] Implement `export` keyword

Fixes #92812
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  8 +++
 clang/lib/Parse/Parser.cpp|  2 +-
 clang/lib/Sema/SemaModule.cpp | 32 
 clang/test/AST/HLSL/export.hlsl   | 23 +
 clang/test/CodeGenHLSL/export.hlsl| 20 
 clang/test/SemaHLSL/export.hlsl   | 50 +++
 7 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/HLSL/export.hlsl
 create mode 100644 clang/test/CodeGenHLSL/export.hlsl
 create mode 100644 clang/test/SemaHLSL/export.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 25a87078a5709..a2465ecc936e0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12265,6 +12265,9 @@ def warn_hlsl_availability_unavailable :
   Warning,
   InGroup, DefaultError;
 
+def err_hlsl_export_not_on_function : Error<
+  "export declaration can only be used on functions">;
+
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
   "a randomized struct can only be initialized with a designated initializer">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 5e3ee5f0579aa..226377e93fe56 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -445,6 +445,14 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
 /// 'export' declaration
 /// 'export' '{' declaration-seq[opt] '}'
 ///
+/// HLSL: Parse export function declaration.
+///
+///  export-function-declaration: 
+/// 'export' function-declaration
+/// 
+///  export-declaration-group:
+/// 'export' '{' function-declaration-seq[opt] '}'
+///
 Decl *Parser::ParseExportDeclaration() {
   assert(Tok.is(tok::kw_export));
   SourceLocation ExportLoc = ConsumeToken();
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 6d0cf7b174e50..ddc8aa9b49e64 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -970,7 +970,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
 SingleDecl = ParseModuleImport(SourceLocation(), IS);
   } break;
   case tok::kw_export:
-if (getLangOpts().CPlusPlusModules) {
+if (getLangOpts().CPlusPlusModules || getLangOpts().HLSL) {
   ProhibitAttributes(Attrs);
   SingleDecl = ParseExportDeclaration();
   break;
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index ad118ac90e4aa..e920b880ecb4d 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -851,6 +851,21 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation 
ExportLoc,
   CurContext->addDecl(D);
   PushDeclContext(S, D);
 
+  if (getLangOpts().HLSL) {
+// exported functions cannot be in an unnamed namespace
+for (const DeclContext *DC = CurContext; DC; DC = DC->getLexicalParent()) {
+  if (const auto *ND = dyn_cast(DC)) {
+if (ND->isAnonymousNamespace()) {
+  Diag(ExportLoc, diag::err_export_within_anonymous_namespace);
+  Diag(ND->getLocation(), diag::note_anonymous_namespace);
+  D->setInvalidDecl();
+  return D;
+}
+  }
+}
+return D;
+  }
+
   // C++2a [module.interface]p1:
   //   An export-declaration shall appear only [...] in the purview of a module
   //   interface unit. An export-declaration shall not appear directly or
@@ -924,6 +939,23 @@ static bool checkExportedDeclContext(Sema &S, DeclContext 
*DC,
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
 
+  // HLSL: export declaration is valid only on functions
+  if (S.getLangOpts().HLSL) {
+auto *FD = dyn_cast(D);
+if (!FD) {
+  if (auto *ED2 = dyn_cast(D)) {
+S.Diag(ED2->getBeginLoc(), diag::err_export_within_export);
+if (auto *ED1 = dyn_cast(D->getDeclContext()))
+  S.Diag(ED1->getBeginLoc(), diag::note_export);
+  }
+  else {
+S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
+  }
+  D->setInvalidDecl();
+  return false;
+}
+  }
+
   //  C++20 [module.interface]p3:
   //   [...] it shall not declare a name with internal linkage.
   bool HasName = false;
diff --git a/clang/test/AST/HLSL/export.hlsl b/clang/test/AST/HLSL/export.hlsl
new file mode 100644
index 0..69c4fb2b457ac
--- /dev/null
+++ b/clang/test/AST/HLSL/export.hlsl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermo

[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits


@@ -129,6 +129,55 @@ class MyClass
   }
 };
 
+// Exported function without body - not used
+export void exportedFunctionUnused(float f);

hekota wrote:

Good catch! This is currently not reporting an error and the redeclaration is 
not recognized as exported function and therefore not included in the 
diagnostic scan. I believe the check whether to scan a function or not should 
be based on whether the function has an external linkage or not. This cannot be 
implemented until issue #92071 is resolved though. I'll see if I can fix this 
without the default linkage change.


https://github.com/llvm/llvm-project/pull/97352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Intangible AST type (PR #97362)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/97362

llvm/llvm-project#90631



>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/4] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/

[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97352

>From b67ecd20cc2c11f4f99c2d90c95fdbd988659947 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 26 Jun 2024 12:31:39 -0700
Subject: [PATCH 1/6] [HLSL] Implement `export` keyword

Fixes #92812
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  8 +++
 clang/lib/Parse/Parser.cpp|  2 +-
 clang/lib/Sema/SemaModule.cpp | 32 
 clang/test/AST/HLSL/export.hlsl   | 23 +
 clang/test/CodeGenHLSL/export.hlsl| 20 
 clang/test/SemaHLSL/export.hlsl   | 50 +++
 7 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/HLSL/export.hlsl
 create mode 100644 clang/test/CodeGenHLSL/export.hlsl
 create mode 100644 clang/test/SemaHLSL/export.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 25a87078a5709..a2465ecc936e0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12265,6 +12265,9 @@ def warn_hlsl_availability_unavailable :
   Warning,
   InGroup, DefaultError;
 
+def err_hlsl_export_not_on_function : Error<
+  "export declaration can only be used on functions">;
+
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
   "a randomized struct can only be initialized with a designated initializer">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 5e3ee5f0579aa..226377e93fe56 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -445,6 +445,14 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
 /// 'export' declaration
 /// 'export' '{' declaration-seq[opt] '}'
 ///
+/// HLSL: Parse export function declaration.
+///
+///  export-function-declaration: 
+/// 'export' function-declaration
+/// 
+///  export-declaration-group:
+/// 'export' '{' function-declaration-seq[opt] '}'
+///
 Decl *Parser::ParseExportDeclaration() {
   assert(Tok.is(tok::kw_export));
   SourceLocation ExportLoc = ConsumeToken();
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 6d0cf7b174e50..ddc8aa9b49e64 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -970,7 +970,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
 SingleDecl = ParseModuleImport(SourceLocation(), IS);
   } break;
   case tok::kw_export:
-if (getLangOpts().CPlusPlusModules) {
+if (getLangOpts().CPlusPlusModules || getLangOpts().HLSL) {
   ProhibitAttributes(Attrs);
   SingleDecl = ParseExportDeclaration();
   break;
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index ad118ac90e4aa..e920b880ecb4d 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -851,6 +851,21 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation 
ExportLoc,
   CurContext->addDecl(D);
   PushDeclContext(S, D);
 
+  if (getLangOpts().HLSL) {
+// exported functions cannot be in an unnamed namespace
+for (const DeclContext *DC = CurContext; DC; DC = DC->getLexicalParent()) {
+  if (const auto *ND = dyn_cast(DC)) {
+if (ND->isAnonymousNamespace()) {
+  Diag(ExportLoc, diag::err_export_within_anonymous_namespace);
+  Diag(ND->getLocation(), diag::note_anonymous_namespace);
+  D->setInvalidDecl();
+  return D;
+}
+  }
+}
+return D;
+  }
+
   // C++2a [module.interface]p1:
   //   An export-declaration shall appear only [...] in the purview of a module
   //   interface unit. An export-declaration shall not appear directly or
@@ -924,6 +939,23 @@ static bool checkExportedDeclContext(Sema &S, DeclContext 
*DC,
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
 
+  // HLSL: export declaration is valid only on functions
+  if (S.getLangOpts().HLSL) {
+auto *FD = dyn_cast(D);
+if (!FD) {
+  if (auto *ED2 = dyn_cast(D)) {
+S.Diag(ED2->getBeginLoc(), diag::err_export_within_export);
+if (auto *ED1 = dyn_cast(D->getDeclContext()))
+  S.Diag(ED1->getBeginLoc(), diag::note_export);
+  }
+  else {
+S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
+  }
+  D->setInvalidDecl();
+  return false;
+}
+  }
+
   //  C++20 [module.interface]p3:
   //   [...] it shall not declare a name with internal linkage.
   bool HasName = false;
diff --git a/clang/test/AST/HLSL/export.hlsl b/clang/test/AST/HLSL/export.hlsl
new file mode 100644
index 0..69c4fb2b457ac
--- /dev/null
+++ b/clang/test/AST/HLSL/export.hlsl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermo

[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits


@@ -129,6 +129,55 @@ class MyClass
   }
 };
 
+// Exported function without body - not used
+export void exportedFunctionUnused(float f);

hekota wrote:

Done.

https://github.com/llvm/llvm-project/pull/97352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add test for export function redeclaration (PR #97370)

2024-07-01 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/97370

Related to llvm/llvm-project#92812

>From 21a7e8bc992ff6e743d0a027469a83e24c48c1d2 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 1 Jul 2024 18:30:20 -0700
Subject: [PATCH] [HLSL] Add test for export function redeclaration

---
 clang/test/SemaHLSL/export.hlsl | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/test/SemaHLSL/export.hlsl b/clang/test/SemaHLSL/export.hlsl
index 9c624d6142232..2d19fa561fa0a 100644
--- a/clang/test/SemaHLSL/export.hlsl
+++ b/clang/test/SemaHLSL/export.hlsl
@@ -35,6 +35,12 @@ static void f9(); // expected-error {{static declaration of 
'f9' follows non-sta
 static void f10(); // expected-note {{previous declaration is here}}
 export void f10(); // expected-error {{cannot export redeclaration 'f10' here 
since the previous declaration has internal linkage}}
 
+export void f11();
+void f11() {}
+
+void f12();   //   expected-note{{previous declaration is here}}
+export void f12() {}  //   expected-error{{cannot export redeclaration 'f12' 
here since the previous declaration is not exported}}
+
 export float V1; // expected-error {{export declaration can only be used on 
functions}}
 
 static export float V2; // expected-error{{expected unqualified-id}}

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


[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-01 Thread Helena Kotas via cfe-commits


@@ -129,6 +129,55 @@ class MyClass
   }
 };
 
+// Exported function without body - not used
+export void exportedFunctionUnused(float f);

hekota wrote:

Also adding test for this here: https://github.com/llvm/llvm-project/pull/97370

https://github.com/llvm/llvm-project/pull/97352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-02 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97352

>From b67ecd20cc2c11f4f99c2d90c95fdbd988659947 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 26 Jun 2024 12:31:39 -0700
Subject: [PATCH 1/6] [HLSL] Implement `export` keyword

Fixes #92812
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  8 +++
 clang/lib/Parse/Parser.cpp|  2 +-
 clang/lib/Sema/SemaModule.cpp | 32 
 clang/test/AST/HLSL/export.hlsl   | 23 +
 clang/test/CodeGenHLSL/export.hlsl| 20 
 clang/test/SemaHLSL/export.hlsl   | 50 +++
 7 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/HLSL/export.hlsl
 create mode 100644 clang/test/CodeGenHLSL/export.hlsl
 create mode 100644 clang/test/SemaHLSL/export.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 25a87078a5709..a2465ecc936e0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12265,6 +12265,9 @@ def warn_hlsl_availability_unavailable :
   Warning,
   InGroup, DefaultError;
 
+def err_hlsl_export_not_on_function : Error<
+  "export declaration can only be used on functions">;
+
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
   "a randomized struct can only be initialized with a designated initializer">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 5e3ee5f0579aa..226377e93fe56 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -445,6 +445,14 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
 /// 'export' declaration
 /// 'export' '{' declaration-seq[opt] '}'
 ///
+/// HLSL: Parse export function declaration.
+///
+///  export-function-declaration: 
+/// 'export' function-declaration
+/// 
+///  export-declaration-group:
+/// 'export' '{' function-declaration-seq[opt] '}'
+///
 Decl *Parser::ParseExportDeclaration() {
   assert(Tok.is(tok::kw_export));
   SourceLocation ExportLoc = ConsumeToken();
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 6d0cf7b174e50..ddc8aa9b49e64 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -970,7 +970,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
 SingleDecl = ParseModuleImport(SourceLocation(), IS);
   } break;
   case tok::kw_export:
-if (getLangOpts().CPlusPlusModules) {
+if (getLangOpts().CPlusPlusModules || getLangOpts().HLSL) {
   ProhibitAttributes(Attrs);
   SingleDecl = ParseExportDeclaration();
   break;
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index ad118ac90e4aa..e920b880ecb4d 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -851,6 +851,21 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation 
ExportLoc,
   CurContext->addDecl(D);
   PushDeclContext(S, D);
 
+  if (getLangOpts().HLSL) {
+// exported functions cannot be in an unnamed namespace
+for (const DeclContext *DC = CurContext; DC; DC = DC->getLexicalParent()) {
+  if (const auto *ND = dyn_cast(DC)) {
+if (ND->isAnonymousNamespace()) {
+  Diag(ExportLoc, diag::err_export_within_anonymous_namespace);
+  Diag(ND->getLocation(), diag::note_anonymous_namespace);
+  D->setInvalidDecl();
+  return D;
+}
+  }
+}
+return D;
+  }
+
   // C++2a [module.interface]p1:
   //   An export-declaration shall appear only [...] in the purview of a module
   //   interface unit. An export-declaration shall not appear directly or
@@ -924,6 +939,23 @@ static bool checkExportedDeclContext(Sema &S, DeclContext 
*DC,
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
 
+  // HLSL: export declaration is valid only on functions
+  if (S.getLangOpts().HLSL) {
+auto *FD = dyn_cast(D);
+if (!FD) {
+  if (auto *ED2 = dyn_cast(D)) {
+S.Diag(ED2->getBeginLoc(), diag::err_export_within_export);
+if (auto *ED1 = dyn_cast(D->getDeclContext()))
+  S.Diag(ED1->getBeginLoc(), diag::note_export);
+  }
+  else {
+S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
+  }
+  D->setInvalidDecl();
+  return false;
+}
+  }
+
   //  C++20 [module.interface]p3:
   //   [...] it shall not declare a name with internal linkage.
   bool HasName = false;
diff --git a/clang/test/AST/HLSL/export.hlsl b/clang/test/AST/HLSL/export.hlsl
new file mode 100644
index 0..69c4fb2b457ac
--- /dev/null
+++ b/clang/test/AST/HLSL/export.hlsl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermo

[clang] [HLSL] Run availability diagnostic on exported functions (PR #97352)

2024-07-02 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed https://github.com/llvm/llvm-project/pull/97352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-02 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/5] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-02 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/6] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/6] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/6] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota ready_for_review 
https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

hekota wrote:

@ChuanqiXu9 - any idea why is your new test `Modules/no-external-type-id.cppm` 
failing on my PR?
It is expecting `// CHECK: https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits


@@ -757,7 +757,8 @@ void USRGenerator::VisitType(QualType T) {
 case BuiltinType::OCLReserveID:
   Out << "@BT@OCLReserveID"; break;
 case BuiltinType::OCLSampler:
-  Out << "@BT@OCLSampler"; break;
+  Out << "@BT@OCLSampler";
+  break;

hekota wrote:

No, this is probably the clang-format side effect. I'll fix it.

https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/7] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits


@@ -2241,6 +2247,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
 Align = ALIGN; 
\
 break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
+  Width = 0;

hekota wrote:

The intangible type is currently implemented as size-less type, but that might 
change as the HLSL implementation evolves. Setting the width to 0 here matches 
what similar types from other languages have done, for example `__externref_t` 
in WebAssembly, which is also an opaque type whose value cannot be accessed or 
manipulated, only passed around.

https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits


@@ -115,6 +116,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
 
 } // namespace
 
+llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
+  assert(T->isHLSLSpecificType() && "Not an HLSL specific type!");
+
+  // Check if the target has a specific translation for this type first.
+  if (llvm::Type *TargetTy = CGM.getTargetCodeGenInfo().getHLSLType(CGM, T))
+return TargetTy;
+
+  // TODO: What do we actually want to do generically here? OpenCL uses a
+  // pointer in a particular address space.
+  llvm_unreachable("Generic handling of HLSL types is not implemented yet");

hekota wrote:

I am not sure if we have any HLSL specific type that will not be handled by 
`getHLSLType`, so this might just become simple `llvm_unreachable` without the 
TODO: comment. @bogner?

https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-03 Thread Helena Kotas via cfe-commits

hekota wrote:

> I see many places where extra cases have been added for the intangible types 
> but no corresponding tests. Is that ok? How did you know to update these 
> places?

I looked at similar types in other languages, such as the `image*` types in 
[OpenCL](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/OpenCLImageTypes.def)
 or `__externref_t` in 
[WebAssembly](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/WebAssemblyReferenceTypes.def).
 I used the same implementation style and defaults as these types (except 
`__externref_t` is a typedef and not a language keyword). Some of the cases are 
tested when the two `builtin_hlsl_resource_t.hlsl` files are parsed and AST 
dumped, but it is not possible to test all case until we can actually use the 
type (llvm/llvm-project#84824).

> I also don't see anywhere that actually successfully uses 
> `__builtin_hlsl_resource_t`. Am I missing it, or should I not expect to see 
> it?

You are correct - the type cannot be directly declared in user code, so the 
tests only check for errors and that the type shows up properly in AST. It is 
possible to use this type internally in Clang or in implicit headers though, 
which are two ways how we could define `RWBuffer` and other builtin types that 
will internally use `__builtin_hlsl_resource_t` handle. That will come alive in 
(llvm/llvm-project#84824).



https://github.com/llvm/llvm-project/pull/97362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Adjust resource binding diagnostic flags code (PR #106657)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/106657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/107160


Fixes #104861

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH] [HLSL] Apply resource attributes to the resource type rather
 than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(

[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107160

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH 1/2] [HLSL] Apply resource attributes to the resource type
 rather than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(Decl *D, con

[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 01/12] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 02/12] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 +++

[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 01/12] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 02/12] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 +++

[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited 
https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107160

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH 1/3] [HLSL] Apply resource attributes to the resource type
 rather than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(Decl *D, con

[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota ready_for_review 
https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited 
https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited 
https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 01/13] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 02/13] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 +++

[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 01/14] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 02/14] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 +++

[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-03 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 01/15] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 02/15] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 +++

[clang] [HLSL] Adjust resource binding diagnostic flags code (PR #106657)

2024-09-04 Thread Helena Kotas via cfe-commits

hekota wrote:

Thank you @kazutakahirata! I will remove the code; the consistency check is 
repeated later in a called function.

https://github.com/llvm/llvm-project/pull/106657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 01/16] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 02/16] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 +++

[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107160

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH 1/4] [HLSL] Apply resource attributes to the resource type
 rather than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(Decl *D, con

[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -5695,6 +5696,15 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+assert(Self.getLangOpts().HLSL && "intangible types are HLSL-only 
feature");
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return false;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,

hekota wrote:

Fixed

https://github.com/llvm/llvm-project/pull/104544
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -249,4 +249,8 @@ FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR)
 /// base classes or fields have a no-return destructor
 FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE)
 
+/// Whether the record type is intangible (if any base classes or fields have
+/// type that is intangible). HLSL only.
+FIELD(IsIntangible, 1, NO_MERGE)

hekota wrote:

Fixed

https://github.com/llvm/llvm-project/pull/104544
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -77,6 +77,23 @@ class SemaHLSL : public SemaBase {
   ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg);
 
   QualType getInoutParameterType(QualType Ty);
+
+  // FIXME: This can be hidden (as static function in SemaHLSL.cpp) once we no
+  // longer need to create builtin buffer types in HLSLExternalSemaSource.

hekota wrote:

I've move it out.

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -1,32 +1,32 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o 
- %s | FileCheck %s
 
-
-// CHECK: -HLSLResourceClassAttr 0x{{[0-9a-f]+}}  SRV
-struct Eg1 {
-  [[hlsl::resource_class(SRV)]] int i;  
+// CHECK: CXXRecordDecl 0x{{[0-9a-f]+}} {{.*}} struct MyBuffer definition
+// CHECK: FieldDecl 0x{{[0-9a-f]+}}  col:51 h 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(UAV)]]':'__hlsl_resource_t'
+struct MyBuffer {
+  __hlsl_resource_t [[hlsl::resource_class(UAV)]] h;
 };
 
-Eg1 e1;
-
-// CHECK: -CXXRecordDecl 0x{{[0-9a-f]+}}  line:13:8 
referenced struct Eg2 definition
-// CHECK: -HLSLResourceClassAttr 0x{{[0-9a-f]+}}  UAV
-struct Eg2 {
-  [[hlsl::resource_class(UAV)]] int i;
-};
-Eg2 e2;
+// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:49 res 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(SRV)]]':'__hlsl_resource_t'
+__hlsl_resource_t [[hlsl::resource_class(SRV)]] res;
 
-// CHECK: -CXXRecordDecl 0x{{[0-9a-f]+}}  line:20:8 
referenced struct Eg3 definition
-// CHECK: -HLSLResourceClassAttr 0x{{[0-9a-f]+}}  CBuffer
-struct Eg3 {
-  [[hlsl::resource_class(CBuffer)]] int i;
-}; 
-Eg3 e3;
+// CHECK: FunctionDecl 0x{{[0-9a-f]+}}  line:14:6 f 
'void ()
+// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:55 r '__hlsl_resource_t 
{{\[\[}}hlsl::resource_class(Sampler)]]':'__hlsl_resource_t'
+void f() {
+  __hlsl_resource_t [[hlsl::resource_class(Sampler)]] r;
+}
 
-// CHECK: -CXXRecordDecl 0x{{[0-9a-f]+}}  line:27:8 
referenced struct Eg4 definition
-// CHECK: -HLSLResourceClassAttr 0x{{[0-9a-f]+}}  Sampler
-struct Eg4 {
-  [[hlsl::resource_class(Sampler)]] int i;
+// CHECK: ClassTemplateDecl 0x{{[0-9a-f]+}}  line:23:29 
MyBuffer2
+// CHECK: TemplateTypeParmDecl 0x{{[0-9a-f]+}}  col:19 
referenced typename depth 0 index 0 T
+// CHECK: CXXRecordDecl 0x{{[0-9a-f]+}}  line:23:29 struct 
MyBuffer2 definition
+// CHECK: CXXRecordDecl 0x{{[0-9a-f]+}}  col:29 implicit 
struct MyBuffer2
+// CHECK: FieldDecl 0x{{[0-9a-f]+}}  col:35 h 'T 
{{\[\[}}hlsl::resource_class(UAV)]]':'T'
+template struct MyBuffer2 {
+  T [[hlsl::resource_class(UAV)]] h;

hekota wrote:

I've updated the tests to use `__hlsl_resource_t` everywhere we use the 
resource attributes.

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Remove variables that are used only in assert (PR #107299)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/107299

Changes the assert to test the same condition without using the variables.

This change is done in response to a comment 
[here](https://github.com/llvm/llvm-project/pull/106657#issuecomment-2327493439).
 

>From 038e47d8ec75c03b895eb8bb5540f1fee9f4b936 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 4 Sep 2024 12:55:43 -0700
Subject: [PATCH] [HLSL] Remove variables used only in assert

---
 clang/lib/Sema/SemaHLSL.cpp | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 778d524a005482..aa41a7c809880b 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -834,17 +834,10 @@ static void ValidateMultipleRegisterAnnotations(Sema &S, 
Decl *TheDecl,
 static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
   Decl *TheDecl, RegisterType regType) 
{
 
-  // Samplers, UAVs, and SRVs are VarDecl types
-  VarDecl *TheVarDecl = dyn_cast(TheDecl);
-  // Cbuffers and Tbuffers are HLSLBufferDecl types
-  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(TheDecl);
-
   // exactly one of these two types should be set
-  assert(((TheVarDecl && !CBufferOrTBuffer) ||
-  (!TheVarDecl && CBufferOrTBuffer)) &&
+  assert(((isa(TheDecl) && !isa(TheDecl)) ||
+  (!isa(TheDecl) && isa(TheDecl))) &&
  "either TheVarDecl or CBufferOrTBuffer should be set");
-  (void)TheVarDecl;
-  (void)CBufferOrTBuffer;
 
   RegisterBindingFlags Flags = HLSLFillRegisterBindingFlags(S, TheDecl);
   assert((int)Flags.Other + (int)Flags.Resource + (int)Flags.Basic +

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


[clang] [HLSL] Remove variables that are used only in assert (PR #107299)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107299

>From 038e47d8ec75c03b895eb8bb5540f1fee9f4b936 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 4 Sep 2024 12:55:43 -0700
Subject: [PATCH 1/2] [HLSL] Remove variables used only in assert

---
 clang/lib/Sema/SemaHLSL.cpp | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 778d524a005482..aa41a7c809880b 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -834,17 +834,10 @@ static void ValidateMultipleRegisterAnnotations(Sema &S, 
Decl *TheDecl,
 static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
   Decl *TheDecl, RegisterType regType) 
{
 
-  // Samplers, UAVs, and SRVs are VarDecl types
-  VarDecl *TheVarDecl = dyn_cast(TheDecl);
-  // Cbuffers and Tbuffers are HLSLBufferDecl types
-  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(TheDecl);
-
   // exactly one of these two types should be set
-  assert(((TheVarDecl && !CBufferOrTBuffer) ||
-  (!TheVarDecl && CBufferOrTBuffer)) &&
+  assert(((isa(TheDecl) && !isa(TheDecl)) ||
+  (!isa(TheDecl) && isa(TheDecl))) &&
  "either TheVarDecl or CBufferOrTBuffer should be set");
-  (void)TheVarDecl;
-  (void)CBufferOrTBuffer;
 
   RegisterBindingFlags Flags = HLSLFillRegisterBindingFlags(S, TheDecl);
   assert((int)Flags.Other + (int)Flags.Resource + (int)Flags.Basic +

>From d50d0259adf08928800e6f82fd6c676aa3b4b808 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 4 Sep 2024 16:02:15 -0700
Subject: [PATCH 2/2] update assert message

---
 clang/lib/Sema/SemaHLSL.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index aa41a7c809880b..a5d941181b2c71 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -837,7 +837,7 @@ static void DiagnoseHLSLRegisterAttribute(Sema &S, 
SourceLocation &ArgLoc,
   // exactly one of these two types should be set
   assert(((isa(TheDecl) && !isa(TheDecl)) ||
   (!isa(TheDecl) && isa(TheDecl))) &&
- "either TheVarDecl or CBufferOrTBuffer should be set");
+ "expecting VarDecl or HLSLBufferDecl");
 
   RegisterBindingFlags Flags = HLSLFillRegisterBindingFlags(S, TheDecl);
   assert((int)Flags.Other + (int)Flags.Resource + (int)Flags.Basic +

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


[clang] [HLSL] Remove variables that are used only in assert (PR #107299)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -834,17 +834,10 @@ static void ValidateMultipleRegisterAnnotations(Sema &S, 
Decl *TheDecl,
 static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
   Decl *TheDecl, RegisterType regType) 
{
 
-  // Samplers, UAVs, and SRVs are VarDecl types
-  VarDecl *TheVarDecl = dyn_cast(TheDecl);
-  // Cbuffers and Tbuffers are HLSLBufferDecl types
-  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(TheDecl);
-
   // exactly one of these two types should be set
-  assert(((TheVarDecl && !CBufferOrTBuffer) ||
-  (!TheVarDecl && CBufferOrTBuffer)) &&
+  assert(((isa(TheDecl) && !isa(TheDecl)) ||
+  (!isa(TheDecl) && isa(TheDecl))) &&
  "either TheVarDecl or CBufferOrTBuffer should be set");

hekota wrote:

Fixed

https://github.com/llvm/llvm-project/pull/107299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Implement '__builtin_hlsl_is_intangible' type trait (PR #104544)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/104544
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Remove variables that are used only in assert (PR #107299)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/107299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -556,46 +562,120 @@ void SemaHLSL::handleShaderAttr(Decl *D, const 
ParsedAttr &AL) {
 D->addAttr(NewAttr);
 }
 
-void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) {
-  if (!AL.isArgIdent(0)) {
-Diag(AL.getLoc(), diag::err_attribute_argument_type)
-<< AL << AANT_ArgumentIdentifier;
-return;
-  }
+bool clang::CreateHLSLAttributedResourceType(
+Sema &S, QualType Wrapped, llvm::SmallVector &AttrList,
+QualType &ResType) {
+  assert(AttrList.size() && "expected list of resource attributes");
 
-  IdentifierLoc *Loc = AL.getArgAsIdent(0);
-  StringRef Identifier = Loc->Ident->getName();
-  SourceLocation ArgLoc = Loc->Loc;
+  QualType Contained = QualType();
+  HLSLAttributedResourceType::Attributes ResAttrs = {};
 
-  // Validate.
-  llvm::dxil::ResourceClass RC;
-  if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
-Diag(ArgLoc, diag::warn_attribute_type_not_supported)
-<< "ResourceClass" << Identifier;
-return;
+  bool hasResourceClass = false;
+  for (auto *Attr : AttrList) {
+if (!Attr)
+  continue;
+switch (Attr->getKind()) {
+case attr::HLSLResourceClass: {
+  llvm::dxil::ResourceClass RC =
+  dyn_cast(Attr)->getResourceClass();
+  if (!hasResourceClass) {
+ResAttrs.ResourceClass = RC;
+hasResourceClass = true;
+  } else if (RC != ResAttrs.ResourceClass) {
+S.Diag(Attr->getLocation(), diag::warn_duplicate_attribute) << Attr;
+return false;
+  }
+  break;
+}
+case attr::HLSLROV:
+  ResAttrs.IsROV = true;
+  break;
+default:
+  llvm_unreachable("unhandled resource attribute type");
+}
   }
 
-  D->addAttr(HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc));
+  if (!hasResourceClass) {
+S.Diag(AttrList.back()->getRange().getEnd(),
+   diag::err_missing_resource_class);
+return false;
+  }
+
+  ResType = S.getASTContext().getHLSLAttributedResourceType(Wrapped, Contained,
+ResAttrs);
+  return true;
 }
 
-// Validates HLSL resource type attribute and adds it to the list to be
-// processed into a single HLSLAttributedResourceType later on.
-// Returns false if the attribute is invalid.
+// Validates and creates an HLSL attribute that is applied as type attribute on
+// HLSL resource. The attributes are collected in HLSLResourcesTypeAttrs and at
+// the end of the declaration they are applied to the declaration type by
+// wrapping it in HLSLAttributedResourceType.
 bool SemaHLSL::handleResourceTypeAttr(const ParsedAttr &AL) {
-  // FIXME: placeholder - not yet implemented
+  Attr *A = nullptr;
+
+  // validate number of arguments
+  if (!AL.checkExactlyNumArgs(SemaRef, AL.getMinArgs()))
+return false;
+
+  switch (AL.getKind()) {
+  case ParsedAttr::AT_HLSLResourceClass: {
+if (!AL.isArgIdent(0)) {
+  Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return false;
+}
+
+IdentifierLoc *Loc = AL.getArgAsIdent(0);
+StringRef Identifier = Loc->Ident->getName();
+SourceLocation ArgLoc = Loc->Loc;
+
+// Validate resource class value
+llvm::dxil::ResourceClass RC;
+if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
+  Diag(ArgLoc, diag::warn_attribute_type_not_supported)
+  << "ResourceClass" << Identifier;
+  return false;
+}
+A = HLSLResourceClassAttr::Create(getASTContext(), RC, AL.getLoc());
+break;
+  }
+  case ParsedAttr::AT_HLSLROV:
+A = HLSLROVAttr::Create(getASTContext(), AL.getLoc());
+break;
+  default:
+llvm_unreachable("unhandled HLSL attribute");
+  }
+
+  HLSLResourcesTypeAttrs.emplace_back(A);
   return true;
 }
 
-// Combines all resource type attributes and create HLSLAttributedResourceType.
+// Combines all resource type attributes and creates 
HLSLAttributedResourceType.
 QualType SemaHLSL::ProcessResourceTypeAttributes(QualType CurrentType) {
-  // FIXME: placeholder - not yet implemented
-  return CurrentType;
+  if (!HLSLResourcesTypeAttrs.size())
+return CurrentType;
+
+  QualType QT = CurrentType;
+  if (CreateHLSLAttributedResourceType(SemaRef, CurrentType,
+   HLSLResourcesTypeAttrs, QT)) {
+const HLSLAttributedResourceType *RT =
+dyn_cast(QT.getTypePtr());
+SourceLocation Loc = HLSLResourcesTypeAttrs[0]->getLoc();

hekota wrote:

I am not sure what you mean.

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -2062,6 +2066,7 @@ void TypePrinter::printBTFTagAttributedAfter(const 
BTFTagAttributedType *T,
 void TypePrinter::printHLSLAttributedResourceBefore(
 const HLSLAttributedResourceType *T, raw_ostream &OS) {
   printBefore(T->getWrappedType(), OS);
+  printAfter(T->getWrappedType(), OS);

hekota wrote:

Yea, we need to print the whole wrapped type before printing the attributes. I 
will move the attribute printing to printHLSLAttributedResourceAfter.

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits


@@ -556,46 +562,120 @@ void SemaHLSL::handleShaderAttr(Decl *D, const 
ParsedAttr &AL) {
 D->addAttr(NewAttr);
 }
 
-void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) {
-  if (!AL.isArgIdent(0)) {
-Diag(AL.getLoc(), diag::err_attribute_argument_type)
-<< AL << AANT_ArgumentIdentifier;
-return;
-  }
+bool clang::CreateHLSLAttributedResourceType(
+Sema &S, QualType Wrapped, llvm::SmallVector &AttrList,

hekota wrote:

Cool! I did not know SmallVector implicitly converts to ArrayRef when the 
argument requires it!

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-04 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107160

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH 1/5] [HLSL] Apply resource attributes to the resource type
 rather than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(Decl *D, con

[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-05 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107160

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH 1/6] [HLSL] Apply resource attributes to the resource type
 rather than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(Decl *D, con

[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-05 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107160

>From 337a9ed1d5e7c71fb5be5741afe7726f5b76af7b Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 3 Sep 2024 15:30:50 -0700
Subject: [PATCH 1/6] [HLSL] Apply resource attributes to the resource type
 rather than the handle member (#6)

---
 clang/include/clang/AST/TypeLoc.h |   8 +
 clang/include/clang/Basic/Attr.td |   6 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Sema/SemaHLSL.h   |  21 ++-
 clang/lib/AST/TypePrinter.cpp |   9 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  10 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  25 ++-
 clang/lib/Sema/SemaDeclAttr.cpp   |   6 -
 clang/lib/Sema/SemaHLSL.cpp   | 177 --
 clang/lib/Sema/TreeTransform.h|  22 ++-
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  10 +-
 ...a-attribute-supported-attributes-list.test |   2 -
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  17 +-
 .../ParserHLSL/hlsl_is_rov_attr_error.hlsl|  21 ++-
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  |  48 ++---
 .../hlsl_resource_class_attr_error.hlsl   |  29 +--
 .../hlsl_resource_handle_attrs.hlsl   |  17 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |   2 +-
 .../resource_binding_attr_error_resource.hlsl |  10 +-
 .../resource_binding_attr_error_udt.hlsl  |  10 +-
 20 files changed, 284 insertions(+), 167 deletions(-)

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 5db39eb3aefa74..03fbdcf60140df 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -951,12 +951,20 @@ class HLSLAttributedResourceTypeLoc
  HLSLAttributedResourceLocInfo> {
 public:
   TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+  TypeLoc getContainedLoc() const {
+return TypeLoc(getTypePtr()->getContainedType(), getNonLocalData());
+  }
+
   void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
   SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
   void initializeLocal(ASTContext &Context, SourceLocation loc) {
 setSourceRange(SourceRange());
   }
   QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+  unsigned getLocalDataSize() const {
+return sizeof(HLSLAttributedResourceLocInfo);
+  }
 };
 
 struct ObjCObjectTypeLocInfo {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8d2a362abc3c32..0c98f8e25a6fbb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,16 +4643,14 @@ def HLSLResource : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
-def HLSLROV : InheritableAttr {
+def HLSLROV : TypeAttr {
   let Spellings = [CXX11<"hlsl", "is_rov">];
-  let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL]; 
   let Documentation = [InternalOnly];
 }
 
-def HLSLResourceClass : InheritableAttr {
+def HLSLResourceClass : TypeAttr {
   let Spellings = [CXX11<"hlsl", "resource_class">];
-  let Subjects = SubjectList<[Field]>;
   let LangOpts = [HLSL];
   let Args = [
EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dcb49d8a67604a..4f522f68f080aa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12364,6 +12364,7 @@ def err_hlsl_packoffset_cross_reg_boundary : 
Error<"packoffset cannot cross regi
 def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not 
match alignment %0 required by %1">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
+def err_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d79ca9a4fa18d1..5131458863e20b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -15,8 +15,11 @@
 
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/SemaBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -59,8 +62,6 @@ class SemaHLSL : public SemaBase {
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
-  void handleROVAttr(Decl *D, const ParsedAttr &AL);
-  void handleResourceClassAttr(Decl *D, con

[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-05 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104856

>From 44e814b925a1ad8ac40fe6904542cbade516c065 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 19 Aug 2024 13:34:13 -0700
Subject: [PATCH 1/4] [DirectX] Add DirectXTargetCodeGenInfo

Adds TargetCodeGenInfo class for DirectX. Currently in only translates 
`target("dx.TypedBuffer", i32, 1, 0, 1)` for now (`RWBuffer`). More work 
us needed to determine the actual target exp type and its parameters based on 
attributes on the handle type (not yet implemented).

Part 1/2 of #95952
---
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/CodeGen/TargetInfo.h|  3 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 60 +++
 4 files changed, 66 insertions(+)
 create mode 100644 clang/lib/CodeGen/Targets/DirectX.cpp

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index deb7b27266d736..aa0c871c5352a8 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -122,6 +122,7 @@ add_clang_library(clangCodeGen
   Targets/AVR.cpp
   Targets/BPF.cpp
   Targets/CSKY.cpp
+  Targets/DirectX.cpp
   Targets/Hexagon.cpp
   Targets/Lanai.cpp
   Targets/LoongArch.cpp
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0b61ef0f89989c..f93e79d1dffecd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -298,6 +298,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
   case llvm::Triple::spirv32:
   case llvm::Triple::spirv64:
 return createSPIRVTargetCodeGenInfo(CGM);
+  case llvm::Triple::dxil:
+return createDirectXTargetCodeGenInfo(CGM);
   case llvm::Triple::ve:
 return createVETargetCodeGenInfo(CGM);
   case llvm::Triple::csky: {
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 0244ca006d498b..3e503538b2b14d 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -555,6 +555,9 @@ createTCETargetCodeGenInfo(CodeGenModule &CGM);
 std::unique_ptr
 createVETargetCodeGenInfo(CodeGenModule &CGM);
 
+std::unique_ptr
+createDirectXTargetCodeGenInfo(CodeGenModule &CGM);
+
 enum class WebAssemblyABIKind {
   MVP = 0,
   ExperimentalMV = 1,
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
new file mode 100644
index 00..847ca7ddce1810
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -0,0 +1,60 @@
+//===- DirectX.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ABIInfoImpl.h"
+#include "TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation for DirectX.
+//===--===//
+
+namespace {
+
+class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
+};
+
+llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
+  const Type *Ty) const {
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  if (auto *BuiltinTy = dyn_cast(Ty)) {
+switch (BuiltinTy->getKind()) {
+case BuiltinType::HLSLResource: {
+  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", i32, 1,
+  // 0, 1) only for now (RWBuffer); more work us needed to determine
+  // the target ext type and its parameters based on the handle type
+  // attributes (not yet implemented)
+  llvm::IntegerType *ElemType = llvm::IntegerType::getInt32Ty(Ctx);
+  ArrayRef Flags = {/*IsWriteable*/ 1, /*IsROV*/ 0,
+  /*IsSigned*/ 1};
+  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, 
Flags);
+}
+default:
+  llvm_unreachable("unhandled builtin type");
+}
+  }
+  return nullptr;
+}
+
+} // namespace
+
+std::unique_ptr
+CodeGen::createDirectXTargetCodeGenInfo(CodeGenModule &CGM) {
+  return std::make_unique(CGM.getTypes());
+}

>From efbf44be7bf6f55deb1d0cfd002b6219fda679bf Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 19 Aug 2024 22:29:37 -0700
Subject: [PATCH 2/4] code review feedback (no test yet)

---
 clang/lib/CodeGen/Targets/DirectX.cpp | 32 ++

[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-05 Thread Helena Kotas via cfe-commits

hekota wrote:

> It would be good to have some test coverage to go along with this.

Test added.

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-05 Thread Helena Kotas via cfe-commits

hekota wrote:

> We should be able to test this by defining a global or calling a function 
> with the `__hlsl_resource_t` type.

Test added.

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-05 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,53 @@
+//===- 
DirectX.cpp-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ABIInfoImpl.h"
+#include "TargetInfo.h"
+#include "llvm/IR/DerivedTypes.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation for DirectX.
+//===--===//
+
+namespace {
+
+class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
+};
+
+llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
+  const Type *Ty) const {
+  auto *BuiltinTy = dyn_cast(Ty);
+  if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+return nullptr;
+
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x 
float>,
+  // 1, 0, 1) only for now (RWBuffer); more work us needed to determine
+  // the target ext type and its parameters based on the handle type
+  // attributes (not yet implemented)
+  llvm::FixedVectorType *ElemType =
+  llvm::FixedVectorType::get(llvm::Type::getFloatTy(Ctx), 4);
+  ArrayRef Flags = {/*IsWriteable*/ 1, /*IsROV*/ 0,

hekota wrote:

`ArrayRef` is required by `llvm::TargetExtType::get` to create the 
type.

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-05 Thread Helena Kotas via cfe-commits


@@ -556,46 +562,120 @@ void SemaHLSL::handleShaderAttr(Decl *D, const 
ParsedAttr &AL) {
 D->addAttr(NewAttr);
 }
 
-void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) {
-  if (!AL.isArgIdent(0)) {
-Diag(AL.getLoc(), diag::err_attribute_argument_type)
-<< AL << AANT_ArgumentIdentifier;
-return;
-  }
+bool clang::CreateHLSLAttributedResourceType(
+Sema &S, QualType Wrapped, llvm::SmallVector &AttrList,
+QualType &ResType) {
+  assert(AttrList.size() && "expected list of resource attributes");
 
-  IdentifierLoc *Loc = AL.getArgAsIdent(0);
-  StringRef Identifier = Loc->Ident->getName();
-  SourceLocation ArgLoc = Loc->Loc;
+  QualType Contained = QualType();
+  HLSLAttributedResourceType::Attributes ResAttrs = {};
 
-  // Validate.
-  llvm::dxil::ResourceClass RC;
-  if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
-Diag(ArgLoc, diag::warn_attribute_type_not_supported)
-<< "ResourceClass" << Identifier;
-return;
+  bool hasResourceClass = false;
+  for (auto *Attr : AttrList) {
+if (!Attr)
+  continue;
+switch (Attr->getKind()) {
+case attr::HLSLResourceClass: {
+  llvm::dxil::ResourceClass RC =
+  dyn_cast(Attr)->getResourceClass();
+  if (!hasResourceClass) {
+ResAttrs.ResourceClass = RC;
+hasResourceClass = true;
+  } else if (RC != ResAttrs.ResourceClass) {
+S.Diag(Attr->getLocation(), diag::warn_duplicate_attribute) << Attr;
+return false;
+  }
+  break;
+}
+case attr::HLSLROV:
+  ResAttrs.IsROV = true;
+  break;
+default:
+  llvm_unreachable("unhandled resource attribute type");
+}
   }
 
-  D->addAttr(HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc));
+  if (!hasResourceClass) {
+S.Diag(AttrList.back()->getRange().getEnd(),
+   diag::err_missing_resource_class);
+return false;
+  }
+
+  ResType = S.getASTContext().getHLSLAttributedResourceType(Wrapped, Contained,
+ResAttrs);
+  return true;
 }
 
-// Validates HLSL resource type attribute and adds it to the list to be
-// processed into a single HLSLAttributedResourceType later on.
-// Returns false if the attribute is invalid.
+// Validates and creates an HLSL attribute that is applied as type attribute on
+// HLSL resource. The attributes are collected in HLSLResourcesTypeAttrs and at
+// the end of the declaration they are applied to the declaration type by
+// wrapping it in HLSLAttributedResourceType.
 bool SemaHLSL::handleResourceTypeAttr(const ParsedAttr &AL) {
-  // FIXME: placeholder - not yet implemented
+  Attr *A = nullptr;
+
+  // validate number of arguments
+  if (!AL.checkExactlyNumArgs(SemaRef, AL.getMinArgs()))
+return false;
+
+  switch (AL.getKind()) {
+  case ParsedAttr::AT_HLSLResourceClass: {
+if (!AL.isArgIdent(0)) {
+  Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return false;
+}
+
+IdentifierLoc *Loc = AL.getArgAsIdent(0);
+StringRef Identifier = Loc->Ident->getName();
+SourceLocation ArgLoc = Loc->Loc;
+
+// Validate resource class value
+llvm::dxil::ResourceClass RC;
+if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
+  Diag(ArgLoc, diag::warn_attribute_type_not_supported)
+  << "ResourceClass" << Identifier;
+  return false;
+}
+A = HLSLResourceClassAttr::Create(getASTContext(), RC, AL.getLoc());
+break;
+  }
+  case ParsedAttr::AT_HLSLROV:
+A = HLSLROVAttr::Create(getASTContext(), AL.getLoc());
+break;
+  default:
+llvm_unreachable("unhandled HLSL attribute");
+  }
+
+  HLSLResourcesTypeAttrs.emplace_back(A);
   return true;
 }
 
-// Combines all resource type attributes and create HLSLAttributedResourceType.
+// Combines all resource type attributes and creates 
HLSLAttributedResourceType.
 QualType SemaHLSL::ProcessResourceTypeAttributes(QualType CurrentType) {
-  // FIXME: placeholder - not yet implemented
-  return CurrentType;
+  if (!HLSLResourcesTypeAttrs.size())
+return CurrentType;
+
+  QualType QT = CurrentType;
+  if (CreateHLSLAttributedResourceType(SemaRef, CurrentType,
+   HLSLResourcesTypeAttrs, QT)) {
+const HLSLAttributedResourceType *RT =
+dyn_cast(QT.getTypePtr());
+SourceLocation Loc = HLSLResourcesTypeAttrs[0]->getLoc();

hekota wrote:

Every attribute will have a different location based on where it is in the 
source code. I picked the location of the first one to be the location of the 
aggregated type because the attributes are stored in `HLSLResourceTypeAttrs` in 
the same order as they are parsed.

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/m

[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-05 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,53 @@
+//===- 
DirectX.cpp-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ABIInfoImpl.h"
+#include "TargetInfo.h"
+#include "llvm/IR/DerivedTypes.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation for DirectX.
+//===--===//
+
+namespace {
+
+class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
+};
+
+llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
+  const Type *Ty) const {
+  auto *BuiltinTy = dyn_cast(Ty);
+  if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+return nullptr;
+
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x 
float>,
+  // 1, 0, 1) only for now (RWBuffer); more work us needed to determine
+  // the target ext type and its parameters based on the handle type
+  // attributes (not yet implemented)
+  llvm::FixedVectorType *ElemType =
+  llvm::FixedVectorType::get(llvm::Type::getFloatTy(Ctx), 4);
+  ArrayRef Flags = {/*IsWriteable*/ 1, /*IsROV*/ 0,
+  /*IsSigned*/ 1};

hekota wrote:

Thanks @efriedma-quic !

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-05 Thread Helena Kotas via cfe-commits


@@ -556,46 +562,120 @@ void SemaHLSL::handleShaderAttr(Decl *D, const 
ParsedAttr &AL) {
 D->addAttr(NewAttr);
 }
 
-void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) {
-  if (!AL.isArgIdent(0)) {
-Diag(AL.getLoc(), diag::err_attribute_argument_type)
-<< AL << AANT_ArgumentIdentifier;
-return;
-  }
+bool clang::CreateHLSLAttributedResourceType(
+Sema &S, QualType Wrapped, llvm::SmallVector &AttrList,
+QualType &ResType) {
+  assert(AttrList.size() && "expected list of resource attributes");
 
-  IdentifierLoc *Loc = AL.getArgAsIdent(0);
-  StringRef Identifier = Loc->Ident->getName();
-  SourceLocation ArgLoc = Loc->Loc;
+  QualType Contained = QualType();
+  HLSLAttributedResourceType::Attributes ResAttrs = {};
 
-  // Validate.
-  llvm::dxil::ResourceClass RC;
-  if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
-Diag(ArgLoc, diag::warn_attribute_type_not_supported)
-<< "ResourceClass" << Identifier;
-return;
+  bool hasResourceClass = false;
+  for (auto *Attr : AttrList) {
+if (!Attr)
+  continue;
+switch (Attr->getKind()) {
+case attr::HLSLResourceClass: {
+  llvm::dxil::ResourceClass RC =
+  dyn_cast(Attr)->getResourceClass();
+  if (!hasResourceClass) {
+ResAttrs.ResourceClass = RC;
+hasResourceClass = true;
+  } else if (RC != ResAttrs.ResourceClass) {
+S.Diag(Attr->getLocation(), diag::warn_duplicate_attribute) << Attr;
+return false;
+  }
+  break;
+}
+case attr::HLSLROV:
+  ResAttrs.IsROV = true;
+  break;
+default:
+  llvm_unreachable("unhandled resource attribute type");
+}
   }
 
-  D->addAttr(HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc));
+  if (!hasResourceClass) {
+S.Diag(AttrList.back()->getRange().getEnd(),
+   diag::err_missing_resource_class);
+return false;
+  }
+
+  ResType = S.getASTContext().getHLSLAttributedResourceType(Wrapped, Contained,
+ResAttrs);
+  return true;
 }
 
-// Validates HLSL resource type attribute and adds it to the list to be
-// processed into a single HLSLAttributedResourceType later on.
-// Returns false if the attribute is invalid.
+// Validates and creates an HLSL attribute that is applied as type attribute on
+// HLSL resource. The attributes are collected in HLSLResourcesTypeAttrs and at
+// the end of the declaration they are applied to the declaration type by
+// wrapping it in HLSLAttributedResourceType.
 bool SemaHLSL::handleResourceTypeAttr(const ParsedAttr &AL) {
-  // FIXME: placeholder - not yet implemented
+  Attr *A = nullptr;
+
+  // validate number of arguments
+  if (!AL.checkExactlyNumArgs(SemaRef, AL.getMinArgs()))
+return false;
+
+  switch (AL.getKind()) {
+  case ParsedAttr::AT_HLSLResourceClass: {
+if (!AL.isArgIdent(0)) {
+  Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return false;
+}
+
+IdentifierLoc *Loc = AL.getArgAsIdent(0);
+StringRef Identifier = Loc->Ident->getName();
+SourceLocation ArgLoc = Loc->Loc;
+
+// Validate resource class value
+llvm::dxil::ResourceClass RC;
+if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
+  Diag(ArgLoc, diag::warn_attribute_type_not_supported)
+  << "ResourceClass" << Identifier;
+  return false;
+}
+A = HLSLResourceClassAttr::Create(getASTContext(), RC, AL.getLoc());
+break;
+  }
+  case ParsedAttr::AT_HLSLROV:
+A = HLSLROVAttr::Create(getASTContext(), AL.getLoc());
+break;
+  default:
+llvm_unreachable("unhandled HLSL attribute");
+  }
+
+  HLSLResourcesTypeAttrs.emplace_back(A);
   return true;
 }
 
-// Combines all resource type attributes and create HLSLAttributedResourceType.
+// Combines all resource type attributes and creates 
HLSLAttributedResourceType.
 QualType SemaHLSL::ProcessResourceTypeAttributes(QualType CurrentType) {
-  // FIXME: placeholder - not yet implemented
-  return CurrentType;
+  if (!HLSLResourcesTypeAttrs.size())
+return CurrentType;
+
+  QualType QT = CurrentType;
+  if (CreateHLSLAttributedResourceType(SemaRef, CurrentType,
+   HLSLResourcesTypeAttrs, QT)) {
+const HLSLAttributedResourceType *RT =
+dyn_cast(QT.getTypePtr());
+SourceLocation Loc = HLSLResourcesTypeAttrs[0]->getLoc();

hekota wrote:

Will do!

https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Apply resource attributes to the resource type rather than the handle member (PR #107160)

2024-09-05 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/107160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104856

>From 44e814b925a1ad8ac40fe6904542cbade516c065 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 19 Aug 2024 13:34:13 -0700
Subject: [PATCH 1/6] [DirectX] Add DirectXTargetCodeGenInfo

Adds TargetCodeGenInfo class for DirectX. Currently in only translates 
`target("dx.TypedBuffer", i32, 1, 0, 1)` for now (`RWBuffer`). More work 
us needed to determine the actual target exp type and its parameters based on 
attributes on the handle type (not yet implemented).

Part 1/2 of #95952
---
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/CodeGen/TargetInfo.h|  3 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 60 +++
 4 files changed, 66 insertions(+)
 create mode 100644 clang/lib/CodeGen/Targets/DirectX.cpp

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index deb7b27266d736..aa0c871c5352a8 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -122,6 +122,7 @@ add_clang_library(clangCodeGen
   Targets/AVR.cpp
   Targets/BPF.cpp
   Targets/CSKY.cpp
+  Targets/DirectX.cpp
   Targets/Hexagon.cpp
   Targets/Lanai.cpp
   Targets/LoongArch.cpp
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0b61ef0f89989c..f93e79d1dffecd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -298,6 +298,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
   case llvm::Triple::spirv32:
   case llvm::Triple::spirv64:
 return createSPIRVTargetCodeGenInfo(CGM);
+  case llvm::Triple::dxil:
+return createDirectXTargetCodeGenInfo(CGM);
   case llvm::Triple::ve:
 return createVETargetCodeGenInfo(CGM);
   case llvm::Triple::csky: {
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 0244ca006d498b..3e503538b2b14d 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -555,6 +555,9 @@ createTCETargetCodeGenInfo(CodeGenModule &CGM);
 std::unique_ptr
 createVETargetCodeGenInfo(CodeGenModule &CGM);
 
+std::unique_ptr
+createDirectXTargetCodeGenInfo(CodeGenModule &CGM);
+
 enum class WebAssemblyABIKind {
   MVP = 0,
   ExperimentalMV = 1,
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
new file mode 100644
index 00..847ca7ddce1810
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -0,0 +1,60 @@
+//===- DirectX.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ABIInfoImpl.h"
+#include "TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation for DirectX.
+//===--===//
+
+namespace {
+
+class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
+};
+
+llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
+  const Type *Ty) const {
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  if (auto *BuiltinTy = dyn_cast(Ty)) {
+switch (BuiltinTy->getKind()) {
+case BuiltinType::HLSLResource: {
+  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", i32, 1,
+  // 0, 1) only for now (RWBuffer); more work us needed to determine
+  // the target ext type and its parameters based on the handle type
+  // attributes (not yet implemented)
+  llvm::IntegerType *ElemType = llvm::IntegerType::getInt32Ty(Ctx);
+  ArrayRef Flags = {/*IsWriteable*/ 1, /*IsROV*/ 0,
+  /*IsSigned*/ 1};
+  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, 
Flags);
+}
+default:
+  llvm_unreachable("unhandled builtin type");
+}
+  }
+  return nullptr;
+}
+
+} // namespace
+
+std::unique_ptr
+CodeGen::createDirectXTargetCodeGenInfo(CodeGenModule &CGM) {
+  return std::make_unique(CGM.getTypes());
+}

>From efbf44be7bf6f55deb1d0cfd002b6219fda679bf Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 19 Aug 2024 22:29:37 -0700
Subject: [PATCH 2/6] code review feedback (no test yet)

---
 clang/lib/CodeGen/Targets/DirectX.cpp | 32 ++

[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-09 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s
+
+void foo(__hlsl_resource_t res);
+
+// CHECK: define void 
@"?bar@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 
1) %a)
+// CHECK: call void 
@"?foo@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 
1) %0)

hekota wrote:

I've changed it to use `-O1` and capture the argument name.

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-09 Thread Helena Kotas via cfe-commits


@@ -879,6 +879,10 @@ static TargetTypeInfo getTargetTypeInfo(const 
TargetExtType *Ty) {
 ScalableVectorType::get(Type::getInt8Ty(C), TotalNumElts));
   }
 
+  // DirectX intangible types
+  if (Name.starts_with("dx."))
+return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal);

hekota wrote:

I've removed `CanBeGlobal`. I copied it from the spirv.Image case, but since we 
always have the handle wrapped in a class we should not need it.

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-09 Thread Helena Kotas via cfe-commits


@@ -879,6 +879,10 @@ static TargetTypeInfo getTargetTypeInfo(const 
TargetExtType *Ty) {
 ScalableVectorType::get(Type::getInt8Ty(C), TotalNumElts));
   }
 
+  // DirectX intangible types
+  if (Name.starts_with("dx."))

hekota wrote:

I have updated the comment.

https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add `[[hlsl::row_access]]` attribute (PR #107954)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/107954

This PR introduces new HLSL resource type attribute `[[hlsl::row_access]]`. 
Presence of this attribute on a resource handle means that the resource must be 
accessed in 16-byte blocks at-a-time, or four 32-bit components, also known as 
rows.

This information is necessary in order to properly distinguish between handles 
for typed buffer types (like `RWBuffer`) which require row-level access 
and will be translated to target extension type `dx.TypedBuffer` versus buffer 
types that do not have this access constraint (like 
`RWStructuredBuffer`) and will be using target ext. type `dx.RawBuffer`.

Fixes #107907

>From 1c66d2767ca20f42b6edaae834cc186be7d23712 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 9 Sep 2024 19:39:02 -0700
Subject: [PATCH] [HLSL] Add `[[hlsl::row_access]]` attribute

This PR introduces new HLSL resource type attribute [[hlsl::row_access]].
Presence of this attribute means that the resource must be accessed in 16-byte
blocks at-a-time, or four 32-bit components, also knows as rows.
This information is necessary in order to properly distinguish between a typed
buffer like `RWBuffer` which is translated to `dx.TypedBuffer` vs.
`RWStructuredBuffer` which does not have this access constraint and
will be translated to `dx.RawBuffer`.

Fixes #107907
---
 clang/include/clang/AST/Type.h   | 11 ---
 clang/include/clang/AST/TypeProperties.td|  5 -
 clang/include/clang/Basic/Attr.td|  6 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp   |  4 ++--
 clang/lib/AST/TypePrinter.cpp|  3 +++
 clang/lib/Sema/HLSLExternalSemaSource.cpp| 14 +-
 clang/lib/Sema/SemaHLSL.cpp  |  6 ++
 clang/lib/Sema/SemaType.cpp  |  3 ++-
 .../ParserHLSL/hlsl_resource_handle_attrs.hlsl   |  4 ++--
 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl  | 16 
 .../ParserHLSL/hlsl_row_access_attr_error.hlsl   | 16 
 11 files changed, 74 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr_error.hlsl

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ef36a73716454f..d8336e1960c64e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6169,9 +6169,13 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 // Data gathered from HLSL resource attributes
 llvm::dxil::ResourceClass ResourceClass;
 uint8_t IsROV : 1;
-Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV)
-: ResourceClass(ResourceClass), IsROV(IsROV) {}
-Attributes() : ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0) {}
+uint8_t RowAccess : 1;
+Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV,
+   bool RowAccess)
+: ResourceClass(ResourceClass), IsROV(IsROV), RowAccess(RowAccess) {}
+Attributes()
+: ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0),
+  RowAccess(0) {}
   };
 
 private:
@@ -6204,6 +6208,7 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 ID.AddPointer(Contained.getAsOpaquePtr());
 ID.AddInteger(static_cast(Attrs.ResourceClass));
 ID.AddBoolean(Attrs.IsROV);
+ID.AddBoolean(Attrs.RowAccess);
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 539a344cb0b690..f310996d144959 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -697,6 +697,9 @@ let Class = HLSLAttributedResourceType in {
   def : Property<"isROV", Bool> {
 let Read = [{ node->getAttrs().IsROV }];
   }
+  def : Property<"rowAccess", Bool> {
+let Read = [{ node->getAttrs().RowAccess }];
+  }
   def : Property<"wrappedTy", QualType> {
 let Read = [{ node->getWrappedType() }];
   }
@@ -704,7 +707,7 @@ let Class = HLSLAttributedResourceType in {
 let Read = [{ node->getContainedType() }];
   }
   def : Creator<[{
-HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV);
+HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV, rowAccess);
 return ctx.getHLSLAttributedResourceType(wrappedTy, containedTy, attrs);
   }]>;
 }
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 9a7b163b2c6da8..7edf33dee93d0a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4669,6 +4669,12 @@ def HLSLResourceClass : TypeAttr {
   let Documentation = [InternalOnly];
 }
 
+def HLSLRowAccess : TypeAttr {
+  let Spellings = [CXX11<"hlsl", "row_access">];
+  let LangOpts = [HLSL]; 
+  let Documentation = [Internal

[clang] [HLSL] Add `[[hlsl::row_access]]` attribute (PR #107954)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107954

>From 1c66d2767ca20f42b6edaae834cc186be7d23712 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 9 Sep 2024 19:39:02 -0700
Subject: [PATCH 1/2] [HLSL] Add `[[hlsl::row_access]]` attribute

This PR introduces new HLSL resource type attribute [[hlsl::row_access]].
Presence of this attribute means that the resource must be accessed in 16-byte
blocks at-a-time, or four 32-bit components, also knows as rows.
This information is necessary in order to properly distinguish between a typed
buffer like `RWBuffer` which is translated to `dx.TypedBuffer` vs.
`RWStructuredBuffer` which does not have this access constraint and
will be translated to `dx.RawBuffer`.

Fixes #107907
---
 clang/include/clang/AST/Type.h   | 11 ---
 clang/include/clang/AST/TypeProperties.td|  5 -
 clang/include/clang/Basic/Attr.td|  6 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp   |  4 ++--
 clang/lib/AST/TypePrinter.cpp|  3 +++
 clang/lib/Sema/HLSLExternalSemaSource.cpp| 14 +-
 clang/lib/Sema/SemaHLSL.cpp  |  6 ++
 clang/lib/Sema/SemaType.cpp  |  3 ++-
 .../ParserHLSL/hlsl_resource_handle_attrs.hlsl   |  4 ++--
 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl  | 16 
 .../ParserHLSL/hlsl_row_access_attr_error.hlsl   | 16 
 11 files changed, 74 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr_error.hlsl

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ef36a73716454f..d8336e1960c64e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6169,9 +6169,13 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 // Data gathered from HLSL resource attributes
 llvm::dxil::ResourceClass ResourceClass;
 uint8_t IsROV : 1;
-Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV)
-: ResourceClass(ResourceClass), IsROV(IsROV) {}
-Attributes() : ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0) {}
+uint8_t RowAccess : 1;
+Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV,
+   bool RowAccess)
+: ResourceClass(ResourceClass), IsROV(IsROV), RowAccess(RowAccess) {}
+Attributes()
+: ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0),
+  RowAccess(0) {}
   };
 
 private:
@@ -6204,6 +6208,7 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 ID.AddPointer(Contained.getAsOpaquePtr());
 ID.AddInteger(static_cast(Attrs.ResourceClass));
 ID.AddBoolean(Attrs.IsROV);
+ID.AddBoolean(Attrs.RowAccess);
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 539a344cb0b690..f310996d144959 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -697,6 +697,9 @@ let Class = HLSLAttributedResourceType in {
   def : Property<"isROV", Bool> {
 let Read = [{ node->getAttrs().IsROV }];
   }
+  def : Property<"rowAccess", Bool> {
+let Read = [{ node->getAttrs().RowAccess }];
+  }
   def : Property<"wrappedTy", QualType> {
 let Read = [{ node->getWrappedType() }];
   }
@@ -704,7 +707,7 @@ let Class = HLSLAttributedResourceType in {
 let Read = [{ node->getContainedType() }];
   }
   def : Creator<[{
-HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV);
+HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV, rowAccess);
 return ctx.getHLSLAttributedResourceType(wrappedTy, containedTy, attrs);
   }]>;
 }
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 9a7b163b2c6da8..7edf33dee93d0a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4669,6 +4669,12 @@ def HLSLResourceClass : TypeAttr {
   let Documentation = [InternalOnly];
 }
 
+def HLSLRowAccess : TypeAttr {
+  let Spellings = [CXX11<"hlsl", "row_access">];
+  let LangOpts = [HLSL]; 
+  let Documentation = [InternalOnly];
+}
+
 def HLSLGroupSharedAddressSpace : TypeAttr {
   let Spellings = [CustomKeyword<"groupshared">];
   let Subjects = SubjectList<[Var]>;
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index f13ca2d08d769f..9896e0f48aed58 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -808,8 +808,8 @@ static bool
 IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const HLSLAttributedResourceType::Attributes &Attrs1,
  const HLSLAttributedRe

[clang] [HLSL] Warn on duplicate is_rov attribute; remove unnecessary parentheses (PR #107973)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/107973

We should issue a warning whenever a duplicate resource type attribute is 
found. Currently we do that only for `resource_class`. This PR fixes that by 
checking for duplicate `is_rov` attributes as well.

Also removes unnecessary parenthesis on `is_rov`.

>From 1f63b9e4a0969f95c6efa8fa42a48307dea8fe28 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 9 Sep 2024 22:14:57 -0700
Subject: [PATCH] [HLSL] Prohibit duplicate is_rov attributes; remove
 unnecessary parentheses

---
 clang/lib/AST/TypePrinter.cpp | 2 +-
 clang/lib/Sema/SemaHLSL.cpp   | 4 
 clang/lib/Sema/SemaType.cpp   | 6 +-
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   | 6 +++---
 clang/test/ParserHLSL/hlsl_is_rov_attr_error.hlsl | 8 
 clang/test/ParserHLSL/hlsl_resource_handle_attrs.hlsl | 2 +-
 6 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index add6a5d10d61f7..be627a6242eb40 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2077,7 +2077,7 @@ void TypePrinter::printHLSLAttributedResourceAfter(
  << HLSLResourceClassAttr::ConvertResourceClassToStr(Attrs.ResourceClass)
  << ")]]";
   if (Attrs.IsROV)
-OS << " [[hlsl::is_rov()]]";
+OS << " [[hlsl::is_rov]]";
 }
 
 void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 3b91303ac8cb8a..eb1b584b805c16 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -591,6 +591,10 @@ bool clang::CreateHLSLAttributedResourceType(Sema &S, 
QualType Wrapped,
   break;
 }
 case attr::HLSLROV:
+  if (ResAttrs.IsROV) {
+S.Diag(A->getLocation(), diag::warn_duplicate_attribute_exact) << A;
+return false;
+  }
   ResAttrs.IsROV = true;
   break;
 default:
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 520dce870b7b78..e627fee51b66b8 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8844,7 +8844,11 @@ static void processTypeAttrs(TypeProcessingState &state, 
QualType &type,
 }
 case ParsedAttr::AT_HLSLResourceClass:
 case ParsedAttr::AT_HLSLROV: {
-  if (state.getSema().HLSL().handleResourceTypeAttr(attr))
+  // Only collect HLSL resource type attributes that are in
+  // decl-specifier-seq; do not collect attributes on declarations or those
+  // that get to slide after declaration name.
+  if (TAL == TAL_DeclSpec &&
+  state.getSema().HLSL().handleResourceTypeAttr(attr))
 attr.setUsedAsTypeAttr();
   break;
 }
diff --git a/clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl 
b/clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl
index 24c85c6ccf7d74..cf21ec4d380dbf 100644
--- a/clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl
+++ b/clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o 
- %s | FileCheck %s
 
 // CHECK: CXXRecordDecl 0x{{[0-9a-f]+}} {{.*}} struct MyBuffer definition
-// CHECK: FieldDecl 0x{{[0-9a-f]+}}  col:68 h 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(UAV)]] 
{{\[\[}}hlsl::is_rov()]]':'__hlsl_resource_t'
+// CHECK: FieldDecl 0x{{[0-9a-f]+}}  col:68 h 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(UAV)]] 
{{\[\[}}hlsl::is_rov]]':'__hlsl_resource_t'
 struct MyBuffer {
   __hlsl_resource_t [[hlsl::resource_class(UAV)]] [[hlsl::is_rov]] h;
 };
 
-// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:66 res 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(SRV)]] 
{{\[\[}}hlsl::is_rov()]]':'__hlsl_resource_t'
+// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:66 res 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(SRV)]] 
{{\[\[}}hlsl::is_rov]]':'__hlsl_resource_t'
 __hlsl_resource_t [[hlsl::is_rov]] [[hlsl::resource_class(SRV)]] res;
 
 // CHECK: FunctionDecl 0x{{[0-9a-f]+}}  line:14:6 f 
'void ()
-// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:72 r '__hlsl_resource_t 
{{\[\[}}hlsl::resource_class(Sampler)]] 
{{\[\[}}hlsl::is_rov()]]':'__hlsl_resource_t'
+// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:72 r '__hlsl_resource_t 
{{\[\[}}hlsl::resource_class(Sampler)]] 
{{\[\[}}hlsl::is_rov]]':'__hlsl_resource_t'
 void f() {
   __hlsl_resource_t [[hlsl::resource_class(Sampler)]] [[hlsl::is_rov]] r;
 }
diff --git a/clang/test/ParserHLSL/hlsl_is_rov_attr_error.hlsl 
b/clang/test/ParserHLSL/hlsl_is_rov_attr_error.hlsl
index 68b2d9ecb190a8..15685bd1a3baa7 100644
--- a/clang/test/ParserHLSL/hlsl_is_rov_attr_error.hlsl
+++ b/clang/test/ParserHLSL/hlsl_is_rov_attr_error.hlsl
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - %s 
-verify
 
 // expected-error@+1{{'is_rov' attribute cannot be applied to a declaration}}
-[[hlsl::is_rov()]] __hlsl_resource_t res0

[clang] [HLSL] Add `[[hlsl::row_access]]` attribute (PR #107954)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107954

>From 1c66d2767ca20f42b6edaae834cc186be7d23712 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 9 Sep 2024 19:39:02 -0700
Subject: [PATCH 1/3] [HLSL] Add `[[hlsl::row_access]]` attribute

This PR introduces new HLSL resource type attribute [[hlsl::row_access]].
Presence of this attribute means that the resource must be accessed in 16-byte
blocks at-a-time, or four 32-bit components, also knows as rows.
This information is necessary in order to properly distinguish between a typed
buffer like `RWBuffer` which is translated to `dx.TypedBuffer` vs.
`RWStructuredBuffer` which does not have this access constraint and
will be translated to `dx.RawBuffer`.

Fixes #107907
---
 clang/include/clang/AST/Type.h   | 11 ---
 clang/include/clang/AST/TypeProperties.td|  5 -
 clang/include/clang/Basic/Attr.td|  6 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp   |  4 ++--
 clang/lib/AST/TypePrinter.cpp|  3 +++
 clang/lib/Sema/HLSLExternalSemaSource.cpp| 14 +-
 clang/lib/Sema/SemaHLSL.cpp  |  6 ++
 clang/lib/Sema/SemaType.cpp  |  3 ++-
 .../ParserHLSL/hlsl_resource_handle_attrs.hlsl   |  4 ++--
 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl  | 16 
 .../ParserHLSL/hlsl_row_access_attr_error.hlsl   | 16 
 11 files changed, 74 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr_error.hlsl

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ef36a73716454f..d8336e1960c64e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6169,9 +6169,13 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 // Data gathered from HLSL resource attributes
 llvm::dxil::ResourceClass ResourceClass;
 uint8_t IsROV : 1;
-Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV)
-: ResourceClass(ResourceClass), IsROV(IsROV) {}
-Attributes() : ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0) {}
+uint8_t RowAccess : 1;
+Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV,
+   bool RowAccess)
+: ResourceClass(ResourceClass), IsROV(IsROV), RowAccess(RowAccess) {}
+Attributes()
+: ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0),
+  RowAccess(0) {}
   };
 
 private:
@@ -6204,6 +6208,7 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 ID.AddPointer(Contained.getAsOpaquePtr());
 ID.AddInteger(static_cast(Attrs.ResourceClass));
 ID.AddBoolean(Attrs.IsROV);
+ID.AddBoolean(Attrs.RowAccess);
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 539a344cb0b690..f310996d144959 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -697,6 +697,9 @@ let Class = HLSLAttributedResourceType in {
   def : Property<"isROV", Bool> {
 let Read = [{ node->getAttrs().IsROV }];
   }
+  def : Property<"rowAccess", Bool> {
+let Read = [{ node->getAttrs().RowAccess }];
+  }
   def : Property<"wrappedTy", QualType> {
 let Read = [{ node->getWrappedType() }];
   }
@@ -704,7 +707,7 @@ let Class = HLSLAttributedResourceType in {
 let Read = [{ node->getContainedType() }];
   }
   def : Creator<[{
-HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV);
+HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV, rowAccess);
 return ctx.getHLSLAttributedResourceType(wrappedTy, containedTy, attrs);
   }]>;
 }
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 9a7b163b2c6da8..7edf33dee93d0a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4669,6 +4669,12 @@ def HLSLResourceClass : TypeAttr {
   let Documentation = [InternalOnly];
 }
 
+def HLSLRowAccess : TypeAttr {
+  let Spellings = [CXX11<"hlsl", "row_access">];
+  let LangOpts = [HLSL]; 
+  let Documentation = [InternalOnly];
+}
+
 def HLSLGroupSharedAddressSpace : TypeAttr {
   let Spellings = [CustomKeyword<"groupshared">];
   let Subjects = SubjectList<[Var]>;
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index f13ca2d08d769f..9896e0f48aed58 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -808,8 +808,8 @@ static bool
 IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const HLSLAttributedResourceType::Attributes &Attrs1,
  const HLSLAttributedRe

[clang] [HLSL] Add `[[hlsl::row_access]]` attribute (PR #107954)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota ready_for_review 
https://github.com/llvm/llvm-project/pull/107954
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104856

>From 44e814b925a1ad8ac40fe6904542cbade516c065 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 19 Aug 2024 13:34:13 -0700
Subject: [PATCH 1/7] [DirectX] Add DirectXTargetCodeGenInfo

Adds TargetCodeGenInfo class for DirectX. Currently in only translates 
`target("dx.TypedBuffer", i32, 1, 0, 1)` for now (`RWBuffer`). More work 
us needed to determine the actual target exp type and its parameters based on 
attributes on the handle type (not yet implemented).

Part 1/2 of #95952
---
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/CodeGen/TargetInfo.h|  3 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 60 +++
 4 files changed, 66 insertions(+)
 create mode 100644 clang/lib/CodeGen/Targets/DirectX.cpp

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index deb7b27266d736..aa0c871c5352a8 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -122,6 +122,7 @@ add_clang_library(clangCodeGen
   Targets/AVR.cpp
   Targets/BPF.cpp
   Targets/CSKY.cpp
+  Targets/DirectX.cpp
   Targets/Hexagon.cpp
   Targets/Lanai.cpp
   Targets/LoongArch.cpp
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0b61ef0f89989c..f93e79d1dffecd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -298,6 +298,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
   case llvm::Triple::spirv32:
   case llvm::Triple::spirv64:
 return createSPIRVTargetCodeGenInfo(CGM);
+  case llvm::Triple::dxil:
+return createDirectXTargetCodeGenInfo(CGM);
   case llvm::Triple::ve:
 return createVETargetCodeGenInfo(CGM);
   case llvm::Triple::csky: {
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 0244ca006d498b..3e503538b2b14d 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -555,6 +555,9 @@ createTCETargetCodeGenInfo(CodeGenModule &CGM);
 std::unique_ptr
 createVETargetCodeGenInfo(CodeGenModule &CGM);
 
+std::unique_ptr
+createDirectXTargetCodeGenInfo(CodeGenModule &CGM);
+
 enum class WebAssemblyABIKind {
   MVP = 0,
   ExperimentalMV = 1,
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
new file mode 100644
index 00..847ca7ddce1810
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -0,0 +1,60 @@
+//===- DirectX.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ABIInfoImpl.h"
+#include "TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation for DirectX.
+//===--===//
+
+namespace {
+
+class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
+};
+
+llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
+  const Type *Ty) const {
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  if (auto *BuiltinTy = dyn_cast(Ty)) {
+switch (BuiltinTy->getKind()) {
+case BuiltinType::HLSLResource: {
+  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", i32, 1,
+  // 0, 1) only for now (RWBuffer); more work us needed to determine
+  // the target ext type and its parameters based on the handle type
+  // attributes (not yet implemented)
+  llvm::IntegerType *ElemType = llvm::IntegerType::getInt32Ty(Ctx);
+  ArrayRef Flags = {/*IsWriteable*/ 1, /*IsROV*/ 0,
+  /*IsSigned*/ 1};
+  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, 
Flags);
+}
+default:
+  llvm_unreachable("unhandled builtin type");
+}
+  }
+  return nullptr;
+}
+
+} // namespace
+
+std::unique_ptr
+CodeGen::createDirectXTargetCodeGenInfo(CodeGenModule &CGM) {
+  return std::make_unique(CGM.getTypes());
+}

>From efbf44be7bf6f55deb1d0cfd002b6219fda679bf Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 19 Aug 2024 22:29:37 -0700
Subject: [PATCH 2/7] code review feedback (no test yet)

---
 clang/lib/CodeGen/Targets/DirectX.cpp | 32 ++

[clang] [HLSL] Warn on duplicate is_rov attribute; remove unnecessary parentheses (PR #107973)

2024-09-10 Thread Helena Kotas via cfe-commits


@@ -8844,7 +8844,11 @@ static void processTypeAttrs(TypeProcessingState &state, 
QualType &type,
 }
 case ParsedAttr::AT_HLSLResourceClass:
 case ParsedAttr::AT_HLSLROV: {
-  if (state.getSema().HLSL().handleResourceTypeAttr(attr))
+  // Only collect HLSL resource type attributes that are in
+  // decl-specifier-seq; do not collect attributes on declarations or those
+  // that get to slide after declaration name.
+  if (TAL == TAL_DeclSpec &&
+  state.getSema().HLSL().handleResourceTypeAttr(attr))

hekota wrote:

When a type attribute is on a declaration the error is reported later on after 
this processing happens, but we want to avoid collecting these attributes in 
SemaHLSL.

https://github.com/llvm/llvm-project/pull/107973
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add DirectXTargetCodeGenInfo (PR #104856)

2024-09-10 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/104856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Warn on duplicate is_rov attribute; remove unnecessary parentheses (PR #107973)

2024-09-10 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/107973
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add `[[hlsl::row_access]]` attribute (PR #107954)

2024-09-10 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/107954

>From 1c66d2767ca20f42b6edaae834cc186be7d23712 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 9 Sep 2024 19:39:02 -0700
Subject: [PATCH 1/4] [HLSL] Add `[[hlsl::row_access]]` attribute

This PR introduces new HLSL resource type attribute [[hlsl::row_access]].
Presence of this attribute means that the resource must be accessed in 16-byte
blocks at-a-time, or four 32-bit components, also knows as rows.
This information is necessary in order to properly distinguish between a typed
buffer like `RWBuffer` which is translated to `dx.TypedBuffer` vs.
`RWStructuredBuffer` which does not have this access constraint and
will be translated to `dx.RawBuffer`.

Fixes #107907
---
 clang/include/clang/AST/Type.h   | 11 ---
 clang/include/clang/AST/TypeProperties.td|  5 -
 clang/include/clang/Basic/Attr.td|  6 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp   |  4 ++--
 clang/lib/AST/TypePrinter.cpp|  3 +++
 clang/lib/Sema/HLSLExternalSemaSource.cpp| 14 +-
 clang/lib/Sema/SemaHLSL.cpp  |  6 ++
 clang/lib/Sema/SemaType.cpp  |  3 ++-
 .../ParserHLSL/hlsl_resource_handle_attrs.hlsl   |  4 ++--
 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl  | 16 
 .../ParserHLSL/hlsl_row_access_attr_error.hlsl   | 16 
 11 files changed, 74 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr.hlsl
 create mode 100644 clang/test/ParserHLSL/hlsl_row_access_attr_error.hlsl

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ef36a73716454f..d8336e1960c64e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6169,9 +6169,13 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 // Data gathered from HLSL resource attributes
 llvm::dxil::ResourceClass ResourceClass;
 uint8_t IsROV : 1;
-Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV)
-: ResourceClass(ResourceClass), IsROV(IsROV) {}
-Attributes() : ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0) {}
+uint8_t RowAccess : 1;
+Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV,
+   bool RowAccess)
+: ResourceClass(ResourceClass), IsROV(IsROV), RowAccess(RowAccess) {}
+Attributes()
+: ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0),
+  RowAccess(0) {}
   };
 
 private:
@@ -6204,6 +6208,7 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 ID.AddPointer(Contained.getAsOpaquePtr());
 ID.AddInteger(static_cast(Attrs.ResourceClass));
 ID.AddBoolean(Attrs.IsROV);
+ID.AddBoolean(Attrs.RowAccess);
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 539a344cb0b690..f310996d144959 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -697,6 +697,9 @@ let Class = HLSLAttributedResourceType in {
   def : Property<"isROV", Bool> {
 let Read = [{ node->getAttrs().IsROV }];
   }
+  def : Property<"rowAccess", Bool> {
+let Read = [{ node->getAttrs().RowAccess }];
+  }
   def : Property<"wrappedTy", QualType> {
 let Read = [{ node->getWrappedType() }];
   }
@@ -704,7 +707,7 @@ let Class = HLSLAttributedResourceType in {
 let Read = [{ node->getContainedType() }];
   }
   def : Creator<[{
-HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV);
+HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV, rowAccess);
 return ctx.getHLSLAttributedResourceType(wrappedTy, containedTy, attrs);
   }]>;
 }
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 9a7b163b2c6da8..7edf33dee93d0a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4669,6 +4669,12 @@ def HLSLResourceClass : TypeAttr {
   let Documentation = [InternalOnly];
 }
 
+def HLSLRowAccess : TypeAttr {
+  let Spellings = [CXX11<"hlsl", "row_access">];
+  let LangOpts = [HLSL]; 
+  let Documentation = [InternalOnly];
+}
+
 def HLSLGroupSharedAddressSpace : TypeAttr {
   let Spellings = [CustomKeyword<"groupshared">];
   let Subjects = SubjectList<[Var]>;
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index f13ca2d08d769f..9896e0f48aed58 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -808,8 +808,8 @@ static bool
 IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const HLSLAttributedResourceType::Attributes &Attrs1,
  const HLSLAttributedRe

[clang] [llvm] [HLSL] Mark exported functions with "hlsl.export" attribute (PR #102275)

2024-08-13 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed 
https://github.com/llvm/llvm-project/pull/102275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Split out the ROV attribute from the resource attribute, make it a new spellable attribute. (PR #102414)

2024-08-13 Thread Helena Kotas via cfe-commits


@@ -296,12 +296,13 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl 
*D, GlobalVariable *GV) {
   for (auto *FD : RD->fields()) {
 const auto *HLSLResAttr = FD->getAttr();
 const auto *HLSLResClassAttr = FD->getAttr();
+const auto *ROVAttr = FD->getAttr();

hekota wrote:

`ROVAttr` is not used

https://github.com/llvm/llvm-project/pull/102414
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Split out the ROV attribute from the resource attribute, make it a new spellable attribute. (PR #102414)

2024-08-13 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited 
https://github.com/llvm/llvm-project/pull/102414
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Split out the ROV attribute from the resource attribute, make it a new spellable attribute. (PR #102414)

2024-08-13 Thread Helena Kotas via cfe-commits

https://github.com/hekota approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/102414
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Implement '__builtin_is_intangible' type trait (PR #104544)

2024-08-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/104544

Implements `__builtin_is_intangible` type trait.

HLSL intangible types are special implementation-defined types such as resource 
handles or samplers. Any class that is an array of intangible type or contains 
base class or members of intangible types is also an intangible type. 

Fixes #[102954](https://github.com/llvm/llvm-project/issues/102954)

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 1/3] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return tru

[clang] [HLSL] Implement '__builtin_is_intangible' type trait (PR #104544)

2024-08-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 1/4] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 2/4] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 -
 

[clang] [HLSL] Implement '__builtin_is_intangible' type trait (PR #104544)

2024-08-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 1/5] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 2/5] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 -
 

[clang] [HLSL] Implement '__builtin_is_intangible' type trait (PR #104544)

2024-08-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/104544

>From 6d5f8991a4ef9e79bc1bed30addf7b29b7ed0d2e Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 19:03:29 -0700
Subject: [PATCH 1/6] Implement `__builtin_is_intangible`

---
 clang/include/clang/Basic/TokenKinds.def |  3 ++
 clang/include/clang/Sema/SemaHLSL.h  |  3 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  8 
 clang/lib/Sema/SemaHLSL.cpp  | 49 
 4 files changed, 63 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d683106bb0e298..f4fc7c321d9c5a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -660,6 +660,9 @@ KEYWORD(out , KEYHLSL)
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
+// HLSL Type traits
+TYPE_TRAIT_1(__builtin_is_intangible, IsIntangibleType, KEYHLSL)
+
 // OpenMP Type Traits
 UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, 
OpenMPRequiredSimdAlign, KEYALL)
 
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index d60cb2a57d4918..13e75a79ec6bf0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,9 @@ class SemaHLSL : public SemaBase {
   void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
 
   bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+
+  // HLSL Type trait implementations
+  bool IsIntangibleType(QualType T1) const;
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..f3f8d511a6e568 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaCUDA.h"
+#include "clang/Sema/SemaHLSL.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
 #include "clang/Sema/SemaObjC.h"
@@ -5683,6 +5684,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return true;
 return false;
   }
+  case UTT_IsIntangibleType:
+if (!T->isVoidType() && !T->isIncompleteArrayType())
+  if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
+   diag::err_incomplete_type))
+return true;
+DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___builtin_is_intangible);
+return Self.HLSL().IsIntangibleType(T);
   }
 }
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index e3e926465e799e..5978c14399ba32 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
@@ -1154,3 +1155,51 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   }
   return false;
 }
+
+bool SemaHLSL::IsIntangibleType(QualType Ty) const {
+  if (Ty.isNull())
+return false;
+
+  Ty = Ty.getCanonicalType().getUnqualifiedType();
+  if (Ty->isBuiltinType())
+return Ty->isHLSLSpecificType();
+
+  llvm::SmallVector TypesToScan;
+  TypesToScan.push_back(Ty);
+  while (!TypesToScan.empty()) {
+QualType T = TypesToScan.pop_back_val();
+assert(T == T.getCanonicalType().getUnqualifiedType() && "expected 
sugar-free type");
+assert(!isa(T) && "Matrix types not yet supported in HLSL");
+
+if (const auto *AT = dyn_cast(T)) {
+  QualType ElTy = 
AT->getElementType().getCanonicalType().getUnqualifiedType();
+  if (ElTy->isBuiltinType())
+return ElTy->isHLSLSpecificType();
+  TypesToScan.push_back(ElTy);
+  continue; 
+}
+
+if (const auto *VT = dyn_cast(T)) {
+  QualType ElTy = 
VT->getElementType().getCanonicalType().getUnqualifiedType();
+  assert(ElTy->isBuiltinType() && "vectors can only contain builtin 
types");
+  if (ElTy->isHLSLSpecificType())
+return true;
+  continue;
+}
+
+if (const auto *RT = dyn_cast(T)) {
+  const RecordDecl *RD = RT->getDecl();
+  for (const auto *FD : RD->fields()) {
+QualType FieldTy = 
FD->getType().getCanonicalType().getUnqualifiedType();
+if (FieldTy->isBuiltinType()) {
+  if (FieldTy->isHLSLSpecificType())
+return true;
+} else {
+  TypesToScan.push_back(FieldTy); 
+}
+  }
+  continue;
+}
+  }
+  return false;
+}

>From d21ca2e2891acbd6c89864b57d864d881a8a8b96 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 15 Aug 2024 20:52:24 -0700
Subject: [PATCH 2/6] add caching

---
 clang/include/clang/Sema/SemaHLSL.h |  5 -
 

[clang] [HLSL] Implement '__builtin_is_intangible' type trait (PR #104544)

2024-08-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota ready_for_review 
https://github.com/llvm/llvm-project/pull/104544
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix spurious non-strict availability warning (PR #94377)

2024-06-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota commented:

LGTM!

https://github.com/llvm/llvm-project/pull/94377
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Use llvm::Triple::EnvironmentType instead of HLSLShaderAttr::ShaderType (PR #93847)

2024-06-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/93847

>From dd175a247480396b9d35cb995333fcd14152e347 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 29 May 2024 18:38:45 -0700
Subject: [PATCH 1/3] [HLSL] Use llvm::Triple::EnvironmentType instead of
 ShaderType

HLSLShaderAttr::ShaderType enum is a subset of llvm::Triple::EnvironmentType 
and is not needed.
---
 clang/include/clang/Basic/Attr.td   |  29 +++-
 clang/include/clang/Sema/SemaHLSL.h |   6 +-
 clang/lib/CodeGen/CGHLSLRuntime.cpp |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp |   4 +-
 clang/lib/Sema/SemaHLSL.cpp | 105 +++-
 5 files changed, 72 insertions(+), 74 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 2665b7353ca4a..e373c073ec906 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4469,36 +4469,23 @@ def HLSLShader : InheritableAttr {
   let Subjects = SubjectList<[HLSLEntry]>;
   let LangOpts = [HLSL];
   let Args = [
-EnumArgument<"Type", "ShaderType", /*is_string=*/true,
+EnumArgument<"Type", "llvm::Triple::EnvironmentType", /*is_string=*/true,
  ["pixel", "vertex", "geometry", "hull", "domain", "compute",
   "raygeneration", "intersection", "anyhit", "closesthit",
   "miss", "callable", "mesh", "amplification"],
  ["Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
   "RayGeneration", "Intersection", "AnyHit", "ClosestHit",
-  "Miss", "Callable", "Mesh", "Amplification"]>
+  "Miss", "Callable", "Mesh", "Amplification"],
+  /*opt=*/0, /*fake=*/0, /*isExternalType=*/1>
   ];
   let Documentation = [HLSLSV_ShaderTypeAttrDocs];
   let AdditionalMembers =
 [{
-  static const unsigned ShaderTypeMaxValue = 
(unsigned)HLSLShaderAttr::Amplification;
-
-  static llvm::Triple::EnvironmentType 
getTypeAsEnvironment(HLSLShaderAttr::ShaderType ShaderType) {
-switch (ShaderType) {
-  case HLSLShaderAttr::Pixel: return llvm::Triple::Pixel;
-  case HLSLShaderAttr::Vertex:return llvm::Triple::Vertex;
-  case HLSLShaderAttr::Geometry:  return llvm::Triple::Geometry;
-  case HLSLShaderAttr::Hull:  return llvm::Triple::Hull;
-  case HLSLShaderAttr::Domain:return llvm::Triple::Domain;
-  case HLSLShaderAttr::Compute:   return llvm::Triple::Compute;
-  case HLSLShaderAttr::RayGeneration: return llvm::Triple::RayGeneration;
-  case HLSLShaderAttr::Intersection:  return llvm::Triple::Intersection;
-  case HLSLShaderAttr::AnyHit:return llvm::Triple::AnyHit;
-  case HLSLShaderAttr::ClosestHit:return llvm::Triple::ClosestHit;
-  case HLSLShaderAttr::Miss:  return llvm::Triple::Miss;
-  case HLSLShaderAttr::Callable:  return llvm::Triple::Callable;
-  case HLSLShaderAttr::Mesh:  return llvm::Triple::Mesh;
-  case HLSLShaderAttr::Amplification: return llvm::Triple::Amplification;
-}
+  static const llvm::Triple::EnvironmentType MinShaderTypeValue = 
llvm::Triple::Pixel;
+  static const llvm::Triple::EnvironmentType MaxShaderTypeValue = 
llvm::Triple::Amplification;
+
+  static bool isValidShaderType(llvm::Triple::EnvironmentType ShaderType) {
+return ShaderType >= MinShaderTypeValue && ShaderType <= 
MaxShaderTypeValue;
   }
 }];
 }
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index eac1f7c07c85d..00df6c2bd15e4 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -38,7 +38,7 @@ class SemaHLSL : public SemaBase {
   const AttributeCommonInfo &AL, int X,
   int Y, int Z);
   HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL,
-  HLSLShaderAttr::ShaderType ShaderType);
+  llvm::Triple::EnvironmentType ShaderType);
   HLSLParamModifierAttr *
   mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL,
  HLSLParamModifierAttr::Spelling Spelling);
@@ -47,8 +47,8 @@ class SemaHLSL : public SemaBase {
   void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
const HLSLAnnotationAttr *AnnotationAttr);
   void DiagnoseAttrStageMismatch(
-  const Attr *A, HLSLShaderAttr::ShaderType Stage,
-  std::initializer_list AllowedStages);
+  const Attr *A, llvm::Triple::EnvironmentType Stage,
+  std::initializer_list AllowedStages);
   void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU);
 };
 
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5e6a3dd4878f4..55ba21ae2ba69 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRu

[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)

2024-06-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/93336
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)

2024-06-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/93336
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Change default linkage of HLSL functions and `groupshared` variables (PR #93336)

2024-06-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/93336
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   7   8   9   >