[PATCH] D53023: Prototype OpenCL BIFs using Tablegen

Joey Gouly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 9 07:27:58 PDT 2018


joey created this revision.
joey added reviewers: asavonic, Anastasia.
Herald added subscribers: cfe-commits, yaxunl, mgorny.

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/D53023

Files:
  Sema/SemaDecl.cpp
  Sema/SemaExpr.cpp
  SemaOpenCL/builtin-new.cl
  TableGen/CMakeLists.txt
  TableGen/ClangOpenCLBuiltinEmitter.cpp
  TableGen/TableGen.cpp
  TableGen/TableGenBackends.h
  clang/Basic/CMakeLists.txt
  clang/Basic/OpenCLBuiltins.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53023.168792.patch
Type: text/x-patch
Size: 20555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181009/b3eacb4e/attachment-0001.bin>


More information about the cfe-commits mailing list