diff --git a/paddle/ir/core/macros.h b/paddle/ir/core/macros.h new file mode 100644 index 0000000000000..962ca6d4107f3 --- /dev/null +++ b/paddle/ir/core/macros.h @@ -0,0 +1,31 @@ +// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once + +namespace ir { +// TODO(Aurelius84): We also has DISABLE_COPY_AND_ASSIGN in phi/core/maros.h, +// howere it's not recommended to use it in ir namspace. So we define this again +// here. + +// Disable the copy and assignment operator for a class. +#ifndef DISABLE_COPY_AND_ASSIGN +#define DISABLE_COPY_AND_ASSIGN(classname) \ + private: \ + classname(const classname&) = delete; \ + classname(classname&&) = delete; \ + classname& operator=(const classname&) = delete; \ + classname& operator=(classname&&) = delete +#endif + +} // namespace ir diff --git a/paddle/ir/core/operation.h b/paddle/ir/core/operation.h index 634f01eeb9b7b..4b2252b6ff7ff 100644 --- a/paddle/ir/core/operation.h +++ b/paddle/ir/core/operation.h @@ -17,6 +17,7 @@ #include #include #include "paddle/ir/core/block.h" +#include "paddle/ir/core/macros.h" #include "paddle/ir/core/op_info.h" #include "paddle/ir/core/operation_utils.h" #include "paddle/ir/core/type.h" @@ -122,6 +123,7 @@ class IR_API alignas(8) Operation final { void Verify(); private: + DISABLE_COPY_AND_ASSIGN(Operation); Operation(const AttributeMap &attribute, ir::OpInfo op_info, uint32_t num_results,