Skip to content

Commit 80c9a4e

Browse files
andrey-golubevAsyaProninahrotuna
committed
[mlir] Apply rule of five to *Pass classes
Define all special member functions for mlir::Pass, mlir::OperationPass and PassGen types since mlir::Pass already provides a custom copy-ctor. Given the nature of the types, however, mark other special member functions deleted: the semantics of a Pass type object seems to be that it is only ever created by being wrapped in a smart pointer. The copy-ctor is special since this is the "delegating" ctor for derived pass types to use during cloning. Co-authored-by: Asya Pronina <[email protected]> Co-authored-by: Harald Rotuna <[email protected]>
1 parent d42f395 commit 80c9a4e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mlir/include/mlir/Pass/Pass.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class Pass {
161161
explicit Pass(TypeID passID, std::optional<StringRef> opName = std::nullopt)
162162
: passID(passID), opName(opName) {}
163163
Pass(const Pass &other) : Pass(other.passID, other.opName) {}
164+
Pass &operator=(const Pass &) = delete;
165+
Pass(Pass &&) = delete;
166+
Pass &operator=(Pass &&) = delete;
164167

165168
/// Returns the current pass state.
166169
detail::PassExecutionState &getPassState() {
@@ -352,6 +355,9 @@ class OperationPass : public Pass {
352355
protected:
353356
OperationPass(TypeID passID) : Pass(passID, OpT::getOperationName()) {}
354357
OperationPass(const OperationPass &) = default;
358+
OperationPass &operator=(const OperationPass &) = delete;
359+
OperationPass(OperationPass &&) = delete;
360+
OperationPass &operator=(OperationPass &&) = delete;
355361

356362
/// Support isa/dyn_cast functionality.
357363
static bool classof(const Pass *pass) {
@@ -391,6 +397,9 @@ class OperationPass<void> : public Pass {
391397
protected:
392398
OperationPass(TypeID passID) : Pass(passID) {}
393399
OperationPass(const OperationPass &) = default;
400+
OperationPass &operator=(const OperationPass &) = delete;
401+
OperationPass(OperationPass &&) = delete;
402+
OperationPass &operator=(OperationPass &&) = delete;
394403

395404
/// Indicate if the current pass can be scheduled on the given operation type.
396405
/// By default, generic operation passes can be scheduled on any operation.

mlir/tools/mlir-tblgen/PassGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ class {0}Base : public {1} {
183183
184184
{0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
185185
{0}Base(const {0}Base &other) : {1}(other) {{}
186+
{0}Base& operator=(const {0}Base &) = delete;
187+
{0}Base({0}Base &&) = delete;
188+
{0}Base& operator=({0}Base &&) = delete;
189+
~{0}Base() = default;
186190
187191
/// Returns the command-line argument attached to this pass.
188192
static constexpr ::llvm::StringLiteral getArgumentName() {
@@ -380,6 +384,10 @@ class {0}Base : public {1} {
380384
381385
{0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
382386
{0}Base(const {0}Base &other) : {1}(other) {{}
387+
{0}Base& operator=(const {0}Base &) = delete;
388+
{0}Base({0}Base &&) = delete;
389+
{0}Base& operator=({0}Base &&) = delete;
390+
~{0}Base() = default;
383391
384392
/// Returns the command-line argument attached to this pass.
385393
static constexpr ::llvm::StringLiteral getArgumentName() {

0 commit comments

Comments
 (0)