Browse Source

[spirv] Creator of an instruction doesn't know its result-id.

Ehsan Nasiri 6 years ago
parent
commit
21b82e4e51

+ 64 - 76
tools/clang/include/clang/SPIRV/SpirvInstruction.h

@@ -167,7 +167,7 @@ public:
 protected:
   // Forbid creating SpirvInstruction directly
   SpirvInstruction(Kind kind, spv::Op opcode, QualType astResultType,
-                   uint32_t resultId, SourceLocation loc);
+                   SourceLocation loc);
 
 protected:
   const Kind kind;
@@ -239,7 +239,7 @@ private:
 /// \brief ExtInstImport instruction
 class SpirvExtInstImport : public SpirvInstruction {
 public:
-  SpirvExtInstImport(uint32_t resultId, SourceLocation loc,
+  SpirvExtInstImport(SourceLocation loc,
                      llvm::StringRef extensionName = "GLSL.std.450");
 
   // For LLVM-style RTTI
@@ -442,8 +442,8 @@ public:
     None = 4
   };
 
-  SpirvVariable(QualType resultType, uint32_t resultId, SourceLocation loc,
-                spv::StorageClass sc, SpirvInstruction *initializerId = 0);
+  SpirvVariable(QualType resultType, SourceLocation loc, spv::StorageClass sc,
+                SpirvInstruction *initializerId = 0);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -464,8 +464,7 @@ private:
 
 class SpirvFunctionParameter : public SpirvInstruction {
 public:
-  SpirvFunctionParameter(QualType resultType, uint32_t resultId,
-                         SourceLocation loc);
+  SpirvFunctionParameter(QualType resultType, SourceLocation loc);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -703,7 +702,7 @@ public:
 /// and InBounds access chains. These are currently not used by CodeGen.
 class SpirvAccessChain : public SpirvInstruction {
 public:
-  SpirvAccessChain(QualType resultType, uint32_t resultId, SourceLocation loc,
+  SpirvAccessChain(QualType resultType, SourceLocation loc,
                    SpirvInstruction *base,
                    llvm::ArrayRef<SpirvInstruction *> indexVec);
 
@@ -745,11 +744,11 @@ private:
 ///                         value, comparator)
 class SpirvAtomic : public SpirvInstruction {
 public:
-  SpirvAtomic(spv::Op opcode, QualType resultType, uint32_t resultId,
-              SourceLocation loc, SpirvInstruction *pointer, spv::Scope,
-              spv::MemorySemanticsMask, SpirvInstruction *value = nullptr);
-  SpirvAtomic(spv::Op opcode, QualType resultType, uint32_t resultId,
-              SourceLocation loc, SpirvInstruction *pointer, spv::Scope,
+  SpirvAtomic(spv::Op opcode, QualType resultType, SourceLocation loc,
+              SpirvInstruction *pointer, spv::Scope, spv::MemorySemanticsMask,
+              SpirvInstruction *value = nullptr);
+  SpirvAtomic(spv::Op opcode, QualType resultType, SourceLocation loc,
+              SpirvInstruction *pointer, spv::Scope,
               spv::MemorySemanticsMask semanticsEqual,
               spv::MemorySemanticsMask semanticsUnequal,
               SpirvInstruction *value, SpirvInstruction *comparator);
@@ -875,9 +874,8 @@ private:
 /// ----------------------------------------------------------------------------
 class SpirvBinaryOp : public SpirvInstruction {
 public:
-  SpirvBinaryOp(spv::Op opcode, QualType resultType, uint32_t resultId,
-                SourceLocation loc, SpirvInstruction *op1,
-                SpirvInstruction *op2);
+  SpirvBinaryOp(spv::Op opcode, QualType resultType, SourceLocation loc,
+                SpirvInstruction *op1, SpirvInstruction *op2);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -915,7 +913,7 @@ public:
 
 protected:
   SpirvBitField(Kind kind, spv::Op opcode, QualType resultType,
-                uint32_t resultId, SourceLocation loc, SpirvInstruction *base,
+                SourceLocation loc, SpirvInstruction *base,
                 SpirvInstruction *offset, SpirvInstruction *count);
 
 private:
@@ -926,10 +924,9 @@ private:
 
 class SpirvBitFieldExtract : public SpirvBitField {
 public:
-  SpirvBitFieldExtract(QualType resultType, uint32_t resultId,
-                       SourceLocation loc, SpirvInstruction *base,
-                       SpirvInstruction *offset, SpirvInstruction *count,
-                       bool isSigned);
+  SpirvBitFieldExtract(QualType resultType, SourceLocation loc,
+                       SpirvInstruction *base, SpirvInstruction *offset,
+                       SpirvInstruction *count, bool isSigned);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -945,10 +942,9 @@ public:
 
 class SpirvBitFieldInsert : public SpirvBitField {
 public:
-  SpirvBitFieldInsert(QualType resultType, uint32_t resultId,
-                      SourceLocation loc, SpirvInstruction *base,
-                      SpirvInstruction *insert, SpirvInstruction *offset,
-                      SpirvInstruction *count);
+  SpirvBitFieldInsert(QualType resultType, SourceLocation loc,
+                      SpirvInstruction *base, SpirvInstruction *insert,
+                      SpirvInstruction *offset, SpirvInstruction *count);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1084,7 +1080,7 @@ public:
 /// and OpCompositeConstruct.
 class SpirvComposite : public SpirvInstruction {
 public:
-  SpirvComposite(QualType resultType, uint32_t resultId, SourceLocation loc,
+  SpirvComposite(QualType resultType, SourceLocation loc,
                  llvm::ArrayRef<SpirvInstruction *> constituentsVec,
                  bool isConstant = false, bool isSpecConstant = false);
 
@@ -1112,8 +1108,8 @@ private:
 /// \brief Extraction instruction (OpCompositeExtract)
 class SpirvCompositeExtract : public SpirvInstruction {
 public:
-  SpirvCompositeExtract(QualType resultType, uint32_t resultId,
-                        SourceLocation loc, SpirvInstruction *composite,
+  SpirvCompositeExtract(QualType resultType, SourceLocation loc,
+                        SpirvInstruction *composite,
                         llvm::ArrayRef<uint32_t> indices);
 
   // For LLVM-style RTTI
@@ -1134,9 +1130,8 @@ private:
 /// \brief Composite insertion instruction (OpCompositeInsert)
 class SpirvCompositeInsert : public SpirvInstruction {
 public:
-  SpirvCompositeInsert(QualType resultType, uint32_t resultId,
-                       SourceLocation loc, SpirvInstruction *composite,
-                       SpirvInstruction *object,
+  SpirvCompositeInsert(QualType resultType, SourceLocation loc,
+                       SpirvInstruction *composite, SpirvInstruction *object,
                        llvm::ArrayRef<uint32_t> indices);
 
   // For LLVM-style RTTI
@@ -1185,9 +1180,8 @@ public:
 /// \brief ExtInst instruction
 class SpirvExtInst : public SpirvInstruction {
 public:
-  SpirvExtInst(QualType resultType, uint32_t resultId, SourceLocation loc,
-               SpirvExtInstImport *set, GLSLstd450 inst,
-               llvm::ArrayRef<SpirvInstruction *> operandsVec);
+  SpirvExtInst(QualType resultType, SourceLocation loc, SpirvExtInstImport *set,
+               GLSLstd450 inst, llvm::ArrayRef<SpirvInstruction *> operandsVec);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1209,7 +1203,7 @@ private:
 /// \brief OpFunctionCall instruction
 class SpirvFunctionCall : public SpirvInstruction {
 public:
-  SpirvFunctionCall(QualType resultType, uint32_t resultId, SourceLocation loc,
+  SpirvFunctionCall(QualType resultType, SourceLocation loc,
                     SpirvFunction *function,
                     llvm::ArrayRef<SpirvInstruction *> argsVec);
 
@@ -1241,8 +1235,7 @@ public:
 
 protected:
   SpirvGroupNonUniformOp(Kind kind, spv::Op opcode, QualType resultType,
-                         uint32_t resultId, SourceLocation loc,
-                         spv::Scope scope);
+                         SourceLocation loc, spv::Scope scope);
 
 private:
   spv::Scope execScope;
@@ -1252,9 +1245,8 @@ private:
 class SpirvNonUniformBinaryOp : public SpirvGroupNonUniformOp {
 public:
   SpirvNonUniformBinaryOp(spv::Op opcode, QualType resultType,
-                          uint32_t resultId, SourceLocation loc,
-                          spv::Scope scope, SpirvInstruction *arg1,
-                          SpirvInstruction *arg2);
+                          SourceLocation loc, spv::Scope scope,
+                          SpirvInstruction *arg1, SpirvInstruction *arg2);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1275,8 +1267,8 @@ private:
 /// non-uniform instruction that takes no other arguments.
 class SpirvNonUniformElect : public SpirvGroupNonUniformOp {
 public:
-  SpirvNonUniformElect(QualType resultType, uint32_t resultId,
-                       SourceLocation loc, spv::Scope scope);
+  SpirvNonUniformElect(QualType resultType, SourceLocation loc,
+                       spv::Scope scope);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1289,7 +1281,7 @@ public:
 /// \brief OpGroupNonUniform* unary instructions.
 class SpirvNonUniformUnaryOp : public SpirvGroupNonUniformOp {
 public:
-  SpirvNonUniformUnaryOp(spv::Op opcode, QualType resultType, uint32_t resultId,
+  SpirvNonUniformUnaryOp(spv::Op opcode, QualType resultType,
                          SourceLocation loc, spv::Scope scope,
                          llvm::Optional<spv::GroupOperation> group,
                          SpirvInstruction *arg);
@@ -1338,18 +1330,20 @@ private:
 ///
 class SpirvImageOp : public SpirvInstruction {
 public:
-  SpirvImageOp(
-      spv::Op opcode, QualType resultType, uint32_t resultId,
-      SourceLocation loc, SpirvInstruction *image, SpirvInstruction *coordinate,
-      spv::ImageOperandsMask mask, SpirvInstruction *dref = nullptr,
-      SpirvInstruction *bias = nullptr, SpirvInstruction *lod = nullptr,
-      SpirvInstruction *gradDx = nullptr, SpirvInstruction *gradDy = nullptr,
-      SpirvInstruction *constOffset = nullptr,
-      SpirvInstruction *offset = nullptr,
-      SpirvInstruction *constOffsets = nullptr,
-      SpirvInstruction *sample = nullptr, SpirvInstruction *minLod = nullptr,
-      SpirvInstruction *component = nullptr,
-      SpirvInstruction *texelToWrite = nullptr);
+  SpirvImageOp(spv::Op opcode, QualType resultType, SourceLocation loc,
+               SpirvInstruction *image, SpirvInstruction *coordinate,
+               spv::ImageOperandsMask mask, SpirvInstruction *dref = nullptr,
+               SpirvInstruction *bias = nullptr,
+               SpirvInstruction *lod = nullptr,
+               SpirvInstruction *gradDx = nullptr,
+               SpirvInstruction *gradDy = nullptr,
+               SpirvInstruction *constOffset = nullptr,
+               SpirvInstruction *offset = nullptr,
+               SpirvInstruction *constOffsets = nullptr,
+               SpirvInstruction *sample = nullptr,
+               SpirvInstruction *minLod = nullptr,
+               SpirvInstruction *component = nullptr,
+               SpirvInstruction *texelToWrite = nullptr);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1421,9 +1415,8 @@ private:
 /// OpImageQuerySizeLod (image, lod)
 class SpirvImageQuery : public SpirvInstruction {
 public:
-  SpirvImageQuery(spv::Op opcode, QualType resultType, uint32_t resultId,
-                  SourceLocation loc, SpirvInstruction *img,
-                  SpirvInstruction *lod = nullptr,
+  SpirvImageQuery(spv::Op opcode, QualType resultType, SourceLocation loc,
+                  SpirvInstruction *img, SpirvInstruction *lod = nullptr,
                   SpirvInstruction *coord = nullptr);
 
   // For LLVM-style RTTI
@@ -1448,8 +1441,8 @@ private:
 /// \brief OpImageSparseTexelsResident instruction
 class SpirvImageSparseTexelsResident : public SpirvInstruction {
 public:
-  SpirvImageSparseTexelsResident(QualType resultType, uint32_t resultId,
-                                 SourceLocation loc, SpirvInstruction *resCode);
+  SpirvImageSparseTexelsResident(QualType resultType, SourceLocation loc,
+                                 SpirvInstruction *resCode);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1470,9 +1463,8 @@ private:
 /// OpTypePointer whose Storage Class operand is Image.
 class SpirvImageTexelPointer : public SpirvInstruction {
 public:
-  SpirvImageTexelPointer(QualType resultType, uint32_t resultId,
-                         SourceLocation loc, SpirvInstruction *image,
-                         SpirvInstruction *coordinate,
+  SpirvImageTexelPointer(QualType resultType, SourceLocation loc,
+                         SpirvInstruction *image, SpirvInstruction *coordinate,
                          SpirvInstruction *sample);
 
   // For LLVM-style RTTI
@@ -1495,8 +1487,7 @@ private:
 /// \brief Load instruction representation
 class SpirvLoad : public SpirvInstruction {
 public:
-  SpirvLoad(QualType resultType, uint32_t resultId, SourceLocation loc,
-            SpirvInstruction *pointer,
+  SpirvLoad(QualType resultType, SourceLocation loc, SpirvInstruction *pointer,
             llvm::Optional<spv::MemoryAccessMask> mask = llvm::None);
 
   // For LLVM-style RTTI
@@ -1523,7 +1514,7 @@ private:
 /// type.
 class SpirvSampledImage : public SpirvInstruction {
 public:
-  SpirvSampledImage(QualType resultType, uint32_t resultId, SourceLocation loc,
+  SpirvSampledImage(QualType resultType, SourceLocation loc,
                     SpirvInstruction *image, SpirvInstruction *sampler);
 
   // For LLVM-style RTTI
@@ -1544,9 +1535,8 @@ private:
 /// \brief Select operation representation.
 class SpirvSelect : public SpirvInstruction {
 public:
-  SpirvSelect(QualType resultType, uint32_t resultId, SourceLocation loc,
-              SpirvInstruction *cond, SpirvInstruction *trueId,
-              SpirvInstruction *falseId);
+  SpirvSelect(QualType resultType, SourceLocation loc, SpirvInstruction *cond,
+              SpirvInstruction *trueId, SpirvInstruction *falseId);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1569,8 +1559,7 @@ private:
 class SpirvSpecConstantBinaryOp : public SpirvInstruction {
 public:
   SpirvSpecConstantBinaryOp(spv::Op specConstantOp, QualType resultType,
-                            uint32_t resultId, SourceLocation loc,
-                            SpirvInstruction *operand1,
+                            SourceLocation loc, SpirvInstruction *operand1,
                             SpirvInstruction *operand2);
 
   // For LLVM-style RTTI
@@ -1594,8 +1583,7 @@ private:
 class SpirvSpecConstantUnaryOp : public SpirvInstruction {
 public:
   SpirvSpecConstantUnaryOp(spv::Op specConstantOp, QualType resultType,
-                           uint32_t resultId, SourceLocation loc,
-                           SpirvInstruction *operand);
+                           SourceLocation loc, SpirvInstruction *operand);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1679,8 +1667,8 @@ private:
 /// ----------------------------------------------------------------------------
 class SpirvUnaryOp : public SpirvInstruction {
 public:
-  SpirvUnaryOp(spv::Op opcode, QualType resultType, uint32_t resultId,
-               SourceLocation loc, SpirvInstruction *op);
+  SpirvUnaryOp(spv::Op opcode, QualType resultType, SourceLocation loc,
+               SpirvInstruction *op);
 
   // For LLVM-style RTTI
   static bool classof(const SpirvInstruction *inst) {
@@ -1699,7 +1687,7 @@ private:
 /// \brief OpVectorShuffle instruction
 class SpirvVectorShuffle : public SpirvInstruction {
 public:
-  SpirvVectorShuffle(QualType resultType, uint32_t resultId, SourceLocation loc,
+  SpirvVectorShuffle(QualType resultType, SourceLocation loc,
                      SpirvInstruction *vec1, SpirvInstruction *vec2,
                      llvm::ArrayRef<uint32_t> componentsVec);
 
@@ -1722,7 +1710,7 @@ private:
 
 class SpirvArrayLength : public SpirvInstruction {
 public:
-  SpirvArrayLength(QualType resultType, uint32_t resultId, SourceLocation loc,
+  SpirvArrayLength(QualType resultType, SourceLocation loc,
                    SpirvInstruction *structure, uint32_t arrayMember);
 
   // For LLVM-style RTTI

+ 59 - 64
tools/clang/lib/SPIRV/SpirvBuilder.cpp

@@ -49,7 +49,7 @@ SpirvFunctionParameter *SpirvBuilder::addFnParam(QualType ptrType,
                                                  SourceLocation loc,
                                                  llvm::StringRef name) {
   assert(function && "found detached parameter");
-  auto *param = new (context) SpirvFunctionParameter(ptrType, /*id*/ 0, loc);
+  auto *param = new (context) SpirvFunctionParameter(ptrType, loc);
   param->setStorageClass(spv::StorageClass::Function);
   param->setDebugName(name);
   function->addParameter(param);
@@ -60,8 +60,8 @@ SpirvVariable *SpirvBuilder::addFnVar(QualType valueType, SourceLocation loc,
                                       llvm::StringRef name,
                                       SpirvInstruction *init) {
   assert(function && "found detached local variable");
-  auto *var = new (context) SpirvVariable(valueType, /*id*/ 0, loc,
-                                          spv::StorageClass::Function, init);
+  auto *var = new (context)
+      SpirvVariable(valueType, loc, spv::StorageClass::Function, init);
   var->setDebugName(name);
   function->addVariable(var);
   return var;
@@ -110,7 +110,7 @@ SpirvComposite *SpirvBuilder::createCompositeConstruct(
     SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction =
-      new (context) SpirvComposite(resultType, /*id*/ 0, loc, constituents);
+      new (context) SpirvComposite(resultType, loc, constituents);
   insertPoint->addInstruction(instruction);
   if (!constituents.empty()) {
     instruction->setLayoutRule(constituents[0]->getLayoutRule());
@@ -122,8 +122,8 @@ SpirvComposite *SpirvBuilder::createCompositeConstruct(
     const SpirvType *resultType,
     llvm::ArrayRef<SpirvInstruction *> constituents, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context)
-      SpirvComposite(/*QualType*/ {}, /*id*/ 0, loc, constituents);
+  auto *instruction =
+      new (context) SpirvComposite(/*QualType*/ {}, loc, constituents);
   instruction->setResultType(resultType);
   if (!constituents.empty()) {
     instruction->setLayoutRule(constituents[0]->getLayoutRule());
@@ -136,8 +136,8 @@ SpirvCompositeExtract *SpirvBuilder::createCompositeExtract(
     QualType resultType, SpirvInstruction *composite,
     llvm::ArrayRef<uint32_t> indexes, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context)
-      SpirvCompositeExtract(resultType, /*id*/ 0, loc, composite, indexes);
+  auto *instruction =
+      new (context) SpirvCompositeExtract(resultType, loc, composite, indexes);
   instruction->setRValue();
   insertPoint->addInstruction(instruction);
   return instruction;
@@ -148,8 +148,8 @@ SpirvCompositeInsert *SpirvBuilder::createCompositeInsert(
     llvm::ArrayRef<uint32_t> indices, SpirvInstruction *object,
     SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context) SpirvCompositeInsert(
-      resultType, /*id*/ 0, loc, composite, object, indices);
+  auto *instruction = new (context)
+      SpirvCompositeInsert(resultType, loc, composite, object, indices);
   insertPoint->addInstruction(instruction);
   return instruction;
 }
@@ -158,8 +158,8 @@ SpirvVectorShuffle *SpirvBuilder::createVectorShuffle(
     QualType resultType, SpirvInstruction *vector1, SpirvInstruction *vector2,
     llvm::ArrayRef<uint32_t> selectors, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context) SpirvVectorShuffle(
-      resultType, /*id*/ 0, loc, vector1, vector2, selectors);
+  auto *instruction = new (context)
+      SpirvVectorShuffle(resultType, loc, vector1, vector2, selectors);
   instruction->setRValue();
   insertPoint->addInstruction(instruction);
   return instruction;
@@ -169,8 +169,7 @@ SpirvLoad *SpirvBuilder::createLoad(QualType resultType,
                                     SpirvInstruction *pointer,
                                     SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction =
-      new (context) SpirvLoad(resultType, /*id*/ 0, loc, pointer);
+  auto *instruction = new (context) SpirvLoad(resultType, loc, pointer);
   instruction->setStorageClass(pointer->getStorageClass());
   instruction->setLayoutRule(pointer->getLayoutRule());
   instruction->setNonUniform(pointer->isNonUniform());
@@ -194,8 +193,7 @@ SpirvLoad *SpirvBuilder::createLoad(const SpirvType *resultType,
                                     SpirvInstruction *pointer,
                                     SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction =
-      new (context) SpirvLoad(/*QualType*/ {}, /*id*/ 0, loc, pointer);
+  auto *instruction = new (context) SpirvLoad(/*QualType*/ {}, loc, pointer);
   instruction->setResultType(resultType);
   instruction->setStorageClass(pointer->getStorageClass());
   instruction->setLayoutRule(pointer->getLayoutRule());
@@ -218,7 +216,7 @@ SpirvBuilder::createFunctionCall(QualType returnType, SpirvFunction *func,
                                  SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction =
-      new (context) SpirvFunctionCall(returnType, /*id*/ 0, loc, func, params);
+      new (context) SpirvFunctionCall(returnType, loc, func, params);
   instruction->setRValue(func->isRValue());
   instruction->setContainsAliasComponent(func->constainsAliasComponent());
 
@@ -242,7 +240,7 @@ SpirvBuilder::createAccessChain(QualType resultType, SpirvInstruction *base,
                                 SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction =
-      new (context) SpirvAccessChain(resultType, /*id*/ 0, loc, base, indexes);
+      new (context) SpirvAccessChain(resultType, loc, base, indexes);
   instruction->setStorageClass(base->getStorageClass());
   instruction->setLayoutRule(base->getLayoutRule());
   bool isNonUniform = base->isNonUniform();
@@ -265,8 +263,8 @@ SpirvAccessChain *SpirvBuilder::createAccessChain(
     const SpirvType *resultType, SpirvInstruction *base,
     llvm::ArrayRef<SpirvInstruction *> indexes, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context)
-      SpirvAccessChain(/*QualType*/ {}, /*id*/ 0, loc, base, indexes);
+  auto *instruction =
+      new (context) SpirvAccessChain(/*QualType*/ {}, loc, base, indexes);
   instruction->setResultType(resultType);
   instruction->setStorageClass(base->getStorageClass());
   instruction->setLayoutRule(base->getLayoutRule());
@@ -290,8 +288,7 @@ SpirvUnaryOp *SpirvBuilder::createUnaryOp(spv::Op op, QualType resultType,
                                           SpirvInstruction *operand,
                                           SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction =
-      new (context) SpirvUnaryOp(op, resultType, /*id*/ 0, loc, operand);
+  auto *instruction = new (context) SpirvUnaryOp(op, resultType, loc, operand);
   instruction->setNonUniform(operand->isNonUniform());
   insertPoint->addInstruction(instruction);
   return instruction;
@@ -303,7 +300,7 @@ SpirvBinaryOp *SpirvBuilder::createBinaryOp(spv::Op op, QualType resultType,
                                             SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction =
-      new (context) SpirvBinaryOp(op, resultType, /*id*/ 0, loc, lhs, rhs);
+      new (context) SpirvBinaryOp(op, resultType, loc, lhs, rhs);
   instruction->setNonUniform(lhs->isNonUniform() || rhs->isNonUniform());
   insertPoint->addInstruction(instruction);
   return instruction;
@@ -316,7 +313,7 @@ SpirvBinaryOp *SpirvBuilder::createBinaryOp(spv::Op op,
                                             SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction =
-      new (context) SpirvBinaryOp(op, /*QualType*/ {}, /*id*/ 0, loc, lhs, rhs);
+      new (context) SpirvBinaryOp(op, /*QualType*/ {}, loc, lhs, rhs);
   instruction->setResultType(resultType);
   instruction->setNonUniform(lhs->isNonUniform() || rhs->isNonUniform());
   insertPoint->addInstruction(instruction);
@@ -327,8 +324,8 @@ SpirvSpecConstantBinaryOp *SpirvBuilder::createSpecConstantBinaryOp(
     spv::Op op, QualType resultType, SpirvInstruction *lhs,
     SpirvInstruction *rhs, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context)
-      SpirvSpecConstantBinaryOp(op, resultType, /*id*/ 0, loc, lhs, rhs);
+  auto *instruction =
+      new (context) SpirvSpecConstantBinaryOp(op, resultType, loc, lhs, rhs);
   insertPoint->addInstruction(instruction);
   return instruction;
 }
@@ -337,7 +334,7 @@ SpirvNonUniformElect *SpirvBuilder::createGroupNonUniformElect(
     spv::Op op, QualType resultType, spv::Scope execScope, SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction =
-      new (context) SpirvNonUniformElect(resultType, /*id*/ 0, loc, execScope);
+      new (context) SpirvNonUniformElect(resultType, loc, execScope);
   insertPoint->addInstruction(instruction);
   return instruction;
 }
@@ -347,8 +344,8 @@ SpirvNonUniformUnaryOp *SpirvBuilder::createGroupNonUniformUnaryOp(
     SpirvInstruction *operand, llvm::Optional<spv::GroupOperation> groupOp,
     SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context) SpirvNonUniformUnaryOp(
-      op, resultType, /*id*/ 0, loc, execScope, groupOp, operand);
+  auto *instruction = new (context)
+      SpirvNonUniformUnaryOp(op, resultType, loc, execScope, groupOp, operand);
   insertPoint->addInstruction(instruction);
   return instruction;
 }
@@ -359,7 +356,7 @@ SpirvNonUniformBinaryOp *SpirvBuilder::createGroupNonUniformBinaryOp(
     SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction = new (context) SpirvNonUniformBinaryOp(
-      op, resultType, /*id*/ 0, loc, execScope, operand1, operand2);
+      op, resultType, loc, execScope, operand1, operand2);
   insertPoint->addInstruction(instruction);
   return instruction;
 }
@@ -369,9 +366,9 @@ SpirvAtomic *SpirvBuilder::createAtomicOp(
     spv::Scope scope, spv::MemorySemanticsMask memorySemantics,
     SpirvInstruction *valueToOp, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context)
-      SpirvAtomic(opcode, resultType, /*id*/ 0, loc, originalValuePtr, scope,
-                  memorySemantics, valueToOp);
+  auto *instruction =
+      new (context) SpirvAtomic(opcode, resultType, loc, originalValuePtr,
+                                scope, memorySemantics, valueToOp);
   insertPoint->addInstruction(instruction);
   return instruction;
 }
@@ -384,7 +381,7 @@ SpirvAtomic *SpirvBuilder::createAtomicCompareExchange(
     SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *instruction = new (context)
-      SpirvAtomic(spv::Op::OpAtomicCompareExchange, resultType, /*id*/ 0, loc,
+      SpirvAtomic(spv::Op::OpAtomicCompareExchange, resultType, loc,
                   originalValuePtr, scope, equalMemorySemantics,
                   unequalMemorySemantics, valueToOp, comparator);
   insertPoint->addInstruction(instruction);
@@ -397,7 +394,7 @@ SpirvSampledImage *SpirvBuilder::createSampledImage(QualType imageType,
                                                     SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *sampledImage =
-      new (context) SpirvSampledImage(imageType, /*id*/ 0, loc, image, sampler);
+      new (context) SpirvSampledImage(imageType, loc, image, sampler);
   sampledImage->setNonUniform(image->isNonUniform() || sampler->isNonUniform());
   insertPoint->addInstruction(sampledImage);
   return sampledImage;
@@ -407,8 +404,8 @@ SpirvImageTexelPointer *SpirvBuilder::createImageTexelPointer(
     QualType resultType, SpirvInstruction *image, SpirvInstruction *coordinate,
     SpirvInstruction *sample, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *instruction = new (context) SpirvImageTexelPointer(
-      resultType, /*id*/ 0, loc, image, coordinate, sample);
+  auto *instruction = new (context)
+      SpirvImageTexelPointer(resultType, loc, image, coordinate, sample);
   instruction->setNonUniform(image->isNonUniform());
   insertPoint->addInstruction(instruction);
   return instruction;
@@ -493,7 +490,7 @@ SpirvInstruction *SpirvBuilder::createImageSample(
       bias, lod, grad, constOffset, varOffset, constOffsets, sample, minLod);
 
   auto *imageSampleInst = new (context)
-      SpirvImageOp(op, texelType, /*id*/ 0, loc, sampledImage, coordinate, mask,
+      SpirvImageOp(op, texelType, loc, sampledImage, coordinate, mask,
                    compareVal, bias, lod, grad.first, grad.second, constOffset,
                    varOffset, constOffsets, sample, minLod);
   insertPoint->addInstruction(imageSampleInst);
@@ -531,7 +528,7 @@ SpirvInstruction *SpirvBuilder::createImageFetchOrRead(
           : (isSparse ? spv::Op::OpImageSparseRead : spv::Op::OpImageRead);
 
   auto *fetchOrReadInst = new (context) SpirvImageOp(
-      op, texelType, /*id*/ 0, loc, image, coordinate, mask,
+      op, texelType, loc, image, coordinate, mask,
       /*dref*/ nullptr, /*bias*/ nullptr, lod, /*gradDx*/ nullptr,
       /*gradDy*/ nullptr, constOffset, varOffset, constOffsets, sample);
   insertPoint->addInstruction(fetchOrReadInst);
@@ -554,7 +551,7 @@ void SpirvBuilder::createImageWrite(QualType imageType, SpirvInstruction *image,
                                     SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *writeInst = new (context) SpirvImageOp(
-      spv::Op::OpImageWrite, imageType, /*id*/ 0, loc, image, coord,
+      spv::Op::OpImageWrite, imageType, loc, image, coord,
       spv::ImageOperandsMask::MaskNone,
       /*dref*/ nullptr, /*bias*/ nullptr, /*lod*/ nullptr, /*gradDx*/ nullptr,
       /*gradDy*/ nullptr, /*constOffset*/ nullptr, /*varOffset*/ nullptr,
@@ -591,7 +588,7 @@ SpirvInstruction *SpirvBuilder::createImageGather(
     component = nullptr;
 
   auto *imageInstruction = new (context) SpirvImageOp(
-      op, texelType, /*id*/ 0, loc, sampledImage, coordinate, mask, compareVal,
+      op, texelType, loc, sampledImage, coordinate, mask, compareVal,
       /*bias*/ nullptr, /*lod*/ nullptr, /*gradDx*/ nullptr,
       /*gradDy*/ nullptr, constOffset, varOffset, constOffsets, sample,
       /*minLod*/ nullptr, component);
@@ -613,8 +610,8 @@ SpirvImageSparseTexelsResident *
 SpirvBuilder::createImageSparseTexelsResident(SpirvInstruction *residentCode,
                                               SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *inst = new (context) SpirvImageSparseTexelsResident(
-      astContext.BoolTy, /*id*/ 0, loc, residentCode);
+  auto *inst = new (context)
+      SpirvImageSparseTexelsResident(astContext.BoolTy, loc, residentCode);
   insertPoint->addInstruction(inst);
   return inst;
 }
@@ -632,9 +629,8 @@ SpirvImageQuery *SpirvBuilder::createImageQuery(spv::Op opcode,
   if (opcode == spv::Op::OpImageQueryLod)
     coordinateParam = lod;
 
-  auto *inst =
-      new (context) SpirvImageQuery(opcode, resultType, /*result-id*/ 0, loc,
-                                    image, lodParam, coordinateParam);
+  auto *inst = new (context) SpirvImageQuery(opcode, resultType, loc, image,
+                                             lodParam, coordinateParam);
   insertPoint->addInstruction(inst);
   return inst;
 }
@@ -646,7 +642,7 @@ SpirvSelect *SpirvBuilder::createSelect(QualType resultType,
                                         SourceLocation loc) {
   assert(insertPoint && "null insert point");
   auto *inst = new (context)
-      SpirvSelect(resultType, /*id*/ 0, loc, condition, trueValue, falseValue);
+      SpirvSelect(resultType, loc, condition, trueValue, falseValue);
   insertPoint->addInstruction(inst);
   return inst;
 }
@@ -730,8 +726,8 @@ SpirvInstruction *SpirvBuilder::createExtInst(
     QualType resultType, SpirvExtInstImport *set, GLSLstd450 inst,
     llvm::ArrayRef<SpirvInstruction *> operands, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *extInst = new (context)
-      SpirvExtInst(resultType, /*id*/ 0, loc, set, inst, operands);
+  auto *extInst =
+      new (context) SpirvExtInst(resultType, loc, set, inst, operands);
   insertPoint->addInstruction(extInst);
   return extInst;
 }
@@ -740,8 +736,8 @@ SpirvInstruction *SpirvBuilder::createExtInst(
     const SpirvType *resultType, SpirvExtInstImport *set, GLSLstd450 inst,
     llvm::ArrayRef<SpirvInstruction *> operands, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *extInst = new (context)
-      SpirvExtInst(/*QualType*/ {}, /*id*/ 0, loc, set, inst, operands);
+  auto *extInst =
+      new (context) SpirvExtInst(/*QualType*/ {}, loc, set, inst, operands);
   extInst->setResultType(resultType);
   insertPoint->addInstruction(extInst);
   return extInst;
@@ -761,8 +757,8 @@ SpirvBitFieldInsert *SpirvBuilder::createBitFieldInsert(
     QualType resultType, SpirvInstruction *base, SpirvInstruction *insert,
     SpirvInstruction *offset, SpirvInstruction *count, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *inst = new (context) SpirvBitFieldInsert(resultType, /*id*/ 0, loc,
-                                                 base, insert, offset, count);
+  auto *inst = new (context)
+      SpirvBitFieldInsert(resultType, loc, base, insert, offset, count);
   insertPoint->addInstruction(inst);
   return inst;
 }
@@ -771,8 +767,8 @@ SpirvBitFieldExtract *SpirvBuilder::createBitFieldExtract(
     QualType resultType, SpirvInstruction *base, SpirvInstruction *offset,
     SpirvInstruction *count, bool isSigned, SourceLocation loc) {
   assert(insertPoint && "null insert point");
-  auto *inst = new (context) SpirvBitFieldExtract(
-      resultType, /*id*/ 0, loc, base, offset, count, isSigned);
+  auto *inst = new (context)
+      SpirvBitFieldExtract(resultType, loc, base, offset, count, isSigned);
   insertPoint->addInstruction(inst);
   return inst;
 }
@@ -794,8 +790,8 @@ SpirvArrayLength *SpirvBuilder::createArrayLength(QualType resultType,
                                                   SpirvInstruction *structure,
                                                   uint32_t arrayMember) {
   assert(insertPoint && "null insert point");
-  auto *inst = new (context) SpirvArrayLength(resultType, /*result-id*/ 0, loc,
-                                              structure, arrayMember);
+  auto *inst =
+      new (context) SpirvArrayLength(resultType, loc, structure, arrayMember);
   insertPoint->addInstruction(inst);
   return inst;
 }
@@ -830,7 +826,7 @@ void SpirvBuilder::addModuleProcessed(llvm::StringRef process) {
 SpirvExtInstImport *SpirvBuilder::getGLSLExtInstSet(SourceLocation loc) {
   SpirvExtInstImport *glslSet = module->getGLSLExtInstSet();
   if (!glslSet) {
-    glslSet = new (context) SpirvExtInstImport(/*id*/ 0, loc, "GLSL.std.450");
+    glslSet = new (context) SpirvExtInstImport(loc, "GLSL.std.450");
     module->addExtInstSet(glslSet);
   }
   return glslSet;
@@ -841,7 +837,7 @@ SpirvVariable *SpirvBuilder::addStageIOVar(QualType type,
                                            std::string name,
                                            SourceLocation loc) {
   // Note: We store the underlying type in the variable, *not* the pointer type.
-  auto *var = new (context) SpirvVariable(type, /*id*/ 0, loc, storageClass);
+  auto *var = new (context) SpirvVariable(type, loc, storageClass);
   var->setDebugName(name);
   module->addVariable(var);
   return var;
@@ -863,7 +859,7 @@ SpirvVariable *SpirvBuilder::addStageBuiltinVar(QualType type,
   }
 
   // Note: We store the underlying type in the variable, *not* the pointer type.
-  auto *var = new (context) SpirvVariable(type, /*id*/ 0, loc, storageClass);
+  auto *var = new (context) SpirvVariable(type, loc, storageClass);
   module->addVariable(var);
 
   // Decorate with the specified Builtin
@@ -882,9 +878,8 @@ SpirvVariable *SpirvBuilder::addModuleVar(
     llvm::Optional<SpirvInstruction *> init, SourceLocation loc) {
   assert(storageClass != spv::StorageClass::Function);
   // Note: We store the underlying type in the variable, *not* the pointer type.
-  auto *var =
-      new (context) SpirvVariable(type, /*id*/ 0, loc, storageClass,
-                                  init.hasValue() ? init.getValue() : nullptr);
+  auto *var = new (context) SpirvVariable(
+      type, loc, storageClass, init.hasValue() ? init.getValue() : nullptr);
   var->setDebugName(name);
   module->addVariable(var);
   return var;
@@ -896,7 +891,7 @@ SpirvVariable *SpirvBuilder::addModuleVar(
   assert(storageClass != spv::StorageClass::Function);
   // Note: We store the underlying type in the variable, *not* the pointer type.
   auto *var =
-      new (context) SpirvVariable(/*QualType*/ {}, /*id*/ 0, loc, storageClass,
+      new (context) SpirvVariable(/*QualType*/ {}, loc, storageClass,
                                   init.hasValue() ? init.getValue() : nullptr);
   var->setResultType(type);
   var->setDebugName(name);

+ 109 - 142
tools/clang/lib/SPIRV/SpirvInstruction.cpp

@@ -85,34 +85,32 @@ DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvArrayLength)
 #undef DEFINE_INVOKE_VISITOR_FOR_CLASS
 
 SpirvInstruction::SpirvInstruction(Kind k, spv::Op op, QualType astType,
-                                   uint32_t id, SourceLocation loc)
-    : kind(k), opcode(op), astResultType(astType), resultId(id), srcLoc(loc),
+                                   SourceLocation loc)
+    : kind(k), opcode(op), astResultType(astType), resultId(0), srcLoc(loc),
       debugName(), resultType(nullptr), resultTypeId(0),
       layoutRule(SpirvLayoutRule::Void), containsAlias(false),
       storageClass(spv::StorageClass::Function), isRValue_(false),
       isRelaxedPrecision_(false), isNonUniform_(false) {}
 
 SpirvCapability::SpirvCapability(SourceLocation loc, spv::Capability cap)
-    : SpirvInstruction(IK_Capability, spv::Op::OpCapability, QualType(),
-                       /*resultId=*/0, loc),
+    : SpirvInstruction(IK_Capability, spv::Op::OpCapability, QualType(), loc),
       capability(cap) {}
 
 SpirvExtension::SpirvExtension(SourceLocation loc,
                                llvm::StringRef extensionName)
-    : SpirvInstruction(IK_Extension, spv::Op::OpExtension, QualType(),
-                       /*resultId=*/0, loc),
+    : SpirvInstruction(IK_Extension, spv::Op::OpExtension, QualType(), loc),
       extName(extensionName) {}
 
-SpirvExtInstImport::SpirvExtInstImport(uint32_t resultId, SourceLocation loc,
+SpirvExtInstImport::SpirvExtInstImport(SourceLocation loc,
                                        llvm::StringRef extensionName)
     : SpirvInstruction(IK_ExtInstImport, spv::Op::OpExtInstImport, QualType(),
-                       resultId, loc),
+                       loc),
       extName(extensionName) {}
 
 SpirvMemoryModel::SpirvMemoryModel(spv::AddressingModel addrModel,
                                    spv::MemoryModel memModel)
     : SpirvInstruction(IK_MemoryModel, spv::Op::OpMemoryModel, QualType(),
-                       /*resultId=*/0, /*SrcLoc*/ {}),
+                       /*SrcLoc*/ {}),
       addressModel(addrModel), memoryModel(memModel) {}
 
 SpirvEntryPoint::SpirvEntryPoint(SourceLocation loc,
@@ -120,8 +118,7 @@ SpirvEntryPoint::SpirvEntryPoint(SourceLocation loc,
                                  SpirvFunction *entryPointFn,
                                  llvm::StringRef nameStr,
                                  llvm::ArrayRef<SpirvVariable *> iface)
-    : SpirvInstruction(IK_EntryPoint, spv::Op::OpEntryPoint, QualType(),
-                       /*resultId=*/0, loc),
+    : SpirvInstruction(IK_EntryPoint, spv::Op::OpEntryPoint, QualType(), loc),
       execModel(executionModel), entryPoint(entryPointFn), name(nameStr),
       interfaceVec(iface.begin(), iface.end()) {}
 
@@ -133,32 +130,29 @@ SpirvExecutionMode::SpirvExecutionMode(SourceLocation loc, SpirvFunction *entry,
     : SpirvInstruction(IK_ExecutionMode,
                        usesIdParams ? spv::Op::OpExecutionModeId
                                     : spv::Op::OpExecutionMode,
-                       QualType(), /*resultId=*/0, loc),
+                       QualType(), loc),
       entryPoint(entry), execMode(em),
       params(paramsVec.begin(), paramsVec.end()) {}
 
 SpirvString::SpirvString(SourceLocation loc, llvm::StringRef stringLiteral)
-    : SpirvInstruction(IK_String, spv::Op::OpString, QualType(),
-                       /*resultId=*/0, loc),
+    : SpirvInstruction(IK_String, spv::Op::OpString, QualType(), loc),
       str(stringLiteral) {}
 
 SpirvSource::SpirvSource(SourceLocation loc, spv::SourceLanguage language,
                          uint32_t ver, SpirvString *fileString,
                          llvm::StringRef src)
-    : SpirvInstruction(IK_Source, spv::Op::OpSource, QualType(),
-                       /*resultId=*/0, loc),
+    : SpirvInstruction(IK_Source, spv::Op::OpSource, QualType(), loc),
       lang(language), version(ver), file(fileString), source(src) {}
 
 SpirvModuleProcessed::SpirvModuleProcessed(SourceLocation loc,
                                            llvm::StringRef processStr)
     : SpirvInstruction(IK_ModuleProcessed, spv::Op::OpModuleProcessed,
-                       QualType(),
-                       /*resultId=*/0, loc),
+                       QualType(), loc),
       process(processStr) {}
 
 SpirvLineInfo::SpirvLineInfo(SpirvString *srcFile, uint32_t srcLine,
                              uint32_t srcCol)
-    : SpirvInstruction(IK_LineInfo, spv::Op::OpLine, QualType(), 0, {}),
+    : SpirvInstruction(IK_LineInfo, spv::Op::OpLine, QualType(), {}),
       file(srcFile), line(srcLine), column(srcCol) {}
 
 SpirvDecoration::SpirvDecoration(SourceLocation loc,
@@ -167,7 +161,7 @@ SpirvDecoration::SpirvDecoration(SourceLocation loc,
                                  llvm::ArrayRef<uint32_t> p,
                                  llvm::Optional<uint32_t> idx)
     : SpirvInstruction(IK_Decoration, getDecorateOpcode(decor, idx),
-                       /*type*/ {}, /*id*/ 0, loc),
+                       /*type*/ {}, loc),
       target(targetInst), decoration(decor), index(idx),
       params(p.begin(), p.end()), idParams() {}
 
@@ -177,7 +171,7 @@ SpirvDecoration::SpirvDecoration(SourceLocation loc,
                                  llvm::StringRef strParam,
                                  llvm::Optional<uint32_t> idx)
     : SpirvInstruction(IK_Decoration, getDecorateOpcode(decor, idx),
-                       /*type*/ {}, /*id*/ 0, loc),
+                       /*type*/ {}, loc),
       target(targetInst), decoration(decor), index(idx), params(), idParams() {
   const auto &stringWords = string::encodeSPIRVString(strParam);
   params.insert(params.end(), stringWords.begin(), stringWords.end());
@@ -188,7 +182,7 @@ SpirvDecoration::SpirvDecoration(SourceLocation loc,
                                  spv::Decoration decor,
                                  llvm::ArrayRef<SpirvInstruction *> ids)
     : SpirvInstruction(IK_Decoration, spv::Op::OpDecorateId,
-                       /*type*/ {}, /*id*/ 0, loc),
+                       /*type*/ {}, loc),
       target(targetInst), decoration(decor), index(llvm::None), params(),
       idParams(ids.begin(), ids.end()) {}
 
@@ -202,25 +196,22 @@ spv::Op SpirvDecoration::getDecorateOpcode(
                                 : spv::Op::OpDecorate;
 }
 
-SpirvVariable::SpirvVariable(QualType resultType, uint32_t resultId,
-                             SourceLocation loc, spv::StorageClass sc,
+SpirvVariable::SpirvVariable(QualType resultType, SourceLocation loc,
+                             spv::StorageClass sc,
                              SpirvInstruction *initializerInst)
-    : SpirvInstruction(IK_Variable, spv::Op::OpVariable, resultType, resultId,
-                       loc),
+    : SpirvInstruction(IK_Variable, spv::Op::OpVariable, resultType, loc),
       initializer(initializerInst) {
   setStorageClass(sc);
 }
 
 SpirvFunctionParameter::SpirvFunctionParameter(QualType resultType,
-                                               uint32_t resultId,
                                                SourceLocation loc)
     : SpirvInstruction(IK_FunctionParameter, spv::Op::OpFunctionParameter,
-                       resultType, resultId, loc) {}
+                       resultType, loc) {}
 
 SpirvMerge::SpirvMerge(Kind kind, spv::Op op, SourceLocation loc,
                        SpirvBasicBlock *mergeLabel)
-    : SpirvInstruction(kind, op, QualType(), /*resultId=*/0, loc),
-      mergeBlock(mergeLabel) {}
+    : SpirvInstruction(kind, op, QualType(), loc), mergeBlock(mergeLabel) {}
 
 SpirvLoopMerge::SpirvLoopMerge(SourceLocation loc, SpirvBasicBlock *mergeBlock,
                                SpirvBasicBlock *contTarget,
@@ -235,7 +226,7 @@ SpirvSelectionMerge::SpirvSelectionMerge(SourceLocation loc,
       selControlMask(mask) {}
 
 SpirvTerminator::SpirvTerminator(Kind kind, spv::Op op, SourceLocation loc)
-    : SpirvInstruction(kind, op, QualType(), /*resultId=*/0, loc) {}
+    : SpirvInstruction(kind, op, QualType(), loc) {}
 
 SpirvBranching::SpirvBranching(Kind kind, spv::Op op, SourceLocation loc)
     : SpirvTerminator(kind, op, loc) {}
@@ -284,20 +275,18 @@ llvm::ArrayRef<SpirvBasicBlock *> SpirvSwitch::getTargetBranches() const {
 SpirvUnreachable::SpirvUnreachable(SourceLocation loc)
     : SpirvTerminator(IK_Unreachable, spv::Op::OpUnreachable, loc) {}
 
-SpirvAccessChain::SpirvAccessChain(QualType resultType, uint32_t resultId,
-                                   SourceLocation loc,
+SpirvAccessChain::SpirvAccessChain(QualType resultType, SourceLocation loc,
                                    SpirvInstruction *baseInst,
                                    llvm::ArrayRef<SpirvInstruction *> indexVec)
-    : SpirvInstruction(IK_AccessChain, spv::Op::OpAccessChain, resultType,
-                       resultId, loc),
+    : SpirvInstruction(IK_AccessChain, spv::Op::OpAccessChain, resultType, loc),
       base(baseInst), indices(indexVec.begin(), indexVec.end()) {}
 
-SpirvAtomic::SpirvAtomic(spv::Op op, QualType resultType, uint32_t resultId,
-                         SourceLocation loc, SpirvInstruction *pointerInst,
-                         spv::Scope s, spv::MemorySemanticsMask mask,
+SpirvAtomic::SpirvAtomic(spv::Op op, QualType resultType, SourceLocation loc,
+                         SpirvInstruction *pointerInst, spv::Scope s,
+                         spv::MemorySemanticsMask mask,
                          SpirvInstruction *valueInst)
-    : SpirvInstruction(IK_Atomic, op, resultType, resultId, loc),
-      pointer(pointerInst), scope(s), memorySemantic(mask),
+    : SpirvInstruction(IK_Atomic, op, resultType, loc), pointer(pointerInst),
+      scope(s), memorySemantic(mask),
       memorySemanticUnequal(spv::MemorySemanticsMask::MaskNone),
       value(valueInst), comparator(nullptr) {
   assert(
@@ -311,14 +300,14 @@ SpirvAtomic::SpirvAtomic(spv::Op op, QualType resultType, uint32_t resultId,
       op == spv::Op::OpAtomicUMax || op == spv::Op::OpAtomicExchange);
 }
 
-SpirvAtomic::SpirvAtomic(spv::Op op, QualType resultType, uint32_t resultId,
-                         SourceLocation loc, SpirvInstruction *pointerInst,
-                         spv::Scope s, spv::MemorySemanticsMask semanticsEqual,
+SpirvAtomic::SpirvAtomic(spv::Op op, QualType resultType, SourceLocation loc,
+                         SpirvInstruction *pointerInst, spv::Scope s,
+                         spv::MemorySemanticsMask semanticsEqual,
                          spv::MemorySemanticsMask semanticsUnequal,
                          SpirvInstruction *valueInst,
                          SpirvInstruction *comparatorInst)
-    : SpirvInstruction(IK_Atomic, op, resultType, resultId, loc),
-      pointer(pointerInst), scope(s), memorySemantic(semanticsEqual),
+    : SpirvInstruction(IK_Atomic, op, resultType, loc), pointer(pointerInst),
+      scope(s), memorySemantic(semanticsEqual),
       memorySemanticUnequal(semanticsUnequal), value(valueInst),
       comparator(comparatorInst) {
   assert(op == spv::Op::OpAtomicCompareExchange);
@@ -330,45 +319,43 @@ SpirvBarrier::SpirvBarrier(SourceLocation loc, spv::Scope memScope,
     : SpirvInstruction(IK_Barrier,
                        execScope.hasValue() ? spv::Op::OpControlBarrier
                                             : spv::Op::OpMemoryBarrier,
-                       QualType(), /*resultId=*/0, loc),
+                       QualType(), loc),
       memoryScope(memScope), memorySemantics(memSemantics),
       executionScope(execScope) {}
 
 SpirvBinaryOp::SpirvBinaryOp(spv::Op opcode, QualType resultType,
-                             uint32_t resultId, SourceLocation loc,
-                             SpirvInstruction *op1, SpirvInstruction *op2)
-    : SpirvInstruction(IK_BinaryOp, opcode, resultType, resultId, loc),
-      operand1(op1), operand2(op2) {}
+                             SourceLocation loc, SpirvInstruction *op1,
+                             SpirvInstruction *op2)
+    : SpirvInstruction(IK_BinaryOp, opcode, resultType, loc), operand1(op1),
+      operand2(op2) {}
 
 SpirvBitField::SpirvBitField(Kind kind, spv::Op op, QualType resultType,
-                             uint32_t resultId, SourceLocation loc,
-                             SpirvInstruction *baseInst,
+                             SourceLocation loc, SpirvInstruction *baseInst,
                              SpirvInstruction *offsetInst,
                              SpirvInstruction *countInst)
-    : SpirvInstruction(kind, op, resultType, resultId, loc), base(baseInst),
+    : SpirvInstruction(kind, op, resultType, loc), base(baseInst),
       offset(offsetInst), count(countInst) {}
 
 SpirvBitFieldExtract::SpirvBitFieldExtract(
-    QualType resultType, uint32_t resultId, SourceLocation loc,
-    SpirvInstruction *baseInst, SpirvInstruction *offsetInst,
-    SpirvInstruction *countInst, bool isSigned)
-    : SpirvBitField(
-          IK_BitFieldExtract,
-          isSigned ? spv::Op::OpBitFieldSExtract : spv::Op::OpBitFieldUExtract,
-          resultType, resultId, loc, baseInst, offsetInst, countInst) {}
-
-SpirvBitFieldInsert::SpirvBitFieldInsert(QualType resultType, uint32_t resultId,
+    QualType resultType, SourceLocation loc, SpirvInstruction *baseInst,
+    SpirvInstruction *offsetInst, SpirvInstruction *countInst, bool isSigned)
+    : SpirvBitField(IK_BitFieldExtract,
+                    isSigned ? spv::Op::OpBitFieldSExtract
+                             : spv::Op::OpBitFieldUExtract,
+                    resultType, loc, baseInst, offsetInst, countInst) {}
+
+SpirvBitFieldInsert::SpirvBitFieldInsert(QualType resultType,
                                          SourceLocation loc,
                                          SpirvInstruction *baseInst,
                                          SpirvInstruction *insertInst,
                                          SpirvInstruction *offsetInst,
                                          SpirvInstruction *countInst)
     : SpirvBitField(IK_BitFieldInsert, spv::Op::OpBitFieldInsert, resultType,
-                    resultId, loc, baseInst, offsetInst, countInst),
+                    loc, baseInst, offsetInst, countInst),
       insert(insertInst) {}
 
 SpirvComposite::SpirvComposite(
-    QualType resultType, uint32_t resultId, SourceLocation loc,
+    QualType resultType, SourceLocation loc,
     llvm::ArrayRef<SpirvInstruction *> constituentsVec, bool isConstant,
     bool isSpecConstant)
     : SpirvInstruction(IK_Composite,
@@ -376,17 +363,17 @@ SpirvComposite::SpirvComposite(
                            ? spv::Op::OpSpecConstantComposite
                            : isConstant ? spv::Op::OpConstantComposite
                                         : spv::Op::OpCompositeConstruct,
-                       resultType, resultId, loc),
+                       resultType, loc),
       consituents(constituentsVec.begin(), constituentsVec.end()) {}
 
 SpirvConstant::SpirvConstant(Kind kind, spv::Op op, const SpirvType *spvType)
-    : SpirvInstruction(kind, op, QualType(), /*result-id*/ 0,
+    : SpirvInstruction(kind, op, QualType(),
                        /*SourceLocation*/ {}) {
   setResultType(spvType);
 }
 
 SpirvConstant::SpirvConstant(Kind kind, spv::Op op, QualType resultType)
-    : SpirvInstruction(kind, op, resultType, /*result-id*/ 0,
+    : SpirvInstruction(kind, op, resultType,
                        /*SourceLocation*/ {}) {}
 
 bool SpirvConstant::isSpecConstant() const {
@@ -469,61 +456,55 @@ bool SpirvConstantNull::operator==(const SpirvConstantNull &that) const {
 }
 
 SpirvCompositeExtract::SpirvCompositeExtract(QualType resultType,
-                                             uint32_t resultId,
                                              SourceLocation loc,
                                              SpirvInstruction *compositeInst,
                                              llvm::ArrayRef<uint32_t> indexVec)
     : SpirvInstruction(IK_CompositeExtract, spv::Op::OpCompositeExtract,
-                       resultType, resultId, loc),
+                       resultType, loc),
       composite(compositeInst), indices(indexVec.begin(), indexVec.end()) {}
 
 SpirvCompositeInsert::SpirvCompositeInsert(QualType resultType,
-                                           uint32_t resultId,
                                            SourceLocation loc,
                                            SpirvInstruction *compositeInst,
                                            SpirvInstruction *objectInst,
                                            llvm::ArrayRef<uint32_t> indexVec)
     : SpirvInstruction(IK_CompositeInsert, spv::Op::OpCompositeInsert,
-                       resultType, resultId, loc),
+                       resultType, loc),
       composite(compositeInst), object(objectInst),
       indices(indexVec.begin(), indexVec.end()) {}
 
 SpirvEmitVertex::SpirvEmitVertex(SourceLocation loc)
-    : SpirvInstruction(IK_EmitVertex, spv::Op::OpEmitVertex, QualType(),
-                       /*resultId=*/0, loc) {}
+    : SpirvInstruction(IK_EmitVertex, spv::Op::OpEmitVertex, QualType(), loc) {}
 
 SpirvEndPrimitive::SpirvEndPrimitive(SourceLocation loc)
     : SpirvInstruction(IK_EndPrimitive, spv::Op::OpEndPrimitive, QualType(),
-                       /*resultId=*/0, loc) {}
+                       loc) {}
 
-SpirvExtInst::SpirvExtInst(QualType resultType, uint32_t resultId,
-                           SourceLocation loc, SpirvExtInstImport *set,
-                           GLSLstd450 inst,
+SpirvExtInst::SpirvExtInst(QualType resultType, SourceLocation loc,
+                           SpirvExtInstImport *set, GLSLstd450 inst,
                            llvm::ArrayRef<SpirvInstruction *> operandsVec)
-    : SpirvInstruction(IK_ExtInst, spv::Op::OpExtInst, resultType, resultId,
-                       loc),
+    : SpirvInstruction(IK_ExtInst, spv::Op::OpExtInst, resultType, loc),
       instructionSet(set), instruction(inst),
       operands(operandsVec.begin(), operandsVec.end()) {}
 
-SpirvFunctionCall::SpirvFunctionCall(QualType resultType, uint32_t resultId,
-                                     SourceLocation loc, SpirvFunction *fn,
+SpirvFunctionCall::SpirvFunctionCall(QualType resultType, SourceLocation loc,
+                                     SpirvFunction *fn,
                                      llvm::ArrayRef<SpirvInstruction *> argsVec)
     : SpirvInstruction(IK_FunctionCall, spv::Op::OpFunctionCall, resultType,
-                       resultId, loc),
+                       loc),
       function(fn), args(argsVec.begin(), argsVec.end()) {}
 
 SpirvGroupNonUniformOp::SpirvGroupNonUniformOp(Kind kind, spv::Op op,
                                                QualType resultType,
-                                               uint32_t resultId,
                                                SourceLocation loc,
                                                spv::Scope scope)
-    : SpirvInstruction(kind, op, resultType, resultId, loc), execScope(scope) {}
+    : SpirvInstruction(kind, op, resultType, loc), execScope(scope) {}
 
 SpirvNonUniformBinaryOp::SpirvNonUniformBinaryOp(
-    spv::Op op, QualType resultType, uint32_t resultId, SourceLocation loc,
-    spv::Scope scope, SpirvInstruction *arg1Inst, SpirvInstruction *arg2Inst)
-    : SpirvGroupNonUniformOp(IK_GroupNonUniformBinaryOp, op, resultType,
-                             resultId, loc, scope),
+    spv::Op op, QualType resultType, SourceLocation loc, spv::Scope scope,
+    SpirvInstruction *arg1Inst, SpirvInstruction *arg2Inst)
+    : SpirvGroupNonUniformOp(IK_GroupNonUniformBinaryOp, op, resultType, loc,
+                             scope),
       arg1(arg1Inst), arg2(arg2Inst) {
   assert(op == spv::Op::OpGroupNonUniformBroadcast ||
          op == spv::Op::OpGroupNonUniformBallotBitExtract ||
@@ -536,18 +517,16 @@ SpirvNonUniformBinaryOp::SpirvNonUniformBinaryOp(
 }
 
 SpirvNonUniformElect::SpirvNonUniformElect(QualType resultType,
-                                           uint32_t resultId,
                                            SourceLocation loc, spv::Scope scope)
     : SpirvGroupNonUniformOp(IK_GroupNonUniformElect,
-                             spv::Op::OpGroupNonUniformElect, resultType,
-                             resultId, loc, scope) {}
+                             spv::Op::OpGroupNonUniformElect, resultType, loc,
+                             scope) {}
 
 SpirvNonUniformUnaryOp::SpirvNonUniformUnaryOp(
-    spv::Op op, QualType resultType, uint32_t resultId, SourceLocation loc,
-    spv::Scope scope, llvm::Optional<spv::GroupOperation> group,
-    SpirvInstruction *argInst)
-    : SpirvGroupNonUniformOp(IK_GroupNonUniformUnaryOp, op, resultType,
-                             resultId, loc, scope),
+    spv::Op op, QualType resultType, SourceLocation loc, spv::Scope scope,
+    llvm::Optional<spv::GroupOperation> group, SpirvInstruction *argInst)
+    : SpirvGroupNonUniformOp(IK_GroupNonUniformUnaryOp, op, resultType, loc,
+                             scope),
       arg(argInst), groupOp(group) {
   assert(op == spv::Op::OpGroupNonUniformAll ||
          op == spv::Op::OpGroupNonUniformAny ||
@@ -577,7 +556,7 @@ SpirvNonUniformUnaryOp::SpirvNonUniformUnaryOp(
 }
 
 SpirvImageOp::SpirvImageOp(
-    spv::Op op, QualType resultType, uint32_t resultId, SourceLocation loc,
+    spv::Op op, QualType resultType, SourceLocation loc,
     SpirvInstruction *imageInst, SpirvInstruction *coordinateInst,
     spv::ImageOperandsMask mask, SpirvInstruction *drefInst,
     SpirvInstruction *biasInst, SpirvInstruction *lodInst,
@@ -586,13 +565,12 @@ SpirvImageOp::SpirvImageOp(
     SpirvInstruction *constOffsetsInst, SpirvInstruction *sampleInst,
     SpirvInstruction *minLodInst, SpirvInstruction *componentInst,
     SpirvInstruction *texelToWriteInst)
-    : SpirvInstruction(IK_ImageOp, op, resultType, resultId, loc),
-      image(imageInst), coordinate(coordinateInst), dref(drefInst),
-      bias(biasInst), lod(lodInst), gradDx(gradDxInst), gradDy(gradDyInst),
-      constOffset(constOffsetInst), offset(offsetInst),
-      constOffsets(constOffsetsInst), sample(sampleInst), minLod(minLodInst),
-      component(componentInst), texelToWrite(texelToWriteInst),
-      operandsMask(mask) {
+    : SpirvInstruction(IK_ImageOp, op, resultType, loc), image(imageInst),
+      coordinate(coordinateInst), dref(drefInst), bias(biasInst), lod(lodInst),
+      gradDx(gradDxInst), gradDy(gradDyInst), constOffset(constOffsetInst),
+      offset(offsetInst), constOffsets(constOffsetsInst), sample(sampleInst),
+      minLod(minLodInst), component(componentInst),
+      texelToWrite(texelToWriteInst), operandsMask(mask) {
   assert(op == spv::Op::OpImageSampleImplicitLod ||
          op == spv::Op::OpImageSampleExplicitLod ||
          op == spv::Op::OpImageSampleDrefImplicitLod ||
@@ -641,12 +619,11 @@ bool SpirvImageOp::isSparse() const {
 }
 
 SpirvImageQuery::SpirvImageQuery(spv::Op op, QualType resultType,
-                                 uint32_t resultId, SourceLocation loc,
-                                 SpirvInstruction *img,
+                                 SourceLocation loc, SpirvInstruction *img,
                                  SpirvInstruction *lodInst,
                                  SpirvInstruction *coordInst)
-    : SpirvInstruction(IK_ImageQuery, op, resultType, resultId, loc),
-      image(img), lod(lodInst), coordinate(coordInst) {
+    : SpirvInstruction(IK_ImageQuery, op, resultType, loc), image(img),
+      lod(lodInst), coordinate(coordInst) {
   assert(op == spv::Op::OpImageQueryFormat ||
          op == spv::Op::OpImageQueryOrder || op == spv::Op::OpImageQuerySize ||
          op == spv::Op::OpImageQueryLevels ||
@@ -659,72 +636,65 @@ SpirvImageQuery::SpirvImageQuery(spv::Op op, QualType resultType,
 }
 
 SpirvImageSparseTexelsResident::SpirvImageSparseTexelsResident(
-    QualType resultType, uint32_t resultId, SourceLocation loc,
-    SpirvInstruction *resCode)
+    QualType resultType, SourceLocation loc, SpirvInstruction *resCode)
     : SpirvInstruction(IK_ImageSparseTexelsResident,
-                       spv::Op::OpImageSparseTexelsResident, resultType,
-                       resultId, loc),
+                       spv::Op::OpImageSparseTexelsResident, resultType, loc),
       residentCode(resCode) {}
 
 SpirvImageTexelPointer::SpirvImageTexelPointer(QualType resultType,
-                                               uint32_t resultId,
                                                SourceLocation loc,
                                                SpirvInstruction *imageInst,
                                                SpirvInstruction *coordinateInst,
                                                SpirvInstruction *sampleInst)
     : SpirvInstruction(IK_ImageTexelPointer, spv::Op::OpImageTexelPointer,
-                       resultType, resultId, loc),
+                       resultType, loc),
       image(imageInst), coordinate(coordinateInst), sample(sampleInst) {}
 
-SpirvLoad::SpirvLoad(QualType resultType, uint32_t resultId, SourceLocation loc,
+SpirvLoad::SpirvLoad(QualType resultType, SourceLocation loc,
                      SpirvInstruction *pointerInst,
                      llvm::Optional<spv::MemoryAccessMask> mask)
-    : SpirvInstruction(IK_Load, spv::Op::OpLoad, resultType, resultId, loc),
+    : SpirvInstruction(IK_Load, spv::Op::OpLoad, resultType, loc),
       pointer(pointerInst), memoryAccess(mask) {}
 
-SpirvSampledImage::SpirvSampledImage(QualType resultType, uint32_t resultId,
-                                     SourceLocation loc,
+SpirvSampledImage::SpirvSampledImage(QualType resultType, SourceLocation loc,
                                      SpirvInstruction *imageInst,
                                      SpirvInstruction *samplerInst)
     : SpirvInstruction(IK_SampledImage, spv::Op::OpSampledImage, resultType,
-                       resultId, loc),
+                       loc),
       image(imageInst), sampler(samplerInst) {}
 
-SpirvSelect::SpirvSelect(QualType resultType, uint32_t resultId,
-                         SourceLocation loc, SpirvInstruction *cond,
-                         SpirvInstruction *trueInst,
+SpirvSelect::SpirvSelect(QualType resultType, SourceLocation loc,
+                         SpirvInstruction *cond, SpirvInstruction *trueInst,
                          SpirvInstruction *falseInst)
-    : SpirvInstruction(IK_Select, spv::Op::OpSelect, resultType, resultId, loc),
+    : SpirvInstruction(IK_Select, spv::Op::OpSelect, resultType, loc),
       condition(cond), trueObject(trueInst), falseObject(falseInst) {}
 
-SpirvSpecConstantBinaryOp::SpirvSpecConstantBinaryOp(
-    spv::Op specConstantOp, QualType resultType, uint32_t resultId,
-    SourceLocation loc, SpirvInstruction *op1, SpirvInstruction *op2)
+SpirvSpecConstantBinaryOp::SpirvSpecConstantBinaryOp(spv::Op specConstantOp,
+                                                     QualType resultType,
+                                                     SourceLocation loc,
+                                                     SpirvInstruction *op1,
+                                                     SpirvInstruction *op2)
     : SpirvInstruction(IK_SpecConstantBinaryOp, spv::Op::OpSpecConstantOp,
-                       resultType, resultId, loc),
+                       resultType, loc),
       specOp(specConstantOp), operand1(op1), operand2(op2) {}
 
 SpirvSpecConstantUnaryOp::SpirvSpecConstantUnaryOp(spv::Op specConstantOp,
                                                    QualType resultType,
-                                                   uint32_t resultId,
                                                    SourceLocation loc,
                                                    SpirvInstruction *op)
     : SpirvInstruction(IK_SpecConstantUnaryOp, spv::Op::OpSpecConstantOp,
-                       resultType, resultId, loc),
+                       resultType, loc),
       specOp(specConstantOp), operand(op) {}
 
 SpirvStore::SpirvStore(SourceLocation loc, SpirvInstruction *pointerInst,
                        SpirvInstruction *objectInst,
                        llvm::Optional<spv::MemoryAccessMask> mask)
-    : SpirvInstruction(IK_Store, spv::Op::OpStore, QualType(),
-                       /*resultId=*/0, loc),
+    : SpirvInstruction(IK_Store, spv::Op::OpStore, QualType(), loc),
       pointer(pointerInst), object(objectInst), memoryAccess(mask) {}
 
 SpirvUnaryOp::SpirvUnaryOp(spv::Op opcode, QualType resultType,
-                           uint32_t resultId, SourceLocation loc,
-                           SpirvInstruction *op)
-    : SpirvInstruction(IK_UnaryOp, opcode, resultType, resultId, loc),
-      operand(op) {}
+                           SourceLocation loc, SpirvInstruction *op)
+    : SpirvInstruction(IK_UnaryOp, opcode, resultType, loc), operand(op) {}
 
 bool SpirvUnaryOp::isConversionOp() const {
   return opcode == spv::Op::OpConvertFToU || opcode == spv::Op::OpConvertFToS ||
@@ -734,22 +704,19 @@ bool SpirvUnaryOp::isConversionOp() const {
          opcode == spv::Op::OpBitcast;
 }
 
-SpirvVectorShuffle::SpirvVectorShuffle(QualType resultType, uint32_t resultId,
-                                       SourceLocation loc,
+SpirvVectorShuffle::SpirvVectorShuffle(QualType resultType, SourceLocation loc,
                                        SpirvInstruction *vec1Inst,
                                        SpirvInstruction *vec2Inst,
                                        llvm::ArrayRef<uint32_t> componentsVec)
     : SpirvInstruction(IK_VectorShuffle, spv::Op::OpVectorShuffle, resultType,
-                       resultId, loc),
+                       loc),
       vec1(vec1Inst), vec2(vec2Inst),
       components(componentsVec.begin(), componentsVec.end()) {}
 
-SpirvArrayLength::SpirvArrayLength(QualType resultType, uint32_t resultId,
-                                   SourceLocation loc,
+SpirvArrayLength::SpirvArrayLength(QualType resultType, SourceLocation loc,
                                    SpirvInstruction *structure_,
                                    uint32_t memberLiteral)
-    : SpirvInstruction(IK_ArrayLength, spv::Op::OpArrayLength, resultType,
-                       resultId, loc),
+    : SpirvInstruction(IK_ArrayLength, spv::Op::OpArrayLength, resultType, loc),
       structure(structure_), arrayMember(memberLiteral) {}
 
 } // namespace spirv

+ 1 - 1
tools/clang/unittests/SPIRV/SpirvBasicBlockTest.cpp

@@ -89,7 +89,7 @@ TEST(SpirvBasicBlockTest, CheckTerminatedByUnreachable) {
 
 TEST(SpirvBasicBlockTest, CheckNotTerminated) {
   SpirvBasicBlock bb("bb");
-  SpirvLoad load({}, 0, {}, nullptr);
+  SpirvLoad load({}, {}, nullptr);
   bb.addInstruction(&load);
   EXPECT_FALSE(bb.hasTerminator());
 }