[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-15 Thread Justin Bogner via cfe-commits

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


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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/9] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/9] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-10 Thread Greg Roth via cfe-commits


@@ -1,9 +1,53 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-O1 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library 
-finclude-default-header -x hlsl -emit-llvm -o - %s | FileCheck %s
 
-void foo(__hlsl_resource_t res);
+using handle_float_t = __hlsl_resource_t [[hlsl::resource_class(UAV)]] 
[[hlsl::contained_type(float)]];
 
-// CHECK: define void 
@"?bar@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 
0) %[[PARAM:[a-zA-Z0-9]+]])
-// CHECK: call void 
@"?foo@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 
0) %[[PARAM]])
-void bar(__hlsl_resource_t a) {
-foo(a);
+// CHECK: %"class.hlsl::RWBuffer" = type { target("dx.TypedBuffer", <4 x 
float>, 1, 0, 0)
+// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", 
%struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }, 1, 0)
+
+// CHECK: define void 
@"?fa@@YAXUHLSLAttributedResourceType@__hlsl@@@Z"(target("dx.TypedBuffer", 
float, 1, 0, 0) %a)
+// CHECK: call void 
@"?foo1@@YAXUHLSLAttributedResourceType@__hlsl@@@Z"(target("dx.TypedBuffer", 
float, 1, 0, 0) %0)
+// CHECK: declare void 
@"?foo1@@YAXUHLSLAttributedResourceType@__hlsl@@@Z"(target("dx.TypedBuffer", 
float, 1, 0, 0))
+
+void foo1(handle_float_t res);
+
+void fa(handle_float_t a) {
+foo1(a);
+}
+
+// CHECK: define void 
@"?fb@@YAXUHLSLAttributedResourceType@__hlsl@@@Z"(target("dx.TypedBuffer", 
float, 1, 0, 0) %a)
+void fb(handle_float_t a) {
+handle_float_t b = a;
 }
+
+// CHECK: define void 
@"?fc@@YAXV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@@Z"(ptr noundef 
byval(%"class.hlsl::RWBuffer") align 16 %a)
+// CHECK: call void 
@"?foo2@@YAXV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@@Z"(ptr noundef 
byval(%"class.hlsl::RWBuffer") align 16 %agg.tmp)  
+// CHECK: declare void 
@"?foo2@@YAXV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@@Z"(ptr noundef 
byval(%"class.hlsl::RWBuffer") align 16)
+void foo2(RWBuffer buf);
+
+void fc(RWBuffer a) {
+  foo2(a);
+}
+
+void fd(RWBuffer a) {
+  RWBuffer b = a;
+}
+
+struct MyStruct {
+  float4 f;
+  int2 i;
+};
+
+// CHECK: define void @"?fe@@YAXV?$StructuredBuffer@UMyStruct@@@hlsl@@@Z"(ptr 
noundef byval(%"class.hlsl::StructuredBuffer") align 16 %a)
+// CHECK: call void @"?foo3@@YAXV?$StructuredBuffer@UMyStruct@@@hlsl@@@Z"(ptr 
noundef byval(%"class.hlsl::StructuredBuffer") align 16 %agg.tmp)
+// CHECK: declare void 
@"?foo3@@YAXV?$StructuredBuffer@UMyStruct@@@hlsl@@@Z"(ptr noundef 
byval(%"class.hlsl::StructuredBuffer") align 16)

pow2clk wrote:

I'm afraid this change #111632 will cause these mangles to change and this test 
to fail. Just a note in case the order of things results in that change going 
in between when this one is last tested and when it's submitted.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -11533,6 +11539,18 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType 
RHS, bool OfBlockPointer,
   return {};
 return LHS;
   }
+  case Type::HLSLAttributedResource: {
+const HLSLAttributedResourceType *LHSTy =
+LHS->castAs();
+const HLSLAttributedResourceType *RHSTy =
+RHS->castAs();
+
+if (LHSTy->getWrappedType() == RHSTy->getWrappedType() &&

hekota wrote:

Yes it is. I guess I can change this to assert.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -4493,28 +4493,34 @@ void CXXNameMangler::mangleType(const 
ArrayParameterType *T) {
 }
 
 void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
-  mangleType(T->getWrappedType());
+  llvm::SmallString<64> Str("_Res");
   const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
   // map resource class to HLSL virtual register letter
   switch (Attrs.ResourceClass) {
-  case llvm::dxil::ResourceClass::UAV:
-Out << 'u';
+  case llvm::dxil::ResourceClass::UAV: 
+Str += "_u";
 break;
-  case llvm::dxil::ResourceClass::SRV:
-Out << 't';
+  case llvm::dxil::ResourceClass::SRV: 
+Str += "_t";
 break;
   case llvm::dxil::ResourceClass::CBuffer:
-Out << 'b';
+Str += "_b";
 break;
   case llvm::dxil::ResourceClass::Sampler:
-Out << 's';
+Str += "_s";
 break;
   }
-  mangleNumber(Attrs.IsROV);
-  mangleNumber(Attrs.RawBuffer);
+  mangleVendorQualifier(Str);
+  if (Attrs.IsROV)
+mangleVendorQualifier("_ROV");
+  if (Attrs.RawBuffer)
+mangleVendorQualifier("_Raw");
 
-  if (!T->hasContainedType())
+  if (!T->hasContainedType()) {
+mangleVendorQualifier("__CT");

hekota wrote:

Nope :) Thanks for the catch!

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-09 Thread Greg Roth via cfe-commits


@@ -4492,6 +4492,37 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
+  llvm::SmallString<64> Str("_Res");
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  // map resource class to HLSL virtual register letter
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Str += "_u";
+break;
+  case llvm::dxil::ResourceClass::SRV:
+Str += "_t";
+break;
+  case llvm::dxil::ResourceClass::CBuffer:
+Str += "_b";
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+Str += "_s";
+break;
+  }
+  mangleVendorQualifier(Str);
+  if (Attrs.IsROV)

pow2clk wrote:

I think these three string literals should probably be munged into the 
preceeding `Str` and `mangledVendorQualifie`d as a unit rather than giving each 
their own character count and prefix. 

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-09 Thread Greg Roth via cfe-commits

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-09 Thread Greg Roth via cfe-commits


@@ -11533,6 +11539,18 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType 
RHS, bool OfBlockPointer,
   return {};
 return LHS;
   }
+  case Type::HLSLAttributedResource: {
+const HLSLAttributedResourceType *LHSTy =
+LHS->castAs();
+const HLSLAttributedResourceType *RHSTy =
+RHS->castAs();
+
+if (LHSTy->getWrappedType() == RHSTy->getWrappedType() &&

pow2clk wrote:

Not objecting so much as confirming I understand, but isn't the wrapped type 
always the same `__hlsl_resource_t`?

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-09 Thread Greg Roth via cfe-commits


@@ -4493,28 +4493,34 @@ void CXXNameMangler::mangleType(const 
ArrayParameterType *T) {
 }
 
 void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
-  mangleType(T->getWrappedType());
+  llvm::SmallString<64> Str("_Res");
   const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
   // map resource class to HLSL virtual register letter
   switch (Attrs.ResourceClass) {
-  case llvm::dxil::ResourceClass::UAV:
-Out << 'u';
+  case llvm::dxil::ResourceClass::UAV: 
+Str += "_u";
 break;
-  case llvm::dxil::ResourceClass::SRV:
-Out << 't';
+  case llvm::dxil::ResourceClass::SRV: 

pow2clk wrote:

nit: introduced trailing whitespace

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-09 Thread Greg Roth via cfe-commits


@@ -4493,28 +4493,34 @@ void CXXNameMangler::mangleType(const 
ArrayParameterType *T) {
 }
 
 void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
-  mangleType(T->getWrappedType());
+  llvm::SmallString<64> Str("_Res");
   const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
   // map resource class to HLSL virtual register letter
   switch (Attrs.ResourceClass) {
-  case llvm::dxil::ResourceClass::UAV:
-Out << 'u';
+  case llvm::dxil::ResourceClass::UAV: 
+Str += "_u";
 break;
-  case llvm::dxil::ResourceClass::SRV:
-Out << 't';
+  case llvm::dxil::ResourceClass::SRV: 
+Str += "_t";
 break;
   case llvm::dxil::ResourceClass::CBuffer:
-Out << 'b';
+Str += "_b";
 break;
   case llvm::dxil::ResourceClass::Sampler:
-Out << 's';
+Str += "_s";
 break;
   }
-  mangleNumber(Attrs.IsROV);
-  mangleNumber(Attrs.RawBuffer);
+  mangleVendorQualifier(Str);
+  if (Attrs.IsROV)
+mangleVendorQualifier("_ROV");
+  if (Attrs.RawBuffer)
+mangleVendorQualifier("_Raw");
 
-  if (!T->hasContainedType())
+  if (!T->hasContainedType()) {
+mangleVendorQualifier("__CT");

pow2clk wrote:

Curious if two underscores was intended?

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-09 Thread Greg Roth via cfe-commits

https://github.com/pow2clk commented:

I'm a bit out of my depth here, but I've been trying to understand Itanium 
mangling better and I think my suggestion to coalesce the vendor mangled 
portions is valid at least.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -32,6 +32,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CRC.h"
+#include "llvm/Support/DXILABI.h"

hekota wrote:

Nope :)

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/7] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -13672,6 +13690,9 @@ static QualType getCommonNonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 TX->getDepth(), TX->getIndex(), TX->isParameterPack(),
 getCommonDecl(TX->getDecl(), TY->getDecl()));
   }
+  case Type::HLSLAttributedResource: {

hekota wrote:

I don't think this type should be sugared. I've added it to the diet types 
above.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -3437,6 +3437,9 @@ static void encodeTypeForFunctionPointerAuth(const 
ASTContext &Ctx,
 OS << II->getLength() << II->getName();
 return;
   }
+  case Type::HLSLAttributedResource:

hekota wrote:

The other "should never get here"' is in a different switch statement. I will 
update the message to match.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits


@@ -32,6 +32,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CRC.h"
+#include "llvm/Support/DXILABI.h"

llvm-beanz wrote:

Do we need this include?

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits


@@ -4205,6 +4208,9 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
   case Type::Atomic:
 // No fields, at least for the moment.
 break;
+
+  case Type::HLSLAttributedResource:
+llvm_unreachable("not yet implemented");

llvm-beanz wrote:

This too should probably be "HLSL doesn't support RTTI".

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits


@@ -3943,6 +3943,9 @@ void ItaniumRTTIBuilder::BuildVTablePointer(const Type 
*Ty) {
 // abi::__pointer_to_member_type_info.
 VTableName = "_ZTVN10__cxxabiv129__pointer_to_member_type_infoE";
 break;
+
+  case Type::HLSLAttributedResource:
+llvm_unreachable("not yet implemented");

llvm-beanz wrote:

I suspect we should probably make this more of an "HLSL doesn't support virtual 
functions".

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits


@@ -3437,6 +3437,9 @@ static void encodeTypeForFunctionPointerAuth(const 
ASTContext &Ctx,
 OS << II->getLength() << II->getName();
 return;
   }
+  case Type::HLSLAttributedResource:

llvm-beanz wrote:

This should maybe be higher up with the "should never get here" because I don't 
think we'll be supporting authenticated pointers for this.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits


@@ -29,19 +29,40 @@ class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
 
 llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
   const Type *Ty) const {
-  auto *BuiltinTy = dyn_cast(Ty);
-  if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+  auto *ResType = dyn_cast(Ty);
+  if (!ResType)
 return nullptr;
 
   llvm::LLVMContext &Ctx = CGM.getLLVMContext();
-  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x 
float>,
-  // 1, 0, 0) 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);
-  unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0};
-  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags);
+  const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
+  switch (ResAttrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+  case llvm::dxil::ResourceClass::SRV: {
+// TypedBuffer and RawBuffer both need element type
+QualType ContainedTy = ResType->getContainedType();
+if (ContainedTy.isNull())
+  return nullptr;
+
+// convert element type
+llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
+
+const char *TypeName =

llvm-beanz wrote:

nit:
```suggestion
llvm::StringRef TypeName =
```

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits


@@ -13672,6 +13690,9 @@ static QualType getCommonNonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
 TX->getDepth(), TX->getIndex(), TX->isParameterPack(),
 getCommonDecl(TX->getDecl(), TY->getDecl()));
   }
+  case Type::HLSLAttributedResource: {

llvm-beanz wrote:

Do we expect these types to be sugared? It seems like we should maybe make 
these "sugar-free" above? The only case I can think of where we might have 
sugar would be if the component type was sugared... not sure.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-08 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

A few (mostly small) comments

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-04 Thread Justin Bogner via cfe-commits

https://github.com/bogner commented:

This LGTM but I'm not familiar enough with the mangling aspects or the 
implications of adding a canonical type to be comfortable signing off on it.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/6] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -3753,6 +3754,32 @@ void MicrosoftCXXNameMangler::mangleType(const 
DependentBitIntType *T,
   Error(Range.getBegin(), "DependentBitInt type") << Range;
 }
 
+void MicrosoftCXXNameMangler::mangleType(const HLSLAttributedResourceType *T,
+ Qualifiers, SourceRange Range) {
+  mangleType(T->getWrappedType(), SourceRange(), QMM_Escape);
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  // map resource class to HLSL virtual register letter
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'u';
+break;
+  case llvm::dxil::ResourceClass::SRV:
+Out << 't';
+break;
+  case llvm::dxil::ResourceClass::CBuffer:
+Out << 'b';
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+Out << 's';
+break;
+  }

hekota wrote:

The plan is to switch DirectX to Itanium ABI (llvm/llvm-project#110736). 
Changing the Microsoft mangling to just typename.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -4492,6 +4492,31 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {

hekota wrote:

Updated to use `mangleVendorQualifier`.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/5] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/4] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -4488,6 +4488,30 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
+  mangleType(T->getWrappedType());
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'U';
+break;
+  case llvm::dxil::ResourceClass::SRV:
+Out << 'T';
+break;
+  case llvm::dxil::ResourceClass::CBuffer:
+Out << 'C';
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+Out << 'S';
+break;
+  }

hekota wrote:

This is intentional. If add a default case, there'll be a warning `Default 
label in switch which covers all enumeration values`. If a new value is added 
to ResourceClass, there'll be a warning that this switch does not cover all 
enum values.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-30 Thread Chris B via cfe-commits


@@ -3753,6 +3754,32 @@ void MicrosoftCXXNameMangler::mangleType(const 
DependentBitIntType *T,
   Error(Range.getBegin(), "DependentBitInt type") << Range;
 }
 
+void MicrosoftCXXNameMangler::mangleType(const HLSLAttributedResourceType *T,
+ Qualifiers, SourceRange Range) {
+  mangleType(T->getWrappedType(), SourceRange(), QMM_Escape);
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  // map resource class to HLSL virtual register letter
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'u';
+break;
+  case llvm::dxil::ResourceClass::SRV:
+Out << 't';
+break;
+  case llvm::dxil::ResourceClass::CBuffer:
+Out << 'b';
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+Out << 's';
+break;
+  }

llvm-beanz wrote:

The MSVC ABI doesn't have a vendor-specific qualifier. We should probably try 
to confer with the MSVC team about how to handle mangling these so that we 
don't interfere with MSVC ABI support.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/3] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-30 Thread Chris B via cfe-commits


@@ -4492,6 +4492,31 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
+  mangleType(T->getWrappedType());
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  // map resource class to HLSL virtual register letter
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'u';
+break;
+  case llvm::dxil::ResourceClass::SRV:
+Out << 't';
+break;
+  case llvm::dxil::ResourceClass::CBuffer:
+Out << 'b';
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+Out << 's';
+break;
+  }
+  mangleNumber(Attrs.IsROV);
+  mangleNumber(Attrs.RawBuffer);

llvm-beanz wrote:

Should we be mangling these as numbers or vendor qualifiers? I think the later. 
Basically something like:

```
if (Attrs.IsROV)
  mangleVendorQualifier("__ROV");
...
```

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -29,19 +29,48 @@ class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
 
 llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
   const Type *Ty) const {
-  auto *BuiltinTy = dyn_cast(Ty);
-  if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+  auto *ResType = dyn_cast(Ty);
+  if (!ResType)
 return nullptr;
 
   llvm::LLVMContext &Ctx = CGM.getLLVMContext();
-  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x 
float>,
-  // 1, 0, 0) 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);
-  unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0};
-  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags);
+  const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
+  switch (ResAttrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+  case llvm::dxil::ResourceClass::SRV: {
+// convert element type
+QualType ContainedTy = ResType->getContainedType();
+llvm::Type *ElemType = nullptr;
+if (!ContainedTy.isNull())
+  ElemType = CGM.getTypes().ConvertType(ContainedTy);
+
+if (ResAttrs.RawBuffer) {
+  // RawBuffer needs element type
+  if (ContainedTy.isNull())
+return nullptr;
+  return llvm::TargetExtType::get(Ctx, "dx.RawBuffer", {ElemType},
+  {/*IsWriteable*/ ResAttrs.ResourceClass 
==
+   llvm::dxil::ResourceClass::UAV,
+   /*IsROV*/ ResAttrs.IsROV});
+}
+
+// TypedBuffer needs element type
+if (ContainedTy.isNull())
+  return nullptr;
+return llvm::TargetExtType::get(
+Ctx, "dx.TypedBuffer", {ElemType},
+{/*IsWriteable*/ ResAttrs.ResourceClass ==
+ llvm::dxil::ResourceClass::UAV,
+ /*IsROV*/ ResAttrs.IsROV,
+ /*IsSigned*/ ContainedTy->isSignedIntegerType()});

hekota wrote:

This code is incomplete but I get what you mean. I've rearranged the code based 
on your suggestion.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-30 Thread Chris B via cfe-commits


@@ -4492,6 +4492,31 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {

llvm-beanz wrote:

I assume the intent is that we're mangling this as a vendor-specific qualifier? 
If so, we should use `mangleVendorQualifier` to ensure that it is properly 
prefixed, and we should probably use more than one letter as the qualifier name.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-30 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 85181788576151cc4b52d38d9b52d04f26179530 
e84c90246c4bdd1f0301ce88ac9055dfa3a9c5b0 --extensions cpp,h -- 
clang/include/clang/AST/Type.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/ASTStructuralEquivalence.cpp clang/lib/AST/DeclCXX.cpp 
clang/lib/AST/ExprConstant.cpp clang/lib/AST/ItaniumMangle.cpp 
clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/Type.cpp 
clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenTypes.cpp 
clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/Targets/DirectX.cpp 
clang/lib/Sema/HLSLExternalSemaSource.cpp clang/lib/Sema/SemaLookup.cpp 
clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplate.cpp 
clang/lib/Sema/SemaTemplateDeduction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
index a33398657f..2a9fb340cf 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -46,14 +46,14 @@ llvm::Type 
*DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
 // convert element type
 llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
 
-const char* TypeName = ResAttrs.RawBuffer ? "dx.RawBuffer" : 
"dx.TypedBuffer";
-SmallVector Ints = {
-  /*IsWriteable*/ ResAttrs.ResourceClass == llvm::dxil::ResourceClass::UAV,
-  /*IsROV*/ ResAttrs.IsROV
-};
+const char *TypeName =
+ResAttrs.RawBuffer ? "dx.RawBuffer" : "dx.TypedBuffer";
+SmallVector Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
+ llvm::dxil::ResourceClass::UAV,
+ /*IsROV*/ ResAttrs.IsROV};
 if (!ResAttrs.RawBuffer)
   Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
-
+
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
   case llvm::dxil::ResourceClass::CBuffer:

``




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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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


@@ -4488,6 +4488,30 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
+  mangleType(T->getWrappedType());
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'U';

hekota wrote:

I have updated it to lower case letters (which is more common) and added a 
comment.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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

>From 4f235c0e9c539cdaa2bab9a7f8228f33c0fea2b8 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 26 Sep 2024 14:34:16 -0700
Subject: [PATCH 1/2] Add codegen for existing resource types and make
 HLSLAttributedResourceType canonical.

---
 clang/include/clang/AST/Type.h| 34 +++
 clang/include/clang/Basic/TypeNodes.td|  2 +-
 clang/lib/AST/ASTContext.cpp  | 25 -
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 +
 clang/lib/AST/DeclCXX.cpp |  6 +-
 clang/lib/AST/ExprConstant.cpp|  1 +
 clang/lib/AST/ItaniumMangle.cpp   | 24 
 clang/lib/AST/MicrosoftMangle.cpp | 26 +
 clang/lib/AST/Type.cpp|  5 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 ++
 clang/lib/CodeGen/Targets/DirectX.cpp | 49 
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  2 -
 clang/lib/Sema/SemaLookup.cpp |  3 +
 clang/lib/Sema/SemaOverload.cpp   | 17 ++
 clang/lib/Sema/SemaTemplate.cpp   |  7 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 
 clang/test/AST/HLSL/RWBuffer-AST.hlsl |  2 -
 .../builtins/RWBuffer-elementtype.hlsl| 14 +
 .../StructuredBuffer-elementtype.hlsl | 14 +
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 56 +--
 .../ParserHLSL/hlsl_contained_type_attr.hlsl  | 13 ++---
 clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl   |  9 +--
 .../test/ParserHLSL/hlsl_raw_buffer_attr.hlsl |  9 +--
 .../ParserHLSL/hlsl_resource_class_attr.hlsl  | 17 ++
 .../hlsl_resource_handle_attrs.hlsl   |  2 -
 27 files changed, 290 insertions(+), 83 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
   return
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  false; // end boolean or operation
+  isHLSLAttributedResourceType();
 }
 
-inline bool Type::isHLSLIntangibleType() const {
-  // All HLSL specific types are currently intangible type as well, but that
-  // might change in the f

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-27 Thread Damyan Pepper via cfe-commits


@@ -4488,6 +4488,30 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
+  mangleType(T->getWrappedType());
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'U';

damyanp wrote:

I think I know why you chose these letters for the manglingbut future 
readers may not have that context. A comment here might be helpful.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-27 Thread Damyan Pepper via cfe-commits


@@ -29,19 +29,48 @@ class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
 
 llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
   const Type *Ty) const {
-  auto *BuiltinTy = dyn_cast(Ty);
-  if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+  auto *ResType = dyn_cast(Ty);
+  if (!ResType)
 return nullptr;
 
   llvm::LLVMContext &Ctx = CGM.getLLVMContext();
-  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x 
float>,
-  // 1, 0, 0) 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);
-  unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0};
-  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags);
+  const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
+  switch (ResAttrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+  case llvm::dxil::ResourceClass::SRV: {
+// convert element type
+QualType ContainedTy = ResType->getContainedType();
+llvm::Type *ElemType = nullptr;
+if (!ContainedTy.isNull())
+  ElemType = CGM.getTypes().ConvertType(ContainedTy);
+
+if (ResAttrs.RawBuffer) {
+  // RawBuffer needs element type
+  if (ContainedTy.isNull())
+return nullptr;
+  return llvm::TargetExtType::get(Ctx, "dx.RawBuffer", {ElemType},
+  {/*IsWriteable*/ ResAttrs.ResourceClass 
==
+   llvm::dxil::ResourceClass::UAV,
+   /*IsROV*/ ResAttrs.IsROV});
+}
+
+// TypedBuffer needs element type
+if (ContainedTy.isNull())
+  return nullptr;
+return llvm::TargetExtType::get(
+Ctx, "dx.TypedBuffer", {ElemType},
+{/*IsWriteable*/ ResAttrs.ResourceClass ==
+ llvm::dxil::ResourceClass::UAV,
+ /*IsROV*/ ResAttrs.IsROV,
+ /*IsSigned*/ ContainedTy->isSignedIntegerType()});

damyanp wrote:

Not sure if this exactly works, or is totally clearer, but I'll include it here 
anyway in case it sparks any ideas.

```suggestion
if (ContainedTy.isNull())
  return nullptr;

const char* TypeName = ResAttrs.RawBuffer ? "dx.RawBuffer" : 
"dx.TypedBuffer";
const bool IsWriteable = (ResAttrs.ResourceClass == 
llvm::dxil::ResourceClass::UAV);

SmallVector Ints{IsWriteable, ResAttrs.IsROV};
if (!ResAttrs.RawBuffer)
  Ints.push_back(ContainedTy->isSignedIntegerType());

ArrayRef Ints = ResAttrs.RawBuffer ? { IsWriteable, 
ResAttrs.IsROV } : { IsWriteable, ResAttrs.Is

return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
```

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-27 Thread Damyan Pepper via cfe-commits


@@ -4488,6 +4488,30 @@ void CXXNameMangler::mangleType(const ArrayParameterType 
*T) {
   mangleType(cast(T));
 }
 
+void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
+  mangleType(T->getWrappedType());
+  const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
+  switch (Attrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+Out << 'U';
+break;
+  case llvm::dxil::ResourceClass::SRV:
+Out << 'T';
+break;
+  case llvm::dxil::ResourceClass::CBuffer:
+Out << 'C';
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+Out << 'S';
+break;
+  }

damyanp wrote:

default case? Or is it intentional that unknown resource classes don't add the 
extra character?

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-27 Thread Damyan Pepper via cfe-commits


@@ -29,19 +29,48 @@ class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
 
 llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
   const Type *Ty) const {
-  auto *BuiltinTy = dyn_cast(Ty);
-  if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
+  auto *ResType = dyn_cast(Ty);
+  if (!ResType)
 return nullptr;
 
   llvm::LLVMContext &Ctx = CGM.getLLVMContext();
-  // FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x 
float>,
-  // 1, 0, 0) 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);
-  unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0};
-  return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags);
+  const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
+  switch (ResAttrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+  case llvm::dxil::ResourceClass::SRV: {
+// convert element type
+QualType ContainedTy = ResType->getContainedType();
+llvm::Type *ElemType = nullptr;
+if (!ContainedTy.isNull())
+  ElemType = CGM.getTypes().ConvertType(ContainedTy);
+
+if (ResAttrs.RawBuffer) {
+  // RawBuffer needs element type
+  if (ContainedTy.isNull())
+return nullptr;
+  return llvm::TargetExtType::get(Ctx, "dx.RawBuffer", {ElemType},
+  {/*IsWriteable*/ ResAttrs.ResourceClass 
==
+   llvm::dxil::ResourceClass::UAV,
+   /*IsROV*/ ResAttrs.IsROV});
+}
+
+// TypedBuffer needs element type
+if (ContainedTy.isNull())
+  return nullptr;

damyanp wrote:

The two "return nullptr's when container type is null" (here and line 49) could 
be both moved to before line 47.

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)


Changes

Translates `RWBuffer` and `StructuredBuffer` resources buffer types to DirectX 
target types `dx.TypedBuffer` and `dx.RawBuffer`.

Includes a change of `HLSLAttributesResourceType` from 'sugar' type to full 
canonical type. This is required for codegen and other clang infrastructure to 
work property on HLSL resource types.

Depends on PR llvm/llvm-project#110079 (test will fail until merged).

Fixes #95952 (part 2/2)

---

Patch is 40.13 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/110327.diff


27 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+23-11) 
- (modified) clang/include/clang/Basic/TypeNodes.td (+1-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+23-2) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+2-13) 
- (modified) clang/lib/AST/DeclCXX.cpp (+3-3) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+24) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+26) 
- (modified) clang/lib/AST/Type.cpp (+5) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+1) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+3) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+6) 
- (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+39-10) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (-2) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+17) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+7) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+11) 
- (modified) clang/test/AST/HLSL/RWBuffer-AST.hlsl (-2) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl (+14) 
- (modified) clang/test/CodeGenHLSL/builtins/StructuredBuffer-elementtype.hlsl 
(+14) 
- (modified) clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl (+50-6) 
- (modified) clang/test/ParserHLSL/hlsl_contained_type_attr.hlsl (+5-8) 
- (modified) clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl (+3-6) 
- (modified) clang/test/ParserHLSL/hlsl_raw_buffer_attr.hlsl (+3-6) 
- (modified) clang/test/ParserHLSL/hlsl_resource_class_attr.hlsl (+6-11) 
- (modified) clang/test/ParserHLSL/hlsl_resource_handle_attrs.hlsl (-2) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::is

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-09-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes

Translates `RWBuffer` and `StructuredBuffer` resources buffer types to DirectX 
target types `dx.TypedBuffer` and `dx.RawBuffer`.

Includes a change of `HLSLAttributesResourceType` from 'sugar' type to full 
canonical type. This is required for codegen and other clang infrastructure to 
work property on HLSL resource types.

Depends on PR llvm/llvm-project#110079 (test will fail until merged).

Fixes #95952 (part 2/2)

---

Patch is 40.13 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/110327.diff


27 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+23-11) 
- (modified) clang/include/clang/Basic/TypeNodes.td (+1-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+23-2) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+2-13) 
- (modified) clang/lib/AST/DeclCXX.cpp (+3-3) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+24) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+26) 
- (modified) clang/lib/AST/Type.cpp (+5) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+1) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+3) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+6) 
- (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+39-10) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (-2) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+17) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+7) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+11) 
- (modified) clang/test/AST/HLSL/RWBuffer-AST.hlsl (-2) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl (+14) 
- (modified) clang/test/CodeGenHLSL/builtins/StructuredBuffer-elementtype.hlsl 
(+14) 
- (modified) clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl (+50-6) 
- (modified) clang/test/ParserHLSL/hlsl_contained_type_attr.hlsl (+5-8) 
- (modified) clang/test/ParserHLSL/hlsl_is_rov_attr.hlsl (+3-6) 
- (modified) clang/test/ParserHLSL/hlsl_raw_buffer_attr.hlsl (+3-6) 
- (modified) clang/test/ParserHLSL/hlsl_resource_class_attr.hlsl (+6-11) 
- (modified) clang/test/ParserHLSL/hlsl_resource_handle_attrs.hlsl (-2) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..f97217dead2139 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2659,6 +2659,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 #include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const; // Any HLSL specific type
   bool isHLSLIntangibleType() const; // Any HLSL intangible type
+  bool isHLSLAttributedResourceType() const;
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -6180,6 +6181,14 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
 
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+
+friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+}
+friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
+  return !(LHS == RHS);
+}
   };
 
 private:
@@ -6189,18 +6198,19 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
   QualType ContainedType;
   const Attributes Attrs;
 
-  HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
- QualType Contained, const Attributes &Attrs)
-  : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
+  HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
+ const Attributes &Attrs)
+  : Type(HLSLAttributedResource, QualType(), Wrapped->getDependence()),
 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
 
 public:
   QualType getWrappedType() const { return WrappedType; }
   QualType getContainedType() const { return ContainedType; }
+  bool hasContainedType() const { return !ContainedType.isNull(); }
   const Attributes &getAttrs() const { return Attrs; }
 
-  bool isSugared() const { return true; }
-  QualType desugar() const { return getWrappedType(); }
+  bool isSugared() const { return false; }
+  QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, WrappedType, ContainedType, Attrs);
@@ -8344,17 +8354,19 @@ inline bool Type::isOpenCLSpecificType() const {
   }
 #include "clang/Basic/HLSLIntangibleTypes.def"
 
-inline bool Type::isHLSLSpecificType() const {
+inline bool Type::isHLSLIntangibleType() const {
 #define HLSL_IN

[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

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

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