[PATCH] D100209: [OpenCL] Do not add builtins with unavailable types

Sven van Haastregt via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 9 08:38:47 PDT 2021


svenvh created this revision.
svenvh added a reviewer: Anastasia.
svenvh added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
svenvh requested review of this revision.
Herald added a subscriber: cfe-commits.

Add functionality to assign extensions to types in `OpenCLBuiltins.td` and use that information to filter candidates that should not be exposed if a type is not available.

Most of the changes affect the addition of scalar base types into the `QT` vector in the generated `OCL2Qual` function (that is, the switch statement as described in step 1 in the `OCL2Qual` top comment).  For types that are associated with an extension, the QualType is now added only if the corresponding extension macro is defined.

The old code was as follows for the `FGenTypeN` GenericType, which represents all floating point types for all vector sizes.

  case OCLT_FGenTypeN:
    QT.append({Context.FloatTy, Context.DoubleTy, Context.HalfTy, Context.FloatTy, Context.DoubleTy, Context.HalfTy, Context.FloatTy, ...
    GenTypeNumTypes = 3;
    GenVectorSizes = ListVecAndScalar;
    break;

With this patch, the generated code becomes:

  case OCLT_FGenTypeN: {
    SmallVector<QualType, 3> TypeList;
    TypeList.push_back(Context.FloatTy);
    if (S.getPreprocessor().isMacroDefined("cl_khr_fp64")) {
      TypeList.push_back(Context.DoubleTy);
    }
    if (S.getPreprocessor().isMacroDefined("cl_khr_fp16")) {
      TypeList.push_back(Context.HalfTy);
    }
    GenTypeNumTypes = TypeList.size();
    QT.reserve(18);
    for (unsigned I = 0; I < 6; I++) {
      QT.append(TypeList);
    }
    GenVectorSizes = ListVecAndScalar;
    break;
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100209

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100209.336476.patch
Type: text/x-patch
Size: 9840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210409/faa3cd12/attachment-0001.bin>


More information about the cfe-commits mailing list