[llvm] [TableGen] Generate library option structs with llvm-min-tblgen (PR #228338)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 23:03:36 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-mc

@llvm/pr-subscribers-llvm-transforms

Author: Fangrui Song (MaskRay)

<details>
<summary>Changes</summary>

-gen-opt-parser-defs lives in llvm-tblgen, so a library whose options
are declared in TableGen (CGData, InstCombine, MC) waits for llvm-tblgen
to build before any of its sources compile, while it otherwise needs
only llvm-min-tblgen.

Move OptionParserEmitter and OptEmitter into TableGen/Basic, which
llvm-min-tblgen consists of, and generate those structs with
llvm-min-tblgen.

Aided by Opus 5.5

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


15 Files Affected:

- (modified) llvm/docs/CommandLine.md (+1) 
- (modified) llvm/lib/CGData/CMakeLists.txt (+1) 
- (modified) llvm/lib/MC/CMakeLists.txt (+1) 
- (modified) llvm/lib/Transforms/InstCombine/CMakeLists.txt (+1) 
- (modified) llvm/utils/TableGen/Basic/CMakeLists.txt (+2) 
- (renamed) llvm/utils/TableGen/Basic/OptEmitter.cpp () 
- (renamed) llvm/utils/TableGen/Basic/OptEmitter.h () 
- (renamed) llvm/utils/TableGen/Basic/OptionParserEmitter.cpp (+1-2) 
- (modified) llvm/utils/TableGen/CMakeLists.txt (-1) 
- (modified) llvm/utils/TableGen/Common/CMakeLists.txt (-1) 
- (modified) llvm/utils/TableGen/OptionRSTEmitter.cpp (+1-1) 
- (modified) llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn (-1) 
- (modified) llvm/utils/gn/secondary/llvm/utils/TableGen/Basic/BUILD.gn (+2) 
- (modified) llvm/utils/gn/secondary/llvm/utils/TableGen/Common/BUILD.gn (-1) 
- (modified) utils/bazel/llvm-project-overlay/llvm/BUILD.bazel (+2) 


``````````diff
diff --git a/llvm/docs/CommandLine.md b/llvm/docs/CommandLine.md
index 2411b4cf9460b13..a6d642943945326 100644
--- a/llvm/docs/CommandLine.md
+++ b/llvm/docs/CommandLine.md
@@ -1597,5 +1597,6 @@ A `std::optional` member defaulting to `std::nullopt` tells whether the option w
 The header declares the struct after including what the member defaults need, and one source file defines it and registers it with `cl::`.
 
 The library then lists `FooOptionsTableGen` under `DEPENDS` and `Option` under `LINK_COMPONENTS`.
+A library that otherwise needs only `llvm-min-tblgen` sets `LLVM_TABLEGEN_PROJECT` to `LLVM_HEADERS` before its `tablegen()` call, so that its sources need not wait for `llvm-tblgen`.
 Code reads `FooOptions::Global.enable_foo`, the instance the command line sets.
 Keep the header in `lib/`, as private as the `static cl::opt` it replaces; another library that needs a value calls a function or takes a parameter.
diff --git a/llvm/lib/CGData/CMakeLists.txt b/llvm/lib/CGData/CMakeLists.txt
index 6c31d76331f6fbb..e01c2c7f2391d6e 100644
--- a/llvm/lib/CGData/CMakeLists.txt
+++ b/llvm/lib/CGData/CMakeLists.txt
@@ -1,3 +1,4 @@
+set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS)
 set(LLVM_TARGET_DEFINITIONS CGDataOptions.td)
 tablegen(LLVM CGDataOptions.inc -gen-opt-parser-defs)
 add_public_tablegen_target(CGDataOptionsTableGen)
diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt
index c93fad8a6a3e266..2ef414d62bc50a6 100644
--- a/llvm/lib/MC/CMakeLists.txt
+++ b/llvm/lib/MC/CMakeLists.txt
@@ -1,3 +1,4 @@
+set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS)
 set(LLVM_TARGET_DEFINITIONS MCCLOptions.td)
 tablegen(LLVM MCCLOptions.inc -gen-opt-parser-defs)
 add_public_tablegen_target(MCCLOptionsTableGen)
diff --git a/llvm/lib/Transforms/InstCombine/CMakeLists.txt b/llvm/lib/Transforms/InstCombine/CMakeLists.txt
index 399e15320a39ab6..23d4552919c1625 100644
--- a/llvm/lib/Transforms/InstCombine/CMakeLists.txt
+++ b/llvm/lib/Transforms/InstCombine/CMakeLists.txt
@@ -1,3 +1,4 @@
+set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS)
 set(LLVM_TARGET_DEFINITIONS InstCombineCLOptions.td)
 tablegen(LLVM InstCombineCLOptions.inc -gen-opt-parser-defs)
 add_public_tablegen_target(InstCombineCLOptionsTableGen)
