From: Guy Benyei Date: Sun, 20 Jan 2013 12:31:11 +0000 (+0000) Subject: Implement OpenCL event_t as Clang builtin type, including event_t related OpenCL... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6b9d802fb7b16d93474c4f1c179ab36202e8a8b;p=clang Implement OpenCL event_t as Clang builtin type, including event_t related OpenCL restrictions (OpenCL 1.2 spec 6.9) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172973 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index fcea6fb292..05f818299b 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -721,6 +721,7 @@ public: CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy; CanQualType OCLImage2dTy, OCLImage2dArrayTy; CanQualType OCLImage3dTy; + CanQualType OCLEventTy; // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/include/clang/AST/BuiltinTypes.def b/include/clang/AST/BuiltinTypes.def index cb7cfedb39..503d963eca 100644 --- a/include/clang/AST/BuiltinTypes.def +++ b/include/clang/AST/BuiltinTypes.def @@ -162,6 +162,9 @@ BUILTIN_TYPE(OCLImage2d, OCLImage2dTy) BUILTIN_TYPE(OCLImage2dArray, OCLImage2dArrayTy) BUILTIN_TYPE(OCLImage3d, OCLImage3dTy) +// OpenCL event_t. +BUILTIN_TYPE(OCLEvent, OCLEventTy) + // This represents the type of an expression whose type is // totally unknown, e.g. 'T::foo'. It is permitted for this to // appear in situations where the structure of the type is diff --git a/include/clang/AST/OperationKinds.h b/include/clang/AST/OperationKinds.h index 18169fd60c..5e41d955cf 100644 --- a/include/clang/AST/OperationKinds.h +++ b/include/clang/AST/OperationKinds.h @@ -292,7 +292,10 @@ enum CastKind { // Convert a builtin function to a function pointer; only allowed in the // callee of a call expression. - CK_BuiltinFnToFnPtr + CK_BuiltinFnToFnPtr, + + // Convert a zero value for OpenCL event_t initialization. + CK_ZeroToOCLEvent }; static const CastKind CK_Invalid = static_cast(-1); diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index f1db761557..cc6c1fd445 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1584,6 +1584,8 @@ public: bool isImageType() const; // Any OpenCL image type + bool isEventT() const; // OpenCL event_t + bool isOpenCLSpecificType() const; // Any OpenCL specific type /// Determines if this type, which must satisfy @@ -4916,6 +4918,10 @@ inline bool Type::isImage2dArrayT() const { inline bool Type::isImage3dT() const { return isSpecificBuiltinType(BuiltinType::OCLImage3d); } +inline bool Type::isEventT() const { + return isSpecificBuiltinType(BuiltinType::OCLEvent); +} + inline bool Type::isImageType() const { return isImage3dT() || isImage2dT() || isImage2dArrayT() || @@ -4923,7 +4929,7 @@ inline bool Type::isImageType() const { } inline bool Type::isOpenCLSpecificType() const { - return isImageType(); + return isImageType() || isEventT(); } inline bool Type::isTemplateTypeParmType() const { diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index c3f034a53a..3999fadc51 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -6081,6 +6081,14 @@ def err_opencl_bitfields : Error< "bitfields are not supported in OpenCL">; def err_opencl_vla : Error< "variable length arrays are not supported in OpenCL">; +def err_event_t_kernel_arg : Error< + "the event_t type cannot be used to declare a kernel function argument">; +def err_event_t_global_var : Error< + "the event_t type cannot be used to declare a program scope variable">; +def err_event_t_struct_field : Error< + "the event_t type cannot be used to declare a structure or union field">; +def err_event_t_addr_space_qual : Error< + "the event_t type can only be used with __private address space qualifier">; } // end of sema category diff --git a/include/clang/Basic/Specifiers.h b/include/clang/Basic/Specifiers.h index 321048f985..533cefeaae 100644 --- a/include/clang/Basic/Specifiers.h +++ b/include/clang/Basic/Specifiers.h @@ -68,6 +68,7 @@ namespace clang { TST_image2d_t, // OpenCL image2d_t TST_image2d_array_t, // OpenCL image2d_array_t TST_image3d_t, // OpenCL image3d_t + TST_event_t, // OpenCL event_t TST_error // erroneous type }; diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index b4c0b2d97f..8008ca60a8 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -455,6 +455,7 @@ KEYWORD(image1d_buffer_t , KEYOPENCL) KEYWORD(image2d_t , KEYOPENCL) KEYWORD(image2d_array_t , KEYOPENCL) KEYWORD(image3d_t , KEYOPENCL) +KEYWORD(event_t , KEYOPENCL) // Borland Extensions. KEYWORD(__pascal , KEYALL) diff --git a/include/clang/Sema/DeclSpec.h b/include/clang/Sema/DeclSpec.h index b232d34c40..0d2c948399 100644 --- a/include/clang/Sema/DeclSpec.h +++ b/include/clang/Sema/DeclSpec.h @@ -282,6 +282,7 @@ public: static const TST TST_image2d_t = clang::TST_image2d_t; static const TST TST_image2d_array_t = clang::TST_image2d_array_t; static const TST TST_image3d_t = clang::TST_image3d_t; + static const TST TST_event_t = clang::TST_event_t; static const TST TST_error = clang::TST_error; // type-qualifiers diff --git a/include/clang/Sema/Initialization.h b/include/clang/Sema/Initialization.h index 778b70b0ec..002a12605d 100644 --- a/include/clang/Sema/Initialization.h +++ b/include/clang/Sema/Initialization.h @@ -624,7 +624,9 @@ public: /// \brief Produce an Objective-C object pointer. SK_ProduceObjCObject, /// \brief Construct a std::initializer_list from an initializer list. - SK_StdInitializerList + SK_StdInitializerList, + /// \brief Passing zero to a function where OpenCL event_t is expected. + SK_OCLZeroEvent }; /// \brief A single step in the initialization sequence. @@ -953,6 +955,10 @@ public: /// initializer list. void AddStdInitializerListConstructionStep(QualType T); + /// \brief Add a step to initialize an OpenCL event_t from a NULL + /// constant. + void AddOCLZeroEventStep(QualType T); + /// \brief Add steps to unwrap a initializer list for a reference around a /// single element and rewrap it at the end. void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic); diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index a938697263..10453ec841 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -715,7 +715,8 @@ namespace clang { /// \brief OpenCL 2d image array type. PREDEF_TYPE_IMAGE2D_ARR_ID = 42, /// \brief OpenCL 3d image type. - PREDEF_TYPE_IMAGE3D_ID = 43 + PREDEF_TYPE_IMAGE3D_ID = 43, + PREDEF_TYPE_EVENT_ID = 44 }; /// \brief The number of predefined type IDs that are reserved for diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ace9dc0146..b18fa679ca 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -893,6 +893,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) { InitBuiltinType(OCLImage2dTy, BuiltinType::OCLImage2d); InitBuiltinType(OCLImage2dArrayTy, BuiltinType::OCLImage2dArray); InitBuiltinType(OCLImage3dTy, BuiltinType::OCLImage3d); + + InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent); } // Builtin type for __objc_yes and __objc_no @@ -1434,6 +1436,7 @@ ASTContext::getTypeInfoImpl(const Type *T) const { Width = Target->getPointerWidth(0); Align = Target->getPointerAlign(0); break; + case BuiltinType::OCLEvent: case BuiltinType::OCLImage1d: case BuiltinType::OCLImage1dArray: case BuiltinType::OCLImage1dBuffer: @@ -4895,6 +4898,7 @@ static char getObjCEncodingForPrimitiveKind(const ASTContext *C, case BuiltinType::OCLImage2d: case BuiltinType::OCLImage2dArray: case BuiltinType::OCLImage3d: + case BuiltinType::OCLEvent: case BuiltinType::Dependent: #define BUILTIN_TYPE(KIND, ID) #define PLACEHOLDER_TYPE(KIND, ID) \ diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 718002f97d..e3ff29d2d0 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1400,6 +1400,7 @@ void CastExpr::CheckCastConsistency() const { case CK_ARCConsumeObject: case CK_ARCReclaimReturnedObject: case CK_ARCExtendBlockObject: + case CK_ZeroToOCLEvent: assert(!getType()->isBooleanType() && "unheralded conversion to bool"); goto CheckNoBasePath; @@ -1531,6 +1532,8 @@ const char *CastExpr::getCastKindName() const { return "CopyAndAutoreleaseBlockObject"; case CK_BuiltinFnToFnPtr: return "BuiltinFnToFnPtr"; + case CK_ZeroToOCLEvent: + return "ZeroToOCLEvent"; } llvm_unreachable("Unhandled cast kind!"); diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 9965e1288b..64fd40b7a6 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -5372,6 +5372,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) { case CK_IntegralComplexCast: case CK_IntegralComplexToFloatingComplex: case CK_BuiltinFnToFnPtr: + case CK_ZeroToOCLEvent: llvm_unreachable("invalid cast kind for integral value"); case CK_BitCast: @@ -5859,6 +5860,7 @@ bool ComplexExprEvaluator::VisitCastExpr(const CastExpr *E) { case CK_ARCExtendBlockObject: case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: + case CK_ZeroToOCLEvent: llvm_unreachable("invalid cast kind for complex value"); case CK_LValueToRValue: diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 65e630eb25..926384decb 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::OCLEvent: Out << "9ocl_event"; break; } } diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index bd0125d639..0b77ac8c78 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::OCLEvent: Out << "PAUocl_event@@"; break; case BuiltinType::NullPtr: Out << "$$T"; break; diff --git a/lib/AST/NSAPI.cpp b/lib/AST/NSAPI.cpp index 35cc7d050b..c8cf920d0c 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::OCLEvent: case BuiltinType::BoundMember: case BuiltinType::Dependent: case BuiltinType::Overload: diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 45ec4edbc5..524d00560c 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 OCLEvent: return "event_t"; } llvm_unreachable("Invalid builtin type."); diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index a5baf703a4..3efa1485ab 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::OCLEvent: case BuiltinType::BuiltinFn: return TST_unspecified; } diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 37df4b33ce..264d075e5c 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -426,6 +426,9 @@ llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) { case BuiltinType::OCLImage3d: return getOrCreateStructPtrType("opencl_image3d_t", OCLImage3dDITy); + case BuiltinType::OCLEvent: + return getOrCreateStructPtrType("opencl_event_t", + OCLEventDITy); case BuiltinType::UChar: case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 3ecf2edfb0..fbbee0b3d2 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -55,6 +55,7 @@ class CGDebugInfo { llvm::DIType OCLImage1dDITy, OCLImage1dArrayDITy, OCLImage1dBufferDITy; llvm::DIType OCLImage2dDITy, OCLImage2dArrayDITy; llvm::DIType OCLImage3dDITy; + llvm::DIType OCLEventDITy; /// TypeCache - Cache of previously constructed Types. llvm::DenseMap TypeCache; diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index cdbd6e7bb7..9bef08b4a5 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2639,6 +2639,8 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { ConvertType(ToType)); return MakeAddrLValue(V, E->getType()); } + case CK_ZeroToOCLEvent: + llvm_unreachable("NULL to OpenCL event lvalue cast is not valid"); } llvm_unreachable("Unhandled lvalue cast kind?"); diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index b037113945..a35ef0c931 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -648,6 +648,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { case CK_ARCExtendBlockObject: case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: + case CK_ZeroToOCLEvent: llvm_unreachable("cast kind invalid for aggregate types"); } } diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp index 127029795c..0a53d4f127 100644 --- a/lib/CodeGen/CGExprComplex.cpp +++ b/lib/CodeGen/CGExprComplex.cpp @@ -428,6 +428,7 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastExpr::CastKind CK, Expr *Op, case CK_ARCExtendBlockObject: case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: + case CK_ZeroToOCLEvent: llvm_unreachable("invalid cast kind for complex value"); case CK_FloatingRealToComplex: diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 2c107cb716..80ab2ed28c 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -747,6 +747,7 @@ public: case CK_FloatingToIntegral: case CK_FloatingToBoolean: case CK_FloatingCast: + case CK_ZeroToOCLEvent: return 0; } llvm_unreachable("Invalid CastKind"); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 5715913b6a..ed927e2fb4 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1383,6 +1383,11 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { return EmitComplexToScalarConversion(V, E->getType(), DestTy); } + case CK_ZeroToOCLEvent: { + assert(DestTy->isEventT() && "CK_ZeroToOCLEvent cast on non event type"); + return llvm::Constant::getNullValue(ConvertType(DestTy)); + } + } llvm_unreachable("unknown scalar cast"); diff --git a/lib/CodeGen/CGOpenCLRuntime.cpp b/lib/CodeGen/CGOpenCLRuntime.cpp index bb239c6c3d..215d09640a 100644 --- a/lib/CodeGen/CGOpenCLRuntime.cpp +++ b/lib/CodeGen/CGOpenCLRuntime.cpp @@ -55,5 +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::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 41b73e23cd..3d65892b2e 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::OCLEvent: return true; case BuiltinType::Dependent: diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 2c5f2d80cf..c186ebff29 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -374,6 +374,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { case BuiltinType::OCLImage2d: case BuiltinType::OCLImage2dArray: case BuiltinType::OCLImage3d: + case BuiltinType::OCLEvent: ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty); break; diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp index 312c86fe9b..215aacdad1 100644 --- a/lib/Edit/RewriteObjCFoundationAPI.cpp +++ b/lib/Edit/RewriteObjCFoundationAPI.cpp @@ -1075,6 +1075,7 @@ static bool rewriteToNumericBoxedExpression(const ObjCMessageExpr *Msg, case CK_NonAtomicToAtomic: case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: + case CK_ZeroToOCLEvent: return false; } } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index f9c68c79b9..cfe5d1b16a 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2783,6 +2783,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, isInvalid = DS.SetTypeSpecType(DeclSpec::TST_image3d_t, Loc, PrevSpec, DiagID); break; + case tok::kw_event_t: + isInvalid = DS.SetTypeSpecType(DeclSpec::TST_event_t, Loc, + PrevSpec, DiagID); + break; case tok::kw___unknown_anytype: isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc, PrevSpec, DiagID); @@ -3633,6 +3637,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_event_t: // struct-or-union-specifier (C99) or class-specifier (C++) case tok::kw_class: @@ -3713,6 +3718,7 @@ bool Parser::isTypeSpecifierQualifier() { case tok::kw_image2d_t: case tok::kw_image2d_array_t: case tok::kw_image3d_t: + case tok::kw_event_t: // struct-or-union-specifier (C99) or class-specifier (C++) case tok::kw_class: @@ -3865,6 +3871,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_event_t: // struct-or-union-specifier (C99) or class-specifier (C++) case tok::kw_class: diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index d6d38c758a..9c788a1336 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_event_t: if (!getLangOpts().CPlusPlus) { Diag(Tok, diag::err_expected_expression); return ExprError(); diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index 78d73bca4c..1116daa4d1 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_event_t: case tok::kw___unknown_anytype: return TPResult::False(); diff --git a/lib/Sema/DeclSpec.cpp b/lib/Sema/DeclSpec.cpp index 35b0736196..6d30b89952 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_event_t: return false; case TST_decltype: @@ -427,6 +428,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_event_t: return "event_t"; case DeclSpec::TST_error: return "(error)"; } llvm_unreachable("Unknown typespec!"); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index dbdbc3d6a2..7936efa136 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4401,6 +4401,22 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, SC = SC_OpenCLWorkGroupLocal; SCAsWritten = SC_OpenCLWorkGroupLocal; } + + // 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 + // address space qualifiers. + if (R->isEventT()) { + if (S->getParent() == 0) { + Diag(D.getLocStart(), diag::err_event_t_global_var); + D.setInvalidType(); + } + + if (R.getAddressSpace()) { + Diag(D.getLocStart(), diag::err_event_t_addr_space_qual); + D.setInvalidType(); + } + } } bool isExplicitSpecialization = false; @@ -6136,12 +6152,26 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } } - // OpenCL v1.2 s6.8 static is invalid for kernel functions. - if ((getLangOpts().OpenCLVersion >= 120) - && NewFD->hasAttr() - && (SC == SC_Static)) { - Diag(D.getIdentifierLoc(), diag::err_static_kernel); - D.setInvalidType(); + if (NewFD->hasAttr()) { + + // OpenCL v1.2 s6.8 static is invalid for kernel functions. + if ((getLangOpts().OpenCLVersion >= 120) + && (SC == SC_Static)) { + Diag(D.getIdentifierLoc(), diag::err_static_kernel); + D.setInvalidType(); + } + + // OpenCL v1.2 s6.8 n: + // Arguments to kernel functions in a program cannot be declared to be of + // type event_t. + for (FunctionDecl::param_iterator PI = NewFD->param_begin(), + PE = NewFD->param_end(); PI != PE; ++PI) { + if ((*PI)->getType()->isEventT()) { + Diag((*PI)->getLocation(), diag::err_event_t_kernel_arg); + D.setInvalidType(); + } + } + } MarkUnusedFileScopedDecl(NewFD); @@ -9776,6 +9806,14 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record, } } + // OpenCL 1.2 spec, s6.9 r: + // The event type cannot be used to declare a structure or union field. + if (LangOpts.OpenCL && T->isEventT()) { + Diag(Loc, diag::err_event_t_struct_field); + D.setInvalidType(); + } + + DiagnoseFunctionSpecifiers(D); if (D.getDeclSpec().isThreadSpecified()) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 26bb6efb8e..e661110832 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_OCLZeroEvent: break; case SK_ConversionSequence: @@ -2652,6 +2653,13 @@ void InitializationSequence::AddStdInitializerListConstructionStep(QualType T) { Steps.push_back(S); } +void InitializationSequence::AddOCLZeroEventStep(QualType T) { + Step S; + S.Kind = SK_OCLZeroEvent; + S.Type = T; + Steps.push_back(S); +} + void InitializationSequence::RewrapReferenceInitList(QualType T, InitListExpr *Syntactic) { assert(Syntactic->getNumInits() == 1 && @@ -4009,6 +4017,27 @@ static bool tryObjCWritebackConversion(Sema &S, return true; } +// +// OpenCL 1.2 spec, s6.12.10 +// +// The event argument can also be used to associate the +// async_work_group_copy with a previous async copy allowing +// an event to be shared by multiple async copies; otherwise +// event should be zero. +// +static bool TryOCLZeroEventInitialization(Sema &S, + InitializationSequence &Sequence, + QualType DestType, + Expr *Initializer) { + if (!S.getLangOpts().OpenCL || !DestType->isEventT() || + !Initializer->isIntegerConstantExpr(S.getASTContext()) || + (Initializer->EvaluateKnownConstInt(S.getASTContext()) != 0)) + return false; + + Sequence.AddOCLZeroEventStep(DestType); + return true; +} + InitializationSequence::InitializationSequence(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, @@ -4152,6 +4181,10 @@ InitializationSequence::InitializationSequence(Sema &S, return; } + + if (TryOCLZeroEventInitialization(S, *this, DestType, Initializer)) + return; + // Handle initialization in C AddCAssignmentStep(DestType); MaybeProduceObjCObject(S, *this, Entity); @@ -4940,7 +4973,8 @@ InitializationSequence::Perform(Sema &S, case SK_PassByIndirectCopyRestore: case SK_PassByIndirectRestore: case SK_ProduceObjCObject: - case SK_StdInitializerList: { + case SK_StdInitializerList: + case SK_OCLZeroEvent: { assert(Args.size() == 1); CurInit = Args[0]; if (!CurInit.get()) return ExprError(); @@ -5453,6 +5487,15 @@ InitializationSequence::Perform(Sema &S, CurInit = S.Owned(Semantic); break; } + case SK_OCLZeroEvent: { + assert(Step->Type->isEventT() && + "Event initialization on non event type."); + + CurInit = S.ImpCastExprToType(CurInit.take(), Step->Type, + CK_ZeroToOCLEvent, + CurInit.get()->getValueKind()); + break; + } } } @@ -6139,6 +6182,10 @@ void InitializationSequence::dump(raw_ostream &OS) const { case SK_StdInitializerList: OS << "std::initializer_list from initializer list"; break; + + case SK_OCLZeroEvent: + OS << "OpenCL event_t from zero"; + break; } } } diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp index 6c7032089a..bb20913dff 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_event_t: case TST_error: break; } diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 35816a42f3..a3b0c45b9d 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_event_t: + Result = Context.OCLEventTy; + break; + case DeclSpec::TST_error: Result = Context.IntTy; declarator.setInvalidType(true); diff --git a/lib/Serialization/ASTCommon.cpp b/lib/Serialization/ASTCommon.cpp index bcd8e87083..bf1e25a412 100644 --- a/lib/Serialization/ASTCommon.cpp +++ b/lib/Serialization/ASTCommon.cpp @@ -66,6 +66,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::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 c378570ddb..00bae0aea3 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -4807,6 +4807,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_EVENT_ID: T = Context.OCLEventTy; break; case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; case PREDEF_TYPE_AUTO_RREF_DEDUCT: diff --git a/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/lib/StaticAnalyzer/Core/ExprEngineC.cpp index f1ef0f6601..ea2fc3c5b2 100644 --- a/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -306,7 +306,8 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex, case CK_CPointerToObjCPointerCast: case CK_BlockPointerToObjCPointerCast: case CK_AnyPointerToBlockPointerCast: - case CK_ObjCObjectLValueCast: { + case CK_ObjCObjectLValueCast: + case CK_ZeroToOCLEvent: { // Delegate to SValBuilder to process. SVal V = state->getSVal(Ex, LCtx); V = svalBuilder.evalCast(V, T, ExTy); diff --git a/test/CodeGenOpenCL/event_t.cl b/test/CodeGenOpenCL/event_t.cl new file mode 100644 index 0000000000..ddf12a9d8b --- /dev/null +++ b/test/CodeGenOpenCL/event_t.cl @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 | FileCheck %s + +void foo(event_t evt); + +void kernel ker() { + event_t e; +// CHECK: alloca %opencl.event_t*, + foo(e); +// CHECK: call void @foo(%opencl.event_t* % + foo(0); +// CHECK: call void @foo(%opencl.event_t* null) +} diff --git a/test/CodeGenOpenCL/opencl_types.cl b/test/CodeGenOpenCL/opencl_types.cl index 35444ed9cb..ab2ebe1ce7 100644 --- a/test/CodeGenOpenCL/opencl_types.cl +++ b/test/CodeGenOpenCL/opencl_types.cl @@ -19,4 +19,6 @@ void fnc3(image3d_t img) {} // CHECK: @fnc3(%opencl.image3d_t* kernel void foo(image1d_t img) { + event_t evt; +// CHECK: alloca %opencl.event_t* } diff --git a/test/PCH/ocl_types.cl b/test/PCH/ocl_types.cl index 972853b50f..29de5e3a0e 100644 --- a/test/PCH/ocl_types.cl +++ b/test/PCH/ocl_types.cl @@ -16,3 +16,7 @@ void foo4(img2d_t img); void foo5(img2darr_t img); void foo6(img3d_t img); + +void foo8(evt_t evt) { + evt_t loc_evt; +} diff --git a/test/PCH/ocl_types.h b/test/PCH/ocl_types.h index bec065afff..829ea03151 100644 --- a/test/PCH/ocl_types.h +++ b/test/PCH/ocl_types.h @@ -17,3 +17,6 @@ typedef image2d_array_t img2darr_t; // image3d_t typedef image3d_t img3d_t; + +// event_t +typedef event_t evt_t; diff --git a/test/SemaOpenCL/event_t.cl b/test/SemaOpenCL/event_t.cl new file mode 100644 index 0000000000..57a0981cf1 --- /dev/null +++ b/test/SemaOpenCL/event_t.cl @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only + +event_t glb_evt; // expected-error {{the event_t type cannot be used to declare a program scope variable}} + +struct evt_s { + event_t evt; // expected-error {{the event_t type cannot be used to declare a structure or union field}} +} evt_str; + +void foo(event_t evt); // expected-note {{passing argument to parameter 'evt' here}} + +void kernel ker(event_t argevt) { // expected-error {{the event_t type cannot be used to declare a kernel function argument}} + event_t e; + constant event_t const_evt; // expected-error {{the event_t type can only be used with __private address space qualifier}} + foo(e); + foo(0); + foo(5); // expected-error {{passing 'int' to parameter of incompatible type 'event_t'}} +} diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index f8c6f69096..5ec0fba1a8 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1397,6 +1397,7 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { case BuiltinType::OCLImage2d: case BuiltinType::OCLImage2dArray: case BuiltinType::OCLImage3d: + case BuiltinType::OCLEvent: #define BUILTIN_TYPE(Id, SingletonId) #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp index 1cfb6a48c5..5942b42ed0 100644 --- a/tools/libclang/CIndexUSRs.cpp +++ b/tools/libclang/CIndexUSRs.cpp @@ -593,6 +593,7 @@ void USRGenerator::VisitType(QualType T) { case BuiltinType::OCLImage2d: case BuiltinType::OCLImage2dArray: case BuiltinType::OCLImage3d: + case BuiltinType::OCLEvent: IgnoreResults = true; return; case BuiltinType::ObjCId: