From 86723787474e7d10e9267bc82e94bb034ed4ec95 Mon Sep 17 00:00:00 2001 From: rkayaith Date: Fri, 21 Oct 2022 14:37:42 -0400 Subject: [PATCH] [mlir] Add conversion function from OwningOpRef to OwningOpRef Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D136480 --- mlir/include/mlir/IR/OwningOpRef.h | 4 ++++ mlir/include/mlir/Tools/ParseUtilties.h | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir/IR/OwningOpRef.h b/mlir/include/mlir/IR/OwningOpRef.h index 378722c..0ca960b 100644 --- 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 @@ public: 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 index 98e2ba0..75b18f8 100644 --- a/mlir/include/mlir/Tools/ParseUtilties.h +++ b/mlir/include/mlir/Tools/ParseUtilties.h @@ -28,9 +28,7 @@ parseSourceFileForTool(llvm::SourceMgr &sourceMgr, const ParserConfig &config, 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); } -- 2.7.4