DefUseManager: rename comparison operators to 'CompareAndPrintDifferences' (#4624)

This make sense, as those are actually debug functions
and shouldn't be used in production code.
This commit is contained in:
Sebastien Alaiwan 2021-12-09 15:41:42 +01:00 committed by GitHub
parent f37551d2b6
commit b9e255b366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 16 deletions

View File

@ -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_) { if (lhs.id_to_def_ != rhs.id_to_def_) {
for (auto p : lhs.id_to_def_) { for (auto p : lhs.id_to_def_) {
if (rhs.id_to_def_.find(p.first) == rhs.id_to_def_.end()) { 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_) { for (auto p : rhs.id_to_def_) {
if (lhs.id_to_def_.find(p.first) == lhs.id_to_def_.end()) { 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_) { if (lhs.id_to_users_ != rhs.id_to_users_) {
for (auto p : lhs.id_to_users_) { for (auto p : lhs.id_to_users_) {
if (rhs.id_to_users_.count(p) == 0) { 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_) { for (auto p : rhs.id_to_users_) {
if (lhs.id_to_users_.count(p) == 0) { 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_) { if (lhs.inst_to_used_ids_ != rhs.inst_to_used_ids_) {
for (auto p : lhs.inst_to_used_ids_) { for (auto p : lhs.inst_to_used_ids_) {
if (rhs.inst_to_used_ids_.count(p.first) == 0) { 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_) { for (auto p : rhs.inst_to_used_ids_) {
if (lhs.inst_to_used_ids_.count(p.first) == 0) { 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 } // namespace analysis

View File

@ -210,10 +210,8 @@ class DefUseManager {
// Erases the records that a given instruction uses its operand ids. // Erases the records that a given instruction uses its operand ids.
void EraseUseRecordsOfOperandIds(const Instruction* inst); void EraseUseRecordsOfOperandIds(const Instruction* inst);
friend bool operator==(const DefUseManager&, const DefUseManager&); friend bool CompareAndPrintDifferences(const DefUseManager&,
friend bool operator!=(const DefUseManager& lhs, const DefUseManager& rhs) { const DefUseManager&);
return !(lhs == rhs);
}
// If |inst| has not already been analysed, then analyses its defintion and // If |inst| has not already been analysed, then analyses its defintion and
// uses. // uses.

View File

@ -317,7 +317,7 @@ bool IRContext::IsConsistent() {
#else #else
if (AreAnalysesValid(kAnalysisDefUse)) { if (AreAnalysesValid(kAnalysisDefUse)) {
analysis::DefUseManager new_def_use(module()); 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; return false;
} }
} }