[Mlir-commits] [mlir] [mlir][ods] Optimize FoldAdaptor constructor (PR #93219)

Mehdi Amini llvmlistbot at llvm.org
Thu May 23 10:39:48 PDT 2024


================
@@ -4163,14 +4164,26 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
   // and the value range from the parameter.
   {
     // Base class is in the cpp file and can simply access the members of the op
-    // class to initialize the template independent fields.
-    auto *constructor = genericAdaptorBase.addConstructor(
-        MethodParameter(op.getCppClassName(), "op"));
+    // class to initialize the template independent fields. If the op doesn't
+    // have properties, we can emit a generic constructor inline. Otherwise,
+    // emit it out-of-line because we need the op to be defined.
+    Constructor *constructor;
+    if (useProperties) {
+      constructor = genericAdaptorBase.addConstructor(
+          MethodParameter(op.getCppClassName(), "op"));
+    } else {
+      constructor = genericAdaptorBase.addConstructor<Method::Inline>(
+          MethodParameter("::mlir::Operation *", "op"));
+    }
     constructor->addMemberInitializer(
-        genericAdaptorBase.getClassName(),
+        "odsAttrs",
         llvm::Twine(!useProperties ? "op->getAttrDictionary()"
-                                   : "op->getDiscardableAttrDictionary()") +
-            ", op.getProperties(), op->getRegions()");
+                                   : "op->getDiscardableAttrDictionary()"));
----------------
joker-eph wrote:

I'm not sure why the check and different APIs here: can't we just emit `getDiscardableAttrDictionary()` always?

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


More information about the Mlir-commits mailing list