Path: blob/main/contrib/llvm-project/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
35230 views
//===- ClangOpenCLBuiltinEmitter.cpp - Generate Clang OpenCL Builtin handling1//2// The LLVM Compiler Infrastructure3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9//10// These backends consume the definitions of OpenCL builtin functions in11// clang/lib/Sema/OpenCLBuiltins.td and produce builtin handling code for12// inclusion in SemaLookup.cpp, or a test file that calls all declared builtins.13//14//===----------------------------------------------------------------------===//1516#include "TableGenBackends.h"17#include "llvm/ADT/MapVector.h"18#include "llvm/ADT/STLExtras.h"19#include "llvm/ADT/SmallSet.h"20#include "llvm/ADT/SmallString.h"21#include "llvm/ADT/StringExtras.h"22#include "llvm/ADT/StringMap.h"23#include "llvm/ADT/StringRef.h"24#include "llvm/ADT/StringSwitch.h"25#include "llvm/Support/ErrorHandling.h"26#include "llvm/Support/raw_ostream.h"27#include "llvm/TableGen/Error.h"28#include "llvm/TableGen/Record.h"29#include "llvm/TableGen/StringMatcher.h"30#include "llvm/TableGen/TableGenBackend.h"3132using namespace llvm;3334namespace {3536// A list of signatures that are shared by one or more builtin functions.37struct BuiltinTableEntries {38SmallVector<StringRef, 4> Names;39std::vector<std::pair<const Record *, unsigned>> Signatures;40};4142// This tablegen backend emits code for checking whether a function is an43// OpenCL builtin function. If so, all overloads of this function are44// added to the LookupResult. The generated include file is used by45// SemaLookup.cpp46//47// For a successful lookup of e.g. the "cos" builtin, isOpenCLBuiltin("cos")48// returns a pair <Index, Len>.49// BuiltinTable[Index] to BuiltinTable[Index + Len] contains the pairs50// <SigIndex, SigLen> of the overloads of "cos".51// SignatureTable[SigIndex] to SignatureTable[SigIndex + SigLen] contains52// one of the signatures of "cos". The SignatureTable entry can be53// referenced by other functions, e.g. "sin", to exploit the fact that54// many OpenCL builtins share the same signature.55//56// The file generated by this TableGen emitter contains the following:57//58// * Structs and enums to represent types and function signatures.59//60// * const char *FunctionExtensionTable[]61// List of space-separated OpenCL extensions. A builtin references an62// entry in this table when the builtin requires a particular (set of)63// extension(s) to be enabled.64//65// * OpenCLTypeStruct TypeTable[]66// Type information for return types and arguments.67//68// * unsigned SignatureTable[]69// A list of types representing function signatures. Each entry is an index70// into the above TypeTable. Multiple entries following each other form a71// signature, where the first entry is the return type and subsequent72// entries are the argument types.73//74// * OpenCLBuiltinStruct BuiltinTable[]75// Each entry represents one overload of an OpenCL builtin function and76// consists of an index into the SignatureTable and the number of arguments.77//78// * std::pair<unsigned, unsigned> isOpenCLBuiltin(llvm::StringRef Name)79// Find out whether a string matches an existing OpenCL builtin function80// name and return an index into BuiltinTable and the number of overloads.81//82// * void OCL2Qual(Sema&, OpenCLTypeStruct, std::vector<QualType>&)83// Convert an OpenCLTypeStruct type to a list of QualType instances.84// One OpenCLTypeStruct can represent multiple types, primarily when using85// GenTypes.86//87class BuiltinNameEmitter {88public:89BuiltinNameEmitter(RecordKeeper &Records, raw_ostream &OS)90: Records(Records), OS(OS) {}9192// Entrypoint to generate the functions and structures for checking93// whether a function is an OpenCL builtin function.94void Emit();9596private:97// A list of indices into the builtin function table.98using BuiltinIndexListTy = SmallVector<unsigned, 11>;99100// Contains OpenCL builtin functions and related information, stored as101// Record instances. They are coming from the associated TableGen file.102RecordKeeper &Records;103104// The output file.105raw_ostream &OS;106107// Helper function for BuiltinNameEmitter::EmitDeclarations. Generate enum108// definitions in the Output string parameter, and save their Record instances109// in the List parameter.110// \param Types (in) List containing the Types to extract.111// \param TypesSeen (inout) List containing the Types already extracted.112// \param Output (out) String containing the enums to emit in the output file.113// \param List (out) List containing the extracted Types, except the Types in114// TypesSeen.115void ExtractEnumTypes(std::vector<Record *> &Types,116StringMap<bool> &TypesSeen, std::string &Output,117std::vector<const Record *> &List);118119// Emit the enum or struct used in the generated file.120// Populate the TypeList at the same time.121void EmitDeclarations();122123// Parse the Records generated by TableGen to populate the SignaturesList,124// FctOverloadMap and TypeMap.125void GetOverloads();126127// Compare two lists of signatures and check that e.g. the OpenCL version,128// function attributes, and extension are equal for each signature.129// \param Candidate (in) Entry in the SignatureListMap to check.130// \param SignatureList (in) List of signatures of the considered function.131// \returns true if the two lists of signatures are identical.132bool CanReuseSignature(133BuiltinIndexListTy *Candidate,134std::vector<std::pair<const Record *, unsigned>> &SignatureList);135136// Group functions with the same list of signatures by populating the137// SignatureListMap.138// Some builtin functions have the same list of signatures, for example the139// "sin" and "cos" functions. To save space in the BuiltinTable, the140// "isOpenCLBuiltin" function will have the same output for these two141// function names.142void GroupBySignature();143144// Emit the FunctionExtensionTable that lists all function extensions.145void EmitExtensionTable();146147// Emit the TypeTable containing all types used by OpenCL builtins.148void EmitTypeTable();149150// Emit the SignatureTable. This table contains all the possible signatures.151// A signature is stored as a list of indexes of the TypeTable.152// The first index references the return type (mandatory), and the followings153// reference its arguments.154// E.g.:155// 15, 2, 15 can represent a function with the signature:156// int func(float, int)157// The "int" type being at the index 15 in the TypeTable.158void EmitSignatureTable();159160// Emit the BuiltinTable table. This table contains all the overloads of161// each function, and is a struct OpenCLBuiltinDecl.162// E.g.:163// // 891 convert_float2_rtn164// { 58, 2, 3, 100, 0 },165// This means that the signature of this convert_float2_rtn overload has166// 1 argument (+1 for the return type), stored at index 58 in167// the SignatureTable. This prototype requires extension "3" in the168// FunctionExtensionTable. The last two values represent the minimum (1.0)169// and maximum (0, meaning no max version) OpenCL version in which this170// overload is supported.171void EmitBuiltinTable();172173// Emit a StringMatcher function to check whether a function name is an174// OpenCL builtin function name.175void EmitStringMatcher();176177// Emit a function returning the clang QualType instance associated with178// the TableGen Record Type.179void EmitQualTypeFinder();180181// Contains a list of the available signatures, without the name of the182// function. Each pair consists of a signature and a cumulative index.183// E.g.: <<float, float>, 0>,184// <<float, int, int, 2>>,185// <<float>, 5>,186// ...187// <<double, double>, 35>.188std::vector<std::pair<std::vector<Record *>, unsigned>> SignaturesList;189190// Map the name of a builtin function to its prototypes (instances of the191// TableGen "Builtin" class).192// Each prototype is registered as a pair of:193// <pointer to the "Builtin" instance,194// cumulative index of the associated signature in the SignaturesList>195// E.g.: The function cos: (float cos(float), double cos(double), ...)196// <"cos", <<ptrToPrototype0, 5>,197// <ptrToPrototype1, 35>,198// <ptrToPrototype2, 79>>199// ptrToPrototype1 has the following signature: <double, double>200MapVector<StringRef, std::vector<std::pair<const Record *, unsigned>>>201FctOverloadMap;202203// Contains the map of OpenCL types to their index in the TypeTable.204MapVector<const Record *, unsigned> TypeMap;205206// List of OpenCL function extensions mapping extension strings to207// an index into the FunctionExtensionTable.208StringMap<unsigned> FunctionExtensionIndex;209210// List of OpenCL type names in the same order as in enum OpenCLTypeID.211// This list does not contain generic types.212std::vector<const Record *> TypeList;213214// Same as TypeList, but for generic types only.215std::vector<const Record *> GenTypeList;216217// Map an ordered vector of signatures to their original Record instances,218// and to a list of function names that share these signatures.219//220// For example, suppose the "cos" and "sin" functions have only three221// signatures, and these signatures are at index Ix in the SignatureTable:222// cos | sin | Signature | Index223// float cos(float) | float sin(float) | Signature1 | I1224// double cos(double) | double sin(double) | Signature2 | I2225// half cos(half) | half sin(half) | Signature3 | I3226//227// Then we will create a mapping of the vector of signatures:228// SignatureListMap[<I1, I2, I3>] = <229// <"cos", "sin">,230// <Signature1, Signature2, Signature3>>231// The function "tan", having the same signatures, would be mapped to the232// same entry (<I1, I2, I3>).233MapVector<BuiltinIndexListTy *, BuiltinTableEntries> SignatureListMap;234};235236/// Base class for emitting a file (e.g. header or test) from OpenCLBuiltins.td237class OpenCLBuiltinFileEmitterBase {238public:239OpenCLBuiltinFileEmitterBase(RecordKeeper &Records, raw_ostream &OS)240: Records(Records), OS(OS) {}241virtual ~OpenCLBuiltinFileEmitterBase() = default;242243// Entrypoint to generate the functions for testing all OpenCL builtin244// functions.245virtual void emit() = 0;246247protected:248struct TypeFlags {249TypeFlags() : IsConst(false), IsVolatile(false), IsPointer(false) {}250bool IsConst : 1;251bool IsVolatile : 1;252bool IsPointer : 1;253StringRef AddrSpace;254};255256// Return a string representation of the given type, such that it can be257// used as a type in OpenCL C code.258std::string getTypeString(const Record *Type, TypeFlags Flags,259int VectorSize) const;260261// Return the type(s) and vector size(s) for the given type. For262// non-GenericTypes, the resulting vectors will contain 1 element. For263// GenericTypes, the resulting vectors typically contain multiple elements.264void getTypeLists(Record *Type, TypeFlags &Flags,265std::vector<Record *> &TypeList,266std::vector<int64_t> &VectorList) const;267268// Expand the TableGen Records representing a builtin function signature into269// one or more function signatures. Return them as a vector of a vector of270// strings, with each string containing an OpenCL C type and optional271// qualifiers.272//273// The Records may contain GenericTypes, which expand into multiple274// signatures. Repeated occurrences of GenericType in a signature expand to275// the same types. For example [char, FGenType, FGenType] expands to:276// [char, float, float]277// [char, float2, float2]278// [char, float3, float3]279// ...280void281expandTypesInSignature(const std::vector<Record *> &Signature,282SmallVectorImpl<SmallVector<std::string, 2>> &Types);283284// Emit extension enabling pragmas.285void emitExtensionSetup();286287// Emit an #if guard for a Builtin's extension. Return the corresponding288// closing #endif, or an empty string if no extension #if guard was emitted.289std::string emitExtensionGuard(const Record *Builtin);290291// Emit an #if guard for a Builtin's language version. Return the292// corresponding closing #endif, or an empty string if no version #if guard293// was emitted.294std::string emitVersionGuard(const Record *Builtin);295296// Emit an #if guard for all type extensions required for the given type297// strings. Return the corresponding closing #endif, or an empty string298// if no extension #if guard was emitted.299StringRef300emitTypeExtensionGuards(const SmallVectorImpl<std::string> &Signature);301302// Map type strings to type extensions (e.g. "half2" -> "cl_khr_fp16").303StringMap<StringRef> TypeExtMap;304305// Contains OpenCL builtin functions and related information, stored as306// Record instances. They are coming from the associated TableGen file.307RecordKeeper &Records;308309// The output file.310raw_ostream &OS;311};312313// OpenCL builtin test generator. This class processes the same TableGen input314// as BuiltinNameEmitter, but generates a .cl file that contains a call to each315// builtin function described in the .td input.316class OpenCLBuiltinTestEmitter : public OpenCLBuiltinFileEmitterBase {317public:318OpenCLBuiltinTestEmitter(RecordKeeper &Records, raw_ostream &OS)319: OpenCLBuiltinFileEmitterBase(Records, OS) {}320321// Entrypoint to generate the functions for testing all OpenCL builtin322// functions.323void emit() override;324};325326// OpenCL builtin header generator. This class processes the same TableGen327// input as BuiltinNameEmitter, but generates a .h file that contains a328// prototype for each builtin function described in the .td input.329class OpenCLBuiltinHeaderEmitter : public OpenCLBuiltinFileEmitterBase {330public:331OpenCLBuiltinHeaderEmitter(RecordKeeper &Records, raw_ostream &OS)332: OpenCLBuiltinFileEmitterBase(Records, OS) {}333334// Entrypoint to generate the header.335void emit() override;336};337338} // namespace339340void BuiltinNameEmitter::Emit() {341emitSourceFileHeader("OpenCL Builtin handling", OS, Records);342343OS << "#include \"llvm/ADT/StringRef.h\"\n";344OS << "using namespace clang;\n\n";345346// Emit enums and structs.347EmitDeclarations();348349// Parse the Records to populate the internal lists.350GetOverloads();351GroupBySignature();352353// Emit tables.354EmitExtensionTable();355EmitTypeTable();356EmitSignatureTable();357EmitBuiltinTable();358359// Emit functions.360EmitStringMatcher();361EmitQualTypeFinder();362}363364void BuiltinNameEmitter::ExtractEnumTypes(std::vector<Record *> &Types,365StringMap<bool> &TypesSeen,366std::string &Output,367std::vector<const Record *> &List) {368raw_string_ostream SS(Output);369370for (const auto *T : Types) {371if (!TypesSeen.contains(T->getValueAsString("Name"))) {372SS << " OCLT_" + T->getValueAsString("Name") << ",\n";373// Save the type names in the same order as their enum value. Note that374// the Record can be a VectorType or something else, only the name is375// important.376List.push_back(T);377TypesSeen.insert(std::make_pair(T->getValueAsString("Name"), true));378}379}380SS.flush();381}382383void BuiltinNameEmitter::EmitDeclarations() {384// Enum of scalar type names (float, int, ...) and generic type sets.385OS << "enum OpenCLTypeID {\n";386387StringMap<bool> TypesSeen;388std::string GenTypeEnums;389std::string TypeEnums;390391// Extract generic types and non-generic types separately, to keep392// gentypes at the end of the enum which simplifies the special handling393// for gentypes in SemaLookup.394std::vector<Record *> GenTypes =395Records.getAllDerivedDefinitions("GenericType");396ExtractEnumTypes(GenTypes, TypesSeen, GenTypeEnums, GenTypeList);397398std::vector<Record *> Types = Records.getAllDerivedDefinitions("Type");399ExtractEnumTypes(Types, TypesSeen, TypeEnums, TypeList);400401OS << TypeEnums;402OS << GenTypeEnums;403OS << "};\n";404405// Structure definitions.406OS << R"(407// Image access qualifier.408enum OpenCLAccessQual : unsigned char {409OCLAQ_None,410OCLAQ_ReadOnly,411OCLAQ_WriteOnly,412OCLAQ_ReadWrite413};414415// Represents a return type or argument type.416struct OpenCLTypeStruct {417// A type (e.g. float, int, ...).418const OpenCLTypeID ID;419// Vector size (if applicable; 0 for scalars and generic types).420const unsigned VectorWidth;421// 0 if the type is not a pointer.422const bool IsPointer : 1;423// 0 if the type is not const.424const bool IsConst : 1;425// 0 if the type is not volatile.426const bool IsVolatile : 1;427// Access qualifier.428const OpenCLAccessQual AccessQualifier;429// Address space of the pointer (if applicable).430const LangAS AS;431};432433// One overload of an OpenCL builtin function.434struct OpenCLBuiltinStruct {435// Index of the signature in the OpenCLTypeStruct table.436const unsigned SigTableIndex;437// Entries between index SigTableIndex and (SigTableIndex + NumTypes - 1) in438// the SignatureTable represent the complete signature. The first type at439// index SigTableIndex is the return type.440const unsigned NumTypes;441// Function attribute __attribute__((pure))442const bool IsPure : 1;443// Function attribute __attribute__((const))444const bool IsConst : 1;445// Function attribute __attribute__((convergent))446const bool IsConv : 1;447// OpenCL extension(s) required for this overload.448const unsigned short Extension;449// OpenCL versions in which this overload is available.450const unsigned short Versions;451};452453)";454}455456// Verify that the combination of GenTypes in a signature is supported.457// To simplify the logic for creating overloads in SemaLookup, only allow458// a signature to contain different GenTypes if these GenTypes represent459// the same number of actual scalar or vector types.460//461// Exit with a fatal error if an unsupported construct is encountered.462static void VerifySignature(const std::vector<Record *> &Signature,463const Record *BuiltinRec) {464unsigned GenTypeVecSizes = 1;465unsigned GenTypeTypes = 1;466467for (const auto *T : Signature) {468// Check all GenericType arguments in this signature.469if (T->isSubClassOf("GenericType")) {470// Check number of vector sizes.471unsigned NVecSizes =472T->getValueAsDef("VectorList")->getValueAsListOfInts("List").size();473if (NVecSizes != GenTypeVecSizes && NVecSizes != 1) {474if (GenTypeVecSizes > 1) {475// We already saw a gentype with a different number of vector sizes.476PrintFatalError(BuiltinRec->getLoc(),477"number of vector sizes should be equal or 1 for all gentypes "478"in a declaration");479}480GenTypeVecSizes = NVecSizes;481}482483// Check number of data types.484unsigned NTypes =485T->getValueAsDef("TypeList")->getValueAsListOfDefs("List").size();486if (NTypes != GenTypeTypes && NTypes != 1) {487if (GenTypeTypes > 1) {488// We already saw a gentype with a different number of types.489PrintFatalError(BuiltinRec->getLoc(),490"number of types should be equal or 1 for all gentypes "491"in a declaration");492}493GenTypeTypes = NTypes;494}495}496}497}498499void BuiltinNameEmitter::GetOverloads() {500// Populate the TypeMap.501std::vector<Record *> Types = Records.getAllDerivedDefinitions("Type");502unsigned I = 0;503for (const auto &T : Types) {504TypeMap.insert(std::make_pair(T, I++));505}506507// Populate the SignaturesList and the FctOverloadMap.508unsigned CumulativeSignIndex = 0;509std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");510for (const auto *B : Builtins) {511StringRef BName = B->getValueAsString("Name");512if (!FctOverloadMap.contains(BName)) {513FctOverloadMap.insert(std::make_pair(514BName, std::vector<std::pair<const Record *, unsigned>>{}));515}516517auto Signature = B->getValueAsListOfDefs("Signature");518// Reuse signatures to avoid unnecessary duplicates.519auto it =520llvm::find_if(SignaturesList,521[&](const std::pair<std::vector<Record *>, unsigned> &a) {522return a.first == Signature;523});524unsigned SignIndex;525if (it == SignaturesList.end()) {526VerifySignature(Signature, B);527SignaturesList.push_back(std::make_pair(Signature, CumulativeSignIndex));528SignIndex = CumulativeSignIndex;529CumulativeSignIndex += Signature.size();530} else {531SignIndex = it->second;532}533FctOverloadMap[BName].push_back(std::make_pair(B, SignIndex));534}535}536537void BuiltinNameEmitter::EmitExtensionTable() {538OS << "static const char *FunctionExtensionTable[] = {\n";539unsigned Index = 0;540std::vector<Record *> FuncExtensions =541Records.getAllDerivedDefinitions("FunctionExtension");542543for (const auto &FE : FuncExtensions) {544// Emit OpenCL extension table entry.545OS << " // " << Index << ": " << FE->getName() << "\n"546<< " \"" << FE->getValueAsString("ExtName") << "\",\n";547548// Record index of this extension.549FunctionExtensionIndex[FE->getName()] = Index++;550}551OS << "};\n\n";552}553554void BuiltinNameEmitter::EmitTypeTable() {555OS << "static const OpenCLTypeStruct TypeTable[] = {\n";556for (const auto &T : TypeMap) {557const char *AccessQual =558StringSwitch<const char *>(T.first->getValueAsString("AccessQualifier"))559.Case("RO", "OCLAQ_ReadOnly")560.Case("WO", "OCLAQ_WriteOnly")561.Case("RW", "OCLAQ_ReadWrite")562.Default("OCLAQ_None");563564OS << " // " << T.second << "\n"565<< " {OCLT_" << T.first->getValueAsString("Name") << ", "566<< T.first->getValueAsInt("VecWidth") << ", "567<< T.first->getValueAsBit("IsPointer") << ", "568<< T.first->getValueAsBit("IsConst") << ", "569<< T.first->getValueAsBit("IsVolatile") << ", "570<< AccessQual << ", "571<< T.first->getValueAsString("AddrSpace") << "},\n";572}573OS << "};\n\n";574}575576void BuiltinNameEmitter::EmitSignatureTable() {577// Store a type (e.g. int, float, int2, ...). The type is stored as an index578// of a struct OpenCLType table. Multiple entries following each other form a579// signature.580OS << "static const unsigned short SignatureTable[] = {\n";581for (const auto &P : SignaturesList) {582OS << " // " << P.second << "\n ";583for (const Record *R : P.first) {584unsigned Entry = TypeMap.find(R)->second;585if (Entry > USHRT_MAX) {586// Report an error when seeing an entry that is too large for the587// current index type (unsigned short). When hitting this, the type588// of SignatureTable will need to be changed.589PrintFatalError("Entry in SignatureTable exceeds limit.");590}591OS << Entry << ", ";592}593OS << "\n";594}595OS << "};\n\n";596}597598// Encode a range MinVersion..MaxVersion into a single bit mask that can be599// checked against LangOpts using isOpenCLVersionContainedInMask().600// This must be kept in sync with OpenCLVersionID in OpenCLOptions.h.601// (Including OpenCLOptions.h here would be a layering violation.)602static unsigned short EncodeVersions(unsigned int MinVersion,603unsigned int MaxVersion) {604unsigned short Encoded = 0;605606// A maximum version of 0 means available in all later versions.607if (MaxVersion == 0) {608MaxVersion = UINT_MAX;609}610611unsigned VersionIDs[] = {100, 110, 120, 200, 300};612for (unsigned I = 0; I < std::size(VersionIDs); I++) {613if (VersionIDs[I] >= MinVersion && VersionIDs[I] < MaxVersion) {614Encoded |= 1 << I;615}616}617618return Encoded;619}620621void BuiltinNameEmitter::EmitBuiltinTable() {622unsigned Index = 0;623624OS << "static const OpenCLBuiltinStruct BuiltinTable[] = {\n";625for (const auto &SLM : SignatureListMap) {626627OS << " // " << (Index + 1) << ": ";628for (const auto &Name : SLM.second.Names) {629OS << Name << ", ";630}631OS << "\n";632633for (const auto &Overload : SLM.second.Signatures) {634StringRef ExtName = Overload.first->getValueAsDef("Extension")->getName();635unsigned int MinVersion =636Overload.first->getValueAsDef("MinVersion")->getValueAsInt("ID");637unsigned int MaxVersion =638Overload.first->getValueAsDef("MaxVersion")->getValueAsInt("ID");639640OS << " { " << Overload.second << ", "641<< Overload.first->getValueAsListOfDefs("Signature").size() << ", "642<< (Overload.first->getValueAsBit("IsPure")) << ", "643<< (Overload.first->getValueAsBit("IsConst")) << ", "644<< (Overload.first->getValueAsBit("IsConv")) << ", "645<< FunctionExtensionIndex[ExtName] << ", "646<< EncodeVersions(MinVersion, MaxVersion) << " },\n";647Index++;648}649}650OS << "};\n\n";651}652653bool BuiltinNameEmitter::CanReuseSignature(654BuiltinIndexListTy *Candidate,655std::vector<std::pair<const Record *, unsigned>> &SignatureList) {656assert(Candidate->size() == SignatureList.size() &&657"signature lists should have the same size");658659auto &CandidateSigs =660SignatureListMap.find(Candidate)->second.Signatures;661for (unsigned Index = 0; Index < Candidate->size(); Index++) {662const Record *Rec = SignatureList[Index].first;663const Record *Rec2 = CandidateSigs[Index].first;664if (Rec->getValueAsBit("IsPure") == Rec2->getValueAsBit("IsPure") &&665Rec->getValueAsBit("IsConst") == Rec2->getValueAsBit("IsConst") &&666Rec->getValueAsBit("IsConv") == Rec2->getValueAsBit("IsConv") &&667Rec->getValueAsDef("MinVersion")->getValueAsInt("ID") ==668Rec2->getValueAsDef("MinVersion")->getValueAsInt("ID") &&669Rec->getValueAsDef("MaxVersion")->getValueAsInt("ID") ==670Rec2->getValueAsDef("MaxVersion")->getValueAsInt("ID") &&671Rec->getValueAsDef("Extension")->getName() ==672Rec2->getValueAsDef("Extension")->getName()) {673return true;674}675}676return false;677}678679void BuiltinNameEmitter::GroupBySignature() {680// List of signatures known to be emitted.681std::vector<BuiltinIndexListTy *> KnownSignatures;682683for (auto &Fct : FctOverloadMap) {684bool FoundReusableSig = false;685686// Gather all signatures for the current function.687auto *CurSignatureList = new BuiltinIndexListTy();688for (const auto &Signature : Fct.second) {689CurSignatureList->push_back(Signature.second);690}691// Sort the list to facilitate future comparisons.692llvm::sort(*CurSignatureList);693694// Check if we have already seen another function with the same list of695// signatures. If so, just add the name of the function.696for (auto *Candidate : KnownSignatures) {697if (Candidate->size() == CurSignatureList->size() &&698*Candidate == *CurSignatureList) {699if (CanReuseSignature(Candidate, Fct.second)) {700SignatureListMap.find(Candidate)->second.Names.push_back(Fct.first);701FoundReusableSig = true;702}703}704}705706if (FoundReusableSig) {707delete CurSignatureList;708} else {709// Add a new entry.710SignatureListMap[CurSignatureList] = {711SmallVector<StringRef, 4>(1, Fct.first), Fct.second};712KnownSignatures.push_back(CurSignatureList);713}714}715716for (auto *I : KnownSignatures) {717delete I;718}719}720721void BuiltinNameEmitter::EmitStringMatcher() {722std::vector<StringMatcher::StringPair> ValidBuiltins;723unsigned CumulativeIndex = 1;724725for (const auto &SLM : SignatureListMap) {726const auto &Ovl = SLM.second.Signatures;727728// A single signature list may be used by different builtins. Return the729// same <index, length> pair for each of those builtins.730for (const auto &FctName : SLM.second.Names) {731std::string RetStmt;732raw_string_ostream SS(RetStmt);733SS << "return std::make_pair(" << CumulativeIndex << ", " << Ovl.size()734<< ");";735SS.flush();736ValidBuiltins.push_back(737StringMatcher::StringPair(std::string(FctName), RetStmt));738}739CumulativeIndex += Ovl.size();740}741742OS << R"(743// Find out whether a string matches an existing OpenCL builtin function name.744// Returns: A pair <0, 0> if no name matches.745// A pair <Index, Len> indexing the BuiltinTable if the name is746// matching an OpenCL builtin function.747static std::pair<unsigned, unsigned> isOpenCLBuiltin(llvm::StringRef Name) {748749)";750751StringMatcher("Name", ValidBuiltins, OS).Emit(0, true);752753OS << " return std::make_pair(0, 0);\n";754OS << "} // isOpenCLBuiltin\n";755}756757// Emit an if-statement with an isMacroDefined call for each extension in758// the space-separated list of extensions.759static void EmitMacroChecks(raw_ostream &OS, StringRef Extensions) {760SmallVector<StringRef, 2> ExtVec;761Extensions.split(ExtVec, " ");762OS << " if (";763for (StringRef Ext : ExtVec) {764if (Ext != ExtVec.front())765OS << " && ";766OS << "S.getPreprocessor().isMacroDefined(\"" << Ext << "\")";767}768OS << ") {\n ";769}770771void BuiltinNameEmitter::EmitQualTypeFinder() {772OS << R"(773774static QualType getOpenCLEnumType(Sema &S, llvm::StringRef Name);775static QualType getOpenCLTypedefType(Sema &S, llvm::StringRef Name);776777// Convert an OpenCLTypeStruct type to a list of QualTypes.778// Generic types represent multiple types and vector sizes, thus a vector779// is returned. The conversion is done in two steps:780// Step 1: A switch statement fills a vector with scalar base types for the781// Cartesian product of (vector sizes) x (types) for generic types,782// or a single scalar type for non generic types.783// Step 2: Qualifiers and other type properties such as vector size are784// applied.785static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,786llvm::SmallVectorImpl<QualType> &QT) {787ASTContext &Context = S.Context;788// Number of scalar types in the GenType.789unsigned GenTypeNumTypes;790// Pointer to the list of vector sizes for the GenType.791llvm::ArrayRef<unsigned> GenVectorSizes;792)";793794// Generate list of vector sizes for each generic type.795for (const auto *VectList : Records.getAllDerivedDefinitions("IntList")) {796OS << " constexpr unsigned List"797<< VectList->getValueAsString("Name") << "[] = {";798for (const auto V : VectList->getValueAsListOfInts("List")) {799OS << V << ", ";800}801OS << "};\n";802}803804// Step 1.805// Start of switch statement over all types.806OS << "\n switch (Ty.ID) {\n";807808// Switch cases for image types (Image2d, Image3d, ...)809std::vector<Record *> ImageTypes =810Records.getAllDerivedDefinitions("ImageType");811812// Map an image type name to its 3 access-qualified types (RO, WO, RW).813StringMap<SmallVector<Record *, 3>> ImageTypesMap;814for (auto *IT : ImageTypes) {815auto Entry = ImageTypesMap.find(IT->getValueAsString("Name"));816if (Entry == ImageTypesMap.end()) {817SmallVector<Record *, 3> ImageList;818ImageList.push_back(IT);819ImageTypesMap.insert(820std::make_pair(IT->getValueAsString("Name"), ImageList));821} else {822Entry->second.push_back(IT);823}824}825826// Emit the cases for the image types. For an image type name, there are 3827// corresponding QualTypes ("RO", "WO", "RW"). The "AccessQualifier" field828// tells which one is needed. Emit a switch statement that puts the829// corresponding QualType into "QT".830for (const auto &ITE : ImageTypesMap) {831OS << " case OCLT_" << ITE.getKey() << ":\n"832<< " switch (Ty.AccessQualifier) {\n"833<< " case OCLAQ_None:\n"834<< " llvm_unreachable(\"Image without access qualifier\");\n";835for (const auto &Image : ITE.getValue()) {836StringRef Exts =837Image->getValueAsDef("Extension")->getValueAsString("ExtName");838OS << StringSwitch<const char *>(839Image->getValueAsString("AccessQualifier"))840.Case("RO", " case OCLAQ_ReadOnly:\n")841.Case("WO", " case OCLAQ_WriteOnly:\n")842.Case("RW", " case OCLAQ_ReadWrite:\n");843if (!Exts.empty()) {844OS << " ";845EmitMacroChecks(OS, Exts);846}847OS << " QT.push_back("848<< Image->getValueAsDef("QTExpr")->getValueAsString("TypeExpr")849<< ");\n";850if (!Exts.empty()) {851OS << " }\n";852}853OS << " break;\n";854}855OS << " }\n"856<< " break;\n";857}858859// Switch cases for generic types.860for (const auto *GenType : Records.getAllDerivedDefinitions("GenericType")) {861OS << " case OCLT_" << GenType->getValueAsString("Name") << ": {\n";862863// Build the Cartesian product of (vector sizes) x (types). Only insert864// the plain scalar types for now; other type information such as vector865// size and type qualifiers will be added after the switch statement.866std::vector<Record *> BaseTypes =867GenType->getValueAsDef("TypeList")->getValueAsListOfDefs("List");868869// Collect all QualTypes for a single vector size into TypeList.870OS << " SmallVector<QualType, " << BaseTypes.size() << "> TypeList;\n";871for (const auto *T : BaseTypes) {872StringRef Exts =873T->getValueAsDef("Extension")->getValueAsString("ExtName");874if (!Exts.empty()) {875EmitMacroChecks(OS, Exts);876}877OS << " TypeList.push_back("878<< T->getValueAsDef("QTExpr")->getValueAsString("TypeExpr") << ");\n";879if (!Exts.empty()) {880OS << " }\n";881}882}883OS << " GenTypeNumTypes = TypeList.size();\n";884885// Duplicate the TypeList for every vector size.886std::vector<int64_t> VectorList =887GenType->getValueAsDef("VectorList")->getValueAsListOfInts("List");888OS << " QT.reserve(" << VectorList.size() * BaseTypes.size() << ");\n"889<< " for (unsigned I = 0; I < " << VectorList.size() << "; I++) {\n"890<< " QT.append(TypeList);\n"891<< " }\n";892893// GenVectorSizes is the list of vector sizes for this GenType.894OS << " GenVectorSizes = List"895<< GenType->getValueAsDef("VectorList")->getValueAsString("Name")896<< ";\n"897<< " break;\n"898<< " }\n";899}900901// Switch cases for non generic, non image types (int, int4, float, ...).902// Only insert the plain scalar type; vector information and type qualifiers903// are added in step 2.904std::vector<Record *> Types = Records.getAllDerivedDefinitions("Type");905StringMap<bool> TypesSeen;906907for (const auto *T : Types) {908// Check this is not an image type909if (ImageTypesMap.contains(T->getValueAsString("Name")))910continue;911// Check we have not seen this Type912if (TypesSeen.contains(T->getValueAsString("Name")))913continue;914TypesSeen.insert(std::make_pair(T->getValueAsString("Name"), true));915916// Check the Type does not have an "abstract" QualType917auto QT = T->getValueAsDef("QTExpr");918if (QT->getValueAsBit("IsAbstract") == 1)919continue;920// Emit the cases for non generic, non image types.921OS << " case OCLT_" << T->getValueAsString("Name") << ":\n";922923StringRef Exts = T->getValueAsDef("Extension")->getValueAsString("ExtName");924// If this type depends on an extension, ensure the extension macros are925// defined.926if (!Exts.empty()) {927EmitMacroChecks(OS, Exts);928}929OS << " QT.push_back(" << QT->getValueAsString("TypeExpr") << ");\n";930if (!Exts.empty()) {931OS << " }\n";932}933OS << " break;\n";934}935936// End of switch statement.937OS << " } // end of switch (Ty.ID)\n\n";938939// Step 2.940// Add ExtVector types if this was a generic type, as the switch statement941// above only populated the list with scalar types. This completes the942// construction of the Cartesian product of (vector sizes) x (types).943OS << " // Construct the different vector types for each generic type.\n";944OS << " if (Ty.ID >= " << TypeList.size() << ") {";945OS << R"(946for (unsigned I = 0; I < QT.size(); I++) {947// For scalars, size is 1.948if (GenVectorSizes[I / GenTypeNumTypes] != 1) {949QT[I] = Context.getExtVectorType(QT[I],950GenVectorSizes[I / GenTypeNumTypes]);951}952}953}954)";955956// Assign the right attributes to the types (e.g. vector size).957OS << R"(958// Set vector size for non-generic vector types.959if (Ty.VectorWidth > 1) {960for (unsigned Index = 0; Index < QT.size(); Index++) {961QT[Index] = Context.getExtVectorType(QT[Index], Ty.VectorWidth);962}963}964965if (Ty.IsVolatile != 0) {966for (unsigned Index = 0; Index < QT.size(); Index++) {967QT[Index] = Context.getVolatileType(QT[Index]);968}969}970971if (Ty.IsConst != 0) {972for (unsigned Index = 0; Index < QT.size(); Index++) {973QT[Index] = Context.getConstType(QT[Index]);974}975}976977// Transform the type to a pointer as the last step, if necessary.978// Builtin functions only have pointers on [const|volatile], no979// [const|volatile] pointers, so this is ok to do it as a last step.980if (Ty.IsPointer != 0) {981for (unsigned Index = 0; Index < QT.size(); Index++) {982QT[Index] = Context.getAddrSpaceQualType(QT[Index], Ty.AS);983QT[Index] = Context.getPointerType(QT[Index]);984}985}986)";987988// End of the "OCL2Qual" function.989OS << "\n} // OCL2Qual\n";990}991992std::string OpenCLBuiltinFileEmitterBase::getTypeString(const Record *Type,993TypeFlags Flags,994int VectorSize) const {995std::string S;996if (Type->getValueAsBit("IsConst") || Flags.IsConst) {997S += "const ";998}999if (Type->getValueAsBit("IsVolatile") || Flags.IsVolatile) {1000S += "volatile ";1001}10021003auto PrintAddrSpace = [&S](StringRef AddrSpace) {1004S += StringSwitch<const char *>(AddrSpace)1005.Case("clang::LangAS::opencl_private", "__private")1006.Case("clang::LangAS::opencl_global", "__global")1007.Case("clang::LangAS::opencl_constant", "__constant")1008.Case("clang::LangAS::opencl_local", "__local")1009.Case("clang::LangAS::opencl_generic", "__generic")1010.Default("__private");1011S += " ";1012};1013if (Flags.IsPointer) {1014PrintAddrSpace(Flags.AddrSpace);1015} else if (Type->getValueAsBit("IsPointer")) {1016PrintAddrSpace(Type->getValueAsString("AddrSpace"));1017}10181019StringRef Acc = Type->getValueAsString("AccessQualifier");1020if (Acc != "") {1021S += StringSwitch<const char *>(Acc)1022.Case("RO", "__read_only ")1023.Case("WO", "__write_only ")1024.Case("RW", "__read_write ");1025}10261027S += Type->getValueAsString("Name").str();1028if (VectorSize > 1) {1029S += std::to_string(VectorSize);1030}10311032if (Type->getValueAsBit("IsPointer") || Flags.IsPointer) {1033S += " *";1034}10351036return S;1037}10381039void OpenCLBuiltinFileEmitterBase::getTypeLists(1040Record *Type, TypeFlags &Flags, std::vector<Record *> &TypeList,1041std::vector<int64_t> &VectorList) const {1042bool isGenType = Type->isSubClassOf("GenericType");1043if (isGenType) {1044TypeList = Type->getValueAsDef("TypeList")->getValueAsListOfDefs("List");1045VectorList =1046Type->getValueAsDef("VectorList")->getValueAsListOfInts("List");1047return;1048}10491050if (Type->isSubClassOf("PointerType") || Type->isSubClassOf("ConstType") ||1051Type->isSubClassOf("VolatileType")) {1052StringRef SubTypeName = Type->getValueAsString("Name");1053Record *PossibleGenType = Records.getDef(SubTypeName);1054if (PossibleGenType && PossibleGenType->isSubClassOf("GenericType")) {1055// When PointerType, ConstType, or VolatileType is applied to a1056// GenericType, the flags need to be taken from the subtype, not from the1057// GenericType.1058Flags.IsPointer = Type->getValueAsBit("IsPointer");1059Flags.IsConst = Type->getValueAsBit("IsConst");1060Flags.IsVolatile = Type->getValueAsBit("IsVolatile");1061Flags.AddrSpace = Type->getValueAsString("AddrSpace");1062getTypeLists(PossibleGenType, Flags, TypeList, VectorList);1063return;1064}1065}10661067// Not a GenericType, so just insert the single type.1068TypeList.push_back(Type);1069VectorList.push_back(Type->getValueAsInt("VecWidth"));1070}10711072void OpenCLBuiltinFileEmitterBase::expandTypesInSignature(1073const std::vector<Record *> &Signature,1074SmallVectorImpl<SmallVector<std::string, 2>> &Types) {1075// Find out if there are any GenTypes in this signature, and if so, calculate1076// into how many signatures they will expand.1077unsigned NumSignatures = 1;1078SmallVector<SmallVector<std::string, 4>, 4> ExpandedGenTypes;1079for (const auto &Arg : Signature) {1080SmallVector<std::string, 4> ExpandedArg;1081std::vector<Record *> TypeList;1082std::vector<int64_t> VectorList;1083TypeFlags Flags;10841085getTypeLists(Arg, Flags, TypeList, VectorList);10861087// Insert the Cartesian product of the types and vector sizes.1088for (const auto &Vector : VectorList) {1089for (const auto &Type : TypeList) {1090std::string FullType = getTypeString(Type, Flags, Vector);1091ExpandedArg.push_back(FullType);10921093// If the type requires an extension, add a TypeExtMap entry mapping1094// the full type name to the extension.1095StringRef Ext =1096Type->getValueAsDef("Extension")->getValueAsString("ExtName");1097if (!Ext.empty() && !TypeExtMap.contains(FullType)) {1098TypeExtMap.insert({FullType, Ext});1099}1100}1101}1102NumSignatures = std::max<unsigned>(NumSignatures, ExpandedArg.size());1103ExpandedGenTypes.push_back(ExpandedArg);1104}11051106// Now the total number of signatures is known. Populate the return list with1107// all signatures.1108for (unsigned I = 0; I < NumSignatures; I++) {1109SmallVector<std::string, 2> Args;11101111// Process a single signature.1112for (unsigned ArgNum = 0; ArgNum < Signature.size(); ArgNum++) {1113// For differently-sized GenTypes in a parameter list, the smaller1114// GenTypes just repeat, so index modulo the number of expanded types.1115size_t TypeIndex = I % ExpandedGenTypes[ArgNum].size();1116Args.push_back(ExpandedGenTypes[ArgNum][TypeIndex]);1117}1118Types.push_back(Args);1119}1120}11211122void OpenCLBuiltinFileEmitterBase::emitExtensionSetup() {1123OS << R"(1124#pragma OPENCL EXTENSION cl_khr_fp16 : enable1125#pragma OPENCL EXTENSION cl_khr_fp64 : enable1126#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable1127#pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable1128#pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable1129#pragma OPENCL EXTENSION cl_khr_mipmap_image_writes : enable1130#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable11311132)";1133}11341135std::string1136OpenCLBuiltinFileEmitterBase::emitExtensionGuard(const Record *Builtin) {1137StringRef Extensions =1138Builtin->getValueAsDef("Extension")->getValueAsString("ExtName");1139if (Extensions.empty())1140return "";11411142OS << "#if";11431144SmallVector<StringRef, 2> ExtVec;1145Extensions.split(ExtVec, " ");1146bool isFirst = true;1147for (StringRef Ext : ExtVec) {1148if (!isFirst) {1149OS << " &&";1150}1151OS << " defined(" << Ext << ")";1152isFirst = false;1153}1154OS << "\n";11551156return "#endif // Extension\n";1157}11581159std::string1160OpenCLBuiltinFileEmitterBase::emitVersionGuard(const Record *Builtin) {1161std::string OptionalEndif;1162auto PrintOpenCLVersion = [this](int Version) {1163OS << "CL_VERSION_" << (Version / 100) << "_" << ((Version % 100) / 10);1164};1165int MinVersion = Builtin->getValueAsDef("MinVersion")->getValueAsInt("ID");1166if (MinVersion != 100) {1167// OpenCL 1.0 is the default minimum version.1168OS << "#if __OPENCL_C_VERSION__ >= ";1169PrintOpenCLVersion(MinVersion);1170OS << "\n";1171OptionalEndif = "#endif // MinVersion\n" + OptionalEndif;1172}1173int MaxVersion = Builtin->getValueAsDef("MaxVersion")->getValueAsInt("ID");1174if (MaxVersion) {1175OS << "#if __OPENCL_C_VERSION__ < ";1176PrintOpenCLVersion(MaxVersion);1177OS << "\n";1178OptionalEndif = "#endif // MaxVersion\n" + OptionalEndif;1179}1180return OptionalEndif;1181}11821183StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(1184const SmallVectorImpl<std::string> &Signature) {1185SmallSet<StringRef, 2> ExtSet;11861187// Iterate over all types to gather the set of required TypeExtensions.1188for (const auto &Ty : Signature) {1189StringRef TypeExt = TypeExtMap.lookup(Ty);1190if (!TypeExt.empty()) {1191// The TypeExtensions are space-separated in the .td file.1192SmallVector<StringRef, 2> ExtVec;1193TypeExt.split(ExtVec, " ");1194for (const auto Ext : ExtVec) {1195ExtSet.insert(Ext);1196}1197}1198}11991200// Emit the #if only when at least one extension is required.1201if (ExtSet.empty())1202return "";12031204OS << "#if ";1205bool isFirst = true;1206for (const auto Ext : ExtSet) {1207if (!isFirst)1208OS << " && ";1209OS << "defined(" << Ext << ")";1210isFirst = false;1211}1212OS << "\n";1213return "#endif // TypeExtension\n";1214}12151216void OpenCLBuiltinTestEmitter::emit() {1217emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS, Records);12181219emitExtensionSetup();12201221// Ensure each test has a unique name by numbering them.1222unsigned TestID = 0;12231224// Iterate over all builtins.1225std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");1226for (const auto *B : Builtins) {1227StringRef Name = B->getValueAsString("Name");12281229SmallVector<SmallVector<std::string, 2>, 4> FTypes;1230expandTypesInSignature(B->getValueAsListOfDefs("Signature"), FTypes);12311232OS << "// Test " << Name << "\n";12331234std::string OptionalExtensionEndif = emitExtensionGuard(B);1235std::string OptionalVersionEndif = emitVersionGuard(B);12361237for (const auto &Signature : FTypes) {1238StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);12391240// Emit function declaration.1241OS << Signature[0] << " test" << TestID++ << "_" << Name << "(";1242if (Signature.size() > 1) {1243for (unsigned I = 1; I < Signature.size(); I++) {1244if (I != 1)1245OS << ", ";1246OS << Signature[I] << " arg" << I;1247}1248}1249OS << ") {\n";12501251// Emit function body.1252OS << " ";1253if (Signature[0] != "void") {1254OS << "return ";1255}1256OS << Name << "(";1257for (unsigned I = 1; I < Signature.size(); I++) {1258if (I != 1)1259OS << ", ";1260OS << "arg" << I;1261}1262OS << ");\n";12631264// End of function body.1265OS << "}\n";1266OS << OptionalTypeExtEndif;1267}12681269OS << OptionalVersionEndif;1270OS << OptionalExtensionEndif;1271}1272}12731274void OpenCLBuiltinHeaderEmitter::emit() {1275emitSourceFileHeader("OpenCL Builtin declarations", OS, Records);12761277emitExtensionSetup();12781279OS << R"(1280#define __ovld __attribute__((overloadable))1281#define __conv __attribute__((convergent))1282#define __purefn __attribute__((pure))1283#define __cnfn __attribute__((const))12841285)";12861287// Iterate over all builtins; sort to follow order of definition in .td file.1288std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");1289llvm::sort(Builtins, LessRecord());12901291for (const auto *B : Builtins) {1292StringRef Name = B->getValueAsString("Name");12931294std::string OptionalExtensionEndif = emitExtensionGuard(B);1295std::string OptionalVersionEndif = emitVersionGuard(B);12961297SmallVector<SmallVector<std::string, 2>, 4> FTypes;1298expandTypesInSignature(B->getValueAsListOfDefs("Signature"), FTypes);12991300for (const auto &Signature : FTypes) {1301StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);13021303// Emit function declaration.1304OS << Signature[0] << " __ovld ";1305if (B->getValueAsBit("IsConst"))1306OS << "__cnfn ";1307if (B->getValueAsBit("IsPure"))1308OS << "__purefn ";1309if (B->getValueAsBit("IsConv"))1310OS << "__conv ";13111312OS << Name << "(";1313if (Signature.size() > 1) {1314for (unsigned I = 1; I < Signature.size(); I++) {1315if (I != 1)1316OS << ", ";1317OS << Signature[I];1318}1319}1320OS << ");\n";13211322OS << OptionalTypeExtEndif;1323}13241325OS << OptionalVersionEndif;1326OS << OptionalExtensionEndif;1327}13281329OS << "\n// Disable any extensions we may have enabled previously.\n"1330"#pragma OPENCL EXTENSION all : disable\n";1331}13321333void clang::EmitClangOpenCLBuiltins(RecordKeeper &Records, raw_ostream &OS) {1334BuiltinNameEmitter NameChecker(Records, OS);1335NameChecker.Emit();1336}13371338void clang::EmitClangOpenCLBuiltinHeader(RecordKeeper &Records,1339raw_ostream &OS) {1340OpenCLBuiltinHeaderEmitter HeaderFileGenerator(Records, OS);1341HeaderFileGenerator.emit();1342}13431344void clang::EmitClangOpenCLBuiltinTests(RecordKeeper &Records,1345raw_ostream &OS) {1346OpenCLBuiltinTestEmitter TestFileGenerator(Records, OS);1347TestFileGenerator.emit();1348}134913501351