@@ -2652,6 +2652,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26522652 bool isHLSLSpecificType () const ; // Any HLSL specific type
26532653 bool isHLSLBuiltinIntangibleType () const ; // Any HLSL builtin intangible type
26542654 bool isHLSLAttributedResourceType () const ;
2655+ bool isHLSLInlineSpirvType () const ;
26552656 bool isHLSLResourceRecord () const ;
26562657 bool isHLSLIntangibleType ()
26572658 const ; // Any HLSL intangible type (builtin, array, class)
@@ -6330,6 +6331,140 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
63306331 findHandleTypeOnResource (const Type *RT);
63316332};
63326333
6334+ // / Instances of this class represent operands to a SPIR-V type instruction.
6335+ class SpirvOperand {
6336+ public:
6337+ enum SpirvOperandKind : unsigned char {
6338+ kInvalid , // /< Uninitialized.
6339+ kConstantId , // /< Integral value to represent as a SPIR-V OpConstant
6340+ // /< instruction ID.
6341+ kLiteral , // /< Integral value to represent as an immediate literal.
6342+ kTypeId , // /< Type to represent as a SPIR-V type ID.
6343+
6344+ kMax ,
6345+ };
6346+
6347+ private:
6348+ SpirvOperandKind Kind = kInvalid ;
6349+
6350+ QualType ResultType;
6351+ llvm::APInt Value; // Signedness of constants is represented by ResultType.
6352+
6353+ public:
6354+ SpirvOperand () : Kind(kInvalid ), ResultType() {}
6355+
6356+ SpirvOperand (SpirvOperandKind Kind, QualType ResultType, llvm::APInt Value)
6357+ : Kind(Kind), ResultType(ResultType), Value(Value) {}
6358+
6359+ SpirvOperand (const SpirvOperand &Other) { *this = Other; }
6360+ ~SpirvOperand () {}
6361+
6362+ SpirvOperand &operator =(const SpirvOperand &Other) {
6363+ this ->Kind = Other.Kind ;
6364+ this ->ResultType = Other.ResultType ;
6365+ this ->Value = Other.Value ;
6366+ return *this ;
6367+ }
6368+
6369+ bool operator ==(const SpirvOperand &Other) const {
6370+ return Kind == Other.Kind && ResultType == Other.ResultType &&
6371+ Value == Other.Value ;
6372+ }
6373+
6374+ bool operator !=(const SpirvOperand &Other) const { return !(*this == Other); }
6375+
6376+ SpirvOperandKind getKind () const { return Kind; }
6377+
6378+ bool isValid () const { return Kind != kInvalid && Kind < kMax ; }
6379+ bool isConstant () const { return Kind == kConstantId ; }
6380+ bool isLiteral () const { return Kind == kLiteral ; }
6381+ bool isType () const { return Kind == kTypeId ; }
6382+
6383+ llvm::APInt getValue () const {
6384+ assert ((isConstant () || isLiteral ()) &&
6385+ " This is not an operand with a value!" );
6386+ return Value;
6387+ }
6388+
6389+ QualType getResultType () const {
6390+ assert ((isConstant () || isType ()) &&
6391+ " This is not an operand with a result type!" );
6392+ return ResultType;
6393+ }
6394+
6395+ static SpirvOperand createConstant (QualType ResultType, llvm::APInt Val) {
6396+ return SpirvOperand (kConstantId , ResultType, Val);
6397+ }
6398+
6399+ static SpirvOperand createLiteral (llvm::APInt Val) {
6400+ return SpirvOperand (kLiteral , QualType (), Val);
6401+ }
6402+
6403+ static SpirvOperand createType (QualType T) {
6404+ return SpirvOperand (kTypeId , T, llvm::APSInt ());
6405+ }
6406+
6407+ void Profile (llvm::FoldingSetNodeID &ID) const {
6408+ ID.AddInteger (Kind);
6409+ ID.AddPointer (ResultType.getAsOpaquePtr ());
6410+ Value.Profile (ID);
6411+ }
6412+ };
6413+
6414+ // / Represents an arbitrary, user-specified SPIR-V type instruction.
6415+ class HLSLInlineSpirvType final
6416+ : public Type,
6417+ public llvm::FoldingSetNode,
6418+ private llvm::TrailingObjects<HLSLInlineSpirvType, SpirvOperand> {
6419+ friend class ASTContext ; // ASTContext creates these
6420+ friend TrailingObjects;
6421+
6422+ private:
6423+ uint32_t Opcode;
6424+ uint32_t Size;
6425+ uint32_t Alignment;
6426+ size_t NumOperands;
6427+
6428+ HLSLInlineSpirvType (uint32_t Opcode, uint32_t Size, uint32_t Alignment,
6429+ ArrayRef<SpirvOperand> Operands)
6430+ : Type(HLSLInlineSpirv, QualType(), TypeDependence::None), Opcode(Opcode),
6431+ Size (Size), Alignment(Alignment), NumOperands(Operands.size()) {
6432+ for (size_t I = 0 ; I < NumOperands; I++) {
6433+ getTrailingObjects<SpirvOperand>()[I] = Operands[I];
6434+ }
6435+ }
6436+
6437+ public:
6438+ uint32_t getOpcode () const { return Opcode; }
6439+ uint32_t getSize () const { return Size; }
6440+ uint32_t getAlignment () const { return Alignment; }
6441+ ArrayRef<SpirvOperand> getOperands () const {
6442+ return {getTrailingObjects<SpirvOperand>(), NumOperands};
6443+ }
6444+
6445+ bool isSugared () const { return false ; }
6446+ QualType desugar () const { return QualType (this , 0 ); }
6447+
6448+ void Profile (llvm::FoldingSetNodeID &ID) {
6449+ Profile (ID, Opcode, Size, Alignment, getOperands ());
6450+ }
6451+
6452+ static void Profile (llvm::FoldingSetNodeID &ID, uint32_t Opcode,
6453+ uint32_t Size, uint32_t Alignment,
6454+ ArrayRef<SpirvOperand> Operands) {
6455+ ID.AddInteger (Opcode);
6456+ ID.AddInteger (Size);
6457+ ID.AddInteger (Alignment);
6458+ for (auto &Operand : Operands) {
6459+ Operand.Profile (ID);
6460+ }
6461+ }
6462+
6463+ static bool classof (const Type *T) {
6464+ return T->getTypeClass () == HLSLInlineSpirv;
6465+ }
6466+ };
6467+
63336468class TemplateTypeParmType : public Type , public llvm ::FoldingSetNode {
63346469 friend class ASTContext ; // ASTContext creates these
63356470
@@ -8458,13 +8593,18 @@ inline bool Type::isHLSLBuiltinIntangibleType() const {
84588593}
84598594
84608595inline bool Type::isHLSLSpecificType () const {
8461- return isHLSLBuiltinIntangibleType () || isHLSLAttributedResourceType ();
8596+ return isHLSLBuiltinIntangibleType () || isHLSLAttributedResourceType () ||
8597+ isHLSLInlineSpirvType ();
84628598}
84638599
84648600inline bool Type::isHLSLAttributedResourceType () const {
84658601 return isa<HLSLAttributedResourceType>(this );
84668602}
84678603
8604+ inline bool Type::isHLSLInlineSpirvType () const {
8605+ return isa<HLSLInlineSpirvType>(this );
8606+ }
8607+
84688608inline bool Type::isTemplateTypeParmType () const {
84698609 return isa<TemplateTypeParmType>(CanonicalType);
84708610}
0 commit comments