diff --git a/llvm/utils/TableGen/Basic/CMakeLists.txt b/llvm/utils/TableGen/Basic/CMakeLists.txt
index fb2510e8bcc3959..0eb8026e2af533a 100644
--- a/llvm/utils/TableGen/Basic/CMakeLists.txt
+++ b/llvm/utils/TableGen/Basic/CMakeLists.txt
@@ -15,6 +15,8 @@ add_llvm_library(LLVMTableGenBasic OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLV
   CodeGenIntrinsics.cpp
   DirectiveEmitter.cpp
   IntrinsicEmitter.cpp
+  OptEmitter.cpp
+  OptionParserEmitter.cpp
   PredicateExpanderDag.cpp
   RISCVTargetDefEmitter.cpp
   RuntimeLibcallsEmitter.cpp
diff --git a/llvm/utils/TableGen/Common/OptEmitter.cpp b/llvm/utils/TableGen/Basic/OptEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/Common/OptEmitter.cpp
rename to llvm/utils/TableGen/Basic/OptEmitter.cpp
diff --git a/llvm/utils/TableGen/Common/OptEmitter.h b/llvm/utils/TableGen/Basic/OptEmitter.h
similarity index 100%
rename from llvm/utils/TableGen/Common/OptEmitter.h
rename to llvm/utils/TableGen/Basic/OptEmitter.h
diff --git a/llvm/utils/TableGen/OptionParserEmitter.cpp b/llvm/utils/TableGen/Basic/OptionParserEmitter.cpp
similarity index 99%
rename from llvm/utils/TableGen/OptionParserEmitter.cpp
rename to llvm/utils/TableGen/Basic/OptionParserEmitter.cpp
index 8a66270f56223f5..b4487c47edacb3b 100644
--- a/llvm/utils/TableGen/OptionParserEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/OptionParserEmitter.cpp
@@ -6,14 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "Common/OptEmitter.h"
+#include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/Twine.h"
-#include "llvm/Option/OptTable.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index e18279cffa74c23..c2f8df1f961b497 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -58,7 +58,6 @@ add_tablegen(llvm-tblgen LLVM
   InstrInfoEmitter.cpp
   llvm-tblgen.cpp
   MacroFusionPredicatorEmitter.cpp
-  OptionParserEmitter.cpp
   OptionRSTEmitter.cpp
   PseudoLoweringEmitter.cpp
   RegisterBankEmitter.cpp
diff --git a/llvm/utils/TableGen/Common/CMakeLists.txt b/llvm/utils/TableGen/Common/CMakeLists.txt
index 84e5e53f9fade90..b1e89a33bb50a1c 100644
--- a/llvm/utils/TableGen/Common/CMakeLists.txt
+++ b/llvm/utils/TableGen/Common/CMakeLists.txt
@@ -31,7 +31,6 @@ add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_
   CodeGenTarget.cpp
   InfoByHwMode.cpp
   InstructionEncoding.cpp
-  OptEmitter.cpp
   PredicateExpander.cpp
   SubtargetFeatureInfo.cpp
   Types.cpp
diff --git a/llvm/utils/TableGen/OptionRSTEmitter.cpp b/llvm/utils/TableGen/OptionRSTEmitter.cpp
index 6eac10e1831f022..4888e460bc674da 100644
--- a/llvm/utils/TableGen/OptionRSTEmitter.cpp
+++ b/llvm/utils/TableGen/OptionRSTEmitter.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "Common/OptEmitter.h"
+#include "Basic/OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/TableGen/Record.h"
diff --git a/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn
index 0ad39c3336801b1..6638d7805c6467e 100644
--- a/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn
@@ -43,7 +43,6 @@ executable("llvm-tblgen") {
     "InstrDocsEmitter.cpp",
     "InstrInfoEmitter.cpp",
     "MacroFusionPredicatorEmitter.cpp",
-    "OptionParserEmitter.cpp",
     "OptionRSTEmitter.cpp",
     "PseudoLoweringEmitter.cpp",
     "RegisterBankEmitter.cpp",
diff --git a/llvm/utils/gn/secondary/llvm/utils/TableGen/Basic/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/TableGen/Basic/BUILD.gn
index 2da886c5469c31f..5fad35d3a1a26b6 100644
--- a/llvm/utils/gn/secondary/llvm/utils/TableGen/Basic/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/utils/TableGen/Basic/BUILD.gn
@@ -10,6 +10,8 @@ source_set("Basic") {
     "CodeGenIntrinsics.cpp",
     "DirectiveEmitter.cpp",
     "IntrinsicEmitter.cpp",
+    "OptEmitter.cpp",
+    "OptionParserEmitter.cpp",
     "PredicateExpanderDag.cpp",
     "RISCVTargetDefEmitter.cpp",
     "RuntimeLibcalls.cpp",
diff --git a/llvm/utils/gn/secondary/llvm/utils/TableGen/Common/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/TableGen/Common/BUILD.gn
index 4c2f587c4395a0f..d6ea0a310bd47e8 100644
--- a/llvm/utils/gn/secondary/llvm/utils/TableGen/Common/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/utils/TableGen/Common/BUILD.gn
@@ -27,7 +27,6 @@ static_library("Common") {
     "GlobalISel/Patterns.cpp",
     "InfoByHwMode.cpp",
     "InstructionEncoding.cpp",
-    "OptEmitter.cpp",
     "PredicateExpander.cpp",
     "SubtargetFeatureInfo.cpp",
     "Types.cpp",
diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index b5132afbe8b06ec..79f35060a304481 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -935,6 +935,8 @@ cc_binary(
         "utils/TableGen/Basic/CodeGenIntrinsics.cpp",
         "utils/TableGen/Basic/DirectiveEmitter.cpp",
         "utils/TableGen/Basic/IntrinsicEmitter.cpp",
+        "utils/TableGen/Basic/OptEmitter.cpp",
+        "utils/TableGen/Basic/OptionParserEmitter.cpp",
         "utils/TableGen/Basic/PredicateExpanderDag.cpp",
         "utils/TableGen/Basic/RISCVTargetDefEmitter.cpp",
         "utils/TableGen/Basic/RuntimeLibcalls.cpp",

``````````

</details>


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


More information about the llvm-commits mailing list