Index: clang/lib/Sema/OpenCLBuiltins.td =================================================================== --- clang/lib/Sema/OpenCLBuiltins.td +++ clang/lib/Sema/OpenCLBuiltins.td @@ -208,13 +208,19 @@ //===----------------------------------------------------------------------===// // OpenCL C class for builtin functions //===----------------------------------------------------------------------===// -class Builtin _Signature> { +class Builtin _Signature, list _Attributes = [0, 0, 0]> { // Name of the builtin function string Name = _Name; // List of types used by the function. The first one is the return type and // the following are the arguments. The list must have at least one element // (the return type). list Signature = _Signature; + // OpenCL attribute : __attribute__((pure)) + bit IsPure = _Attributes[0]; + // OpenCL attribute : __attribute__((const)) + bit IsConst = _Attributes[1]; + // OpenCL attribute : __attribute__((convergent)) + bit IsConv = _Attributes[2]; // OpenCL extensions to which the function belongs (e.g.: cl_khr_subgroups) FctExtension Extension = NoFctExt; // Version of OpenCL from which the function is available (e.g.: CL10). @@ -322,12 +328,13 @@ UShort, Int, UInt, Long, ULong] in { foreach sat = ["", "_sat"] in { foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in { - def : Builtin<"convert_"#RType.Name#sat#rnd, [RType, IType]>; + def : Builtin<"convert_"#RType.Name#sat#rnd, [RType, IType], [0, 1, 0]>; foreach v = [2, 3, 4, 8, 16] in { def : Builtin<"convert_"#RType.Name#v#sat#rnd, [VectorType, - VectorType]>; + VectorType], + [0, 1, 0]>; } } } @@ -337,11 +344,11 @@ //-------------------------------------------------------------------- // OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions // --- Table 7 --- -def : Builtin<"get_work_dim", [UInt]>; +def : Builtin<"get_work_dim", [UInt], [0, 1, 0]>; foreach name = ["get_global_size", "get_global_id", "get_local_size", "get_local_id", "get_num_groups", "get_group_id", "get_global_offset"] in { - def : Builtin; + def : Builtin; } let MinVersion = CL20 in { @@ -493,18 +500,18 @@ foreach name = ["acos", "acosh", "acospi", "asin", "asinh", "asinpi", "atan", "atanh", "atanpi"] in { - def : Builtin; + def : Builtin; } foreach name = ["atan2", "atan2pi"] in { - def : Builtin; + def : Builtin; } foreach name = ["fmax", "fmin"] in { def : Builtin; - def : Builtin; - def : Builtin; - def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; } @@ -514,13 +521,13 @@ foreach name = ["read_imageh"] in { foreach Type1 = [Int, Float] in { foreach Type2 = [Image2d, Image1dArray] in { - def : Builtin, ImageType, Sampler, VectorType]>; + def : Builtin, ImageType, Sampler, VectorType], [1, 0, 0]>; } foreach Type2 = [Image3d, Image2dArray] in { - def : Builtin, ImageType, Sampler, VectorType]>; + def : Builtin, ImageType, Sampler, VectorType], [1, 0, 0]>; } foreach Type2 = [Image1d] in { - def : Builtin, ImageType, Sampler, Type1]>; + def : Builtin, ImageType, Sampler, Type1], [1, 0, 0]>; } } } Index: clang/lib/Sema/SemaLookup.cpp =================================================================== --- clang/lib/Sema/SemaLookup.cpp +++ clang/lib/Sema/SemaLookup.cpp @@ -885,7 +885,19 @@ } NewOpenCLBuiltin->setParams(ParmList); } - NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context)); + + // Add function attributes. + if (OpenCLBuiltin.IsPure) + NewOpenCLBuiltin->addAttr(PureAttr::CreateImplicit( + Context)); + if (OpenCLBuiltin.IsConst) + NewOpenCLBuiltin->addAttr(ConstAttr::CreateImplicit( + Context)); + if (OpenCLBuiltin.IsConv) + NewOpenCLBuiltin->addAttr(ConvergentAttr::CreateImplicit( + Context)); + if (GenTypeMaxCnt > 1 || Len > 1) + NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context)); // Add extensions AddExtensions(S, OpenCLBuiltin, NewOpenCLBuiltin, Index); Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp =================================================================== --- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp +++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp @@ -461,6 +461,12 @@ // the SignatureTable must be considered to build the signature. // The first type at index SigTableIndex is the return type. const unsigned NumTypes; + // OpenCL attribute : __attribute__((pure)) + const bool IsPure; + // OpenCL attribute : __attribute__((const)) + const bool IsConst; + // OpenCL attribute : __attribute__((convergent)) + const bool IsConv; // Extension to which the signature belongs (e.g.: cl_khr_subgroups) const enum OpenCLFctExtensionID Extension; // Version in which it was introduced (e.g.: CL20). MinVersion is inclusive. @@ -614,6 +620,9 @@ OS << " { " << Overload.second << ", " << Overload.first->getValueAsListOfDefs("Signature").size() << ", " + << (Overload.first->getValueAsBit("IsPure")) << ", " + << (Overload.first->getValueAsBit("IsConst")) << ", " + << (Overload.first->getValueAsBit("IsConv")) << ", " << "OCLE_" << Overload.first->getValueAsDef("Extension")->getValueAsString("ID") << ", " << Overload.first->getValueAsDef("MinVersion")->getValueAsInt("Name") << ", " << Overload.first->getValueAsDef("MaxVersion")->getValueAsInt("Name") @@ -634,7 +643,13 @@ for (unsigned Index = 0; Index < Candidate->size(); Index++) { Rec = SignatureList[Index].first; Rec2 = (SignatureListMap.find(Candidate)->second.first)[Index].first; - if (Rec->getValueAsDef("MinVersion")->getValueAsInt("Name") == + if (Rec->getValueAsBit("IsPure") == + Rec2->getValueAsBit("IsPure") && + Rec->getValueAsBit("IsConst") == + Rec2->getValueAsBit("IsConst") && + Rec->getValueAsBit("IsConv") == + Rec2->getValueAsBit("IsConv") && + Rec->getValueAsDef("MinVersion")->getValueAsInt("Name") == Rec2->getValueAsDef("MinVersion")->getValueAsInt("Name") && Rec->getValueAsDef("MaxVersion")->getValueAsInt("Name") == Rec2->getValueAsDef("MaxVersion")->getValueAsInt("Name") &&