================
@@ -576,4 +578,50 @@ bool SemaOpenCL::checkBuiltinToAddr(unsigned BuiltinID,
CallExpr *Call) {
return false;
}
+void SemaOpenCL::checkBuiltinReadImage(FunctionDecl *FDecl, CallExpr *Call) {
+ IdentifierInfo *II = FDecl->getIdentifier();
+ if (!II)
+ return;
+ StringRef Name = II->getName();
+ if (Name != "read_imagei" && Name != "read_imageui")
+ return;
+
+ // read_image{i|ui} take (image, sampler, coord); sampler is arg[1].
+ if (Call->getNumArgs() < 2)
+ return;
+ Expr *SamplerArg = Call->getArg(1);
+ QualType ArgTy = SamplerArg->getType().getCanonicalType();
+ if (!ArgTy->isSamplerT() && !ArgTy->isIntegerType())
+ return;
+
+ Expr *IntExpr = nullptr;
+ Expr *Inner = SamplerArg->IgnoreParenCasts();
+
+ if (auto *DRE = dyn_cast<DeclRefExpr>(Inner)) {
+ if (auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
+ if (const Expr *Init = Var->getAnyInitializer()) {
+ Init = Init->IgnoreParenImpCasts();
+ if (Init->getType()->isIntegerType())
+ IntExpr = const_cast<Expr *>(Init);
+ }
+ }
+ } else if (Inner->getType()->isIntegerType()) {
+ IntExpr = Inner;
+ }
+
+ if (!IntExpr)
+ return;
+
+ Expr::EvalResult EVResult;
+ if (!IntExpr->EvaluateAsInt(EVResult, getASTContext()))
+ return;
+
+ uint64_t SamplerValue = EVResult.Val.getInt().getLimitedValue();
+ // Bit layout: |...|FilterMode[5:4]|AddressMode[3:1]|NormalizedCoords[0]|
----------------
svenvh wrote:
Instead of repeating the bit layout, we might want `constexpr unsigned
FilterModeMask = 0x30u;` here and a comment that this needs to be kept in sync
with the `CLK_FILTER_*` defines in `opencl-c-base.h`.
https://github.com/llvm/llvm-project/pull/204086
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits