diff --git a/mlir/include/mlir/IR/OwningOpRef.h b/mlir/include/mlir/IR/OwningOpRef.h --- a/mlir/include/mlir/IR/OwningOpRef.h +++ b/mlir/include/mlir/IR/OwningOpRef.h @@ -16,6 +16,7 @@ #include namespace mlir { +class Operation; /// This class acts as an owning reference to an op, and will automatically /// destroy the held op on destruction if the held op is valid. @@ -51,6 +52,9 @@ OpTy *operator->() { return &op; } explicit operator bool() const { return op; } + /// Downcast to generic operation. + operator OwningOpRef() && { return release().getOperation(); } + /// Release the referenced op. OpTy release() { OpTy released(nullptr); diff --git a/mlir/include/mlir/Tools/ParseUtilties.h b/mlir/include/mlir/Tools/ParseUtilties.h --- a/mlir/include/mlir/Tools/ParseUtilties.h +++ b/mlir/include/mlir/Tools/ParseUtilties.h @@ -28,9 +28,7 @@ bool insertImplicitModule) { if (insertImplicitModule) { // TODO: Move implicit module logic out of 'parseSourceFile' and into here. - return parseSourceFile(sourceMgr, config) - .release() - .getOperation(); + return parseSourceFile(sourceMgr, config); } return parseSourceFile(sourceMgr, config); }