[clang] 73e1888 - [OpenCL] Guard write_only image3d_t with TypeExtension
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 21 05:46:11 PDT 2022
Author: Sven van Haastregt
Date: 2022-03-21T12:45:58Z
New Revision: 73e1888e530afefd4a9a774ef9c29bf24baca3d4
URL: https://github.com/llvm/llvm-project/commit/73e1888e530afefd4a9a774ef9c29bf24baca3d4
DIFF: https://github.com/llvm/llvm-project/commit/73e1888e530afefd4a9a774ef9c29bf24baca3d4.diff
LOG: [OpenCL] Guard write_only image3d_t with TypeExtension
Ensure that the TypeExtension of an `ImageType` is also taken into
account when generating `OpenCLBuiltins.inc`.
This aligns the handling of the `write_only image3d_t` type for
`-fdeclare-opencl-builtins` with opencl-c.h with respect to the
`cl_khr_3d_image_writes` extension.
Since the `write_only image3d_t` type is not available when the
extension is disabled, this commit does not add a test to
`SemaOpenCL/fdeclare-opencl-builtins.cl`.
Added:
Modified:
clang/lib/Sema/OpenCLBuiltins.td
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index ff23a1c52ff38..9c1a39cdb1a56 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -134,9 +134,6 @@ def FuncExtFloatAtomicsFp64GenericASMinMax : FunctionExtension<"cl_ext_float_
// Not a real extension, but a workaround to add C++ for OpenCL specific builtins.
def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
-// Multiple extensions
-def FuncExtKhrMipmapWritesAndWrite3d : FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">;
-
// Arm extensions.
def ArmIntegerDotProductInt8 : FunctionExtension<"cl_arm_integer_dot_product_int8">;
def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
@@ -246,7 +243,10 @@ class ImageType<Type _Ty, string _AccessQualifier> :
let IsConst = _Ty.IsConst;
let IsVolatile = _Ty.IsVolatile;
let AddrSpace = _Ty.AddrSpace;
- let Extension = _Ty.Extension;
+ // Add TypeExtension for "write_only image3d_t".
+ let Extension = !cond(
+ !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : TypeExtension<"cl_khr_3d_image_writes">,
+ true : _Ty.Extension);
}
// OpenCL enum type (e.g. memory_scope).
@@ -1625,12 +1625,10 @@ let Extension = FuncExtKhrMipmapImageWrites in {
def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
}
def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
- let Extension = FuncExtKhrMipmapWritesAndWrite3d in {
- foreach imgTy = [Image3d] in {
- def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
- def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
- def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
- }
+ foreach imgTy = [Image3d] in {
+ def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
+ def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
+ def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
}
}
}
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index a2d0cfb0b6ca9..dca9970444a73 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -822,15 +822,24 @@ static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,
<< " case OCLAQ_None:\n"
<< " llvm_unreachable(\"Image without access qualifier\");\n";
for (const auto &Image : ITE.getValue()) {
+ StringRef Exts =
+ Image->getValueAsDef("Extension")->getValueAsString("ExtName");
OS << StringSwitch<const char *>(
Image->getValueAsString("AccessQualifier"))
.Case("RO", " case OCLAQ_ReadOnly:\n")
.Case("WO", " case OCLAQ_WriteOnly:\n")
- .Case("RW", " case OCLAQ_ReadWrite:\n")
- << " QT.push_back("
+ .Case("RW", " case OCLAQ_ReadWrite:\n");
+ if (!Exts.empty()) {
+ OS << " ";
+ EmitMacroChecks(OS, Exts);
+ }
+ OS << " QT.push_back("
<< Image->getValueAsDef("QTExpr")->getValueAsString("TypeExpr")
- << ");\n"
- << " break;\n";
+ << ");\n";
+ if (!Exts.empty()) {
+ OS << " }\n";
+ }
+ OS << " break;\n";
}
OS << " }\n"
<< " break;\n";
More information about the cfe-commits
mailing list