diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 4758b54ec9..9de4f075bf 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -5657,19 +5657,20 @@ bool LLVMToSPIRVBase::transExecutionMode() { auto AddSingleArgExecutionMode = [&](ExecutionMode EMode) { uint32_t Arg = ~0u; N.get(Arg); - BF->addExecutionMode(BM->add(new SPIRVExecutionMode(BF, EMode, Arg))); + BF->addExecutionMode( + BM->add(new SPIRVExecutionMode(OpExecutionMode, BF, EMode, Arg))); }; switch (EMode) { case spv::ExecutionModeContractionOff: - BF->addExecutionMode(BM->add( - new SPIRVExecutionMode(BF, static_cast(EMode)))); + BF->addExecutionMode(BM->add(new SPIRVExecutionMode( + OpExecutionMode, BF, static_cast(EMode)))); break; case spv::ExecutionModeInitializer: case spv::ExecutionModeFinalizer: if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_1)) { - BF->addExecutionMode(BM->add( - new SPIRVExecutionMode(BF, static_cast(EMode)))); + BF->addExecutionMode(BM->add(new SPIRVExecutionMode( + OpExecutionMode, BF, static_cast(EMode)))); } else { getErrorLog().checkError(false, SPIRVEC_Requires1_1, "Initializer/Finalizer Execution Mode"); @@ -5681,7 +5682,7 @@ bool LLVMToSPIRVBase::transExecutionMode() { unsigned X = 0, Y = 0, Z = 0; N.get(X).get(Y).get(Z); BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), X, Y, Z))); + OpExecutionMode, BF, static_cast(EMode), X, Y, Z))); } break; case spv::ExecutionModeMaxWorkgroupSizeINTEL: { if (BM->isAllowedToUseExtension( @@ -5689,7 +5690,8 @@ bool LLVMToSPIRVBase::transExecutionMode() { unsigned X = 0, Y = 0, Z = 0; N.get(X).get(Y).get(Z); BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), X, Y, Z))); + OpExecutionMode, BF, static_cast(EMode), X, Y, + Z))); BM->addExtension(ExtensionID::SPV_INTEL_kernel_attributes); BM->addCapability(CapabilityKernelAttributesINTEL); } @@ -5698,8 +5700,8 @@ bool LLVMToSPIRVBase::transExecutionMode() { if (!BM->isAllowedToUseExtension( ExtensionID::SPV_INTEL_kernel_attributes)) break; - BF->addExecutionMode(BM->add( - new SPIRVExecutionMode(BF, static_cast(EMode)))); + BF->addExecutionMode(BM->add(new SPIRVExecutionMode( + OpExecutionMode, BF, static_cast(EMode)))); BM->addExtension(ExtensionID::SPV_INTEL_kernel_attributes); BM->addCapability(CapabilityKernelAttributesINTEL); } break; @@ -5743,7 +5745,8 @@ bool LLVMToSPIRVBase::transExecutionMode() { unsigned NBarrierCnt = 0; N.get(NBarrierCnt); BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), NBarrierCnt))); + OpExecutionMode, BF, static_cast(EMode), + NBarrierCnt))); BM->addExtension(ExtensionID::SPV_INTEL_vector_compute); BM->addCapability(CapabilityVectorComputeINTEL); } break; @@ -5773,8 +5776,8 @@ bool LLVMToSPIRVBase::transExecutionMode() { } break; case spv::internal::ExecutionModeFastCompositeKernelINTEL: { if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fast_composite)) - BF->addExecutionMode(BM->add( - new SPIRVExecutionMode(BF, static_cast(EMode)))); + BF->addExecutionMode(BM->add(new SPIRVExecutionMode( + OpExecutionMode, BF, static_cast(EMode)))); } break; default: llvm_unreachable("invalid execution mode"); @@ -5819,8 +5822,8 @@ void LLVMToSPIRVBase::transFPContract() { } if (DisableContraction) { - BF->addExecutionMode(BF->getModule()->add( - new SPIRVExecutionMode(BF, spv::ExecutionModeContractionOff))); + BF->addExecutionMode(BF->getModule()->add(new SPIRVExecutionMode( + OpExecutionMode, BF, spv::ExecutionModeContractionOff))); } } } diff --git a/lib/SPIRV/libSPIRV/SPIRVEntry.cpp b/lib/SPIRV/libSPIRV/SPIRVEntry.cpp index 25f054ecdd..a522d71943 100644 --- a/lib/SPIRV/libSPIRV/SPIRVEntry.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVEntry.cpp @@ -612,7 +612,7 @@ SPIRVEntryPoint::SPIRVEntryPoint(SPIRVModule *TheModule, SPIRVExecutionModelKind TheExecModel, SPIRVId TheId, const std::string &TheName, std::vector Variables) - : SPIRVAnnotation(TheModule->get(TheId), + : SPIRVAnnotation(OpEntryPoint, TheModule->get(TheId), getSizeInWords(TheName) + Variables.size() + 3), ExecModel(TheExecModel), Name(TheName), Variables(Variables) {} @@ -681,7 +681,8 @@ SPIRVForward *SPIRVAnnotationGeneric::getOrCreateTarget() const { } SPIRVName::SPIRVName(const SPIRVEntry *TheTarget, const std::string &TheStr) - : SPIRVAnnotation(TheTarget, getSizeInWords(TheStr) + 2), Str(TheStr) {} + : SPIRVAnnotation(OpName, TheTarget, getSizeInWords(TheStr) + 2), + Str(TheStr) {} void SPIRVName::encode(spv_ostream &O) const { getEncoder(O) << Target << Str; } diff --git a/lib/SPIRV/libSPIRV/SPIRVEntry.h b/lib/SPIRV/libSPIRV/SPIRVEntry.h index 5131a2a1e2..7218e4ac32 100644 --- a/lib/SPIRV/libSPIRV/SPIRVEntry.h +++ b/lib/SPIRV/libSPIRV/SPIRVEntry.h @@ -521,23 +521,24 @@ class SPIRVAnnotationGeneric : public SPIRVEntryNoIdGeneric { SPIRVId Target; }; -template class SPIRVAnnotation : public SPIRVAnnotationGeneric { +class SPIRVAnnotation : public SPIRVAnnotationGeneric { public: // Complete constructor - SPIRVAnnotation(const SPIRVEntry *TheTarget, unsigned TheWordCount) + SPIRVAnnotation(Op OC, const SPIRVEntry *TheTarget, unsigned TheWordCount) : SPIRVAnnotationGeneric(TheTarget->getModule(), TheWordCount, OC, TheTarget->getId()) {} - // Incomplete constructor - SPIRVAnnotation() : SPIRVAnnotationGeneric(OC) {} + // Incomplete constructors + SPIRVAnnotation(Op OC) : SPIRVAnnotationGeneric(OC) {} + SPIRVAnnotation() : SPIRVAnnotationGeneric(OpNop) {} }; -class SPIRVEntryPoint : public SPIRVAnnotation { +class SPIRVEntryPoint : public SPIRVAnnotation { public: static const SPIRVWord FixedWC = 4; SPIRVEntryPoint(SPIRVModule *TheModule, SPIRVExecutionModelKind, SPIRVId TheId, const std::string &TheName, std::vector Variables); - SPIRVEntryPoint() {} + SPIRVEntryPoint() : SPIRVAnnotation(OpEntryPoint) {} _SPIRV_DCL_ENCDEC protected: @@ -548,12 +549,12 @@ class SPIRVEntryPoint : public SPIRVAnnotation { std::vector Variables; }; -class SPIRVName : public SPIRVAnnotation { +class SPIRVName : public SPIRVAnnotation { public: // Complete constructor SPIRVName(const SPIRVEntry *TheTarget, const std::string &TheStr); // Incomplete constructor - SPIRVName() {} + SPIRVName() : SPIRVAnnotation(OpName) {} protected: _SPIRV_DCL_ENCDEC @@ -562,18 +563,18 @@ class SPIRVName : public SPIRVAnnotation { std::string Str; }; -class SPIRVMemberName : public SPIRVAnnotation { +class SPIRVMemberName : public SPIRVAnnotation { public: static const SPIRVWord FixedWC = 3; // Complete constructor SPIRVMemberName(const SPIRVEntry *TheTarget, SPIRVWord TheMemberNumber, const std::string &TheStr) - : SPIRVAnnotation(TheTarget, FixedWC + getSizeInWords(TheStr)), + : SPIRVAnnotation(OpName, TheTarget, FixedWC + getSizeInWords(TheStr)), MemberNumber(TheMemberNumber), Str(TheStr) { validate(); } // Incomplete constructor - SPIRVMemberName() : MemberNumber(SPIRVWORD_MAX) {} + SPIRVMemberName() : SPIRVAnnotation(OpName), MemberNumber(SPIRVWORD_MAX) {} protected: _SPIRV_DCL_ENCDEC @@ -649,31 +650,33 @@ class SPIRVLine : public SPIRVEntry { SPIRVWord Column; }; -class SPIRVExecutionMode : public SPIRVAnnotation { +class SPIRVExecutionMode : public SPIRVAnnotation { public: // Complete constructor for LocalSize, LocalSizeHint - SPIRVExecutionMode(SPIRVEntry *TheTarget, SPIRVExecutionModeKind TheExecMode, - SPIRVWord X, SPIRVWord Y, SPIRVWord Z) - : SPIRVAnnotation(TheTarget, 6), ExecMode(TheExecMode) { + SPIRVExecutionMode(Op OC, SPIRVEntry *TheTarget, + SPIRVExecutionModeKind TheExecMode, SPIRVWord X, + SPIRVWord Y, SPIRVWord Z) + : SPIRVAnnotation(OC, TheTarget, 6), ExecMode(TheExecMode) { WordLiterals.push_back(X); WordLiterals.push_back(Y); WordLiterals.push_back(Z); updateModuleVersion(); } // Complete constructor for VecTypeHint, SubgroupSize, SubgroupsPerWorkgroup - SPIRVExecutionMode(SPIRVEntry *TheTarget, SPIRVExecutionModeKind TheExecMode, - SPIRVWord Code) - : SPIRVAnnotation(TheTarget, 4), ExecMode(TheExecMode) { + SPIRVExecutionMode(Op OC, SPIRVEntry *TheTarget, + SPIRVExecutionModeKind TheExecMode, SPIRVWord Code) + : SPIRVAnnotation(OC, TheTarget, 4), ExecMode(TheExecMode) { WordLiterals.push_back(Code); - updateModuleVersion(); } // Complete constructor for ContractionOff - SPIRVExecutionMode(SPIRVEntry *TheTarget, SPIRVExecutionModeKind TheExecMode) - : SPIRVAnnotation(TheTarget, 3), ExecMode(TheExecMode) { + SPIRVExecutionMode(Op OC, SPIRVEntry *TheTarget, + SPIRVExecutionModeKind TheExecMode) + : SPIRVAnnotation(OC, TheTarget, 3), ExecMode(TheExecMode) { updateModuleVersion(); } // Incomplete constructor - SPIRVExecutionMode() : ExecMode(ExecutionModeInvocations) {} + SPIRVExecutionMode() + : SPIRVAnnotation(OpExecutionMode), ExecMode(ExecutionModeInvocations) {} SPIRVExecutionModeKind getExecutionMode() const { return ExecMode; } const std::vector &getLiterals() const { return WordLiterals; } SPIRVCapVec getRequiredCapability() const override { @@ -699,6 +702,28 @@ class SPIRVExecutionMode : public SPIRVAnnotation { std::vector WordLiterals; }; +class SPIRVExecutionModeId : public SPIRVExecutionMode { +public: + // Complete constructor for LocalSizeId, LocalSizeHintId + SPIRVExecutionModeId(SPIRVEntry *TheTarget, + SPIRVExecutionModeKind TheExecMode, SPIRVWord X, + SPIRVWord Y, SPIRVWord Z) + : SPIRVExecutionMode(OpExecutionModeId, TheTarget, TheExecMode, X, Y, Z) { + updateModuleVersion(); + } + // Complete constructor for SubgroupsPerWorkgroupId + SPIRVExecutionModeId(SPIRVEntry *TheTarget, + SPIRVExecutionModeKind TheExecMode, SPIRVWord Code) + : SPIRVExecutionMode(OpExecutionModeId, TheTarget, TheExecMode, Code) { + updateModuleVersion(); + } + // Incomplete constructor + SPIRVExecutionModeId() : SPIRVExecutionMode() {} + SPIRVWord getRequiredSPIRVVersion() const override { + return static_cast(VersionNumber::SPIRV_1_2); + } +}; + class SPIRVComponentExecutionModes { typedef std::multimap SPIRVExecutionModeMap; diff --git a/lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h b/lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h index 9b8872fe40..0d81003e6f 100644 --- a/lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h +++ b/lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h @@ -295,6 +295,7 @@ _SPIRV_OP(TypePipeStorage, 322) _SPIRV_OP(ConstantPipeStorage, 323) _SPIRV_OP(CreatePipeFromPipeStorage, 324) _SPIRV_OP(ModuleProcessed, 330) +_SPIRV_OP(ExecutionModeId, 331) _SPIRV_OP(DecorateId, 332) _SPIRV_OP(GroupNonUniformElect, 333) _SPIRV_OP(GroupNonUniformAll, 334)