[PATCH] D60763: Prototype OpenCL BIFs using Tablegen

Pierre via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 07:52:24 PDT 2019


Pierre added a comment.

I also think we could reduce the size of the tables.
To sum up how this is working right now:

1. 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.
2. 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.
3. The OpenCLSignature is storing the possible signatures.

E.g.: For the prototype float cos(float):

1. isOpenCLBuiltin("cos") is returning the pair (345, 18)
2. OpenCLBuiltinDecl[345] to  OpenCLBuiltinDecl[345+18] are the available signatures of the builtin function "cos". Let say OpenCLBuiltinDecl[346] is containing our "float cos(float)" prototype.  OpenCLBuiltinDecl[346] is containing the pair (123, 2), indexing the OpenCLSignature table and how many entries we have to read.
3. OpenCLSignature[123] is storing the return type of the function, so the "float" type. OpenCLSignature[124] is containing the type of the first argument, so the float type again. We are not looking further in the table because we are only looking for 2 types.

---------------------------------------------------------------------------------------

In the "float cos(float)" prototype, the information about the "float" type is duplicated. Plus, this "float" type is also the same as in the "float sin(float)" function. A third table, storing the different types, would discard duplicated definitions of types. The OpenCLSignature would store indexes of the required types, and the third table the type itself. This third table would be called OpenCLTypes, and would be as:

  struct OpenCLTypes {
    // A type (e.g.: float, int, ...)
    OpenCLTypeID ID;
    // Size of the vector (if applicable)
    unsigned VectorWidth;
    // 0 if the type is not a pointer
    unsigned isPointer;
    // Address space of the pointer (if applicable)
    clang::LangAS AS;
  }

and OpenCLSignature:

  struct OpenCLSignature {
  unsigned OpenCLTypesIndex
  }

---------------------------------------------------------------------------------------

Another way to save space would be to group functions. The "sin" and "cos" functions are similar (identical, we could say), regarding their use/ signature. However, they have two distinct lists of signatures in the OpenCLBuiltinDecl table. The consequence would be that isOpenCLBuiltin("cos") and isOpenCLBuiltin("sin") would give the same output. Such group of functions could be created manually by adding an attribute in the OpenCLBuiltins.td file, or automatically generated in the ClangOpenCLBuiltinEmitter.cpp file. The first solution would however make the feature potentially less understandable/ more complex to add new functions. The second solution is complex to implement/ could require a lot of time to process.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60763/new/

https://reviews.llvm.org/D60763





More information about the cfe-commits mailing list