aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGuy Benyei <guy.benyei@intel.com>2013-02-07 10:55:47 +0000
committerGuy Benyei <guy.benyei@intel.com>2013-02-07 10:55:47 +0000
commit21f18c4fda167dc5f72feddbd6a7ac1b63200a0d (patch)
tree80c1b120c64d3066fd4f5799174a16d8ed49eca0 /lib
parentf5a6aefa37d73fff3c47953e2c447f074e726a0e (diff)
Add OpenCL samplers as Clang builtin types and check sampler related restrictions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174601 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp7
-rw-r--r--lib/AST/ItaniumMangle.cpp1
-rw-r--r--lib/AST/MicrosoftMangle.cpp1
-rw-r--r--lib/AST/NSAPI.cpp1
-rw-r--r--lib/AST/Type.cpp1
-rw-r--r--lib/AST/TypeLoc.cpp1
-rw-r--r--lib/CodeGen/CGDebugInfo.cpp5
-rw-r--r--lib/CodeGen/CGOpenCLRuntime.cpp2
-rw-r--r--lib/CodeGen/CGRTTI.cpp1
-rw-r--r--lib/CodeGen/CodeGenTypes.cpp1
-rw-r--r--lib/Parse/ParseDecl.cpp7
-rw-r--r--lib/Parse/ParseExpr.cpp1
-rw-r--r--lib/Parse/ParseTentative.cpp1
-rw-r--r--lib/Sema/DeclSpec.cpp2
-rw-r--r--lib/Sema/SemaDecl.cpp8
-rw-r--r--lib/Sema/SemaInit.cpp46
-rw-r--r--lib/Sema/SemaOverload.cpp4
-rw-r--r--lib/Sema/SemaTemplateVariadic.cpp1
-rw-r--r--lib/Sema/SemaType.cpp4
-rw-r--r--lib/Serialization/ASTCommon.cpp1
-rw-r--r--lib/Serialization/ASTReader.cpp1
21 files changed, 95 insertions, 2 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index f97e6e9119..bdb464c531 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -906,6 +906,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) {
InitBuiltinType(OCLImage2dArrayTy, BuiltinType::OCLImage2dArray);
InitBuiltinType(OCLImage3dTy, BuiltinType::OCLImage3d);
+ InitBuiltinType(OCLSamplerTy, BuiltinType::OCLSampler);
InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent);
}
@@ -1448,6 +1449,11 @@ ASTContext::getTypeInfoImpl(const Type *T) const {
Width = Target->getPointerWidth(0);
Align = Target->getPointerAlign(0);
break;
+ case BuiltinType::OCLSampler:
+ // Samplers are modeled as integers.
+ Width = Target->getIntWidth();
+ Align = Target->getIntAlign();
+ break;
case BuiltinType::OCLEvent:
case BuiltinType::OCLImage1d:
case BuiltinType::OCLImage1dArray:
@@ -4923,6 +4929,7 @@ static char getObjCEncodingForPrimitiveKind(const ASTContext *C,
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage3d:
case BuiltinType::OCLEvent:
+ case BuiltinType::OCLSampler:
case BuiltinType::Dependent:
#define BUILTIN_TYPE(KIND, ID)
#define PLACEHOLDER_TYPE(KIND, ID) \
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp
index 926384decb..792bda6354 100644
--- a/lib/AST/ItaniumMangle.cpp
+++ b/lib/AST/ItaniumMangle.cpp
@@ -1886,6 +1886,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
case BuiltinType::OCLImage2d: Out << "11ocl_image2d"; break;
case BuiltinType::OCLImage2dArray: Out << "16ocl_image2darray"; break;
case BuiltinType::OCLImage3d: Out << "11ocl_image3d"; break;
+ case BuiltinType::OCLSampler: Out << "11ocl_sampler"; break;
case BuiltinType::OCLEvent: Out << "9ocl_event"; break;
}
}
diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp
index 0b77ac8c78..326b0d3e3d 100644
--- a/lib/AST/MicrosoftMangle.cpp
+++ b/lib/AST/MicrosoftMangle.cpp
@@ -1060,6 +1060,7 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T,
case BuiltinType::OCLImage2d: Out << "PAUocl_image2d@@"; break;
case BuiltinType::OCLImage2dArray: Out << "PAUocl_image2darray@@"; break;
case BuiltinType::OCLImage3d: Out << "PAUocl_image3d@@"; break;
+ case BuiltinType::OCLSampler: Out << "PAUocl_sampler@@"; break;
case BuiltinType::OCLEvent: Out << "PAUocl_event@@"; break;
case BuiltinType::NullPtr: Out << "$$T"; break;
diff --git a/lib/AST/NSAPI.cpp b/lib/AST/NSAPI.cpp
index c8cf920d0c..4c20235ed8 100644
--- a/lib/AST/NSAPI.cpp
+++ b/lib/AST/NSAPI.cpp
@@ -351,6 +351,7 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage3d:
+ case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::BoundMember:
case BuiltinType::Dependent:
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 524d00560c..efd588a57a 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -1518,6 +1518,7 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
case OCLImage2d: return "image2d_t";
case OCLImage2dArray: return "image2d_array_t";
case OCLImage3d: return "image3d_t";
+ case OCLSampler: return "sampler_t";
case OCLEvent: return "event_t";
}
diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp
index 3efa1485ab..010ea2d9a8 100644
--- a/lib/AST/TypeLoc.cpp
+++ b/lib/AST/TypeLoc.cpp
@@ -268,6 +268,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage3d:
+ case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::BuiltinFn:
return TST_unspecified;
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 5e60bd8f66..a4153d3712 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -426,6 +426,11 @@ llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) {
case BuiltinType::OCLImage3d:
return getOrCreateStructPtrType("opencl_image3d_t",
OCLImage3dDITy);
+ case BuiltinType::OCLSampler:
+ return DBuilder.createBasicType("opencl_sampler_t",
+ CGM.getContext().getTypeSize(BT),
+ CGM.getContext().getTypeAlign(BT),
+ llvm::dwarf::DW_ATE_unsigned);
case BuiltinType::OCLEvent:
return getOrCreateStructPtrType("opencl_event_t",
OCLEventDITy);
diff --git a/lib/CodeGen/CGOpenCLRuntime.cpp b/lib/CodeGen/CGOpenCLRuntime.cpp
index 215d09640a..7c454ac7c6 100644
--- a/lib/CodeGen/CGOpenCLRuntime.cpp
+++ b/lib/CodeGen/CGOpenCLRuntime.cpp
@@ -55,6 +55,8 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
case BuiltinType::OCLImage3d:
return llvm::PointerType::get(llvm::StructType::create(
CGM.getLLVMContext(), "opencl.image3d_t"), 0);
+ case BuiltinType::OCLSampler:
+ return llvm::IntegerType::get(CGM.getLLVMContext(),32);
case BuiltinType::OCLEvent:
return llvm::PointerType::get(llvm::StructType::create(
CGM.getLLVMContext(), "opencl.event_t"), 0);
diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp
index 366ce29fc0..869843cbd4 100644
--- a/lib/CodeGen/CGRTTI.cpp
+++ b/lib/CodeGen/CGRTTI.cpp
@@ -197,6 +197,7 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage3d:
+ case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
return true;
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index e78cbabda8..c82e1d829d 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -378,6 +378,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
case BuiltinType::OCLImage2d:
case BuiltinType::OCLImage2dArray:
case BuiltinType::OCLImage3d:
+ case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
break;
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index e11fb913a7..8e24a14d0b 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -2781,6 +2781,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_image3d_t, Loc,
PrevSpec, DiagID);
break;
+ case tok::kw_sampler_t:
+ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_sampler_t, Loc,
+ PrevSpec, DiagID);
+ break;
case tok::kw_event_t:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_event_t, Loc,
PrevSpec, DiagID);
@@ -3635,6 +3639,7 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
case tok::kw_image2d_t:
case tok::kw_image2d_array_t:
case tok::kw_image3d_t:
+ case tok::kw_sampler_t:
case tok::kw_event_t:
// struct-or-union-specifier (C99) or class-specifier (C++)
@@ -3716,6 +3721,7 @@ bool Parser::isTypeSpecifierQualifier() {
case tok::kw_image2d_t:
case tok::kw_image2d_array_t:
case tok::kw_image3d_t:
+ case tok::kw_sampler_t:
case tok::kw_event_t:
// struct-or-union-specifier (C99) or class-specifier (C++)
@@ -3869,6 +3875,7 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
case tok::kw_image2d_t:
case tok::kw_image2d_array_t:
case tok::kw_image3d_t:
+ case tok::kw_sampler_t:
case tok::kw_event_t:
// struct-or-union-specifier (C99) or class-specifier (C++)
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 4ed0bd0c6e..7775909cf5 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -1024,6 +1024,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
case tok::kw_image2d_t:
case tok::kw_image2d_array_t:
case tok::kw_image3d_t:
+ case tok::kw_sampler_t:
case tok::kw_event_t: {
if (!getLangOpts().CPlusPlus) {
Diag(Tok, diag::err_expected_expression);
diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp
index 1116daa4d1..b3cf983bbc 100644
--- a/lib/Parse/ParseTentative.cpp
+++ b/lib/Parse/ParseTentative.cpp
@@ -843,6 +843,7 @@ Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) {
case tok::kw_image2d_t:
case tok::kw_image2d_array_t:
case tok::kw_image3d_t:
+ case tok::kw_sampler_t:
case tok::kw_event_t:
case tok::kw___unknown_anytype:
return TPResult::False();
diff --git a/lib/Sema/DeclSpec.cpp b/lib/Sema/DeclSpec.cpp
index 6d30b89952..569352ecb9 100644
--- a/lib/Sema/DeclSpec.cpp
+++ b/lib/Sema/DeclSpec.cpp
@@ -286,6 +286,7 @@ bool Declarator::isDeclarationOfFunction() const {
case TST_image2d_t:
case TST_image2d_array_t:
case TST_image3d_t:
+ case TST_sampler_t:
case TST_event_t:
return false;
@@ -428,6 +429,7 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
case DeclSpec::TST_image2d_t: return "image2d_t";
case DeclSpec::TST_image2d_array_t: return "image2d_array_t";
case DeclSpec::TST_image3d_t: return "image3d_t";
+ case DeclSpec::TST_sampler_t: return "sampler_t";
case DeclSpec::TST_event_t: return "event_t";
case DeclSpec::TST_error: return "(error)";
}
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 45f7cae960..7c31be6c13 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -4483,6 +4483,14 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
SCAsWritten = SC_OpenCLWorkGroupLocal;
}
+ // OpenCL v1.2 s6.9.b p4:
+ // The sampler type cannot be used with the __local and __global address
+ // space qualifiers.
+ if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local ||
+ R.getAddressSpace() == LangAS::opencl_global)) {
+ Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
+ }
+
// OpenCL 1.2 spec, p6.9 r:
// The event type cannot be used to declare a program scope variable.
// The event type cannot be used with the __local, __constant and __global
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 87e6648d92..0612c73f89 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -2424,6 +2424,7 @@ void InitializationSequence::Step::Destroy() {
case SK_PassByIndirectRestore:
case SK_ProduceObjCObject:
case SK_StdInitializerList:
+ case SK_OCLSamplerInit:
case SK_OCLZeroEvent:
break;
@@ -2653,6 +2654,13 @@ void InitializationSequence::AddStdInitializerListConstructionStep(QualType T) {
Steps.push_back(S);
}
+void InitializationSequence::AddOCLSamplerInitStep(QualType T) {
+ Step S;
+ S.Kind = SK_OCLSamplerInit;
+ S.Type = T;
+ Steps.push_back(S);
+}
+
void InitializationSequence::AddOCLZeroEventStep(QualType T) {
Step S;
S.Kind = SK_OCLZeroEvent;
@@ -4017,6 +4025,18 @@ static bool tryObjCWritebackConversion(Sema &S,
return true;
}
+static bool TryOCLSamplerInitialization(Sema &S,
+ InitializationSequence &Sequence,
+ QualType DestType,
+ Expr *Initializer) {
+ if (!S.getLangOpts().OpenCL || !DestType->isSamplerT() ||
+ !Initializer->isIntegerConstantExpr(S.getASTContext()))
+ return false;
+
+ Sequence.AddOCLSamplerInitStep(DestType);
+ return true;
+}
+
//
// OpenCL 1.2 spec, s6.12.10
//
@@ -4180,7 +4200,9 @@ InitializationSequence::InitializationSequence(Sema &S,
tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
return;
}
-
+
+ if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
+ return;
if (TryOCLZeroEventInitialization(S, *this, DestType, Initializer))
return;
@@ -4974,6 +4996,7 @@ InitializationSequence::Perform(Sema &S,
case SK_PassByIndirectRestore:
case SK_ProduceObjCObject:
case SK_StdInitializerList:
+ case SK_OCLSamplerInit:
case SK_OCLZeroEvent: {
assert(Args.size() == 1);
CurInit = Args[0];
@@ -5490,6 +5513,23 @@ InitializationSequence::Perform(Sema &S,
CurInit = S.Owned(Semantic);
break;
}
+ case SK_OCLSamplerInit: {
+ assert(Step->Type->isSamplerT() &&
+ "Sampler initialization on non sampler type.");
+
+ QualType SourceType = CurInit.get()->getType();
+ InitializedEntity::EntityKind EntityKind = Entity.getKind();
+
+ if (EntityKind == InitializedEntity::EK_Parameter) {
+ if (!SourceType->isSamplerT())
+ S.Diag(Kind.getLocation(), diag::err_sampler_argument_required)
+ << SourceType;
+ } else if (EntityKind != InitializedEntity::EK_Variable) {
+ llvm_unreachable("Invalid EntityKind!");
+ }
+
+ break;
+ }
case SK_OCLZeroEvent: {
assert(Step->Type->isEventT() &&
"Event initialization on non event type.");
@@ -6186,6 +6226,10 @@ void InitializationSequence::dump(raw_ostream &OS) const {
OS << "std::initializer_list from initializer list";
break;
+ case SK_OCLSamplerInit:
+ OS << "OpenCL sampler_t from integer constant";
+ break;
+
case SK_OCLZeroEvent:
OS << "OpenCL event_t from zero";
break;
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 2d4d159908..ac9dec4e6c 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -1664,7 +1664,9 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
== CanonTo.getLocalUnqualifiedType() &&
(CanonFrom.getLocalCVRQualifiers() != CanonTo.getLocalCVRQualifiers()
|| CanonFrom.getObjCGCAttr() != CanonTo.getObjCGCAttr()
- || CanonFrom.getObjCLifetime() != CanonTo.getObjCLifetime())) {
+ || CanonFrom.getObjCLifetime() != CanonTo.getObjCLifetime()
+ || (CanonFrom->isSamplerT() &&
+ CanonFrom.getAddressSpace() != CanonTo.getAddressSpace()))) {
FromType = ToType;
CanonFrom = CanonTo;
}
diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp
index 470896e0dd..c13a2f6ce9 100644
--- a/lib/Sema/SemaTemplateVariadic.cpp
+++ b/lib/Sema/SemaTemplateVariadic.cpp
@@ -737,6 +737,7 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
case TST_image2d_t:
case TST_image2d_array_t:
case TST_image3d_t:
+ case TST_sampler_t:
case TST_event_t:
case TST_error:
break;
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index ae8d030255..b257a59c10 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -952,6 +952,10 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
Result = Context.OCLImage3dTy;
break;
+ case DeclSpec::TST_sampler_t:
+ Result = Context.OCLSamplerTy;
+ break;
+
case DeclSpec::TST_event_t:
Result = Context.OCLEventTy;
break;
diff --git a/lib/Serialization/ASTCommon.cpp b/lib/Serialization/ASTCommon.cpp
index 955dc96229..9f1514bdff 100644
--- a/lib/Serialization/ASTCommon.cpp
+++ b/lib/Serialization/ASTCommon.cpp
@@ -67,6 +67,7 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
case BuiltinType::OCLImage2d: ID = PREDEF_TYPE_IMAGE2D_ID; break;
case BuiltinType::OCLImage2dArray: ID = PREDEF_TYPE_IMAGE2D_ARR_ID; break;
case BuiltinType::OCLImage3d: ID = PREDEF_TYPE_IMAGE3D_ID; break;
+ case BuiltinType::OCLSampler: ID = PREDEF_TYPE_SAMPLER_ID; break;
case BuiltinType::OCLEvent: ID = PREDEF_TYPE_EVENT_ID; break;
case BuiltinType::BuiltinFn:
ID = PREDEF_TYPE_BUILTIN_FN; break;
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 1213084e36..a00d40659f 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -4903,6 +4903,7 @@ QualType ASTReader::GetType(TypeID ID) {
case PREDEF_TYPE_IMAGE2D_ID: T = Context.OCLImage2dTy; break;
case PREDEF_TYPE_IMAGE2D_ARR_ID: T = Context.OCLImage2dArrayTy; break;
case PREDEF_TYPE_IMAGE3D_ID: T = Context.OCLImage3dTy; break;
+ case PREDEF_TYPE_SAMPLER_ID: T = Context.OCLSamplerTy; break;
case PREDEF_TYPE_EVENT_ID: T = Context.OCLEventTy; break;
case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break;