[Mlir-commits] [mlir] [mlir] Apply rule of five for Pass / OperationPass (PR #80998)

Andrei Golubev llvmlistbot at llvm.org
Wed Feb 7 07:15:21 PST 2024


https://github.com/andrey-golubev updated https://github.com/llvm/llvm-project/pull/80998

>From f9a93d3d5ad5bd70e1f3a810c27c31e72117b417 Mon Sep 17 00:00:00 2001
From: "Golubev, Andrey" <andrey.golubev at intel.com>
Date: Wed, 7 Feb 2024 15:14:50 +0000
Subject: [PATCH] [mlir] Apply rule of five for Pass / OperationPass

Define all special member functions of C++ types (mlir::Pass and
mlir::OperationPass) since one of them is already provided.
As part of this, enable move semantics for these types as it
probably makes sense since copy semantics is present.

Co-authored-by: Asya Pronina <anastasiya.pronina at intel.com>
---
 mlir/include/mlir/Pass/Pass.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h
index 121b253eb83fea..328f0a5a41bce1 100644
--- a/mlir/include/mlir/Pass/Pass.h
+++ b/mlir/include/mlir/Pass/Pass.h
@@ -161,6 +161,13 @@ class Pass {
   explicit Pass(TypeID passID, std::optional<StringRef> opName = std::nullopt)
       : passID(passID), opName(opName) {}
   Pass(const Pass &other) : Pass(other.passID, other.opName) {}
+  Pass &operator=(const Pass &other) {
+    this->passID = other.passID;
+    this->opName = other.opName;
+    return *this;
+  }
+  Pass(Pass &&) = default;
+  Pass &operator=(Pass &&) = default;
 
   /// Returns the current pass state.
   detail::PassExecutionState &getPassState() {
@@ -352,6 +359,9 @@ class OperationPass : public Pass {
 protected:
   OperationPass(TypeID passID) : Pass(passID, OpT::getOperationName()) {}
   OperationPass(const OperationPass &) = default;
+  OperationPass &operator=(const OperationPass &) = default;
+  OperationPass(OperationPass &&) = default;
+  OperationPass &operator=(OperationPass &&) = default;
 
   /// Support isa/dyn_cast functionality.
   static bool classof(const Pass *pass) {
@@ -391,6 +401,9 @@ class OperationPass<void> : public Pass {
 protected:
   OperationPass(TypeID passID) : Pass(passID) {}
   OperationPass(const OperationPass &) = default;
+  OperationPass &operator=(const OperationPass &) = default;
+  OperationPass(OperationPass &&) = default;
+  OperationPass &operator=(OperationPass &&) = default;
 
   /// Indicate if the current pass can be scheduled on the given operation type.
   /// By default, generic operation passes can be scheduled on any operation.



More information about the Mlir-commits mailing list