[OpenCL] Complete image types support.

I. Current implementation of images is not conformant to spec in the following points:
  1. It makes no distinction with respect to access qualifiers and therefore allows to use images with different access type interchangeably. The following code would compile just fine:

        void write_image(write_only image2d_t img);
        kernel void foo(read_only image2d_t img) { write_image(img); } // Accepted code

     which is disallowed according to s6.13.14.

  2. It discards access qualifier on generated code, which leads to generated code for the above example:

        call void @write_image(%opencl.image2d_t* %img);

     In OpenCL2.0 however we can have different calls into write_image with read_only and wite_only images.
     Also generally following compiler steps have no easy way to take different path depending on the image access: linking to the right implementation of image types, performing IR opts and backend codegen differently.

  3. Image types are language keywords and can't be redeclared s6.1.9, which can happen currently as they are just typedef names.
  4. Default access qualifier read_only is to be added if not provided explicitly.

II. This patch corrects the above points as follows:
  1. All images are encapsulated into a separate .def file that is inserted in different points where image handling is required. This avoid a lot of code repetition as all images are handled the same way in the code with no distinction of their exact type.
  2. The Cartesian product of image types and image access qualifiers is added to the builtin types. This simplifies a lot handling of access type mismatch as no operations are allowed by default on distinct Builtin types. Also spec intended access qualifier as special type qualifier that are combined with an image type to form a distinct type (see statement above - images can't be created w/o access qualifiers).
  3. Improves testing of images in Clang.

Author: Anastasia Stulova
Reviewers: bader, mgrang.
Subscribers: pxli168, pekka.jaaskelainen, yaxunl.
Differential Revision: http://reviews.llvm.org/D17821

llvm-svn: 265783
This commit is contained in:
Alexey Bader 2016-04-08 13:40:33 +00:00
parent 829b5d42af
commit 954ba21f85
40 changed files with 310 additions and 550 deletions

View File

@ -902,11 +902,9 @@ public:
CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
CanQualType ObjCBuiltinBoolTy;
CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy;
CanQualType OCLImage2dTy, OCLImage2dArrayTy, OCLImage2dDepthTy;
CanQualType OCLImage2dArrayDepthTy, OCLImage2dMSAATy, OCLImage2dArrayMSAATy;
CanQualType OCLImage2dMSAADepthTy, OCLImage2dArrayMSAADepthTy;
CanQualType OCLImage3dTy;
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
CanQualType SingletonId;
#include "clang/AST/OpenCLImageTypes.def"
CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
CanQualType OCLQueueTy, OCLNDRangeTy, OCLReserveIDTy;
CanQualType OMPArraySectionTy;

View File

@ -154,20 +154,6 @@ BUILTIN_TYPE(ObjCClass, ObjCBuiltinClassTy)
// type is a typedef of a PointerType to this.
BUILTIN_TYPE(ObjCSel, ObjCBuiltinSelTy)
// OpenCL image types.
BUILTIN_TYPE(OCLImage1d, OCLImage1dTy)
BUILTIN_TYPE(OCLImage1dArray, OCLImage1dArrayTy)
BUILTIN_TYPE(OCLImage1dBuffer, OCLImage1dBufferTy)
BUILTIN_TYPE(OCLImage2d, OCLImage2dTy)
BUILTIN_TYPE(OCLImage2dArray, OCLImage2dArrayTy)
BUILTIN_TYPE(OCLImage2dDepth, OCLImage2dDepthTy)
BUILTIN_TYPE(OCLImage2dArrayDepth, OCLImage2dArrayDepthTy)
BUILTIN_TYPE(OCLImage2dMSAA, OCLImage2dMSAATy)
BUILTIN_TYPE(OCLImage2dArrayMSAA, OCLImage2dArrayMSAATy)
BUILTIN_TYPE(OCLImage2dMSAADepth, OCLImage2dMSAADepthTy)
BUILTIN_TYPE(OCLImage2dArrayMSAADepth, OCLImage2dArrayMSAADepthTy)
BUILTIN_TYPE(OCLImage3d, OCLImage3dTy)
// OpenCL sampler_t.
BUILTIN_TYPE(OCLSampler, OCLSamplerTy)

View File

@ -0,0 +1,82 @@
//===-- OpenCLImageTypes.def - Metadata about BuiltinTypes ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This file extends builtin types database with OpenCL image singleton types.
// Custom code should define one of those two macros:
// GENERIC_IMAGE_TYPE(Type, Id) - a generic image with its Id without an
// access type
// IMAGE_TYPE(Type, Id, SingletonId, AccessType, CGSuffix) - an image type
// with given ID, singleton ID access type and a codegen suffix
#ifdef GENERIC_IMAGE_TYPE
#define IMAGE_READ_TYPE(Type, Id) GENERIC_IMAGE_TYPE(Type, Id)
#define IMAGE_WRITE_TYPE(Type, Id)
#define IMAGE_READ_WRITE_TYPE(Type, Id)
#else
#ifndef IMAGE_READ_TYPE
#define IMAGE_READ_TYPE(Type, Id) \
IMAGE_TYPE(Type, Id##RO, Id##ROTy, read_only, ro)
#endif
#ifndef IMAGE_WRITE_TYPE
#define IMAGE_WRITE_TYPE(Type, Id) \
IMAGE_TYPE(Type, Id##WO, Id##WOTy, write_only, wo)
#endif
#ifndef IMAGE_READ_WRITE_TYPE
#define IMAGE_READ_WRITE_TYPE(Type, Id) \
IMAGE_TYPE(Type, Id##RW, Id##RWTy, read_write, rw)
#endif
#endif
IMAGE_READ_TYPE(image1d, OCLImage1d)
IMAGE_READ_TYPE(image1d_array, OCLImage1dArray)
IMAGE_READ_TYPE(image1d_buffer, OCLImage1dBuffer)
IMAGE_READ_TYPE(image2d, OCLImage2d)
IMAGE_READ_TYPE(image2d_array, OCLImage2dArray)
IMAGE_READ_TYPE(image2d_depth, OCLImage2dDepth)
IMAGE_READ_TYPE(image2d_array_depth, OCLImage2dArrayDepth)
IMAGE_READ_TYPE(image2d_msaa, OCLImage2dMSAA)
IMAGE_READ_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA)
IMAGE_READ_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth)
IMAGE_READ_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth)
IMAGE_READ_TYPE(image3d, OCLImage3d)
IMAGE_WRITE_TYPE(image1d, OCLImage1d)
IMAGE_WRITE_TYPE(image1d_array, OCLImage1dArray)
IMAGE_WRITE_TYPE(image1d_buffer, OCLImage1dBuffer)
IMAGE_WRITE_TYPE(image2d, OCLImage2d)
IMAGE_WRITE_TYPE(image2d_array, OCLImage2dArray)
IMAGE_WRITE_TYPE(image2d_depth, OCLImage2dDepth)
IMAGE_WRITE_TYPE(image2d_array_depth, OCLImage2dArrayDepth)
IMAGE_WRITE_TYPE(image2d_msaa, OCLImage2dMSAA)
IMAGE_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA)
IMAGE_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth)
IMAGE_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth)
IMAGE_WRITE_TYPE(image3d, OCLImage3d)
IMAGE_READ_WRITE_TYPE(image1d, OCLImage1d)
IMAGE_READ_WRITE_TYPE(image1d_array, OCLImage1dArray)
IMAGE_READ_WRITE_TYPE(image1d_buffer, OCLImage1dBuffer)
IMAGE_READ_WRITE_TYPE(image2d, OCLImage2d)
IMAGE_READ_WRITE_TYPE(image2d_array, OCLImage2dArray)
IMAGE_READ_WRITE_TYPE(image2d_depth, OCLImage2dDepth)
IMAGE_READ_WRITE_TYPE(image2d_array_depth, OCLImage2dArrayDepth)
IMAGE_READ_WRITE_TYPE(image2d_msaa, OCLImage2dMSAA)
IMAGE_READ_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA)
IMAGE_READ_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth)
IMAGE_READ_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth)
IMAGE_READ_WRITE_TYPE(image3d, OCLImage3d)
#undef IMAGE_TYPE
#undef GENERIC_IMAGE_TYPE
#undef IMAGE_READ_TYPE
#undef IMAGE_WRITE_TYPE
#undef IMAGE_READ_WRITE_TYPE

