Skip to content

Commit f6a7c28

Browse files
andrey-golubevAsyaProninahrotuna
committed
[mlir][NFC] Apply rule of five to *Pass classes
Define all special member functions for mlir::Pass, mlir::OperationPass, mlir::PassWrapper and PassGen types since these classes explicitly specify 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, so the special member functions are never to be used externally (except for the copy-ctor - it is "special" since it is a "delegating" ctor for derived pass types to use during cloning - see https://reviews.llvm.org/D104302 for details). Co-authored-by: Asya Pronina <[email protected]> Co-authored-by: Harald Rotuna <[email protected]>
1 parent afa6b5e commit f6a7c28

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

mlir/include/mlir/Pass/Pass.h

Lines changed: 17 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() {
@@ -349,9 +352,14 @@ class Pass {
349352
/// - A 'std::unique_ptr<Pass> clonePass() const' method.
350353
template <typename OpT = void>
351354
class OperationPass : public Pass {
355+
public:
356+
~OperationPass() = default;
352357
protected:
353358
OperationPass(TypeID passID) : Pass(passID, OpT::getOperationName()) {}
354359
OperationPass(const OperationPass &) = default;
360+
OperationPass &operator=(const OperationPass &) = delete;
361+
OperationPass(OperationPass &&) = delete;
362+
OperationPass &operator=(OperationPass &&) = delete;
355363

356364
/// Support isa/dyn_cast functionality.
357365
static bool classof(const Pass *pass) {
@@ -388,9 +396,14 @@ class OperationPass : public Pass {
388396
/// - A 'std::unique_ptr<Pass> clonePass() const' method.
389397
template <>
390398
class OperationPass<void> : public Pass {
399+
public:
400+
~OperationPass() = default;
391401
protected:
392402
OperationPass(TypeID passID) : Pass(passID) {}
393403
OperationPass(const OperationPass &) = default;
404+
OperationPass &operator=(const OperationPass &) = delete;
405+
OperationPass(OperationPass &&) = delete;
406+
OperationPass &operator=(OperationPass &&) = delete;
394407

395408
/// Indicate if the current pass can be scheduled on the given operation type.
396409
/// By default, generic operation passes can be scheduled on any operation.
@@ -444,10 +457,14 @@ class PassWrapper : public BaseT {
444457
static bool classof(const Pass *pass) {
445458
return pass->getTypeID() == TypeID::get<PassT>();
446459
}
460+
~PassWrapper() = default;
447461

448462
protected:
449463
PassWrapper() : BaseT(TypeID::get<PassT>()) {}
450464
PassWrapper(const PassWrapper &) = default;
465+
PassWrapper &operator=(const PassWrapper &) = delete;
466+
PassWrapper(PassWrapper &&) = delete;
467+
PassWrapper &operator=(PassWrapper &&) = delete;
451468

452469
/// Returns the derived pass name.
453470
StringRef getName() const override { return llvm::getTypeName<PassT>(); }

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)