[PATCH] D64608: [OpenCL] Make TableGen'd builtin tables and helper functions static
Pierre added a comment. Hello Tom, Thank you for adding me, the changes seem correct to me. There is a new version of the tablegen builtin functions that makes these tables static/const. It still needs some work, so I thing it's relevant to make this change in the meantime : https://reviews.llvm.org/D63434 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D64608/new/ https://reviews.llvm.org/D64608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions
Pierre added a comment. Just one comment, Thank you again for making everything clearer :) Comment at: clang/lib/Sema/OpenCLBuiltins.td:116 +// combination of Types and vector sizes. +// +// E.g.: If TypeListField = and VectorList = <1, 2, 4>, then Maybe it would be worth adding more information on how to use GenTypes. I was thinking of something like this : When using multiple generic types : * The maximal cardinal of the used GenTypes must be the PGCM of all the cardinals. * The generic types combine as if it was an array like GenType[Type][VecSize]. I.e: With GT1 = [half, <1, 2>] and GT2 = [float, int, <1, 2>], they will combine as , , , The maximal cardinal of GT1 and GT2 is 4 (= 2 types * 2 vector sizes). 4 is the PGCM of GT1 (=2) and GT2 (=4). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D65456/new/ https://reviews.llvm.org/D65456 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D64319: [OpenCL] Add function attributes handling for builtin functions
Pierre created this revision. Pierre added reviewers: Anastasia, svenvh. Pierre added projects: clang, LLVM. Herald added subscribers: cfe-commits, kristina. Add handling to for the "overload, "pure", "constant" and "convergent" function attributes for OpenCL builtin functions. Repository: rC Clang https://reviews.llvm.org/D64319 Files: clang/lib/Sema/OpenCLBuiltins.td clang/lib/Sema/SemaLookup.cpp clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 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") && 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/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,1
[PATCH] D64320: [OpenCL] Print builtin function prototypes if ambiguous
Pierre created this revision. Pierre added reviewers: Anastasia, svenvh. Pierre added projects: clang, LLVM. Herald added subscribers: cfe-commits, kristina. When hitting an ambigous call to a builtin function with the -fdeclare-opencl-builtins option, diagnostics don't print the prototypes that clash. When not using the option above, they are displayed. This patch prints them. This is changing this diagnostic: test.cl:86:11: error: call to 'acos' is ambiguous int a = acos(p); ^~~~ test.cl:86:11: note: candidate function test.cl:86:11: note: candidate function [not printing everything ...] test.cl:86:11: note: candidate function 1 error generated. To this: test.cl:86:11: error: call to 'acos' is ambiguous int a = acos(p); ^~~~ test.cl:86:11: note: candidate function float acos(float) test.cl:86:11: note: candidate function double acos(double) [not printing everything ...] test.cl:86:11: note: candidate function __fp16 __attribute__((ext_vector_type(16))) acos(__fp16 __attribute__((ext_vector_type(16 1 error generated. Repository: rC Clang https://reviews.llvm.org/D64320 Files: clang/lib/Sema/SemaOverload.cpp Index: clang/lib/Sema/SemaOverload.cpp === --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -10425,6 +10425,25 @@ // We don't really have anything else to say about viable candidates. S.NoteOverloadCandidate(Cand->FoundDecl, Fn); + +// If this is a builtin function, give the available definitions. +if (S.getLangOpts().OpenCL && Fn->isImplicit()) { + raw_ostream &OS = llvm::outs(); + unsigned NumParams = Fn->getNumParams(); + + OS << Fn->getReturnType().getAsString() << " "; + OS << Fn->getNameInfo().getAsString() << "("; + + if (NumParams > 0) { +OS << Fn->getParamDecl(0)->getOriginalType().getAsString(); + } + for (unsigned i = 1; i < NumParams; i++) { +OS << ", "; +OS << Fn->getParamDecl(i)->getOriginalType().getAsString(); + } + OS << ")\n"; +} + return; } Index: clang/lib/Sema/SemaOverload.cpp === --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -10425,6 +10425,25 @@ // We don't really have anything else to say about viable candidates. S.NoteOverloadCandidate(Cand->FoundDecl, Fn); + +// If this is a builtin function, give the available definitions. +if (S.getLangOpts().OpenCL && Fn->isImplicit()) { + raw_ostream &OS = llvm::outs(); + unsigned NumParams = Fn->getNumParams(); + + OS << Fn->getReturnType().getAsString() << " "; + OS << Fn->getNameInfo().getAsString() << "("; + + if (NumParams > 0) { +OS << Fn->getParamDecl(0)->getOriginalType().getAsString(); + } + for (unsigned i = 1; i < NumParams; i++) { +OS << ", "; +OS << Fn->getParamDecl(i)->getOriginalType().getAsString(); + } + OS << ")\n"; +} + return; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D64321: [OpenCL] Change diagnostic for function declaration
Pierre created this revision. Pierre added reviewers: Anastasia, svenvh. Pierre added projects: clang, LLVM. Herald added a subscriber: cfe-commits. When declaring functions only differing by their return type, diagnostic was indicating "conflicting types for" the function. Similarly to c++, it is now indicating that "functions that differ only in their return type cannot be overloaded". For this code example: float test (float p) {return 2.;} double test (float p) {return 2.;} This is changing this diagnostic: tmp.cl:5:37: error: conflicting types for 'tee' float __attribute__((overloadable)) test (float p) {return 2.;} ^ tmp.cl:4:38: note: previous definition is here double __attribute__((overloadable)) test (float p) {return 2.;} ^ 1 error generated. To this: tmp.cl:5:37: error: functions that differ only in their return type cannot be overloaded float __attribute__((overloadable)) test (float p) {return 2.;} ~ ^ 1 error generated. This should maybe be extended to other languages. Repository: rC Clang https://reviews.llvm.org/D64321 Files: clang/lib/Sema/SemaDecl.cpp Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -3466,6 +3466,18 @@ return false; // Fall through for conflicting redeclarations and redefinitions. + } else if (getLangOpts().OpenCL) { +QualType OldDeclaredReturnType = Old->getDeclaredReturnType(); +QualType NewDeclaredReturnType = New->getDeclaredReturnType(); + +if (!Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) && +canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType, + OldDeclaredReturnType)) { + +Diag(New->getLocation(), diag::err_ovl_diff_return_type) +<< New->getReturnTypeSourceRange(); +return true; +} } // C: Function types need to be compatible, not identical. This handles Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -3466,6 +3466,18 @@ return false; // Fall through for conflicting redeclarations and redefinitions. + } else if (getLangOpts().OpenCL) { +QualType OldDeclaredReturnType = Old->getDeclaredReturnType(); +QualType NewDeclaredReturnType = New->getDeclaredReturnType(); + +if (!Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) && +canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType, + OldDeclaredReturnType)) { + +Diag(New->getLocation(), diag::err_ovl_diff_return_type) +<< New->getReturnTypeSourceRange(); +return true; +} } // C: Function types need to be compatible, not identical. This handles ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits