Skip to content

Commit

Permalink
[NewIR]Disable copy and assign for Operation (PaddlePaddle#55328)
Browse files Browse the repository at this point in the history
* [NewIR]Disable copy and assign for Operation

* add macros.h
  • Loading branch information
Aurelius84 authored and cqulilujia committed Jul 24, 2023
1 parent 492eedc commit b48e8fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions paddle/ir/core/macros.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions paddle/ir/core/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <ostream>
#include <vector>
#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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b48e8fd

Please sign in to comment.