[clang] [HLSL] Add HLSLAttributedResourceType (PR #106181)
Justin Bogner via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 27 01:04:24 PDT 2024
================
@@ -6155,6 +6155,63 @@ class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
}
};
+class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
+public:
+ struct Attributes {
+ // This is where data gathered from HLSL resource attributes are stored,
+ // such as resource class, is_rov, dimension, is_array, is_feedback
+ // or is_multisample. The values will be accessed individually via fields
+ // on the embedded struct. The Data alias is used for the AST type
+ // serialization.
+ union {
+ struct {
+ uint8_t ResourceClass; // maps to llvm::dxil::ResourceClass
+ uint8_t IsROV : 1;
+ // FIXME: add additional resource properties here
+ };
+ unsigned Data;
+ };
----------------
bogner wrote:
Unfortunately, type punning through a union is undefined behaviour in C++ ([ISO/IEC 14882:2017 [class.union]](https://timsong-cpp.github.io/cppwp/n4659/class.union)), but [better explained on cppreference](https://en.cppreference.com/w/cpp/language/union#Member_lifetime)). So while most compilers do happen to do what you're hoping for here, we can't actually do this this way.
I think FoldingSetNode does fine with a series of `AddBoolean`, so we can presumably keep these as bitfields to save space in memory but add each individually in `Profile` without it causing too much trouble.
https://github.com/llvm/llvm-project/pull/106181
More information about the cfe-commits
mailing list