[mlir] Split Dialect::addOperations into two functions
authorRiver Riddle <riddleriver@gmail.com>
Thu, 1 Oct 2020 00:23:11 +0000 (17:23 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Thu, 1 Oct 2020 01:03:14 +0000 (18:03 -0700)
The current implementation uses a fold expression to add all of the operations at once. This is really nice, but apparently the lifetime of each of the AbstractOperation instances is for the entire expression which may lead to a stack overflow for large numbers of operations. This splits the method in two to allow for the lifetime of the AbstractOperation to be properly scoped.

mlir/include/mlir/IR/Dialect.h

index 6395b33..5bd8a74 100644 (file)
@@ -150,10 +150,11 @@ protected:
   /// This method is used by derived classes to add their operations to the set.
   ///
   template <typename... Args> void addOperations() {
-    (void)std::initializer_list<int>{
-        0, (addOperation(AbstractOperation::get<Args>(*this)), 0)...};
+    (void)std::initializer_list<int>{0, (addOperation<Args>(), 0)...};
+  }
+  template <typename Arg> void addOperation() {
+    addOperation(AbstractOperation::get<Arg>(*this));
   }
-
   void addOperation(AbstractOperation opInfo);
 
   /// Register a set of type classes with this dialect.