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

Andrei Golubev llvmlistbot at llvm.org
Wed Feb 7 07:12:49 PST 2024


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

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.

>From fc97bb41e3cd13ea15201d5384b1759f9a68ad34 Mon Sep 17 00:00:00 2001
From: "Golubev, Andrey" <andrey.golubev at intel.com>
Date: Wed, 7 Feb 2024 15:03:53 +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..efe482fd726f7e 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