Skip to content

[clang][TableGen] Change OpenCL emitter to use const RecordKeeper #108213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct BuiltinTableEntries {
//
class BuiltinNameEmitter {
public:
BuiltinNameEmitter(RecordKeeper &Records, raw_ostream &OS)
BuiltinNameEmitter(const RecordKeeper &Records, raw_ostream &OS)
: Records(Records), OS(OS) {}

// Entrypoint to generate the functions and structures for checking
Expand All @@ -100,7 +100,7 @@ class BuiltinNameEmitter {

// Contains OpenCL builtin functions and related information, stored as
// Record instances. They are coming from the associated TableGen file.
RecordKeeper &Records;
const RecordKeeper &Records;

// The output file.
raw_ostream &OS;
Expand All @@ -113,7 +113,7 @@ class BuiltinNameEmitter {
// \param Output (out) String containing the enums to emit in the output file.
// \param List (out) List containing the extracted Types, except the Types in
// TypesSeen.
void ExtractEnumTypes(std::vector<Record *> &Types,
void ExtractEnumTypes(ArrayRef<const Record *> Types,
StringMap<bool> &TypesSeen, std::string &Output,
std::vector<const Record *> &List);

Expand Down Expand Up @@ -237,7 +237,7 @@ class BuiltinNameEmitter {
/// Base class for emitting a file (e.g. header or test) from OpenCLBuiltins.td
class OpenCLBuiltinFileEmitterBase {
public:
OpenCLBuiltinFileEmitterBase(RecordKeeper &Records, raw_ostream &OS)
OpenCLBuiltinFileEmitterBase(const RecordKeeper &Records, raw_ostream &OS)
: Records(Records), OS(OS) {}
virtual ~OpenCLBuiltinFileEmitterBase() = default;

Expand Down Expand Up @@ -305,7 +305,7 @@ class OpenCLBuiltinFileEmitterBase {

// Contains OpenCL builtin functions and related information, stored as
// Record instances. They are coming from the associated TableGen file.
RecordKeeper &Records;
const RecordKeeper &Records;

// The output file.
raw_ostream &OS;
Expand All @@ -316,7 +316,7 @@ class OpenCLBuiltinFileEmitterBase {
// builtin function described in the .td input.
class OpenCLBuiltinTestEmitter : public OpenCLBuiltinFileEmitterBase {
public:
OpenCLBuiltinTestEmitter(RecordKeeper &Records, raw_ostream &OS)
OpenCLBuiltinTestEmitter(const RecordKeeper &Records, raw_ostream &OS)
: OpenCLBuiltinFileEmitterBase(Records, OS) {}

// Entrypoint to generate the functions for testing all OpenCL builtin
Expand All @@ -329,7 +329,7 @@ class OpenCLBuiltinTestEmitter : public OpenCLBuiltinFileEmitterBase {
// prototype for each builtin function described in the .td input.
class OpenCLBuiltinHeaderEmitter : public OpenCLBuiltinFileEmitterBase {
public:
OpenCLBuiltinHeaderEmitter(RecordKeeper &Records, raw_ostream &OS)
OpenCLBuiltinHeaderEmitter(const RecordKeeper &Records, raw_ostream &OS)
: OpenCLBuiltinFileEmitterBase(Records, OS) {}

// Entrypoint to generate the header.
Expand Down Expand Up @@ -362,7 +362,7 @@ void BuiltinNameEmitter::Emit() {
EmitQualTypeFinder();
}

void BuiltinNameEmitter::ExtractEnumTypes(std::vector<Record *> &Types,
void BuiltinNameEmitter::ExtractEnumTypes(ArrayRef<const Record *> Types,
StringMap<bool> &TypesSeen,
std::string &Output,
std::vector<const Record *> &List) {
Expand Down Expand Up @@ -392,11 +392,11 @@ void BuiltinNameEmitter::EmitDeclarations() {
// Extract generic types and non-generic types separately, to keep
// gentypes at the end of the enum which simplifies the special handling
// for gentypes in SemaLookup.
std::vector<Record *> GenTypes =
ArrayRef<const Record *> GenTypes =
Records.getAllDerivedDefinitions("GenericType");
ExtractEnumTypes(GenTypes, TypesSeen, GenTypeEnums, GenTypeList);

std::vector<Record *> Types = Records.getAllDerivedDefinitions("Type");
ArrayRef<const Record *> Types = Records.getAllDerivedDefinitions("Type");
ExtractEnumTypes(Types, TypesSeen, TypeEnums, TypeList);

OS << TypeEnums;
Expand Down Expand Up @@ -499,15 +499,16 @@ static void VerifySignature(const std::vector<Record *> &Signature,

void BuiltinNameEmitter::GetOverloads() {
// Populate the TypeMap.
std::vector<Record *> Types = Records.getAllDerivedDefinitions("Type");
ArrayRef<const Record *> Types = Records.getAllDerivedDefinitions("Type");
unsigned I = 0;
for (const auto &T : Types) {
TypeMap.insert(std::make_pair(T, I++));
}

// Populate the SignaturesList and the FctOverloadMap.
unsigned CumulativeSignIndex = 0;
std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");
ArrayRef<const Record *> Builtins =
Records.getAllDerivedDefinitions("Builtin");
for (const auto *B : Builtins) {
StringRef BName = B->getValueAsString("Name");
FctOverloadMap.try_emplace(BName);
Expand Down Expand Up @@ -535,7 +536,7 @@ void BuiltinNameEmitter::GetOverloads() {
void BuiltinNameEmitter::EmitExtensionTable() {
OS << "static const char *FunctionExtensionTable[] = {\n";
unsigned Index = 0;
std::vector<Record *> FuncExtensions =
ArrayRef<const Record *> FuncExtensions =
Records.getAllDerivedDefinitions("FunctionExtension");

for (const auto &FE : FuncExtensions) {
Expand Down Expand Up @@ -804,11 +805,11 @@ static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,
OS << "\n switch (Ty.ID) {\n";

// Switch cases for image types (Image2d, Image3d, ...)
std::vector<Record *> ImageTypes =
ArrayRef<const Record *> ImageTypes =
Records.getAllDerivedDefinitions("ImageType");

// Map an image type name to its 3 access-qualified types (RO, WO, RW).
StringMap<SmallVector<Record *, 3>> ImageTypesMap;
StringMap<SmallVector<const Record *, 3>> ImageTypesMap;
for (auto *IT : ImageTypes)
ImageTypesMap[IT->getValueAsString("Name")].push_back(IT);

Expand Down Expand Up @@ -890,7 +891,7 @@ static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,
// Switch cases for non generic, non image types (int, int4, float, ...).
// Only insert the plain scalar type; vector information and type qualifiers
// are added in step 2.
std::vector<Record *> Types = Records.getAllDerivedDefinitions("Type");
ArrayRef<const Record *> Types = Records.getAllDerivedDefinitions("Type");
StringMap<bool> TypesSeen;

for (const auto *T : Types) {
Expand Down Expand Up @@ -1211,7 +1212,8 @@ void OpenCLBuiltinTestEmitter::emit() {
unsigned TestID = 0;

// Iterate over all builtins.
std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");
ArrayRef<const Record *> Builtins =
Records.getAllDerivedDefinitions("Builtin");
for (const auto *B : Builtins) {
StringRef Name = B->getValueAsString("Name");

Expand Down Expand Up @@ -1274,7 +1276,8 @@ void OpenCLBuiltinHeaderEmitter::emit() {
)";

// Iterate over all builtins; sort to follow order of definition in .td file.
std::vector<Record *> Builtins = Records.getAllDerivedDefinitions("Builtin");
std::vector<const Record *> Builtins =
Records.getAllDerivedDefinitions("Builtin");
llvm::sort(Builtins, LessRecord());

for (const auto *B : Builtins) {
Expand Down Expand Up @@ -1319,18 +1322,19 @@ void OpenCLBuiltinHeaderEmitter::emit() {
"#pragma OPENCL EXTENSION all : disable\n";
}

void clang::EmitClangOpenCLBuiltins(RecordKeeper &Records, raw_ostream &OS) {
void clang::EmitClangOpenCLBuiltins(const RecordKeeper &Records,
raw_ostream &OS) {
BuiltinNameEmitter NameChecker(Records, OS);
NameChecker.Emit();
}

void clang::EmitClangOpenCLBuiltinHeader(RecordKeeper &Records,
void clang::EmitClangOpenCLBuiltinHeader(const RecordKeeper &Records,
raw_ostream &OS) {
OpenCLBuiltinHeaderEmitter HeaderFileGenerator(Records, OS);
HeaderFileGenerator.emit();
}

void clang::EmitClangOpenCLBuiltinTests(RecordKeeper &Records,
void clang::EmitClangOpenCLBuiltinTests(const RecordKeeper &Records,
raw_ostream &OS) {
OpenCLBuiltinTestEmitter TestFileGenerator(Records, OS);
TestFileGenerator.emit();
Expand Down
6 changes: 3 additions & 3 deletions clang/utils/TableGen/TableGenBackends.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ void EmitClangAttrDocs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitClangDiagDocs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitClangOptDocs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);

void EmitClangOpenCLBuiltins(llvm::RecordKeeper &Records,
void EmitClangOpenCLBuiltins(const llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
void EmitClangOpenCLBuiltinHeader(llvm::RecordKeeper &Records,
void EmitClangOpenCLBuiltinHeader(const llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
void EmitClangOpenCLBuiltinTests(llvm::RecordKeeper &Records,
void EmitClangOpenCLBuiltinTests(const llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);

void EmitClangDataCollectors(llvm::RecordKeeper &Records,
Expand Down
Loading