[Mlir-commits] [mlir] 8672378 - [mlir] Add conversion function from OwningOpRef<T> to OwningOpRef<Operation *>
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 21 12:52:10 PDT 2022
Author: rkayaith
Date: 2022-10-21T15:52:05-04:00
New Revision: 86723787474e7d10e9267bc82e94bb034ed4ec95
URL: https://github.com/llvm/llvm-project/commit/86723787474e7d10e9267bc82e94bb034ed4ec95
DIFF: https://github.com/llvm/llvm-project/commit/86723787474e7d10e9267bc82e94bb034ed4ec95.diff
LOG: [mlir] Add conversion function from OwningOpRef<T> to OwningOpRef<Operation *>
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D136480
Added:
Modified:
mlir/include/mlir/IR/OwningOpRef.h
mlir/include/mlir/Tools/ParseUtilties.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OwningOpRef.h b/mlir/include/mlir/IR/OwningOpRef.h
index 378722c4d9962..0ca960b90ab0d 100644
--- a/mlir/include/mlir/IR/OwningOpRef.h
+++ b/mlir/include/mlir/IR/OwningOpRef.h
@@ -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 @@ class OwningOpRef {
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);
diff --git a/mlir/include/mlir/Tools/ParseUtilties.h b/mlir/include/mlir/Tools/ParseUtilties.h
index 98e2ba049b9cf..75b18f89e75a3 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<ModuleOp>(sourceMgr, config)
- .release()
- .getOperation();
+ return parseSourceFile<ModuleOp>(sourceMgr, config);
}
return parseSourceFile(sourceMgr, config);
}
More information about the Mlir-commits
mailing list