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; }
I am trying to understand why would we need a special abstraction for the type? Would it not be easier if we just guard the BIFs by the extensions that allow the use of the type?
We would need to separate the definitions of course but this can be more helpful in order to understand what overloads are available conditionally?