Skip to content

Conversation

rupprecht
Copy link
Collaborator

Similar to #91329, mlir-pdll is a tool used in tablegen macros that unregisters from common flags, including -D macros. Because a macro may be used globally, e.g. configured via LLVM_TABLEGEN_FLAGS, we want this tool to just ignore the macro instead of a fatal failure due to the unrecognized flag.

Similar to PR91329, `mlir-pdll` is a tool used in tablegen macros that unregisters from common flags, including `-D` macros. Because a macro may be used globally, e.g. configured via `LLVM_TABLEGEN_FLAGS`, we want this tool to just ignore the macro instead of a fatal failure due to the unrecognized flag.
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Jan 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Jordan Rupprecht (rupprecht)

Changes

Similar to #91329, mlir-pdll is a tool used in tablegen macros that unregisters from common flags, including -D macros. Because a macro may be used globally, e.g. configured via LLVM_TABLEGEN_FLAGS, we want this tool to just ignore the macro instead of a fatal failure due to the unrecognized flag.


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

1 Files Affected:

  • (modified) mlir/tools/mlir-pdll/mlir-pdll.cpp (+9)
diff --git a/mlir/tools/mlir-pdll/mlir-pdll.cpp b/mlir/tools/mlir-pdll/mlir-pdll.cpp
index 0fcf8d1b12d60f..88a5f3639c9625 100644
--- a/mlir/tools/mlir-pdll/mlir-pdll.cpp
+++ b/mlir/tools/mlir-pdll/mlir-pdll.cpp
@@ -167,6 +167,15 @@ int main(int argc, char **argv) {
       "write-if-changed",
       llvm::cl::desc("Only write to the output file if it changed"));
 
+  // `ResetCommandLineParser` at the above unregistered the "D" option
+  // of `llvm-tblgen`, which causes tblgen usage to fail due to
+  // "Unknnown command line argument '-D...`" when a macros name is
+  // present. The following is a workaround to re-register it again.
+  llvm::cl::list<std::string> macroNames(
+      "D",
+      llvm::cl::desc("Name of the macro to be defined -- ignored by mlir-pdll"),
+      llvm::cl::value_desc("macro name"), llvm::cl::Prefix);
+
   llvm::InitLLVM y(argc, argv);
   llvm::cl::ParseCommandLineOptions(argc, argv, "PDLL Frontend");
 

@rupprecht rupprecht merged commit e10d551 into llvm:main Jan 23, 2025
9 of 10 checks passed
@rupprecht rupprecht deleted the mlir-pdll-tblgen-macro branch August 14, 2025 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants