diff --git a/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl b/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl index 1e8aae588fc33..85face8eaeb6c 100644 --- a/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl +++ b/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl @@ -18,7 +18,8 @@ struct MyStruct { // DXIL: %"class.hlsl::AppendStructuredBuffer.9" = type { target("dx.RawBuffer", <3 x i32>, 1, 0) // DXIL: %"class.hlsl::AppendStructuredBuffer.10" = type { target("dx.RawBuffer", <2 x half>, 1, 0) // DXIL: %"class.hlsl::AppendStructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 1, 0) -// DXIL: %"class.hlsl::AppendStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }, 1, 0) +// DXIL: %"class.hlsl::AppendStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct, 1, 0) +// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] } AppendStructuredBuffer BufI16; AppendStructuredBuffer BufU16; diff --git a/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl b/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl index f8574c6460d4e..5ed9e9ad8160f 100644 --- a/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl +++ b/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl @@ -18,7 +18,8 @@ struct MyStruct { // DXIL: %"class.hlsl::ConsumeStructuredBuffer.9" = type { target("dx.RawBuffer", <3 x i32>, 1, 0) // DXIL: %"class.hlsl::ConsumeStructuredBuffer.10" = type { target("dx.RawBuffer", <2 x half>, 1, 0) // DXIL: %"class.hlsl::ConsumeStructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 1, 0) -// DXIL: %"class.hlsl::ConsumeStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }, 1, 0) +// DXIL: %"class.hlsl::ConsumeStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct, 1, 0) +// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] } ConsumeStructuredBuffer BufI16; ConsumeStructuredBuffer BufU16; diff --git a/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl b/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl index 7057988de24b3..68d626de689f2 100644 --- a/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl +++ b/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl @@ -18,7 +18,7 @@ struct MyStruct { // DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.9" = type { target("dx.RawBuffer", <3 x i32>, 1, 1) } // DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.10" = type { target("dx.RawBuffer", <2 x half>, 1, 1) } // DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 1, 1) } -// DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }, 1, 1) } +// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] } RasterizerOrderedStructuredBuffer BufI16; RasterizerOrderedStructuredBuffer BufU16; diff --git a/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl b/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl index 7de62a363eedb..fda034ce7f203 100644 --- a/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl +++ b/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl @@ -3,7 +3,8 @@ using handle_float_t = __hlsl_resource_t [[hlsl::resource_class(UAV)]] [[hlsl::contained_type(float)]]; // 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] }, 0, 0) +// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", %struct.MyStruct, 0, 0) +// CHECK: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] } // CHECK: define void @_Z2faU9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0) %a) // CHECK: call void @_Z4foo1U9_Res_u_CTfu17__hlsl_resource_t(target("dx.TypedBuffer", float, 1, 0, 0) %0) diff --git a/clang/test/CodeGenHLSL/resource-bindings.hlsl b/clang/test/CodeGenHLSL/resource-bindings.hlsl index bfec90e1871f8..d4e6308210653 100644 --- a/clang/test/CodeGenHLSL/resource-bindings.hlsl +++ b/clang/test/CodeGenHLSL/resource-bindings.hlsl @@ -15,5 +15,5 @@ struct S { int i; }; -// CHECK: %T3S0_h = call target("dx.RawBuffer", %struct.S = type { <4 x float>, i32, [12 x i8] }, 0, 0) @llvm.dx.handle.fromBinding.tdx.RawBuffer_s_struct.Ss_0_0t(i32 0, i32 3, i32 1, i32 0, i1 false) +// CHECK: %T3S0_h = call target("dx.RawBuffer", %struct.S, 0, 0) @llvm.dx.handle.fromBinding.tdx.RawBuffer_s_struct.Ss_0_0t(i32 0, i32 3, i32 1, i32 0, i1 false) StructuredBuffer T3S0 : register(t3); diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index f8183774f4056..a37a8901489cf 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -649,8 +649,10 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) { OS << "target(\""; printEscapedString(Ty->getTargetExtName(), OS); OS << "\""; - for (Type *Inner : TETy->type_params()) - OS << ", " << *Inner; + for (Type *Inner : TETy->type_params()) { + OS << ", "; + Inner->print(OS, /*IsForDebug=*/false, /*NoDetails=*/true); + } for (unsigned IntParam : TETy->int_params()) OS << ", " << IntParam; OS << ")"; diff --git a/llvm/unittests/IR/TypesTest.cpp b/llvm/unittests/IR/TypesTest.cpp index 855262fc4e787..4436ed5118f4f 100644 --- a/llvm/unittests/IR/TypesTest.cpp +++ b/llvm/unittests/IR/TypesTest.cpp @@ -40,10 +40,40 @@ TEST(TypesTest, TargetExtType) { Type *A = TargetExtType::get(Context, "typea"); Type *Aparam = TargetExtType::get(Context, "typea", {}, {0, 1}); Type *Aparam2 = TargetExtType::get(Context, "typea", {}, {0, 1}); + // Opaque types with same parameters are identical... EXPECT_EQ(Aparam, Aparam2); // ... but just having the same name is not enough. EXPECT_NE(A, Aparam); + + // ensure struct types in targest extension types + // only show the struct name, not the struct body + Type *Int32Type = Type::getInt32Ty(Context); + Type *FloatType = Type::getFloatTy(Context); + std::array Elements = {Int32Type, FloatType}; + + StructType *Struct = llvm::StructType::create(Context, Elements, "MyStruct", + /*isPacked=*/false); + SmallVector TETV; + llvm::raw_svector_ostream TETStream(TETV); + Type *TargetExtensionType = + TargetExtType::get(Context, "structTET", {Struct}, {0, 1}); + TargetExtensionType->print(TETStream); + + EXPECT_STREQ(TETStream.str().str().data(), + "target(\"structTET\", %MyStruct, 0, 1)"); + + // ensure that literal structs in the target extension type print the struct + // body + Struct = StructType::get(Context, Struct->elements(), /*isPacked=*/false); + + TargetExtensionType = + TargetExtType::get(Context, "structTET", {Struct}, {0, 1}); + TETV.clear(); + TargetExtensionType->print(TETStream); + + EXPECT_STREQ(TETStream.str().str().data(), + "target(\"structTET\", { i32, float }, 0, 1)"); } TEST(TypedPointerType, PrintTest) {