summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorAlexey Bader <aleksey.bader@mail.ru>2016-04-08 13:40:33 +0000
committerAlexey Bader <aleksey.bader@mail.ru>2016-04-08 13:40:33 +0000
commit954ba21f852534c24dc1caf023d957adc06eef20 (patch)
treeb04909d95bbcd3eb75d39053f586b7bdc5185f60 /clang/lib/Sema
parent829b5d42af932f2320a1677393e5f82fb924aca9 (diff)
downloadbcm5719-llvm-954ba21f852534c24dc1caf023d957adc06eef20.tar.gz
bcm5719-llvm-954ba21f852534c24dc1caf023d957adc06eef20.zip
[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
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/DeclSpec.cpp6
-rw-r--r--clang/lib/Sema/Sema.cpp14
-rw-r--r--clang/lib/Sema/SemaExpr.cpp7
-rw-r--r--clang/lib/Sema/SemaTemplateVariadic.cpp2
-rw-r--r--clang/lib/Sema/SemaType.cpp46
5 files changed, 55 insertions, 20 deletions
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index ae0242cce07..cbe19939807 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -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!");
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 997d967aa19..5a8e5510f75 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -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);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index cfd58983dfc..32e189a843e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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;
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index c692c9f75ca..d2b359b24c0 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -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;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 924cd07e021..3b0e3274e57 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -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);
OpenPOWER on IntegriCloud