[clang] [clang][TableGen] Change OpenCL emitter to use const RecordKeeper (PR #108213)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 11 08:56:17 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
Change OpenCL builtins emitter to use const RecordKeeper
This is a part of effort to have better const correctness in TableGen backends:
https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
---
Full diff: https://github.com/llvm/llvm-project/pull/108213.diff
2 Files Affected:
- (modified) clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp (+25-21)
- (modified) clang/utils/TableGen/TableGenBackends.h (+3-3)
``````````diff
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 74c3a856ab6937..d68dcc472a7bdb 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -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
@@ -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;
@@ -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);
@@ -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;
@@ -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;
@@ -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
@@ -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.
@@ -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) {
@@ -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;
@@ -499,7 +499,7 @@ 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++));
@@ -507,7 +507,8 @@ void BuiltinNameEmitter::GetOverloads() {
// 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);
@@ -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) {
@@ -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);
@@ -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) {
@@ -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");
@@ -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) {
@@ -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();
diff --git a/clang/utils/TableGen/TableGenBackends.h b/clang/utils/TableGen/TableGenBackends.h
index 3a424c9c91fe71..601d7243e93807 100644
--- a/clang/utils/TableGen/TableGenBackends.h
+++ b/clang/utils/TableGen/TableGenBackends.h
@@ -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,
``````````
</details>
https://github.com/llvm/llvm-project/pull/108213
More information about the cfe-commits
mailing list