@@ -1255,8 +1255,9 @@ static bool isBFloat16Type(const SPIRVType *TypeDef) {
12551255}
12561256
12571257void addInstrRequirements (const MachineInstr &MI,
1258- SPIRV::RequirementHandler &Reqs ,
1258+ SPIRV::ModuleAnalysisInfo &MAI ,
12591259 const SPIRVSubtarget &ST) {
1260+ SPIRV::RequirementHandler &Reqs = MAI.Reqs ;
12601261 switch (MI.getOpcode ()) {
12611262 case SPIRV::OpMemoryModel: {
12621263 int64_t Addr = MI.getOperand (0 ).getImm ();
@@ -1812,15 +1813,45 @@ void addInstrRequirements(const MachineInstr &MI,
18121813 break ;
18131814 case SPIRV::OpConvertHandleToImageINTEL:
18141815 case SPIRV::OpConvertHandleToSamplerINTEL:
1815- case SPIRV::OpConvertHandleToSampledImageINTEL:
1816+ case SPIRV::OpConvertHandleToSampledImageINTEL: {
18161817 if (!ST.canUseExtension (SPIRV::Extension::SPV_INTEL_bindless_images))
18171818 report_fatal_error (" OpConvertHandleTo[Image/Sampler/SampledImage]INTEL "
18181819 " instructions require the following SPIR-V extension: "
18191820 " SPV_INTEL_bindless_images" ,
18201821 false );
1822+ SPIRVGlobalRegistry *GR = ST.getSPIRVGlobalRegistry ();
1823+ SPIRV::AddressingModel::AddressingModel AddrModel = MAI.Addr ;
1824+ SPIRVType *TyDef = GR->getSPIRVTypeForVReg (MI.getOperand (1 ).getReg ());
1825+ if (MI.getOpcode () == SPIRV::OpConvertHandleToImageINTEL &&
1826+ TyDef->getOpcode () != SPIRV::OpTypeImage) {
1827+ report_fatal_error (" Incorrect return type for the instruction "
1828+ " OpConvertHandleToImageINTEL" ,
1829+ false );
1830+ } else if (MI.getOpcode () == SPIRV::OpConvertHandleToSamplerINTEL &&
1831+ TyDef->getOpcode () != SPIRV::OpTypeSampler) {
1832+ report_fatal_error (" Incorrect return type for the instruction "
1833+ " OpConvertHandleToSamplerINTEL" ,
1834+ false );
1835+ } else if (MI.getOpcode () == SPIRV::OpConvertHandleToSampledImageINTEL &&
1836+ TyDef->getOpcode () != SPIRV::OpTypeSampledImage) {
1837+ report_fatal_error (" Incorrect return type for the instruction "
1838+ " OpConvertHandleToSampledImageINTEL" ,
1839+ false );
1840+ }
1841+ SPIRVType *SpvTy = GR->getSPIRVTypeForVReg (MI.getOperand (2 ).getReg ());
1842+ unsigned Bitwidth = GR->getScalarOrVectorBitWidth (SpvTy);
1843+ if (!(Bitwidth == 32 && AddrModel == SPIRV::AddressingModel::Physical32) &&
1844+ !(Bitwidth == 64 && AddrModel == SPIRV::AddressingModel::Physical64)) {
1845+ report_fatal_error (
1846+ " Parameter value must be a 32-bit scalar in case of "
1847+ " Physical32 addressing model or a 64-bit scalar in case of "
1848+ " Physical64 addressing model" ,
1849+ false );
1850+ }
18211851 Reqs.addExtension (SPIRV::Extension::SPV_INTEL_bindless_images);
18221852 Reqs.addCapability (SPIRV::Capability::BindlessImagesINTEL);
18231853 break ;
1854+ }
18241855 case SPIRV::OpSubgroup2DBlockLoadINTEL:
18251856 case SPIRV::OpSubgroup2DBlockLoadTransposeINTEL:
18261857 case SPIRV::OpSubgroup2DBlockLoadTransformINTEL:
@@ -1958,7 +1989,7 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
19581989 continue ;
19591990 for (const MachineBasicBlock &MBB : *MF)
19601991 for (const MachineInstr &MI : MBB)
1961- addInstrRequirements (MI, MAI. Reqs , ST);
1992+ addInstrRequirements (MI, MAI, ST);
19621993 }
19631994 // Collect requirements for OpExecutionMode instructions.
19641995 auto Node = M.getNamedMetadata (" spirv.ExecutionMode" );
0 commit comments