@@ -690,6 +690,8 @@ bool SPIRVToLLVM::isDirectlyTranslatedToOCL(Op OpCode) const {
690690 if (isSubgroupAvcINTELInstructionOpCode (OpCode) ||
691691 isIntelSubgroupOpCode (OpCode))
692692 return true ;
693+ if (OpCode == OpImageSampleExplicitLod || OpCode == OpSampledImage)
694+ return false ;
693695 if (OCLSPIRVBuiltinMap::rfind (OpCode, nullptr )) {
694696 // Not every spirv opcode which is placed in OCLSPIRVBuiltinMap is
695697 // translated directly to OCL builtin. Some of them are translated
@@ -1280,60 +1282,6 @@ static char getTypeSuffix(Type *T) {
12801282 return Suffix;
12811283}
12821284
1283- // ToDo: Handle unsigned integer return type. May need spec change.
1284- Instruction *SPIRVToLLVM::postProcessOCLReadImage (SPIRVInstruction *BI,
1285- CallInst *CI,
1286- const std::string &FuncName) {
1287- assert (CI->getCalledFunction () && " Unexpected indirect call" );
1288- AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1289- StringRef ImageTypeName;
1290- bool IsDepthImage = false ;
1291- if (isOCLImageType (
1292- (cast<CallInst>(CI->getOperand (0 )))->getArgOperand (0 )->getType (),
1293- &ImageTypeName))
1294- IsDepthImage = ImageTypeName.contains (" _depth_" );
1295- return mutateCallInstOCL (
1296- M, CI,
1297- [=](CallInst *, std::vector<Value *> &Args, llvm::Type *&RetTy) {
1298- CallInst *CallSampledImg = cast<CallInst>(Args[0 ]);
1299- auto Img = CallSampledImg->getArgOperand (0 );
1300- assert (isOCLImageType (Img->getType ()));
1301- auto Sampler = CallSampledImg->getArgOperand (1 );
1302- Args[0 ] = Img;
1303- Args.insert (Args.begin () + 1 , Sampler);
1304- if (Args.size () > 4 ) {
1305- ConstantInt *ImOp = dyn_cast<ConstantInt>(Args[3 ]);
1306- ConstantFP *LodVal = dyn_cast<ConstantFP>(Args[4 ]);
1307- // Drop "Image Operands" argument.
1308- Args.erase (Args.begin () + 3 , Args.begin () + 4 );
1309- // If the image operand is LOD and its value is zero, drop it too.
1310- if (ImOp && LodVal && LodVal->isNullValue () &&
1311- ImOp->getZExtValue () == ImageOperandsMask::ImageOperandsLodMask)
1312- Args.erase (Args.begin () + 3 , Args.end ());
1313- }
1314- if (CallSampledImg->hasOneUse ()) {
1315- CallSampledImg->replaceAllUsesWith (
1316- UndefValue::get (CallSampledImg->getType ()));
1317- CallSampledImg->dropAllReferences ();
1318- CallSampledImg->eraseFromParent ();
1319- }
1320- Type *T = CI->getType ();
1321- if (auto VT = dyn_cast<VectorType>(T))
1322- T = VT->getElementType ();
1323- RetTy = IsDepthImage ? T : CI->getType ();
1324- return std::string (kOCLBuiltinName ::SampledReadImage) +
1325- getTypeSuffix (T);
1326- },
1327- [=](CallInst *NewCI) -> Instruction * {
1328- if (IsDepthImage)
1329- return InsertElementInst::Create (
1330- UndefValue::get (FixedVectorType::get (NewCI->getType (), 4 )), NewCI,
1331- getSizet (M, 0 ), " " , NewCI->getParent ());
1332- return NewCI;
1333- },
1334- &Attrs);
1335- }
1336-
13371285CallInst *
13381286SPIRVToLLVM::postProcessOCLWriteImage (SPIRVInstruction *BI, CallInst *CI,
13391287 const std::string &DemangledName) {
@@ -3050,8 +2998,6 @@ SPIRVToLLVM::transOCLBuiltinPostproc(SPIRVInstruction *BI, CallInst *CI,
30502998 return CastInst::Create (Instruction::Trunc, CI, transType (BI->getType ()),
30512999 " cvt" , BB);
30523000 }
3053- if (OC == OpImageSampleExplicitLod)
3054- return postProcessOCLReadImage (BI, CI, DemangledName);
30553001 if (OC == OpImageWrite) {
30563002 return postProcessOCLWriteImage (BI, CI, DemangledName);
30573003 }
@@ -3428,6 +3374,9 @@ Instruction *SPIRVToLLVM::transSPIRVBuiltinFromInst(SPIRVInstruction *BI,
34283374 IsRetSigned = true ;
34293375 }
34303376
3377+ if (OC == OpImageSampleExplicitLod)
3378+ AddRetTypePostfix = true ;
3379+
34313380 if (AddRetTypePostfix) {
34323381 const Type *RetTy =
34333382 BI->hasType () ? transType (BI->getType ()) : Type::getVoidTy (*Context);
0 commit comments