Explorar o código

[spirv] Add QualType constructor for composite constants.

Ehsan %!s(int64=6) %!d(string=hai) anos
pai
achega
d4e02b6557

+ 4 - 0
tools/clang/include/clang/SPIRV/SpirvInstruction.h

@@ -964,6 +964,7 @@ public:
 
 protected:
   SpirvConstant(Kind, spv::Op, const SpirvType *);
+  SpirvConstant(Kind, spv::Op, QualType);
 };
 
 class SpirvConstantBoolean : public SpirvConstant {
@@ -1063,6 +1064,9 @@ public:
   SpirvConstantComposite(const SpirvType *type,
                          llvm::ArrayRef<const SpirvConstant *> constituents,
                          bool isSpecConst = false);
+  SpirvConstantComposite(QualType type,
+                         llvm::ArrayRef<const SpirvConstant *> constituents,
+                         bool isSpecConst = false);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {

+ 16 - 0
tools/clang/lib/SPIRV/SpirvInstruction.cpp

@@ -372,6 +372,10 @@ SpirvConstant::SpirvConstant(Kind kind, spv::Op op, const SpirvType *spvType)
   setResultType(spvType);
 }
 
+SpirvConstant::SpirvConstant(Kind kind, spv::Op op, QualType resultType)
+    : SpirvInstruction(kind, op, resultType, /*result-id*/ 0,
+                       /*SourceLocation*/ {}) {}
+
 bool SpirvConstant::isSpecConstant() const {
   return opcode == spv::Op::OpSpecConstant ||
          opcode == spv::Op::OpSpecConstantTrue ||
@@ -566,6 +570,15 @@ SpirvConstantComposite::SpirvConstantComposite(
                     type),
       constituents(constituentsVec.begin(), constituentsVec.end()) {}
 
+SpirvConstantComposite::SpirvConstantComposite(
+    QualType type, llvm::ArrayRef<const SpirvConstant *> constituentsVec,
+    bool isSpecConst)
+    : SpirvConstant(IK_ConstantComposite,
+                    isSpecConst ? spv::Op::OpSpecConstantComposite
+                                : spv::Op::OpConstantComposite,
+                    type),
+      constituents(constituentsVec.begin(), constituentsVec.end()) {}
+
 bool SpirvConstantComposite::
 operator==(const SpirvConstantComposite &other) const {
   if (opcode != other.getopcode())
@@ -574,6 +587,9 @@ operator==(const SpirvConstantComposite &other) const {
   if (resultType != other.getResultType())
     return false;
 
+  if (astResultType != other.getAstResultType())
+    return false;
+
   auto otherMembers = other.getConstituents();
   if (constituents.size() != otherMembers.size())
     return false;