[libc-commits] [libc] 98563b1 - [libc][TableGen] Migrate libc-hdrgen backend to use const RecordKeeper (#107542)

via libc-commits libc-commits at lists.llvm.org
Sat Sep 7 15:14:10 PDT 2024


Author: Rahul Joshi
Date: 2024-09-07T15:14:07-07:00
New Revision: 98563b19c2d13bac7fb5ee2717ccae6279699e4c

URL: https://github.com/llvm/llvm-project/commit/98563b19c2d13bac7fb5ee2717ccae6279699e4c
DIFF: https://github.com/llvm/llvm-project/commit/98563b19c2d13bac7fb5ee2717ccae6279699e4c.diff

LOG: [libc][TableGen] Migrate libc-hdrgen backend to use const RecordKeeper (#107542)

Migrate libc-hdrgen backend to use const RecordKeeper

Added: 
    

Modified: 
    libc/utils/HdrGen/Command.h
    libc/utils/HdrGen/Generator.cpp
    libc/utils/HdrGen/Generator.h
    libc/utils/HdrGen/IncludeFileCommand.cpp
    libc/utils/HdrGen/IncludeFileCommand.h
    libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
    libc/utils/HdrGen/PublicAPICommand.cpp
    libc/utils/HdrGen/PublicAPICommand.h
    libc/utils/LibcTableGenUtil/APIIndexer.cpp
    libc/utils/LibcTableGenUtil/APIIndexer.h
    llvm/include/llvm/TableGen/Record.h
    llvm/lib/TableGen/Record.cpp

Removed: 
    


################################################################################
diff  --git a/libc/utils/HdrGen/Command.h b/libc/utils/HdrGen/Command.h
index 895f472c3ad32d..42516798ffaec0 100644
--- a/libc/utils/HdrGen/Command.h
+++ b/libc/utils/HdrGen/Command.h
@@ -45,7 +45,7 @@ class Command {
   virtual ~Command();
 
   virtual void run(llvm::raw_ostream &OS, const ArgVector &Args,
-                   llvm::StringRef StdHeader, llvm::RecordKeeper &Records,
+                   llvm::StringRef StdHeader, const llvm::RecordKeeper &Records,
                    const ErrorReporter &Reporter) const = 0;
 };
 

diff  --git a/libc/utils/HdrGen/Generator.cpp b/libc/utils/HdrGen/Generator.cpp
index d926d5d9ac3c8d..b4e1166b1a37b2 100644
--- a/libc/utils/HdrGen/Generator.cpp
+++ b/libc/utils/HdrGen/Generator.cpp
@@ -64,7 +64,8 @@ void Generator::parseCommandArgs(llvm::StringRef ArgStr, ArgVector &Args) {
   }
 }
 
-void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
+void Generator::generate(llvm::raw_ostream &OS,
+                         const llvm::RecordKeeper &Records) {
   auto DefFileBuffer = llvm::MemoryBuffer::getFile(HeaderDefFile);
   if (!DefFileBuffer) {
     llvm::errs() << "Unable to open " << HeaderDefFile << ".\n";
@@ -126,7 +127,7 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
 }
 
 void Generator::generateDecls(llvm::raw_ostream &OS,
-                              llvm::RecordKeeper &Records) {
+                              const llvm::RecordKeeper &Records) {
 
   OS << "//===-- C standard declarations for " << StdHeader << " "
      << std::string(80 - (42 + StdHeader.size()), '-') << "===//\n"
@@ -161,15 +162,15 @@ void Generator::generateDecls(llvm::raw_ostream &OS,
     if (G.FunctionSpecMap.find(Name) == G.FunctionSpecMap.end())
       continue;
 
-    llvm::Record *FunctionSpec = G.FunctionSpecMap[Name];
-    llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
-    llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
+    const llvm::Record *FunctionSpec = G.FunctionSpecMap[Name];
+    const llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
+    const llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
 
     OS << G.getTypeAsString(ReturnType) << " " << Name << "(";
 
     auto ArgsList = FunctionSpec->getValueAsListOfDefs("Args");
     for (size_t i = 0; i < ArgsList.size(); ++i) {
-      llvm::Record *ArgType = ArgsList[i]->getValueAsDef("ArgType");
+      const llvm::Record *ArgType = ArgsList[i]->getValueAsDef("ArgType");
       OS << G.getTypeAsString(ArgType);
       if (i < ArgsList.size() - 1)
         OS << ", ";
@@ -182,7 +183,7 @@ void Generator::generateDecls(llvm::raw_ostream &OS,
   for (const auto &Name : EntrypointNameList) {
     if (G.ObjectSpecMap.find(Name) == G.ObjectSpecMap.end())
       continue;
-    llvm::Record *ObjectSpec = G.ObjectSpecMap[Name];
+    const llvm::Record *ObjectSpec = G.ObjectSpecMap[Name];
     auto Type = ObjectSpec->getValueAsString("Type");
     OS << "extern " << Type << " " << Name << " __LIBC_ATTRS;\n";
   }

diff  --git a/libc/utils/HdrGen/Generator.h b/libc/utils/HdrGen/Generator.h
index 76a8a110832112..1c149d21156407 100644
--- a/libc/utils/HdrGen/Generator.h
+++ b/libc/utils/HdrGen/Generator.h
@@ -51,8 +51,8 @@ class Generator {
       : HeaderDefFile(DefFile), EntrypointNameList(EN), StdHeader(Header),
         ArgMap(Map) {}
 
-  void generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records);
-  void generateDecls(llvm::raw_ostream &OS, llvm::RecordKeeper &Records);
+  void generate(llvm::raw_ostream &OS, const llvm::RecordKeeper &Records);
+  void generateDecls(llvm::raw_ostream &OS, const llvm::RecordKeeper &Records);
 };
 
 } // namespace llvm_libc

diff  --git a/libc/utils/HdrGen/IncludeFileCommand.cpp b/libc/utils/HdrGen/IncludeFileCommand.cpp
index 02cfb65b06b200..43efe43585eb20 100644
--- a/libc/utils/HdrGen/IncludeFileCommand.cpp
+++ b/libc/utils/HdrGen/IncludeFileCommand.cpp
@@ -19,7 +19,7 @@ const char IncludeFileCommand::Name[] = "include_file";
 
 void IncludeFileCommand::run(llvm::raw_ostream &OS, const ArgVector &Args,
                              llvm::StringRef StdHeader,
-                             llvm::RecordKeeper &Records,
+                             const llvm::RecordKeeper &Records,
                              const Command::ErrorReporter &Reporter) const {
   if (Args.size() != 1) {
     Reporter.printFatalError(

diff  --git a/libc/utils/HdrGen/IncludeFileCommand.h b/libc/utils/HdrGen/IncludeFileCommand.h
index 240e803a7dc2b4..b3a6ff5462ded0 100644
--- a/libc/utils/HdrGen/IncludeFileCommand.h
+++ b/libc/utils/HdrGen/IncludeFileCommand.h
@@ -23,7 +23,7 @@ class IncludeFileCommand : public Command {
   static const char Name[];
 
   void run(llvm::raw_ostream &OS, const ArgVector &Args,
-           llvm::StringRef StdHeader, llvm::RecordKeeper &Records,
+           llvm::StringRef StdHeader, const llvm::RecordKeeper &Records,
            const Command::ErrorReporter &Reporter) const override;
 };
 

diff  --git a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
index 551b97caf81fd6..7acaf75c4c1c8b 100644
--- a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
+++ b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
@@ -21,7 +21,8 @@ llvm::cl::list<std::string>
 
 } // anonymous namespace
 
-bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
+bool TestGeneratorMain(llvm::raw_ostream &OS,
+                       const llvm::RecordKeeper &records) {
   OS << "#include \"src/__support/CPP/type_traits.h\"\n";
   llvm_libc::APIIndexer G(records);
   std::unordered_set<std::string> headerFileSet;

diff  --git a/libc/utils/HdrGen/PublicAPICommand.cpp b/libc/utils/HdrGen/PublicAPICommand.cpp
index 37cd3b7ea77565..2a7f63eb25c722 100644
--- a/libc/utils/HdrGen/PublicAPICommand.cpp
+++ b/libc/utils/HdrGen/PublicAPICommand.cpp
@@ -70,7 +70,7 @@ static bool isAsciiIdentifier(llvm::StringRef S) {
   return true;
 }
 
-static AttributeStyle getAttributeStyle(llvm::Record *Instance) {
+static AttributeStyle getAttributeStyle(const llvm::Record *Instance) {
   llvm::StringRef Style = Instance->getValueAsString("Style");
   return llvm::StringSwitch<AttributeStyle>(Style)
       .Case("cxx11", AttributeStyle::Cxx11)
@@ -79,7 +79,7 @@ static AttributeStyle getAttributeStyle(llvm::Record *Instance) {
       .Default(AttributeStyle::Gnu);
 }
 
-static AttributeNamespace getAttributeNamespace(llvm::Record *Instance) {
+static AttributeNamespace getAttributeNamespace(const llvm::Record *Instance) {
   llvm::StringRef Namespace = Instance->getValueAsString("Namespace");
   return llvm::StringSwitch<AttributeNamespace>(Namespace)
       .Case("clang", AttributeNamespace::Clang)
@@ -87,21 +87,20 @@ static AttributeNamespace getAttributeNamespace(llvm::Record *Instance) {
       .Default(AttributeNamespace::None);
 }
 
-using AttributeMap = llvm::DenseMap<llvm::StringRef, llvm::Record *>;
+using AttributeMap = llvm::DenseMap<llvm::StringRef, const llvm::Record *>;
 
 template <class SpecMap, class FuncList>
 static AttributeMap collectAttributeMacros(const SpecMap &Spec,
                                            const FuncList &Funcs) {
-  llvm::DenseMap<llvm::StringRef, llvm::Record *> MacroAttr;
+  llvm::DenseMap<llvm::StringRef, const llvm::Record *> MacroAttr;
   for (const auto &Name : Funcs) {
     auto Iter = Spec.find(Name);
     if (Iter == Spec.end())
       continue;
 
-    llvm::Record *FunctionSpec = Iter->second;
-    std::vector<llvm::Record *> Attributes =
-        FunctionSpec->getValueAsListOfDefs("Attributes");
-    for (llvm::Record *Attr : Attributes)
+    const llvm::Record *FunctionSpec = Iter->second;
+    for (const llvm::Record *Attr :
+         FunctionSpec->getValueAsListOfDefs("Attributes"))
       MacroAttr[Attr->getValueAsString("Macro")] = Attr;
   }
   return MacroAttr;
@@ -112,11 +111,11 @@ static void emitAttributeMacroDecls(const AttributeMap &MacroAttr,
   for (auto &[Macro, Attr] : MacroAttr) {
     std::vector<llvm::Record *> Instances =
         Attr->getValueAsListOfDefs("Instances");
-    llvm::SmallVector<std::pair<AttributeStyle, llvm::Record *>> Styles;
+    llvm::SmallVector<std::pair<AttributeStyle, const llvm::Record *>> Styles;
     std::transform(Instances.begin(), Instances.end(),
                    std::back_inserter(Styles),
-                   [&](llvm::Record *Instance)
-                       -> std::pair<AttributeStyle, llvm::Record *> {
+                   [&](const llvm::Record *Instance)
+                       -> std::pair<AttributeStyle, const llvm::Record *> {
                      auto Style = getAttributeStyle(Instance);
                      return {Style, Instance};
                    });
@@ -195,7 +194,7 @@ static void emitAttributeMacroForFunction(const llvm::Record *FunctionSpec,
       FunctionSpec->getValueAsListOfDefs("Attributes");
   llvm::interleave(
       Attributes.begin(), Attributes.end(),
-      [&](llvm::Record *Attr) { OS << Attr->getValueAsString("Macro"); },
+      [&](const llvm::Record *Attr) { OS << Attr->getValueAsString("Macro"); },
       [&]() { OS << ' '; });
   if (!Attributes.empty())
     OS << ' ';
@@ -217,7 +216,7 @@ static void writeAPIFromIndex(APIIndexer &G,
     if (!G.MacroSpecMap.count(Name))
       llvm::PrintFatalError(Name + " not found in any standard spec.\n");
 
-    llvm::Record *MacroDef = Pair.second;
+    const llvm::Record *MacroDef = Pair.second;
     dedentAndWrite(MacroDef->getValueAsString("Defn"), OS);
 
     OS << '\n';
@@ -237,7 +236,7 @@ static void writeAPIFromIndex(APIIndexer &G,
       llvm::PrintFatalError(
           Name + " is not listed as an enumeration in any standard spec.\n");
 
-    llvm::Record *EnumerationSpec = G.EnumerationSpecMap[Name];
+    const llvm::Record *EnumerationSpec = G.EnumerationSpecMap[Name];
     OS << "  " << EnumerationSpec->getValueAsString("Name");
     auto Value = EnumerationSpec->getValueAsString("Value");
     if (Value == "__default__") {
@@ -267,9 +266,9 @@ static void writeAPIFromIndex(APIIndexer &G,
     if (Iter == G.FunctionSpecMap.end())
       continue;
 
-    llvm::Record *FunctionSpec = Iter->second;
-    llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
-    llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
+    const llvm::Record *FunctionSpec = Iter->second;
+    const llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
+    const llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
 
     // TODO: https://github.com/llvm/llvm-project/issues/81208
     //   Ideally, we should group functions based on their guarding macros.
@@ -285,7 +284,7 @@ static void writeAPIFromIndex(APIIndexer &G,
 
     auto ArgsList = FunctionSpec->getValueAsListOfDefs("Args");
     for (size_t i = 0; i < ArgsList.size(); ++i) {
-      llvm::Record *ArgType = ArgsList[i]->getValueAsDef("ArgType");
+      const llvm::Record *ArgType = ArgsList[i]->getValueAsDef("ArgType");
       OS << G.getTypeAsString(ArgType);
       if (i < ArgsList.size() - 1)
         OS << ", ";
@@ -304,7 +303,7 @@ static void writeAPIFromIndex(APIIndexer &G,
     auto Iter = G.ObjectSpecMap.find(Name);
     if (Iter == G.ObjectSpecMap.end())
       continue;
-    llvm::Record *ObjectSpec = Iter->second;
+    const llvm::Record *ObjectSpec = Iter->second;
     auto Type = ObjectSpec->getValueAsString("Type");
     OS << "extern " << Type << " " << Name << ";\n";
   }
@@ -314,13 +313,13 @@ static void writeAPIFromIndex(APIIndexer &G,
   emitUndefsForAttributeMacros(MacroAttr, OS);
 }
 
-void writePublicAPI(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {}
+void writePublicAPI(llvm::raw_ostream &OS, const llvm::RecordKeeper &Records) {}
 
 const char PublicAPICommand::Name[] = "public_api";
 
 void PublicAPICommand::run(llvm::raw_ostream &OS, const ArgVector &Args,
                            llvm::StringRef StdHeader,
-                           llvm::RecordKeeper &Records,
+                           const llvm::RecordKeeper &Records,
                            const Command::ErrorReporter &Reporter) const {
   if (Args.size() != 0)
     Reporter.printFatalError("public_api command does not take any arguments.");

diff  --git a/libc/utils/HdrGen/PublicAPICommand.h b/libc/utils/HdrGen/PublicAPICommand.h
index 41aa53e51c3269..49078f4857f900 100644
--- a/libc/utils/HdrGen/PublicAPICommand.h
+++ b/libc/utils/HdrGen/PublicAPICommand.h
@@ -39,7 +39,7 @@ class PublicAPICommand : public Command {
       : EntrypointNameList(EntrypointNames) {}
 
   void run(llvm::raw_ostream &OS, const ArgVector &Args,
-           llvm::StringRef StdHeader, llvm::RecordKeeper &Records,
+           llvm::StringRef StdHeader, const llvm::RecordKeeper &Records,
            const Command::ErrorReporter &Reporter) const override;
 };
 

diff  --git a/libc/utils/LibcTableGenUtil/APIIndexer.cpp b/libc/utils/LibcTableGenUtil/APIIndexer.cpp
index deb82a4f95e96a..65814b96f7f43e 100644
--- a/libc/utils/LibcTableGenUtil/APIIndexer.cpp
+++ b/libc/utils/LibcTableGenUtil/APIIndexer.cpp
@@ -24,7 +24,7 @@ static const char StructTypeClassName[] = "Struct";
 static const char StandardSpecClassName[] = "StandardSpec";
 static const char PublicAPIClassName[] = "PublicAPI";
 
-static bool isa(llvm::Record *Def, llvm::Record *TypeClass) {
+static bool isa(const llvm::Record *Def, const llvm::Record *TypeClass) {
   llvm::RecordRecTy *RecordType = Def->getType();
   llvm::ArrayRef<llvm::Record *> Classes = RecordType->getClasses();
   // We want exact types. That is, we don't want the classes listed in
@@ -35,35 +35,35 @@ static bool isa(llvm::Record *Def, llvm::Record *TypeClass) {
   return Classes[0] == TypeClass;
 }
 
-bool APIIndexer::isaNamedType(llvm::Record *Def) {
+bool APIIndexer::isaNamedType(const llvm::Record *Def) {
   return isa(Def, NamedTypeClass);
 }
 
-bool APIIndexer::isaStructType(llvm::Record *Def) {
+bool APIIndexer::isaStructType(const llvm::Record *Def) {
   return isa(Def, StructClass);
 }
 
-bool APIIndexer::isaPtrType(llvm::Record *Def) {
+bool APIIndexer::isaPtrType(const llvm::Record *Def) {
   return isa(Def, PtrTypeClass);
 }
 
-bool APIIndexer::isaConstType(llvm::Record *Def) {
+bool APIIndexer::isaConstType(const llvm::Record *Def) {
   return isa(Def, ConstTypeClass);
 }
 
-bool APIIndexer::isaRestrictedPtrType(llvm::Record *Def) {
+bool APIIndexer::isaRestrictedPtrType(const llvm::Record *Def) {
   return isa(Def, RestrictedPtrTypeClass);
 }
 
-bool APIIndexer::isaStandardSpec(llvm::Record *Def) {
+bool APIIndexer::isaStandardSpec(const llvm::Record *Def) {
   return isa(Def, StandardSpecClass);
 }
 
-bool APIIndexer::isaPublicAPI(llvm::Record *Def) {
+bool APIIndexer::isaPublicAPI(const llvm::Record *Def) {
   return isa(Def, PublicAPIClass);
 }
 
-std::string APIIndexer::getTypeAsString(llvm::Record *TypeRecord) {
+std::string APIIndexer::getTypeAsString(const llvm::Record *TypeRecord) {
   if (isaNamedType(TypeRecord) || isaStructType(TypeRecord)) {
     return std::string(TypeRecord->getValueAsString("Name"));
   } else if (isaPtrType(TypeRecord)) {
@@ -79,7 +79,7 @@ std::string APIIndexer::getTypeAsString(llvm::Record *TypeRecord) {
   }
 }
 
-void APIIndexer::indexStandardSpecDef(llvm::Record *StandardSpec) {
+void APIIndexer::indexStandardSpecDef(const llvm::Record *StandardSpec) {
   auto HeaderSpecList = StandardSpec->getValueAsListOfDefs("Headers");
   for (llvm::Record *HeaderSpec : HeaderSpecList) {
     llvm::StringRef Header = HeaderSpec->getValueAsString("Name");
@@ -119,7 +119,7 @@ void APIIndexer::indexStandardSpecDef(llvm::Record *StandardSpec) {
   }
 }
 
-void APIIndexer::indexPublicAPIDef(llvm::Record *PublicAPI) {
+void APIIndexer::indexPublicAPIDef(const llvm::Record *PublicAPI) {
   // While indexing the public API, we do not check if any of the entities
   // requested is from an included standard. Such a check is done while
   // generating the API.
@@ -148,7 +148,7 @@ void APIIndexer::indexPublicAPIDef(llvm::Record *PublicAPI) {
     Objects.insert(std::string(ObjectName));
 }
 
-void APIIndexer::index(llvm::RecordKeeper &Records) {
+void APIIndexer::index(const llvm::RecordKeeper &Records) {
   NamedTypeClass = Records.getClass(NamedTypeClassName);
   PtrTypeClass = Records.getClass(PtrTypeClassName);
   RestrictedPtrTypeClass = Records.getClass(RestrictedPtrTypeClassName);
@@ -159,7 +159,7 @@ void APIIndexer::index(llvm::RecordKeeper &Records) {
 
   const auto &DefsMap = Records.getDefs();
   for (auto &Pair : DefsMap) {
-    llvm::Record *Def = Pair.second.get();
+    const llvm::Record *Def = Pair.second.get();
     if (isaStandardSpec(Def))
       indexStandardSpecDef(Def);
     if (isaPublicAPI(Def)) {

diff  --git a/libc/utils/LibcTableGenUtil/APIIndexer.h b/libc/utils/LibcTableGenUtil/APIIndexer.h
index d530dc7174555c..b8bca15ba131c1 100644
--- a/libc/utils/LibcTableGenUtil/APIIndexer.h
+++ b/libc/utils/LibcTableGenUtil/APIIndexer.h
@@ -24,36 +24,38 @@ class APIIndexer {
   std::optional<llvm::StringRef> StdHeader;
 
   // TableGen classes in spec.td.
-  llvm::Record *NamedTypeClass;
-  llvm::Record *PtrTypeClass;
-  llvm::Record *RestrictedPtrTypeClass;
-  llvm::Record *ConstTypeClass;
-  llvm::Record *StructClass;
-  llvm::Record *StandardSpecClass;
-  llvm::Record *PublicAPIClass;
-
-  bool isaNamedType(llvm::Record *Def);
-  bool isaStructType(llvm::Record *Def);
-  bool isaPtrType(llvm::Record *Def);
-  bool isaConstType(llvm::Record *Def);
-  bool isaRestrictedPtrType(llvm::Record *Def);
-  bool isaStandardSpec(llvm::Record *Def);
-  bool isaPublicAPI(llvm::Record *Def);
-
-  void indexStandardSpecDef(llvm::Record *StandardSpec);
-  void indexPublicAPIDef(llvm::Record *PublicAPI);
-  void index(llvm::RecordKeeper &Records);
+  const llvm::Record *NamedTypeClass;
+  const llvm::Record *PtrTypeClass;
+  const llvm::Record *RestrictedPtrTypeClass;
+  const llvm::Record *ConstTypeClass;
+  const llvm::Record *StructClass;
+  const llvm::Record *StandardSpecClass;
+  const llvm::Record *PublicAPIClass;
+
+  bool isaNamedType(const llvm::Record *Def);
+  bool isaStructType(const llvm::Record *Def);
+  bool isaPtrType(const llvm::Record *Def);
+  bool isaConstType(const llvm::Record *Def);
+  bool isaRestrictedPtrType(const llvm::Record *Def);
+  bool isaStandardSpec(const llvm::Record *Def);
+  bool isaPublicAPI(const llvm::Record *Def);
+
+  void indexStandardSpecDef(const llvm::Record *StandardSpec);
+  void indexPublicAPIDef(const llvm::Record *PublicAPI);
+  void index(const llvm::RecordKeeper &Records);
 
 public:
-  using NameToRecordMapping = std::unordered_map<std::string, llvm::Record *>;
+  using NameToRecordMapping =
+      std::unordered_map<std::string, const llvm::Record *>;
   using NameSet = std::unordered_set<std::string>;
 
   // This indexes all headers, not just a specified one.
-  explicit APIIndexer(llvm::RecordKeeper &Records) : StdHeader(std::nullopt) {
+  explicit APIIndexer(const llvm::RecordKeeper &Records)
+      : StdHeader(std::nullopt) {
     index(Records);
   }
 
-  APIIndexer(llvm::StringRef Header, llvm::RecordKeeper &Records)
+  APIIndexer(llvm::StringRef Header, const llvm::RecordKeeper &Records)
       : StdHeader(Header) {
     index(Records);
   }
@@ -76,7 +78,7 @@ class APIIndexer {
   NameSet Objects;
   NameSet PublicHeaders;
 
-  std::string getTypeAsString(llvm::Record *TypeRecord);
+  std::string getTypeAsString(const llvm::Record *TypeRecord);
 };
 
 } // namespace llvm_libc

diff  --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 5d36fcf57e23e3..3b36173f6f1d19 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1737,7 +1737,7 @@ class Record {
   void updateClassLoc(SMLoc Loc);
 
   // Make the type that this record should have based on its superclasses.
-  RecordRecTy *getType();
+  RecordRecTy *getType() const;
 
   /// get the corresponding DefInit.
   DefInit *getDefInit();

diff  --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 17afa2f7eb1b99..692667f9753283 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -2802,7 +2802,7 @@ void Record::checkName() {
                                   "' is not a string!");
 }
 
-RecordRecTy *Record::getType() {
+RecordRecTy *Record::getType() const {
   SmallVector<Record *, 4> DirectSCs;
   getDirectSuperClasses(DirectSCs);
   return RecordRecTy::get(TrackedRecords, DirectSCs);


        


More information about the libc-commits mailing list