[Mlir-commits] [mlir] 25ba11d - [mlir] Constant-initialize registered operation hook tables (NFC) (#226320)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 24 15:59:11 PDT 2026


Author: Mehdi Amini
Date: 2026-09-24T22:59:04Z
New Revision: 25ba11d9dd3053d82af538e8b2cd7d449dcc867c

URL: https://github.com/llvm/llvm-project/commit/25ba11d9dd3053d82af538e8b2cd7d449dcc867c
DIFF: https://github.com/llvm/llvm-project/commit/25ba11d9dd3053d82af538e8b2cd7d449dcc867c.diff

LOG: [mlir] Constant-initialize registered operation hook tables (NFC) (#226320)

Make the generic operation hook accessors constexpr so registered
operation hook tables can be constant-initialized. Keep the table
declared static const to support non-constexpr downstream overrides.

In OpenMPDialect.cpp this removes 72 initialization guards and 10,368
bytes of object text, and saves about 0.56B compiler instructions.

Assisted-by: Codex

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpDefinition.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 36bff607c2a69..0ab6679187c8e 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -1940,7 +1940,7 @@ class Op : public OpState, public Traits<ConcreteType>... {
   using VerifyInvariantsFn = LogicalResult (*)(Operation *);
 
   /// Return the internal implementations of each of the OperationName hooks.
-  static FoldHookFn getFoldHookFn() {
+  static constexpr FoldHookFn getFoldHookFn() {
     // If the operation is single result and defines a `fold` method.
     if constexpr (llvm::is_one_of<OpTrait::OneResult<ConcreteType>,
                                   Traits<ConcreteType>...>::value &&
@@ -2013,11 +2013,11 @@ class Op : public OpState, public Traits<ConcreteType>... {
     return result;
   }
 
-  static HasTraitFn getHasTraitFn() {
+  static constexpr HasTraitFn getHasTraitFn() {
     return
         [](TypeID id) { return op_definition_impl::hasTrait<Traits...>(id); };
   }
-  static PrintAssemblyFn getPrintAssemblyFn() {
+  static constexpr PrintAssemblyFn getPrintAssemblyFn() {
     if constexpr (detect_has_print<ConcreteType>::value)
       return [](Operation *op, OpAsmPrinter &p, StringRef defaultDialect) {
         OpState::printOpName(op, p, defaultDialect);
@@ -2118,7 +2118,7 @@ class Op : public OpState, public Traits<ConcreteType>... {
         failed(op_definition_impl::verifyTraits<Traits<ConcreteType>...>(op)) ||
         failed(cast<ConcreteType>(op).verify()));
   }
-  static VerifyInvariantsFn getVerifyInvariantsFn() {
+  static constexpr VerifyInvariantsFn getVerifyInvariantsFn() {
     return &verifyInvariants;
   }
   /// Implementation of `VerifyRegionInvariantsFn` OperationName hook.
@@ -2130,7 +2130,7 @@ class Op : public OpState, public Traits<ConcreteType>... {
             op)) ||
         failed(cast<ConcreteType>(op).verifyRegions()));
   }
-  static VerifyInvariantsFn getVerifyRegionInvariantsFn() {
+  static constexpr VerifyInvariantsFn getVerifyRegionInvariantsFn() {
     return &verifyRegionInvariants;
   }
 


        


More information about the Mlir-commits mailing list