[Mlir-commits] [mlir] 8c05a11 - [mlir] Outline registered operation-model allocation (NFC) (#222803)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 10 15:52:13 PDT 2026


Author: Mehdi Amini
Date: 2026-09-10T22:52:08Z
New Revision: 8c05a1167dd2f00cfa64966cb1572a6d97178c8b

URL: https://github.com/llvm/llvm-project/commit/8c05a1167dd2f00cfa64966cb1572a6d97178c8b
DIFF: https://github.com/llvm/llvm-project/commit/8c05a1167dd2f00cfa64966cb1572a6d97178c8b.diff

LOG: [mlir] Outline registered operation-model allocation (NFC) (#222803)

Allocate operation-model storage through an out-of-line helper so every
registration TU does not instantiate the allocation machinery.

Across three controlled -j16 rebuilds of 44 registration TUs, median
instructions fell from 2.284T to 2.202T (-3.594%) and median wall time
fell from 40.44s to 38.54s (-4.698%).

Assisted-by: Codex

Added: 
    

Modified: 
    mlir/include/mlir/IR/OperationSupport.h
    mlir/lib/IR/MLIRContext.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 13510379d184d..54beafdeab27e 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -711,7 +711,11 @@ class RegisteredOperationName : public OperationName {
   /// of operations they contain.
   template <typename T>
   static void insert(Dialect &dialect) {
-    insert(std::make_unique<Model<T>>(&dialect), T::getAttributeNames());
+    static_assert(sizeof(Model<T>) == sizeof(Impl));
+    static_assert(alignof(Model<T>) == alignof(Impl));
+    std::unique_ptr<Impl> ownedModel(new (allocateModelStorage())
+                                         Model<T>(&dialect));
+    insert(std::move(ownedModel), T::getAttributeNames());
   }
   /// The use of this method is in general discouraged in favor of
   /// 'insert<CustomOp>(dialect)'.
@@ -729,6 +733,9 @@ class RegisteredOperationName : public OperationName {
   }
 
 private:
+  /// Allocate storage for one type-erased operation model.
+  static void *allocateModelStorage();
+
   RegisteredOperationName(Impl *impl) : OperationName(impl) {}
 
   /// Allow access to the constructor.

diff  --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 5efbe0e284147..a376c42020dd8 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -1120,6 +1120,10 @@ void RegisteredOperationName::insert(
       value);
 }
 
+void *RegisteredOperationName::allocateModelStorage() {
+  return ::operator new(sizeof(Impl));
+}
+
 //===----------------------------------------------------------------------===//
 // AbstractType
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list