[PATCH] D75649: [mlir] Introduce OwningFuncRef following the same pattern as OwningModuleRef

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 10:53:05 PDT 2020


rriddle added a comment.

In D75649#1914044 <https://reviews.llvm.org/D75649#1914044>, @tberghammer wrote:

> Hi River, I have two (somewhat related) usecases for having a FuncOp without adding it to a module:
>
> 1. I would like to write an `mlir::OwingFuncRef BuildFunc(...)` function what takes some internal/domain specific input (e.g. IR from the front end) and returns the newly built function. I could just pass in the ModuleOp as an argument and add the FuncOp to it but returning an OwningFuncRef feels like a nicer API
> 2. My code what builds a FuncOp might fail (e.g. due to invalid input) and in that case I want to report an error without modifying the existing ModuleOp as adding a broken function to it would make the module op broken as well. My approach for it is to create an OwningFuncRef, use it to own the FuncOp during the building process (so in case of a failure it will correctly destroy it) and then in case of success I would move the FuncOp from the OwningFuncRef to the ModuleOp.


I would rather not encourage this type of usage. `FuncOp::create` is something that I've been meaning to remove for a long time, but I keep getting distracted. It is a relic of the time when `FuncOp` was `Function`, and not represented as an Operation. You also don't necessarily need to pass in a ModuleOp, using `OpBuilder::create` is much more idiomatic with the rest of the infra.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75649/new/

https://reviews.llvm.org/D75649





More information about the llvm-commits mailing list