@@ -39,17 +39,18 @@ using namespace llvm;
3939using namespace IGC ;
4040using namespace IGC ::IGCMD;
4141
42- void CCommand::execute (CallInst* Inst)
42+ void CCommand::execute (CallInst* Inst, CodeGenContext* CodeGenContext )
4343{
44- init (Inst);
44+ init (Inst, CodeGenContext );
4545 createIntrinsic ();
4646}
4747
48- void CCommand::init (CallInst* Inst)
48+ void CCommand::init (CallInst* Inst, CodeGenContext* CodeGenContext )
4949{
5050 m_pCallInst = Inst;
5151 m_pFunc = m_pCallInst->getParent ()->getParent ();
5252 m_pCtx = &(m_pFunc->getContext ());
53+ m_pCodeGenContext = CodeGenContext;
5354 m_pFloatType = Type::getFloatTy (*m_pCtx);
5455 m_pIntType = Type::getInt32Ty (*m_pCtx);
5556 m_pFloatZero = Constant::getNullValue (m_pFloatType);
@@ -191,11 +192,11 @@ void CImagesBI::prepareImageBTI()
191192 }
192193}
193194
194- void CImagesBI::verifiyCommand (CodeGenContext* context )
195+ void CImagesBI::verifyCommand ( )
195196{
196197 if (m_IncorrectBti)
197198 {
198- context ->EmitError (" Inconsistent use of image!" );
199+ m_pCodeGenContext ->EmitError (" Inconsistent use of image!" );
199200 }
200201}
201202
@@ -767,6 +768,11 @@ class COCL_sample : public CImagesBI
767768 {
768769 ConstantInt* samplerIndex = nullptr ;
769770 Value* samplerParam = CImagesBI::CImagesUtils::traceImageOrSamplerArgument (m_pCallInst, 1 , m_pMdUtils, m_modMD);
771+ if (!samplerParam) {
772+ m_pCodeGenContext->EmitError (" There are instructions that use a sampler, but no sampler found in the kernel!" );
773+ return nullptr ;
774+ }
775+
770776 // Argument samplers are looked up in the parameter map
771777 if (isa<Argument>(samplerParam))
772778 {
@@ -961,12 +967,14 @@ class COCL_sample : public CImagesBI
961967 }
962968 }
963969
964- void prepareSamplerIndex ()
970+ bool prepareSamplerIndex ()
965971 {
966972 ConstantInt* samplerIndex = getSamplerIndex ();
973+ if (!samplerIndex) return false ;
967974 unsigned int addrSpace = EncodeAS4GFXResource (*samplerIndex, SAMPLER, 0 );
968975 Value* sampler = ConstantPointerNull::get (PointerType::get (samplerIndex->getType (), addrSpace));
969976 m_args.push_back (sampler);
977+ return true ;
970978 }
971979
972980 void prepareGradients (Dimension Dim, Value* gradX, Value* gradY)
@@ -1057,7 +1065,9 @@ class COCL_sample_l : public COCL_sample
10571065 m_args.push_back (CoordZ);
10581066 m_args.push_back (m_pFloatZero); // ai (?)
10591067 createGetBufferPtr ();
1060- prepareSamplerIndex ();
1068+ bool samplerIndexFound = prepareSamplerIndex ();
1069+ if (!samplerIndexFound) return ;
1070+
10611071 prepareZeroOffsets ();
10621072 Type* types[] = { m_pCallInst->getType (), m_pFloatType, m_args[5 ]->getType (), m_args[6 ]->getType () };
10631073 replaceGenISACallInst (GenISAIntrinsic::GenISA_sampleLptr, types);
@@ -1936,8 +1946,8 @@ bool CBuiltinsResolver::resolveBI(CallInst* Inst)
19361946 {
19371947 return false ;
19381948 }
1939- m_CommandMap[calleeName]->execute (Inst);
1940- m_CommandMap[calleeName]->verifiyCommand (m_CodeGenContext );
1949+ m_CommandMap[calleeName]->execute (Inst, m_CodeGenContext );
1950+ m_CommandMap[calleeName]->verifyCommand ( );
19411951
1942- return true ;
1952+ return !m_CodeGenContext-> HasError () ;
19431953}
0 commit comments