- User Since
- Apr 15 2019, 3:20 AM (8 w, 5 d)
Tue, Jun 11
Dependencies were not satisfied with the last version:
clangSema was built after ClangOpenCLBuiltinsImpl,
but it didn't imply that OpenCLBuiltins.inc had to be built before SemaLookup.cpp
Mon, Jun 10
It was not necessary to add the .inc file in the add_clang_library
Wed, Jun 5
At the right location this time
Tue, Jun 4
Thu, May 23
Tue, May 21
The wrong patch was uploaded. Sorry for this.
Fri, May 17
Corrections from the comments on the previous version.
May 3 2019
Requested changes have been made in this diff. Some comments/ TODO have not been done yet. They will be done in a next patch. This first patch is meant to start introducing the feature in Clang.
This patch integrates the new command line option introduced in https://reviews.llvm.org/D60764
Apr 25 2019
I also think we could reduce the size of the tables.
To sum up how this is working right now:
- The isOpenCLBuiltin(char* functionName) funcion is called to determine if a function is part of OpenCL builtin functions. If so, it returns its associated pair (index, number of signatures) in the OpenCLBuiltinDecl, otherwise it returns 0.
- The OpenCLBuiltinDecl table is storing, for each OpenCL builtin function, the list of the possible signature associated for this function (e.g. cos can be "float cos(float)", "double cos(double)", ...). The available signatures are stored in the OpenCLSignature table. In the OpenCLBuiltinDecl are stored the indexes corresponding to the possible signature for each function.
- The OpenCLSignature is storing the possible signatures.
When a header file is included, its function declarations are decorated with the "nounwind" attribute, meaning that the function is not supposed to throw an exception. This decorator is currently not added with the new mechanism.
The "readnone" decorator is also present for these builtin functions and added somewhere y clang, but not added with the new mechanism.
This can be tested with the following command line, on an .cl file containing a function calling a builtin function (e.g.: acos):
clang -cc1 -cl-std=CL2.0 -emit-llvm -O0 -I<path_to>/llvm-project/clang/lib/Headers <your_file.cl> [-fadd-opencl-builtins|-finclude-default-header]
When the function definition is inserted, it seems to be actually just resolving the identifier for the current lookup. Calling the same builtin function multiple times currently result in multiple lookup. Maybe there is a way to add the function declaration for the scope/file, so the lookup is only performed one time for each function. This part is done around the code taken from Sema::LazilyCreateBuiltin function, and I will spend more time on it.
I haven't looked at the test file yet.
If you have any suggestion/comment, feel free to share.
In this new patch:
- Documentation has been added
- The multiclasses in OpenCLBuiltins.td filehave been slighly changed to have a more generic way to generate function prototypes
- In ClangOpenCLBuiltinEmitter.cpp, the code of the Emit() function has been shifted to functions
- In SemaLookUp.cpp, the OCL2Qual function, used to retrieve the QualType instance of a type, is now generated by Tablegen backend
Forgot to update one argument
Apr 24 2019
The name of the command line option has been updated.
Apr 16 2019
Deleted blank line