Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t> BufI16;
AppendStructuredBuffer<uint16_t> BufU16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t> BufI16;
ConsumeStructuredBuffer<uint16_t> BufU16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t> BufI16;
RasterizerOrderedStructuredBuffer<uint16_t> BufU16;
Expand Down
3 changes: 2 additions & 1 deletion clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ")";
Expand Down
31 changes: 31 additions & 0 deletions llvm/unittests/IR/TypesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,41 @@ 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<Type *, 2> Elements = {Int32Type, FloatType};

StructType *Struct = llvm::StructType::create(Context, Elements, "MyStruct",
/*isPacked=*/false);
SmallVector<char, 50> 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();
llvm::raw_svector_ostream TETStream(TETV);
TargetExtensionType->print(TETStream);

EXPECT_STREQ(TETStream.str().str().data(),
"target(\"structTET\", { i32, float }, 0, 1)");
}

TEST(TypedPointerType, PrintTest) {
Expand Down
Loading