[libc-commits] [clang] [libc] [llvm] [mlir] [TableGen] Change TableGenMain to use const RecordKeeper (PR #110578)

via libc-commits libc-commits at lists.llvm.org
Mon Sep 30 18:52:16 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: Rahul Joshi (jurahul)

<details>
<summary>Changes</summary>

Change TableGenMain's `MainFn` argument to be a function that accepts a const reference to RecordKeeper.

---
Full diff: https://github.com/llvm/llvm-project/pull/110578.diff


5 Files Affected:

- (modified) clang/utils/TableGen/TableGen.cpp (+1-1) 
- (modified) libc/utils/HdrGen/Main.cpp (+12-17) 
- (modified) llvm/include/llvm/TableGen/Main.h (+1-1) 
- (modified) llvm/lib/TableGen/TableGenBackendSkeleton.cpp (+4-4) 
- (modified) mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp (+1-1) 


``````````diff
diff --git a/clang/utils/TableGen/TableGen.cpp b/clang/utils/TableGen/TableGen.cpp
index 84afd4c0afb269..39c178bc4f9baf 100644
--- a/clang/utils/TableGen/TableGen.cpp
+++ b/clang/utils/TableGen/TableGen.cpp
@@ -317,7 +317,7 @@ ClangComponent("clang-component",
                cl::desc("Only use warnings from specified component"),
                cl::value_desc("component"), cl::Hidden);
 
-bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
+bool ClangTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
   switch (Action) {
   case PrintRecords:
     OS << Records;           // No argument, dump all contents
diff --git a/libc/utils/HdrGen/Main.cpp b/libc/utils/HdrGen/Main.cpp
index d3418f206b10e9..f795e96e45c57a 100644
--- a/libc/utils/HdrGen/Main.cpp
+++ b/libc/utils/HdrGen/Main.cpp
@@ -15,42 +15,39 @@
 #include <string>
 #include <unordered_map>
 
-namespace {
-
-llvm::cl::opt<std::string>
+static llvm::cl::opt<std::string>
     HeaderDefFile("def", llvm::cl::desc("Path to the .h.def file."),
                   llvm::cl::value_desc("<filename>"), llvm::cl::Required);
-llvm::cl::opt<std::string> StandardHeader(
+static llvm::cl::opt<std::string> StandardHeader(
     "header",
     llvm::cl::desc("The standard header file which is to be generated."),
     llvm::cl::value_desc("<header file>"));
-llvm::cl::list<std::string> EntrypointNamesOption(
+static llvm::cl::list<std::string> EntrypointNamesOption(
     "e", llvm::cl::value_desc("<list of entrypoints>"),
     llvm::cl::desc(
         "Each --e is one entrypoint (generated from entrypoints.txt)"),
     llvm::cl::OneOrMore);
-llvm::cl::list<std::string> ReplacementValues(
+static llvm::cl::list<std::string> ReplacementValues(
     "args", llvm::cl::desc("Command separated <argument name>=<value> pairs."),
     llvm::cl::value_desc("<name=value>[,name=value]"));
-llvm::cl::opt<bool> ExportDecls(
+static llvm::cl::opt<bool> ExportDecls(
     "export-decls",
     llvm::cl::desc("Output a new header containing only the entrypoints."));
 
-void ParseArgValuePairs(std::unordered_map<std::string, std::string> &Map) {
+static void
+ParseArgValuePairs(std::unordered_map<std::string, std::string> &Map) {
   for (std::string &R : ReplacementValues) {
     auto Pair = llvm::StringRef(R).split('=');
     Map[std::string(Pair.first)] = std::string(Pair.second);
   }
 }
 
-} // anonymous namespace
-
-namespace llvm_libc {
-
-bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
+static bool HeaderGeneratorMain(llvm::raw_ostream &OS,
+                                const llvm::RecordKeeper &Records) {
   std::unordered_map<std::string, std::string> ArgMap;
   ParseArgValuePairs(ArgMap);
-  Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader, ArgMap);
+  llvm_libc::Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader,
+                         ArgMap);
   if (ExportDecls)
     G.generateDecls(OS, Records);
   else
@@ -59,9 +56,7 @@ bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
   return false;
 }
 
-} // namespace llvm_libc
-
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv);
-  return TableGenMain(argv[0], &llvm_libc::HeaderGeneratorMain);
+  return TableGenMain(argv[0], &HeaderGeneratorMain);
 }
diff --git a/llvm/include/llvm/TableGen/Main.h b/llvm/include/llvm/TableGen/Main.h
index 4639ec756e9b17..e8c60e28699022 100644
--- a/llvm/include/llvm/TableGen/Main.h
+++ b/llvm/include/llvm/TableGen/Main.h
@@ -22,7 +22,7 @@ class RecordKeeper;
 
 /// Perform the action using Records, and write output to OS.
 /// Returns true on error, false otherwise.
-using TableGenMainFn = bool (raw_ostream &OS, RecordKeeper &Records);
+using TableGenMainFn = bool(raw_ostream &OS, const RecordKeeper &Records);
 
 int TableGenMain(const char *argv0,
                  std::function<TableGenMainFn> MainFn = nullptr);
diff --git a/llvm/lib/TableGen/TableGenBackendSkeleton.cpp b/llvm/lib/TableGen/TableGenBackendSkeleton.cpp
index 8e65b7a5b300fd..a7c4a8925799a2 100644
--- a/llvm/lib/TableGen/TableGenBackendSkeleton.cpp
+++ b/llvm/lib/TableGen/TableGenBackendSkeleton.cpp
@@ -1,4 +1,4 @@
-//===- SkeletonEmitter.cpp - Skeleton TableGen backend          -*- C++ -*-===//
+//===- TableGenBackendSkeleton.cpp - Skeleton TableGen backend --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -29,10 +29,10 @@ namespace {
 
 class SkeletonEmitter {
 private:
-  RecordKeeper &Records;
+  const RecordKeeper &Records;
 
 public:
-  SkeletonEmitter(RecordKeeper &RK) : Records(RK) {}
+  SkeletonEmitter(const RecordKeeper &RK) : Records(RK) {}
 
   void run(raw_ostream &OS);
 }; // emitter class
@@ -55,7 +55,7 @@ static TableGen::Emitter::OptClass<SkeletonEmitter>
 //===----------------------------------------------------------------------===//
 // Option B: Register "EmitSkeleton" directly
 // The emitter entry may be private scope.
-static void EmitSkeleton(RecordKeeper &RK, raw_ostream &OS) {
+static void EmitSkeleton(const RecordKeeper &RK, raw_ostream &OS) {
   // Instantiate the emitter class and invoke run().
   SkeletonEmitter(RK).run(OS);
 }
diff --git a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
index 1911b6e3aa3927..7119324dd125d5 100644
--- a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
+++ b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
@@ -126,7 +126,7 @@ static const mlir::GenInfo *generator;
 
 // TableGenMain requires a function pointer so this function is passed in which
 // simply wraps the call to the generator.
-static bool mlirTableGenMain(raw_ostream &os, RecordKeeper &records) {
+static bool mlirTableGenMain(raw_ostream &os, const RecordKeeper &records) {
   if (actionOnDeprecatedValue != DeprecatedAction::None)
     warnOfDeprecatedUses(records);
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/110578


More information about the libc-commits mailing list