From 73f3313d57db994fdf04ab635d82ed9678c2bdfb Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Wed, 20 Sep 2023 17:15:44 +0200 Subject: [PATCH] alan feedback --- lib/SamplerUtils.cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/SamplerUtils.cpp b/lib/SamplerUtils.cpp index 1950e23d61..2962e3e757 100644 --- a/lib/SamplerUtils.cpp +++ b/lib/SamplerUtils.cpp @@ -13,8 +13,10 @@ // limitations under the License. #include "SamplerUtils.h" -#include "Types.h" +#include "Builtins.h" +#include "BuiltinsEnum.h" #include "Constants.h" +#include "Types.h" using namespace llvm; @@ -44,20 +46,27 @@ Value *NormalizedCoordinate(Module &M, IRBuilder<> &B, Value *Coord, } bool isReadImage3DWithNonLiteralSampler(CallInst *call) { - DenseMap cache; - auto Name = call->getCalledFunction()->getName(); - if (Name.contains("read_image") && Name.contains("ocl_sampler")) { - Type *ImgTy = - clspv::InferType(call->getOperand(0), call->getContext(), &cache); - auto sampler_call = dyn_cast(call->getOperand(1)); - bool literal_sampler = - sampler_call && (sampler_call->getCalledFunction()->getName().contains( - TranslateSamplerInitializerFunction()) || - sampler_call->getCalledFunction()->getName().contains( - LiteralSamplerFunction())); - if (clspv::ImageDimensionality(ImgTy) == spv::Dim3D && !literal_sampler) { - return true; + auto FI = Builtins::Lookup(call->getCalledFunction()); + switch (FI.getType()) { + case Builtins::kReadImagef: + case Builtins::kReadImagei: + case Builtins::kReadImageui: { + if (FI.getParameter(1).isSampler()) { + Type *ImgTy = call->getOperand(0)->getType(); + auto sampler_call = dyn_cast(call->getOperand(1)); + bool literal_sampler = + sampler_call && + (sampler_call->getCalledFunction()->getName().contains( + TranslateSamplerInitializerFunction()) || + sampler_call->getCalledFunction()->getName().contains( + LiteralSamplerFunction())); + if (clspv::ImageDimensionality(ImgTy) == spv::Dim3D && !literal_sampler) { + return true; + } } + } break; + default: + break; } return false; }