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

Tamas Berghammer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 03:46:42 PDT 2020


tberghammer added a comment.

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.


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