llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Joshua Batista (bob80905) <details> <summary>Changes</summary> This PR changes the way that final DXIL is printed by adjusting the way the type definition section of the DXIL output is printed. Specifically, when defining a target extension type, if the RHS involves a struct type, then rather than printing the entire struct type definition, only the struct body is printed. This prevents repetitive phrases like "struct = type {...}" from being repeated over and over in the RHS. Additionally, it should allow opt to not crash when parsing the DXIL output. Fixes [#<!-- -->114131](https://github.com/llvm/llvm-project/issues/114131) --- Full diff: https://github.com/llvm/llvm-project/pull/115971.diff 2 Files Affected: - (added) clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl (+30) - (modified) llvm/lib/IR/AsmWriter.cpp (+8-2) ``````````diff diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl new file mode 100644 index 00000000000000..73073b3f6f2839 --- /dev/null +++ b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl @@ -0,0 +1,30 @@ +// RUN: %clang_dxc -T cs_6_6 %s | FileCheck %s + +// The purpose of this test is to ensure that the AST writer +// only emits struct bodies when within the context of a +// larger object that is being outputted on the RHS. + + +// note that "{ <4 x float> }" in the check below is a struct type, but only the +// body is emitted on the RHS because we are already in the context of a +// target extension type definition (class.hlsl::StructuredBuffer) +// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", { <4 x float> }, 0, 0), %struct.mystruct } +// CHECK: %struct.mystruct = type { <4 x float> } +// CHECK: %dx.types.Handle = type { ptr } +// CHECK: %dx.types.ResBind = type { i32, i32, i32, i8 } +// CHECK: %dx.types.ResourceProperties = type { i32, i32 } + +struct mystruct +{ + float4 Color; +}; + +StructuredBuffer<mystruct> my_buffer : register(t2, space4); + +export float4 test() +{ + return my_buffer[0].Color; +} + +[numthreads(1,1,1)] +void main() {} diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 3c1cb76622bbb7..d2705ff4b30fb8 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -649,8 +649,14 @@ 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 << ", "; + if (Inner->isStructTy()) { + StructType *STy = cast<StructType>(Inner); + printStructBody(STy, OS); + } else + OS << *Inner; + } for (unsigned IntParam : TETy->int_params()) OS << ", " << IntParam; OS << ")"; `````````` </details> https://github.com/llvm/llvm-project/pull/115971 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits