From b9e255b3663c29686ef91e0d332c1ba82930bbb5 Mon Sep 17 00:00:00 2001 From: Sebastien Alaiwan Date: Thu, 9 Dec 2021 15:41:42 +0100 Subject: [PATCH] DefUseManager: rename comparison operators to 'CompareAndPrintDifferences' (#4624) This make sense, as those are actually debug functions and shouldn't be used in production code. --- source/opt/def_use_manager.cpp | 26 +++++++++++++++----------- source/opt/def_use_manager.h | 6 ++---- source/opt/ir_context.cpp | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/opt/def_use_manager.cpp b/source/opt/def_use_manager.cpp index 824956f1f..d54fdb65d 100644 --- a/source/opt/def_use_manager.cpp +++ b/source/opt/def_use_manager.cpp @@ -259,49 +259,53 @@ void DefUseManager::EraseUseRecordsOfOperandIds(const Instruction* inst) { } } -bool operator==(const DefUseManager& lhs, const DefUseManager& rhs) { +bool CompareAndPrintDifferences(const DefUseManager& lhs, + const DefUseManager& rhs) { + bool same = true; + if (lhs.id_to_def_ != rhs.id_to_def_) { for (auto p : lhs.id_to_def_) { if (rhs.id_to_def_.find(p.first) == rhs.id_to_def_.end()) { - return false; + printf("Diff in id_to_def: missing value in rhs\n"); } } for (auto p : rhs.id_to_def_) { if (lhs.id_to_def_.find(p.first) == lhs.id_to_def_.end()) { - return false; + printf("Diff in id_to_def: missing value in lhs\n"); } } - return false; + same = false; } if (lhs.id_to_users_ != rhs.id_to_users_) { for (auto p : lhs.id_to_users_) { if (rhs.id_to_users_.count(p) == 0) { - return false; + printf("Diff in id_to_users: missing value in rhs\n"); } } for (auto p : rhs.id_to_users_) { if (lhs.id_to_users_.count(p) == 0) { - return false; + printf("Diff in id_to_users: missing value in lhs\n"); } } - return false; + same = false; } if (lhs.inst_to_used_ids_ != rhs.inst_to_used_ids_) { for (auto p : lhs.inst_to_used_ids_) { if (rhs.inst_to_used_ids_.count(p.first) == 0) { - return false; + printf("Diff in inst_to_used_ids: missing value in rhs\n"); } } for (auto p : rhs.inst_to_used_ids_) { if (lhs.inst_to_used_ids_.count(p.first) == 0) { - return false; + printf("Diff in inst_to_used_ids: missing value in lhs\n"); } } - return false; + same = false; } - return true; + + return same; } } // namespace analysis diff --git a/source/opt/def_use_manager.h b/source/opt/def_use_manager.h index 9d31de535..c4901f8f6 100644 --- a/source/opt/def_use_manager.h +++ b/source/opt/def_use_manager.h @@ -210,10 +210,8 @@ class DefUseManager { // Erases the records that a given instruction uses its operand ids. void EraseUseRecordsOfOperandIds(const Instruction* inst); - friend bool operator==(const DefUseManager&, const DefUseManager&); - friend bool operator!=(const DefUseManager& lhs, const DefUseManager& rhs) { - return !(lhs == rhs); - } + friend bool CompareAndPrintDifferences(const DefUseManager&, + const DefUseManager&); // If |inst| has not already been analysed, then analyses its defintion and // uses. diff --git a/source/opt/ir_context.cpp b/source/opt/ir_context.cpp index fef0f7cef..789184614 100644 --- a/source/opt/ir_context.cpp +++ b/source/opt/ir_context.cpp @@ -317,7 +317,7 @@ bool IRContext::IsConsistent() { #else if (AreAnalysesValid(kAnalysisDefUse)) { analysis::DefUseManager new_def_use(module()); - if (*get_def_use_mgr() != new_def_use) { + if (!CompareAndPrintDifferences(*get_def_use_mgr(), new_def_use)) { return false; } }