Skip to content

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Oct 6, 2025

Op constraints are emitted as static standalone functions and need not be surrounded by the Dialect's C++ namespace. Currently they are, and this change stops emitting a namespace around these static functions.

Op constraints are emitted as uniqued static standalone funtions
and need not be surrounded by the Op's C++ namespace.
@jurahul jurahul force-pushed the nfc_drop_op_constraints_ns branch from 59df1df to ed233e1 Compare October 6, 2025 18:13
@jurahul jurahul marked this pull request as ready for review October 6, 2025 19:22
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir:gpu mlir labels Oct 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 6, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-gpu

Author: Rahul Joshi (jurahul)

Changes

Op constraints are emitted as uniqued static standalone funtions and need not be surrounded by the Op's C++ namespace.


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

4 Files Affected:

  • (modified) mlir/include/mlir/TableGen/CodeGenHelpers.h (+1-1)
  • (modified) mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp (+2-5)
  • (modified) mlir/lib/TableGen/CodeGenHelpers.cpp (+1-3)
  • (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+1-1)
diff --git a/mlir/include/mlir/TableGen/CodeGenHelpers.h b/mlir/include/mlir/TableGen/CodeGenHelpers.h
index 252da21419b6e..997aef26bdc01 100644
--- a/mlir/include/mlir/TableGen/CodeGenHelpers.h
+++ b/mlir/include/mlir/TableGen/CodeGenHelpers.h
@@ -88,7 +88,7 @@ class StaticVerifierFunctionEmitter {
   ///
   /// Constraints that do not meet the restriction that they can only reference
   /// `$_self` and `$_op` are not uniqued.
-  void emitOpConstraints(ArrayRef<const llvm::Record *> opDefs);
+  void emitOpConstraints();
 
   /// Unique all compatible type and attribute constraints from a pattern file
   /// and emit them at the top of the generated file.
diff --git a/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp b/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
index 81b5788d0b9b4..e0a8ac40648e0 100644
--- a/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
+++ b/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
@@ -20,8 +20,8 @@
 
 #define DEBUG_TYPE "xegpu"
 
-namespace mlir {
-namespace xegpu {
+using namespace mlir;
+using namespace mlir::xegpu;
 
 static bool isSharedMemory(const MemRefType &memrefTy) {
   Attribute attr = memrefTy.getMemorySpace();
@@ -1133,9 +1133,6 @@ LogicalResult MemDescSubviewOp::verify() {
   return success();
 }
 
-} // namespace xegpu
-} // namespace mlir
-
 namespace mlir {
 #include <mlir/Dialect/XeGPU/IR/XeGPUAttrInterface.cpp.inc>
 } // namespace mlir
diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp
index cb90ef82c1c39..d52d5e769ee6d 100644
--- a/mlir/lib/TableGen/CodeGenHelpers.cpp
+++ b/mlir/lib/TableGen/CodeGenHelpers.cpp
@@ -49,9 +49,7 @@ StaticVerifierFunctionEmitter::StaticVerifierFunctionEmitter(
     raw_ostream &os, const RecordKeeper &records, StringRef tag)
     : os(os), uniqueOutputLabel(getUniqueOutputLabel(records, tag)) {}
 
-void StaticVerifierFunctionEmitter::emitOpConstraints(
-    ArrayRef<const Record *> opDefs) {
-  NamespaceEmitter namespaceEmitter(os, Operator(*opDefs[0]).getCppNamespace());
+void StaticVerifierFunctionEmitter::emitOpConstraints() {
   emitTypeConstraints();
   emitAttrConstraints();
   emitPropConstraints();
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 2ddb07de48a76..f6cfe74729be0 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -4871,7 +4871,7 @@ static void emitOpClassDefs(const RecordKeeper &records,
                                                       constraintPrefix);
   os << formatv(opCommentHeader, "Local Utility Method", "Definitions");
   staticVerifierEmitter.collectOpConstraints(defs);
-  staticVerifierEmitter.emitOpConstraints(defs);
+  staticVerifierEmitter.emitOpConstraints();
 
   // Emit the classes.
   emitOpClasses(records, defs, os, staticVerifierEmitter,

@llvmbot
Copy link
Member

llvmbot commented Oct 6, 2025

@llvm/pr-subscribers-mlir-core

Author: Rahul Joshi (jurahul)

Changes

Op constraints are emitted as uniqued static standalone funtions and need not be surrounded by the Op's C++ namespace.


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

4 Files Affected:

  • (modified) mlir/include/mlir/TableGen/CodeGenHelpers.h (+1-1)
  • (modified) mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp (+2-5)
  • (modified) mlir/lib/TableGen/CodeGenHelpers.cpp (+1-3)
  • (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+1-1)
diff --git a/mlir/include/mlir/TableGen/CodeGenHelpers.h b/mlir/include/mlir/TableGen/CodeGenHelpers.h
index 252da21419b6e..997aef26bdc01 100644
--- a/mlir/include/mlir/TableGen/CodeGenHelpers.h
+++ b/mlir/include/mlir/TableGen/CodeGenHelpers.h
@@ -88,7 +88,7 @@ class StaticVerifierFunctionEmitter {
   ///
   /// Constraints that do not meet the restriction that they can only reference
   /// `$_self` and `$_op` are not uniqued.
-  void emitOpConstraints(ArrayRef<const llvm::Record *> opDefs);
+  void emitOpConstraints();
 
   /// Unique all compatible type and attribute constraints from a pattern file
   /// and emit them at the top of the generated file.
diff --git a/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp b/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
index 81b5788d0b9b4..e0a8ac40648e0 100644
--- a/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
+++ b/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
@@ -20,8 +20,8 @@
 
 #define DEBUG_TYPE "xegpu"
 
-namespace mlir {
-namespace xegpu {
+using namespace mlir;
+using namespace mlir::xegpu;
 
 static bool isSharedMemory(const MemRefType &memrefTy) {
   Attribute attr = memrefTy.getMemorySpace();
@@ -1133,9 +1133,6 @@ LogicalResult MemDescSubviewOp::verify() {
   return success();
 }
 
-} // namespace xegpu
-} // namespace mlir
-
 namespace mlir {
 #include <mlir/Dialect/XeGPU/IR/XeGPUAttrInterface.cpp.inc>
 } // namespace mlir
diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp
index cb90ef82c1c39..d52d5e769ee6d 100644
--- a/mlir/lib/TableGen/CodeGenHelpers.cpp
+++ b/mlir/lib/TableGen/CodeGenHelpers.cpp
@@ -49,9 +49,7 @@ StaticVerifierFunctionEmitter::StaticVerifierFunctionEmitter(
     raw_ostream &os, const RecordKeeper &records, StringRef tag)
     : os(os), uniqueOutputLabel(getUniqueOutputLabel(records, tag)) {}
 
-void StaticVerifierFunctionEmitter::emitOpConstraints(
-    ArrayRef<const Record *> opDefs) {
-  NamespaceEmitter namespaceEmitter(os, Operator(*opDefs[0]).getCppNamespace());
+void StaticVerifierFunctionEmitter::emitOpConstraints() {
   emitTypeConstraints();
   emitAttrConstraints();
   emitPropConstraints();
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 2ddb07de48a76..f6cfe74729be0 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -4871,7 +4871,7 @@ static void emitOpClassDefs(const RecordKeeper &records,
                                                       constraintPrefix);
   os << formatv(opCommentHeader, "Local Utility Method", "Definitions");
   staticVerifierEmitter.collectOpConstraints(defs);
-  staticVerifierEmitter.emitOpConstraints(defs);
+  staticVerifierEmitter.emitOpConstraints();
 
   // Emit the classes.
   emitOpClasses(records, defs, os, staticVerifierEmitter,

@jurahul
Copy link
Contributor Author

jurahul commented Oct 15, 2025

To clarify what this does, currently gen-op-defs generates a .cpp.inc file with this structure for GET_OP_CLASSES:

//===----------------------------------------------------------------------===//
// Local Utility Method Definitions
//===----------------------------------------------------------------------===//

namespace mlir::LLVM {
static ::llvm::LogicalResult __mlir_ods_local_type_constraint_LLVMIntrinsicOps1(...)
..
} // } // namespace mlir::LLVM

This code is generated by emitOpConstraints function. Now all these op constraint functions are static, so there is no need to surround them with the namespace. That is what this change is doing. The other (minor) delta is that any references to types within these static functions that are in mlir::LLVM namespace for example may break. In most cases, the generated .cpp.inc is included in a file that already have appropriate "using namespace" for this to not be an issue. XeGpu dialect did not have that, so changing that there fixed it as well.

@jurahul jurahul changed the title [NFC][MLIR][TableGen] Drop namespace around op constraints functions [NFC][MLIR][TableGen] Drop namespace around static Op constraints functions Oct 15, 2025
@jurahul
Copy link
Contributor Author

jurahul commented Oct 15, 2025

The new code is:

//===----------------------------------------------------------------------===//
// Local Utility Method Definitions
//===----------------------------------------------------------------------===//

static ::llvm::LogicalResult __mlir_ods_local_type_constraint_LLVMIntrinsicOps1(

@jurahul jurahul changed the title [NFC][MLIR][TableGen] Drop namespace around static Op constraints functions [NFC][MLIR][TableGen] Drop namespace around static Op constraint functions Oct 15, 2025
Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems fine, even though I'm not sure I understand all the implications. We can land and follow-up on any potential fallout.

@jurahul jurahul merged commit 333c758 into llvm:main Oct 16, 2025
10 checks passed
@jurahul jurahul deleted the nfc_drop_op_constraints_ns branch October 16, 2025 00:18
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to openxla/xla that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to openxla/xla that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to openxla/xla that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to openxla/xla that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820713725
copybara-service bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

LiteRT-Converter-PiperOrigin-RevId: 820836649
copybara-service bot pushed a commit to tensorflow/mlir-hlo that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820836649
copybara-service bot pushed a commit to openxla/xla that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820836649
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Oct 17, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820836649
shawnwang18 pushed a commit to shawnwang18/xla that referenced this pull request Oct 20, 2025
…ons, so we need to explicitly specify some namespaces now. This is needed

for the LLVM integrate.

PiperOrigin-RevId: 820836649
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:gpu mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants