[mlir] Add conversion function from OwningOpRef<T> to OwningOpRef<Operation *>
authorrkayaith <rkayaith@gmail.com>
Fri, 21 Oct 2022 18:37:42 +0000 (14:37 -0400)
committerrkayaith <rkayaith@gmail.com>
Fri, 21 Oct 2022 19:52:05 +0000 (15:52 -0400)
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D136480

mlir/include/mlir/IR/OwningOpRef.h
mlir/include/mlir/Tools/ParseUtilties.h

index 378722c..0ca960b 100644 (file)
@@ -16,6 +16,7 @@
 #include <utility>
 
 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<Operation *>() && { return release().getOperation(); }
+
   /// Release the referenced op.
   OpTy release() {
     OpTy released(nullptr);
index 98e2ba0..75b18f8 100644 (file)
@@ -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<ModuleOp>(sourceMgr, config)
-        .release()
-        .getOperation();
+    return parseSourceFile<ModuleOp>(sourceMgr, config);
   }
   return parseSourceFile(sourceMgr, config);
 }