View File

@ -1705,18 +1705,9 @@ public:
bool isNullPtrType() const; // C++0x nullptr_t
bool isAtomicType() const; // C11 _Atomic()
bool isImage1dT() const; // OpenCL image1d_t
bool isImage1dArrayT() const; // OpenCL image1d_array_t
bool isImage1dBufferT() const; // OpenCL image1d_buffer_t
bool isImage2dT() const; // OpenCL image2d_t
bool isImage2dArrayT() const; // OpenCL image2d_array_t
bool isImage2dDepthT() const; // OpenCL image_2d_depth_t
bool isImage2dArrayDepthT() const; // OpenCL image_2d_array_depth_t
bool isImage2dMSAAT() const; // OpenCL image_2d_msaa_t
bool isImage2dArrayMSAAT() const; // OpenCL image_2d_array_msaa_t
bool isImage2dMSAATDepth() const; // OpenCL image_2d_msaa_depth_t
bool isImage2dArrayMSAATDepth() const; // OpenCL image_2d_array_msaa_depth_t
bool isImage3dT() const; // OpenCL image3d_t
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
bool is##Id##Type() const;
#include "clang/AST/OpenCLImageTypes.def"
bool isImageType() const; // Any OpenCL image type
@ -2017,6 +2008,10 @@ template <> inline const Class##Type *Type::castAs() const { \
class BuiltinType : public Type {
public:
enum Kind {
// OpenCL image types
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
#include "clang/AST/OpenCLImageTypes.def"
// All other builtin types
#define BUILTIN_TYPE(Id, SingletonId) Id,
#define LAST_BUILTIN_TYPE(Id) LastKind = Id
#include "clang/AST/BuiltinTypes.def"
@ -5557,53 +5552,11 @@ inline bool Type::isObjCBuiltinType() const {
return isObjCIdType() || isObjCClassType() || isObjCSelType();
}
inline bool Type::isImage1dT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage1d);
}
inline bool Type::isImage1dArrayT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage1dArray);
}
inline bool Type::isImage1dBufferT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage1dBuffer);
}
inline bool Type::isImage2dT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2d);
}
inline bool Type::isImage2dArrayT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dArray);
}
inline bool Type::isImage2dDepthT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dDepth);
}
inline bool Type::isImage2dArrayDepthT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dArrayDepth);
}
inline bool Type::isImage2dMSAAT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dMSAA);
}
inline bool Type::isImage2dArrayMSAAT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dArrayMSAA);
}
inline bool Type::isImage2dMSAATDepth() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dMSAADepth);
}
inline bool Type::isImage2dArrayMSAATDepth() const {
return isSpecificBuiltinType(BuiltinType::OCLImage2dArrayMSAADepth);
}
inline bool Type::isImage3dT() const {
return isSpecificBuiltinType(BuiltinType::OCLImage3d);
}
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
inline bool Type::is##Id##Type() const { \
return isSpecificBuiltinType(BuiltinType::Id); \
}
#include "clang/AST/OpenCLImageTypes.def"
inline bool Type::isSamplerT() const {
return isSpecificBuiltinType(BuiltinType::OCLSampler);
@ -5630,11 +5583,10 @@ inline bool Type::isReserveIDT() const {
}
inline bool Type::isImageType() const {
return isImage3dT() || isImage2dT() || isImage2dArrayT() ||
isImage2dDepthT() || isImage2dArrayDepthT() || isImage2dMSAAT() ||
isImage2dArrayMSAAT() || isImage2dMSAATDepth() ||
isImage2dArrayMSAATDepth() || isImage1dT() || isImage1dArrayT() ||
isImage1dBufferT();
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
return
#include "clang/AST/OpenCLImageTypes.def"
0; // end boolean or operation
}
inline bool Type::isPipeType() const {

View File

@ -73,9 +73,11 @@ namespace clang {
TST_auto_type, // __auto_type extension
TST_unknown_anytype, // __unknown_anytype extension
TST_atomic, // C11 _Atomic
TST_error // erroneous type
#define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image types
#include "clang/AST/OpenCLImageTypes.def"
TST_error // erroneous type
};
/// \brief Structure that packs information about the type specifiers that
/// were written in a particular type specifier sequence.
struct WrittenBuiltinSpecs {

View File

@ -518,6 +518,8 @@ ALIAS("read_write", __read_write , KEYOPENCL)
// OpenCL builtins
KEYWORD(__builtin_astype , KEYOPENCL)
KEYWORD(vec_step , KEYOPENCL|KEYALTIVEC|KEYZVECTOR)
#define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCL)
#include "clang/AST/OpenCLImageTypes.def"
// OpenMP Type Traits
KEYWORD(__builtin_omp_required_simd_align, KEYALL)

View File

@ -299,6 +299,9 @@ public:
static const TST TST_auto_type = clang::TST_auto_type;
static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
static const TST TST_atomic = clang::TST_atomic;
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
#include "clang/AST/OpenCLImageTypes.def"
static const TST TST_error = clang::TST_error;
// type-qualifiers

View File

@ -784,44 +784,24 @@ namespace clang {
PREDEF_TYPE_PSEUDO_OBJECT = 35,
/// \brief The placeholder type for builtin functions.
PREDEF_TYPE_BUILTIN_FN = 36,
/// \brief OpenCL 1d image type.
PREDEF_TYPE_IMAGE1D_ID = 37,
/// \brief OpenCL 1d image array type.
PREDEF_TYPE_IMAGE1D_ARR_ID = 38,
/// \brief OpenCL 1d image buffer type.
PREDEF_TYPE_IMAGE1D_BUFF_ID = 39,
/// \brief OpenCL 2d image type.
PREDEF_TYPE_IMAGE2D_ID = 40,
/// \brief OpenCL 2d image array type.
PREDEF_TYPE_IMAGE2D_ARR_ID = 41,
/// \brief OpenCL 2d image depth type.
PREDEF_TYPE_IMAGE2D_DEP_ID = 42,
/// \brief OpenCL 2d image array depth type.
PREDEF_TYPE_IMAGE2D_ARR_DEP_ID = 43,
/// \brief OpenCL 2d image MSAA type.
PREDEF_TYPE_IMAGE2D_MSAA_ID = 44,
/// \brief OpenCL 2d image array MSAA type.
PREDEF_TYPE_IMAGE2D_ARR_MSAA_ID = 45,
/// \brief OpenCL 2d image MSAA depth type.
PREDEF_TYPE_IMAGE2D_MSAA_DEP_ID = 46,
/// \brief OpenCL 2d image array MSAA depth type.
PREDEF_TYPE_IMAGE2D_ARR_MSAA_DEPTH_ID = 47,
/// \brief OpenCL 3d image type.
PREDEF_TYPE_IMAGE3D_ID = 48,
/// \brief OpenCL event type.
PREDEF_TYPE_EVENT_ID = 49,
PREDEF_TYPE_EVENT_ID = 37,
/// \brief OpenCL clk event type.
PREDEF_TYPE_CLK_EVENT_ID = 50,
PREDEF_TYPE_CLK_EVENT_ID = 38,
/// \brief OpenCL sampler type.
PREDEF_TYPE_SAMPLER_ID = 51,
PREDEF_TYPE_SAMPLER_ID = 39,
/// \brief OpenCL queue type.
PREDEF_TYPE_QUEUE_ID = 52,
PREDEF_TYPE_QUEUE_ID = 40,
/// \brief OpenCL ndrange type.
PREDEF_TYPE_NDRANGE_ID = 53,
PREDEF_TYPE_NDRANGE_ID = 41,
/// \brief OpenCL reserve_id type.
PREDEF_TYPE_RESERVE_ID_ID = 54,
PREDEF_TYPE_RESERVE_ID_ID = 42,
/// \brief The placeholder type for OpenMP array section.
PREDEF_TYPE_OMP_ARRAY_SECTION = 55
PREDEF_TYPE_OMP_ARRAY_SECTION = 43,
/// \brief OpenCL image types with auto numeration
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
PREDEF_TYPE_##Id##_ID,
#include "clang/AST/OpenCLImageTypes.def"
};
/// \brief The number of predefined type IDs that are reserved for

View File

@ -1090,20 +1090,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass);
InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel);
if (LangOpts.OpenCL) {
InitBuiltinType(OCLImage1dTy, BuiltinType::OCLImage1d);
InitBuiltinType(OCLImage1dArrayTy, BuiltinType::OCLImage1dArray);
InitBuiltinType(OCLImage1dBufferTy, BuiltinType::OCLImage1dBuffer);
InitBuiltinType(OCLImage2dTy, BuiltinType::OCLImage2d);
InitBuiltinType(OCLImage2dArrayTy, BuiltinType::OCLImage2dArray);
InitBuiltinType(OCLImage2dDepthTy, BuiltinType::OCLImage2dDepth);
InitBuiltinType(OCLImage2dArrayDepthTy, BuiltinType::OCLImage2dArrayDepth);
InitBuiltinType(OCLImage2dMSAATy, BuiltinType::OCLImage2dMSAA);
InitBuiltinType(OCLImage2dArrayMSAATy, BuiltinType::OCLImage2dArrayMSAA);
InitBuiltinType(OCLImage2dMSAADepthTy, BuiltinType::OCLImage2dMSAADepth);
InitBuiltinType(OCLImage2dArrayMSAADepthTy,
BuiltinType::OCLImage2dArrayMSAADepth);
InitBuiltinType(OCLImage3dTy, BuiltinType::OCLImage3d);
if (LangOpts.OpenCL) {
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
InitBuiltinType(SingletonId, BuiltinType::Id);
#include "clang/AST/OpenCLImageTypes.def"
InitBuiltinType(OCLSamplerTy, BuiltinType::OCLSampler);
InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent);
@ -1681,18 +1671,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
case BuiltinType::OCLQueue:
case BuiltinType::OCLNDRange:
case BuiltinType::OCLReserveID:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
// Currently these types are pointers to opaque types.
Width = Target->getPointerWidth(0);
Align = Target->getPointerAlign(0);
@ -5517,18 +5499,9 @@ static char getObjCEncodingForPrimitiveKind(const ASTContext *C,
llvm_unreachable("@encoding ObjC primitive type");
// OpenCL and placeholder types don't need @encodings.
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:
case BuiltinType::OCLQueue:

View File

@ -1509,6 +1509,10 @@ QualType ASTNodeImporter::VisitType(const Type *T) {
QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
switch (T->getKind()) {
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id: \
return Importer.getToContext().SingletonId;
#include "clang/AST/OpenCLImageTypes.def"
#define SHARED_SINGLETON_TYPE(Expansion)
#define BUILTIN_TYPE(Id, SingletonId) \
case BuiltinType::Id: return Importer.getToContext().SingletonId;

View File

@ -6301,18 +6301,9 @@ static int EvaluateBuiltinClassifyType(const CallExpr *E,
case BuiltinType::ObjCId:
case BuiltinType::ObjCClass:
case BuiltinType::ObjCSel:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:

View File

@ -2001,6 +2001,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
// ::= Ds # char16_t
// ::= Dn # std::nullptr_t (i.e., decltype(nullptr))
// ::= u <source-name> # vendor extended type
std::string type_name;
switch (T->getKind()) {
case BuiltinType::Void:
Out << 'v';
@ -2091,42 +2092,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
case BuiltinType::ObjCSel:
Out << "13objc_selector";
break;
case BuiltinType::OCLImage1d:
Out << "11ocl_image1d";
break;
case BuiltinType::OCLImage1dArray:
Out << "16ocl_image1darray";
break;
case BuiltinType::OCLImage1dBuffer:
Out << "17ocl_image1dbuffer";
break;
case BuiltinType::OCLImage2d:
Out << "11ocl_image2d";
break;
case BuiltinType::OCLImage2dArray:
Out << "16ocl_image2darray";
break;
case BuiltinType::OCLImage2dDepth:
Out << "16ocl_image2ddepth";
break;
case BuiltinType::OCLImage2dArrayDepth:
Out << "21ocl_image2darraydepth";
break;
case BuiltinType::OCLImage2dMSAA:
Out << "15ocl_image2dmsaa";
break;
case BuiltinType::OCLImage2dArrayMSAA:
Out << "20ocl_image2darraymsaa";
break;
case BuiltinType::OCLImage2dMSAADepth:
Out << "20ocl_image2dmsaadepth";
break;
case BuiltinType::OCLImage2dArrayMSAADepth:
Out << "25ocl_image2darraymsaadepth";
break;
case BuiltinType::OCLImage3d:
Out << "11ocl_image3d";
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id: \
type_name = "ocl_" #ImgType "_" #Suffix; \
Out << type_name.size() << type_name; \
break;
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
Out << "11ocl_sampler";
break;

View File

@ -1717,54 +1717,11 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
mangleArtificalTagType(TTK_Struct, "objc_selector");
break;
case BuiltinType::OCLImage1d:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image1d");
break;
case BuiltinType::OCLImage1dArray:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image1darray");
break;
case BuiltinType::OCLImage1dBuffer:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image1dbuffer");
break;
case BuiltinType::OCLImage2d:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2d");
break;
case BuiltinType::OCLImage2dArray:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2darray");
break;
case BuiltinType::OCLImage2dDepth:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2ddepth");
break;
case BuiltinType::OCLImage2dArrayDepth:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2darraydepth");
break;
case BuiltinType::OCLImage2dMSAA:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2dmsaa");
break;
case BuiltinType::OCLImage2dArrayMSAA:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2darraymsaa");
break;
case BuiltinType::OCLImage2dMSAADepth:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2dmsaadepth");
break;
case BuiltinType::OCLImage2dArrayMSAADepth:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image2darraymsaadepth");
break;
case BuiltinType::OCLImage3d:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_image3d");
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id: \
Out << "PAUocl_" #ImgType "_" #Suffix "@@"; \
break;
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
Out << "PA";
mangleArtificalTagType(TTK_Struct, "ocl_sampler");

View File

@ -445,18 +445,9 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
case BuiltinType::ObjCClass:
case BuiltinType::ObjCId:
case BuiltinType::ObjCSel:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:

View File

@ -2581,30 +2581,10 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
return "Class";
case ObjCSel:
return "SEL";
case OCLImage1d:
return "image1d_t";
case OCLImage1dArray:
return "image1d_array_t";
case OCLImage1dBuffer:
return "image1d_buffer_t";
case OCLImage2d:
return "image2d_t";
case OCLImage2dArray:
return "image2d_array_t";
case OCLImage2dDepth:
return "image2d_depth_t";
case OCLImage2dArrayDepth:
return "image2d_array_depth_t";
case OCLImage2dMSAA:
return "image2d_msaa_t";
case OCLImage2dArrayMSAA:
return "image2d_array_msaa_t";
case OCLImage2dMSAADepth:
return "image2d_msaa_depth_t";
case OCLImage2dArrayMSAADepth:
return "image2d_array_msaa_depth_t";
case OCLImage3d:
return "image3d_t";
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case Id: \
return "__" #Access " " #ImgType "_t";
#include "clang/AST/OpenCLImageTypes.def"
case OCLSampler:
return "sampler_t";
case OCLEvent:
@ -3578,18 +3558,9 @@ bool Type::canHaveNullability() const {
case BuiltinType::ObjCId:
case BuiltinType::ObjCClass:
case BuiltinType::ObjCSel:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:

View File

@ -333,18 +333,9 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
case BuiltinType::ObjCId:
case BuiltinType::ObjCClass:
case BuiltinType::ObjCSel:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:

View File

@ -619,6 +619,9 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
// Various types which are non-trivial to correct.
return false;
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
#define SIGNED_TYPE(Id, SingletonId)
#define UNSIGNED_TYPE(Id, SingletonId)
#define FLOATING_TYPE(Id, SingletonId)

View File

@ -463,39 +463,11 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
return SelTy;
}
case BuiltinType::OCLImage1d:
return getOrCreateStructPtrType("opencl_image1d_t", OCLImage1dDITy);
case BuiltinType::OCLImage1dArray:
return getOrCreateStructPtrType("opencl_image1d_array_t",
OCLImage1dArrayDITy);
case BuiltinType::OCLImage1dBuffer:
return getOrCreateStructPtrType("opencl_image1d_buffer_t",
OCLImage1dBufferDITy);
case BuiltinType::OCLImage2d:
return getOrCreateStructPtrType("opencl_image2d_t", OCLImage2dDITy);
case BuiltinType::OCLImage2dArray:
return getOrCreateStructPtrType("opencl_image2d_array_t",
OCLImage2dArrayDITy);
case BuiltinType::OCLImage2dDepth:
return getOrCreateStructPtrType("opencl_image2d_depth_t",
OCLImage2dDepthDITy);
case BuiltinType::OCLImage2dArrayDepth:
return getOrCreateStructPtrType("opencl_image2d_array_depth_t",
OCLImage2dArrayDepthDITy);
case BuiltinType::OCLImage2dMSAA:
return getOrCreateStructPtrType("opencl_image2d_msaa_t",
OCLImage2dMSAADITy);
case BuiltinType::OCLImage2dArrayMSAA:
return getOrCreateStructPtrType("opencl_image2d_array_msaa_t",
OCLImage2dArrayMSAADITy);
case BuiltinType::OCLImage2dMSAADepth:
return getOrCreateStructPtrType("opencl_image2d_msaa_depth_t",
OCLImage2dMSAADepthDITy);
case BuiltinType::OCLImage2dArrayMSAADepth:
return getOrCreateStructPtrType("opencl_image2d_array_msaa_depth_t",
OCLImage2dArrayMSAADepthDITy);
case BuiltinType::OCLImage3d:
return getOrCreateStructPtrType("opencl_image3d_t", OCLImage3dDITy);
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id: \
return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
SingletonId);
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
return DBuilder.createBasicType(
"opencl_sampler_t", CGM.getContext().getTypeSize(BT),

View File

@ -64,18 +64,9 @@ class CGDebugInfo {
llvm::DIType *ClassTy = nullptr;
llvm::DICompositeType *ObjTy = nullptr;
llvm::DIType *SelTy = nullptr;
llvm::DIType *OCLImage1dDITy = nullptr;
llvm::DIType *OCLImage1dArrayDITy = nullptr;
llvm::DIType *OCLImage1dBufferDITy = nullptr;
llvm::DIType *OCLImage2dDITy = nullptr;
llvm::DIType *OCLImage2dArrayDITy = nullptr;
llvm::DIType *OCLImage2dDepthDITy = nullptr;
llvm::DIType *OCLImage2dArrayDepthDITy = nullptr;
llvm::DIType *OCLImage2dMSAADITy = nullptr;
llvm::DIType *OCLImage2dArrayMSAADITy = nullptr;
llvm::DIType *OCLImage2dMSAADepthDITy = nullptr;
llvm::DIType *OCLImage2dArrayMSAADepthDITy = nullptr;
llvm::DIType *OCLImage3dDITy = nullptr;
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
llvm::DIType *SingletonId = nullptr;
#include "clang/AST/OpenCLImageTypes.def"
llvm::DIType *OCLEventDITy = nullptr;
llvm::DIType *OCLClkEventDITy = nullptr;
llvm::DIType *OCLQueueDITy = nullptr;

View File

@ -40,46 +40,12 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
default:
llvm_unreachable("Unexpected opencl builtin type!");
return nullptr;
case BuiltinType::OCLImage1d:
return llvm::PointerType::get(llvm::StructType::create(
Ctx, "opencl.image1d_t"), ImgAddrSpc);
case BuiltinType::OCLImage1dArray:
return llvm::PointerType::get(llvm::StructType::create(
Ctx, "opencl.image1d_array_t"), ImgAddrSpc);
case BuiltinType::OCLImage1dBuffer:
return llvm::PointerType::get(llvm::StructType::create(
Ctx, "opencl.image1d_buffer_t"), ImgAddrSpc);
case BuiltinType::OCLImage2d:
return llvm::PointerType::get(llvm::StructType::create(
Ctx, "opencl.image2d_t"), ImgAddrSpc);
case BuiltinType::OCLImage2dArray:
return llvm::PointerType::get(llvm::StructType::create(
Ctx, "opencl.image2d_array_t"), ImgAddrSpc);
case BuiltinType::OCLImage2dDepth:
return llvm::PointerType::get(
llvm::StructType::create(Ctx, "opencl.image2d_depth_t"), ImgAddrSpc);
case BuiltinType::OCLImage2dArrayDepth:
return llvm::PointerType::get(
llvm::StructType::create(Ctx, "opencl.image2d_array_depth_t"),
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id: \
return llvm::PointerType::get( \
llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \
ImgAddrSpc);
case BuiltinType::OCLImage2dMSAA:
return llvm::PointerType::get(
llvm::StructType::create(Ctx, "opencl.image2d_msaa_t"), ImgAddrSpc);
case BuiltinType::OCLImage2dArrayMSAA:
return llvm::PointerType::get(
llvm::StructType::create(Ctx, "opencl.image2d_array_msaa_t"),
ImgAddrSpc);
case BuiltinType::OCLImage2dMSAADepth:
return llvm::PointerType::get(
llvm::StructType::create(Ctx, "opencl.image2d_msaa_depth_t"),
ImgAddrSpc);
case BuiltinType::OCLImage2dArrayMSAADepth:
return llvm::PointerType::get(
llvm::StructType::create(Ctx, "opencl.image2d_array_msaa_depth_t"),
ImgAddrSpc);
case BuiltinType::OCLImage3d:
return llvm::PointerType::get(llvm::StructType::create(
Ctx, "opencl.image3d_t"), ImgAddrSpc);
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
return llvm::IntegerType::get(Ctx, 32);
case BuiltinType::OCLEvent:

View File

@ -464,18 +464,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
ResultType = llvm::IntegerType::get(getLLVMContext(), 128);
break;
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:

View File

@ -2536,18 +2536,9 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
case BuiltinType::UInt128:
return true;
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:

View File

@ -624,18 +624,9 @@ void USRGenerator::VisitType(QualType T) {
#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
#include "clang/AST/BuiltinTypes.def"
case BuiltinType::Dependent:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:
case BuiltinType::OCLQueue:

View File

@ -3363,6 +3363,12 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
}
isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
break;
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
case tok::kw_##ImgType##_t: \
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, \
DiagID, Policy); \
break;
#include "clang/AST/OpenCLImageTypes.def"
case tok::kw___unknown_anytype:
isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc,
PrevSpec, DiagID, Policy);
@ -4300,6 +4306,8 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
case tok::kw__Decimal64:
case tok::kw__Decimal128:
case tok::kw___vector:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
// struct-or-union-specifier (C99) or class-specifier (C++)
case tok::kw_class:
@ -4372,6 +4380,8 @@ bool Parser::isTypeSpecifierQualifier() {
case tok::kw__Decimal64:
case tok::kw__Decimal128:
case tok::kw___vector:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
// struct-or-union-specifier (C99) or class-specifier (C++)
case tok::kw_class:
@ -4608,6 +4618,8 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
case tok::kw___read_only:
case tok::kw___read_write:
case tok::kw___write_only:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
return true;
}

View File

@ -1169,7 +1169,10 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
case tok::kw_void:
case tok::kw_typename:
case tok::kw_typeof:
case tok::kw___vector: {
case tok::kw___vector:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
{
if (!getLangOpts().CPlusPlus) {
Diag(Tok, diag::err_expected_expression);
return ExprError();

View File

@ -987,6 +987,8 @@ Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) {
case tok::kw___pixel:
case tok::kw___bool:
case tok::kw__Atomic:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
case tok::kw___unknown_anytype:
return TPResult::False;

View File

@ -302,6 +302,8 @@ bool Declarator::isDeclarationOfFunction() const {
case TST_unspecified:
case TST_void:
case TST_wchar:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
return false;
case TST_decltype_auto:
@ -474,6 +476,10 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
case DeclSpec::TST_underlyingType: return "__underlying_type";
case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
case DeclSpec::TST_atomic: return "_Atomic";
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
case DeclSpec::TST_##ImgType##_t: \
return #ImgType "_t";
#include "clang/AST/OpenCLImageTypes.def"
case DeclSpec::TST_error: return "(error)";
}
llvm_unreachable("Unknown typespec!");

View File

@ -208,23 +208,9 @@ void Sema::Initialize() {
// Initialize predefined OpenCL types.
if (getLangOpts().OpenCL) {
addImplicitTypedef("image1d_t", Context.OCLImage1dTy);
addImplicitTypedef("image1d_array_t", Context.OCLImage1dArrayTy);
addImplicitTypedef("image1d_buffer_t", Context.OCLImage1dBufferTy);
addImplicitTypedef("image2d_t", Context.OCLImage2dTy);
addImplicitTypedef("image2d_array_t", Context.OCLImage2dArrayTy);
addImplicitTypedef("image3d_t", Context.OCLImage3dTy);
addImplicitTypedef("sampler_t", Context.OCLSamplerTy);
addImplicitTypedef("event_t", Context.OCLEventTy);
if (getLangOpts().OpenCLVersion >= 200) {
addImplicitTypedef("image2d_depth_t", Context.OCLImage2dDepthTy);
addImplicitTypedef("image2d_array_depth_t",
Context.OCLImage2dArrayDepthTy);
addImplicitTypedef("image2d_msaa_t", Context.OCLImage2dMSAATy);
addImplicitTypedef("image2d_array_msaa_t", Context.OCLImage2dArrayMSAATy);
addImplicitTypedef("image2d_msaa_depth_t", Context.OCLImage2dMSAADepthTy);
addImplicitTypedef("image2d_array_msaa_depth_t",
Context.OCLImage2dArrayMSAADepthTy);
addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);
addImplicitTypedef("queue_t", Context.OCLQueueTy);
addImplicitTypedef("ndrange_t", Context.OCLNDRangeTy);

View File

@ -4915,6 +4915,9 @@ static bool isPlaceholderToRemoveAsArg(QualType type) {
switch (placeholder->getKind()) {
// Ignore all the non-placeholder types.
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
#define PLACEHOLDER_TYPE(ID, SINGLETON_ID)
#define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID:
#include "clang/AST/BuiltinTypes.def"
@ -14840,8 +14843,10 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
return ExprError();
// Everything else should be impossible.
#define BUILTIN_TYPE(Id, SingletonId) \
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
#define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id:
#define PLACEHOLDER_TYPE(Id, SingletonId)
#include "clang/AST/BuiltinTypes.def"
break;

View File

@ -739,6 +739,8 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
case TST_auto:
case TST_auto_type:
case TST_decltype_auto:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
#include "clang/AST/OpenCLImageTypes.def"
case TST_unknown_anytype:
case TST_error:
break;

View File

@ -11,7 +11,6 @@
//
//===----------------------------------------------------------------------===//
#include "clang/Sema/SemaInternal.h"
#include "TypeLocBuilder.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
@ -22,17 +21,19 @@
#include "clang/AST/Expr.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeLocVisitor.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Template.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
using namespace clang;
@ -1178,6 +1179,21 @@ TypeResult Sema::actOnObjCTypeArgsAndProtocolQualifiers(
return CreateParsedType(Result, ResultTInfo);
}
static StringRef getImageAccessAttrStr(AttributeList *attrs) {
if (attrs) {
AttributeList *Next;
do {
AttributeList &Attr = *attrs;
Next = Attr.getNext();
if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
return Attr.getName()->getName();
}
} while (Next);
}
return "";
}
/// \brief Convert the specified declspec to the appropriate type
/// object.
/// \param state Specifies the declarator containing the declaration specifier
@ -1362,6 +1378,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
}
break;
case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
break;
case DeclSpec::TST_decimal32: // _Decimal32
case DeclSpec::TST_decimal64: // _Decimal64
case DeclSpec::TST_decimal128: // _Decimal128
@ -1430,9 +1447,18 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
declarator.setInvalidType(true);
}
} else if (!S.getOpenCLOptions().cl_khr_gl_msaa_sharing &&
(Result->isImage2dMSAAT() || Result->isImage2dArrayMSAAT() ||
Result->isImage2dArrayMSAATDepth() ||
Result->isImage2dMSAATDepth())) {
(Result->isOCLImage2dArrayMSAADepthROType() ||
Result->isOCLImage2dArrayMSAADepthWOType() ||
Result->isOCLImage2dArrayMSAADepthRWType() ||
Result->isOCLImage2dArrayMSAAROType() ||
Result->isOCLImage2dArrayMSAARWType() ||
Result->isOCLImage2dArrayMSAAWOType() ||
Result->isOCLImage2dMSAADepthROType() ||
Result->isOCLImage2dMSAADepthRWType() ||
Result->isOCLImage2dMSAADepthWOType() ||
Result->isOCLImage2dMSAAROType() ||
Result->isOCLImage2dMSAARWType() ||
Result->isOCLImage2dMSAAWOType())) {
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
<< Result << "cl_khr_gl_msaa_sharing";
declarator.setInvalidType(true);
@ -1546,6 +1572,16 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
}
break;
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
case DeclSpec::TST_##ImgType##_t: \
Result = llvm::StringSwitch<QualType>( \
getImageAccessAttrStr(DS.getAttributes().getList())) \
.Cases("write_only", "__write_only", Context.Id##WOTy) \
.Cases("read_write", "__read_write", Context.Id##RWTy) \
.Default(Context.Id##ROTy); \
break;
#include "clang/AST/OpenCLImageTypes.def"
case DeclSpec::TST_error:
Result = Context.IntTy;
declarator.setInvalidType(true);

View File

@ -127,42 +127,11 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
case BuiltinType::ObjCSel:
ID = PREDEF_TYPE_OBJC_SEL;
break;
case BuiltinType::OCLImage1d:
ID = PREDEF_TYPE_IMAGE1D_ID;
break;
case BuiltinType::OCLImage1dArray:
ID = PREDEF_TYPE_IMAGE1D_ARR_ID;
break;
case BuiltinType::OCLImage1dBuffer:
ID = PREDEF_TYPE_IMAGE1D_BUFF_ID;
break;
case BuiltinType::OCLImage2d:
ID = PREDEF_TYPE_IMAGE2D_ID;
break;
case BuiltinType::OCLImage2dArray:
ID = PREDEF_TYPE_IMAGE2D_ARR_ID;
break;
case BuiltinType::OCLImage2dDepth:
ID = PREDEF_TYPE_IMAGE2D_DEP_ID;
break;
case BuiltinType::OCLImage2dArrayDepth:
ID = PREDEF_TYPE_IMAGE2D_ARR_DEP_ID;
break;
case BuiltinType::OCLImage2dMSAA:
ID = PREDEF_TYPE_IMAGE2D_MSAA_ID;
break;
case BuiltinType::OCLImage2dArrayMSAA:
ID = PREDEF_TYPE_IMAGE2D_ARR_MSAA_ID;
break;
case BuiltinType::OCLImage2dMSAADepth:
ID = PREDEF_TYPE_IMAGE2D_MSAA_DEP_ID;
break;
case BuiltinType::OCLImage2dArrayMSAADepth:
ID = PREDEF_TYPE_IMAGE2D_ARR_MSAA_DEPTH_ID;
break;
case BuiltinType::OCLImage3d:
ID = PREDEF_TYPE_IMAGE3D_ID;
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id: \
ID = PREDEF_TYPE_##Id##_ID; \
break;
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
ID = PREDEF_TYPE_SAMPLER_ID;
break;

View File

@ -6092,42 +6092,11 @@ QualType ASTReader::GetType(TypeID ID) {
case PREDEF_TYPE_OBJC_SEL:
T = Context.ObjCBuiltinSelTy;
break;
case PREDEF_TYPE_IMAGE1D_ID:
T = Context.OCLImage1dTy;
break;
case PREDEF_TYPE_IMAGE1D_ARR_ID:
T = Context.OCLImage1dArrayTy;
break;
case PREDEF_TYPE_IMAGE1D_BUFF_ID:
T = Context.OCLImage1dBufferTy;
break;
case PREDEF_TYPE_IMAGE2D_ID:
T = Context.OCLImage2dTy;
break;
case PREDEF_TYPE_IMAGE2D_ARR_ID:
T = Context.OCLImage2dArrayTy;
break;
case PREDEF_TYPE_IMAGE2D_DEP_ID:
T = Context.OCLImage2dDepthTy;
break;
case PREDEF_TYPE_IMAGE2D_ARR_DEP_ID:
T = Context.OCLImage2dArrayDepthTy;
break;
case PREDEF_TYPE_IMAGE2D_MSAA_ID:
T = Context.OCLImage2dMSAATy;
break;
case PREDEF_TYPE_IMAGE2D_ARR_MSAA_ID:
T = Context.OCLImage2dArrayMSAATy;
break;
case PREDEF_TYPE_IMAGE2D_MSAA_DEP_ID:
T = Context.OCLImage2dMSAADepthTy;
break;
case PREDEF_TYPE_IMAGE2D_ARR_MSAA_DEPTH_ID:
T = Context.OCLImage2dArrayMSAADepthTy;
break;
case PREDEF_TYPE_IMAGE3D_ID:
T = Context.OCLImage3dTy;
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case PREDEF_TYPE_##Id##_ID: \
T = Context.SingletonId; \
break;
#include "clang/AST/OpenCLImageTypes.def"
case PREDEF_TYPE_SAMPLER_ID:
T = Context.OCLSamplerTy;
break;

View File

@ -0,0 +1,11 @@
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -emit-llvm -o - | FileCheck %s
__attribute__((overloadable)) void read_image(read_only image1d_t img_ro);
__attribute__((overloadable)) void read_image(write_only image1d_t img_wo);
kernel void test_read_image(read_only image1d_t img_ro, write_only image1d_t img_wo) {
// CHECK: call void @_Z10read_image14ocl_image1d_ro(%opencl.image1d_ro_t* %{{[0-9]+}})
read_image(img_ro);
// CHECK: call void @_Z10read_image14ocl_image1d_wo(%opencl.image1d_wo_t* %{{[0-9]+}})
read_image(img_wo);
}

View File

@ -4,37 +4,37 @@ constant sampler_t glb_smp = 7;
// CHECK: constant i32 7
void fnc1(image1d_t img) {}
// CHECK: @fnc1(%opencl.image1d_t*
// CHECK: @fnc1(%opencl.image1d_ro_t*
void fnc1arr(image1d_array_t img) {}
// CHECK: @fnc1arr(%opencl.image1d_array_t*
// CHECK: @fnc1arr(%opencl.image1d_array_ro_t*
void fnc1buff(image1d_buffer_t img) {}
// CHECK: @fnc1buff(%opencl.image1d_buffer_t*
// CHECK: @fnc1buff(%opencl.image1d_buffer_ro_t*
void fnc2(image2d_t img) {}
// CHECK: @fnc2(%opencl.image2d_t*
// CHECK: @fnc2(%opencl.image2d_ro_t*
void fnc2arr(image2d_array_t img) {}
// CHECK: @fnc2arr(%opencl.image2d_array_t*
// CHECK: @fnc2arr(%opencl.image2d_array_ro_t*
void fnc3(image3d_t img) {}
// CHECK: @fnc3(%opencl.image3d_t*
// CHECK: @fnc3(%opencl.image3d_ro_t*
void fnc4smp(sampler_t s) {}
// CHECK-LABEL: define {{.*}}void @fnc4smp(i32
kernel void foo(image1d_t img) {
sampler_t smp = 5;
// CHECK: alloca i32
event_t evt;
// CHECK: alloca %opencl.event_t*
// CHECK: store i32 5,
sampler_t smp = 5;
// CHECK: alloca i32
event_t evt;
// CHECK: alloca %opencl.event_t*
// CHECK: store i32 5,
fnc4smp(smp);
// CHECK: call {{.*}}void @fnc4smp(i32
// CHECK: call {{.*}}void @fnc4smp(i32
fnc4smp(glb_smp);
// CHECK: call {{.*}}void @fnc4smp(i32
// CHECK: call {{.*}}void @fnc4smp(i32
}
void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {}
// CHECK-LABEL: @{{_Z4bad111ocl_image1d11ocl_image2dS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d@@PAUocl_image2d@@1@Z"}}
// CHECK-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}}

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument to parameter 'img' here}} expected-note{{passing argument to parameter 'img' here}}
void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, image3d_t img3dro) {
img2d_ro(img2dro);
img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to parameter of incompatible type '__read_only image2d_t'}}
img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to parameter of incompatible type '__read_only image2d_t'}}
}

View File

@ -10,5 +10,5 @@ void test3(read_only read_only image1d_t i){} // expected-error{{multiple access
#ifdef CL20
void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe'}}
#else
void test4(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL2.0 version}}
#endif

View File

@ -1,8 +1,8 @@
// RUN: %clang_cc1 -verify %s
void test1(image1d_t *i){} // expected-error {{pointer to type 'image1d_t' is invalid in OpenCL}}
void test1(image1d_t *i) {} // expected-error {{pointer to type '__read_only image1d_t' is invalid in OpenCL}}
void test2(image1d_t i) {
image1d_t ti; // expected-error {{type 'image1d_t' can only be used as a function parameter}}
image1d_t ai[] = {i,i};// expected-error {{array of 'image1d_t' type is invalid in OpenCL}}
image1d_t ti; // expected-error {{type '__read_only image1d_t' can only be used as a function parameter}}
image1d_t ai[] = {i, i}; // expected-error {{array of '__read_only image1d_t' type is invalid in OpenCL}}
}

View File

@ -27,7 +27,7 @@ typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' de
// TODO: Clean up needed - we don't really need to check for image, event, etc
// as a note here any longer.
// They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r).
image2d_t imageField; // expected-note{{field of illegal type 'image2d_t' declared here}} expected-error{{the 'image2d_t' type cannot be used to declare a structure or union field}}
image2d_t imageField; // expected-note{{field of illegal type '__read_only image2d_t' declared here}} expected-error{{the '__read_only image2d_t' type cannot be used to declare a structure or union field}}
} FooImage2D;
kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}}

View File

@ -1454,18 +1454,9 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
case BuiltinType::Void:
case BuiltinType::NullPtr:
case BuiltinType::Dependent:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
case BuiltinType::OCLImage1dBuffer:
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage2dDepth:
case BuiltinType::OCLImage2dArrayDepth:
case BuiltinType::OCLImage2dMSAA:
case BuiltinType::OCLImage2dArrayMSAA:
case BuiltinType::OCLImage2dMSAADepth:
case BuiltinType::OCLImage2dArrayMSAADepth:
case BuiltinType::OCLImage3d:
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/AST/OpenCLImageTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent: