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

Greg Roth via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 09:56:51 PDT 2024


================
@@ -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 at __hlsl@@@Z"(target("dx.TypedBuffer", float, 1, 0, 0) %a)
+// CHECK: call void @"?foo1@@YAXUHLSLAttributedResourceType at __hlsl@@@Z"(target("dx.TypedBuffer", float, 1, 0, 0) %0)
+// CHECK: declare void @"?foo1@@YAXUHLSLAttributedResourceType at __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 at __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 at T?$__vector at M$03 at __clang@@@hlsl@@@Z"(ptr noundef byval(%"class.hlsl::RWBuffer") align 16 %a)
+// CHECK: call void @"?foo2@@YAXV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@@Z"(ptr noundef byval(%"class.hlsl::RWBuffer") align 16 %agg.tmp)  
+// CHECK: declare void @"?foo2@@YAXV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@@Z"(ptr noundef byval(%"class.hlsl::RWBuffer") align 16)
+void foo2(RWBuffer<float4> buf);
+
+void fc(RWBuffer<float4> a) {
+  foo2(a);
+}
+
+void fd(RWBuffer<float4> a) {
+  RWBuffer<float4> b = a;
+}
+
+struct MyStruct {
+  float4 f;
+  int2 i;
+};
+
+// CHECK: define void @"?fe@@YAXV?$StructuredBuffer at UMyStruct@@@hlsl@@@Z"(ptr noundef byval(%"class.hlsl::StructuredBuffer") align 16 %a)
+// CHECK: call void @"?foo3@@YAXV?$StructuredBuffer at UMyStruct@@@hlsl@@@Z"(ptr noundef byval(%"class.hlsl::StructuredBuffer") align 16 %agg.tmp)
+// CHECK: declare void @"?foo3@@YAXV?$StructuredBuffer at 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


More information about the cfe-commits mailing list