[PATCH] D60763: Prototype OpenCL BIFs using Tablegen
Pierre via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 16 01:45:13 PDT 2019
Pierre created this revision.
Pierre added reviewers: Anastasia, svenvh.
Herald added subscribers: cfe-commits, yaxunl, mgorny.
Herald added a project: clang.
**This is a re-upload of the patch from Joey GOULY, posted at: https://reviews.llvm.org/D53023 . I am re-uploading it because I will continue his work on this, and it is better if I have control on the post on phabricator.**
This patch contains a prototype to generate OpenCL builtin functions with Tablegen. Not all builtin functions have been implemented. This prototype is intented to replace the use of the opencl-c.h file currently included in all OpenCL programs. To recall, this file contains contains all the overloaded builtin functions. Using clang-tblgen would allow to factorize all these function declarations and include them only if they are called.
**A copy-paste from the original description:**
This is the prototype for the approach that was mentioned by Anastasia in http://lists.llvm.org/pipermail/cfe-dev/2018-September/059529.html
The tablegen file describes the BIFs and all their overloads, in hopefully a concise manner.
There are 3 things generated from the OpenCLBuiltins.td file.
1. OpenCLArgTypes[], this is a table containing all the different types of overloads. This is a separate table so it can be shared by the BIFs.
2. OpenCLBuiltins[], this is a table that contains all the overloads for the BIFs.
3. isOpenCLBuiltin, this is a function that uses a trie-like switch/case to determine if a StringRef is the name of a BIF.
Just a quick snippet of the above:
OpenCLType OpenCLArgTypes[] = {
// 0
{ OCLT_float, 0, 0, clang::LangAS::Default, },
// 1
{ OCLT_float, 2, 0, clang::LangAS::Default, },
OpenCLBuiltinDecl OpenCLBuiltins[] = {
// acos
{ { OCLT_float, 0, 0, clang::LangAS::Default, }, 1, 0, "", 100, },
{ { OCLT_float, 2, 0, clang::LangAS::Default, }, 1, 1, "", 100, },
std::pair<unsigned, unsigned> isOpenCLBuiltin(llvm::StringRef name) {
switch (name.size()) {
default: break;
case 3: // 1 string to match.
if (memcmp(name.data()+0, "foo", 3) != 0)
break;
return std::make_pair(707, 2); // "foo"
}
While it's a prototype, I have tried to keep it as clean as possible.
TODO:
1. Bit-pack the tables to reduce the size.
2. Include the return type in the ArgTypes table to reduce the size.
3. Measure the performance / size impact
4. Auto-generate parts of OCL2Qual, to reduce repeated typing
5. OCL2Qual does not support pointers-to-pointers currently, but I believe no BIFs use that.
6. InsertBuiltinDeclarations builds up an AST function declaration manually, perhaps there is a helper function for this.
7. There is a FIXME in SemaDecl.cpp that needs to be implemented.
Repository:
rC Clang
https://reviews.llvm.org/D60763
Files:
clang/include/clang/Basic/CMakeLists.txt
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/OpenCLBuiltins.td
clang/lib/Sema/SemaLookup.cpp
clang/test/SemaOpenCL/builtin-new.cl
clang/utils/TableGen/CMakeLists.txt
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
clang/utils/TableGen/TableGen.cpp
clang/utils/TableGen/TableGenBackends.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60763.195331.patch
Type: text/x-patch
Size: 20820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190416/14f244d8/attachment-0001.bin>
More information about the cfe-commits
mailing list