Skip to content

Commit f0451cf

Browse files
authored
[PIR] adjust the value == function. (#61346)
1 parent c31c979 commit f0451cf

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

paddle/pir/core/operation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class IR_API alignas(8) Operation final
277277
const uint32_t num_operands_ = 0;
278278
const uint32_t num_regions_ = 0;
279279
const uint32_t num_successors_ = 0;
280-
const uint64_t id_ = 0;
280+
const uint64_t id_;
281281

282282
detail::BlockOperandImpl *block_operands_{nullptr};
283283
Region *regions_{nullptr};

paddle/pir/core/value.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131

3232
namespace pir {
3333
bool Value::operator==(const Value &other) const {
34-
return impl_ == other.impl_;
34+
return impl_ == other.impl_ &&
35+
(impl_ == nullptr || impl_->id() == other.impl_->id());
3536
}
3637

3738
bool Value::operator!=(const Value &other) const {
38-
return impl_ != other.impl_;
39+
return !(operator==(other));
3940
}
4041

4142
bool Value::operator!() const { return impl_ == nullptr; }

paddle/pir/core/value_impl.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
// limitations under the License.
1414
#include "paddle/pir/core/value_impl.h"
1515

16+
namespace {
17+
uint64_t GenerateId() {
18+
static std::atomic<std::uint64_t> uid{0};
19+
return ++uid;
20+
}
21+
} // namespace
1622
namespace pir {
1723

1824
namespace detail {
@@ -40,7 +46,7 @@ std::string ValueImpl::PrintUdChain() {
4046
result << "nullptr";
4147
return result.str();
4248
}
43-
ValueImpl::ValueImpl(Type type, uint32_t kind) {
49+
ValueImpl::ValueImpl(Type type, uint32_t kind) : id_(GenerateId()) {
4450
if (kind > BLOCK_ARG_IDX) {
4551
LOG(FATAL) << "The kind of value_impl(" << kind
4652
<< "), is bigger than BLOCK_ARG_IDX(7)";

paddle/pir/core/value_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class alignas(8) ValueImpl {
7171
return T::classof(*this);
7272
}
7373

74+
uint64_t id() const { return id_; }
75+
7476
protected:
7577
///
7678
/// \brief Only can be constructed by derived classes such as OpResultImpl.
@@ -92,6 +94,8 @@ class alignas(8) ValueImpl {
9294
/// outline output(OpOutlineResultImpl); (3) index = 7 is reserved.
9395
///
9496
OpOperandImpl *first_use_offseted_by_kind_ = nullptr;
97+
98+
const uint64_t id_ = 0;
9599
};
96100

97101
} // namespace detail

0 commit comments

Comments
 (0)