From a9ef1d9c4a4ef48ba73cee967630ab7c04a6b9c3 Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Thu, 1 Jul 2021 08:25:30 -0700 Subject: [PATCH] [GISel] Print better error messages for missing Combiner Observer calls Differential revision: https://reviews.llvm.org/D105290 --- lib/CodeGen/GlobalISel/CSEInfo.cpp | 19 ++++++++++++++++--- lib/CodeGen/GlobalISel/Combiner.cpp | 12 +++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/GlobalISel/CSEInfo.cpp b/lib/CodeGen/GlobalISel/CSEInfo.cpp index f146271718e..f9bfe851808 100644 --- a/lib/CodeGen/GlobalISel/CSEInfo.cpp +++ b/lib/CodeGen/GlobalISel/CSEInfo.cpp @@ -260,8 +260,17 @@ void GISelCSEInfo::releaseMemory() { #endif } +#ifndef NDEBUG +static const char *stringify(const MachineInstr *MI, std::string &S) { + raw_string_ostream OS(S); + OS << *MI; + return OS.str().c_str(); +} +#endif + Error GISelCSEInfo::verify() { #ifndef NDEBUG + std::string S1, S2; handleRecordedInsts(); // For each instruction in map from MI -> UMI, // Profile(MI) and make sure UMI is found for that profile. @@ -274,7 +283,8 @@ Error GISelCSEInfo::verify() { if (FoundNode != It.second) return createStringError(std::errc::not_supported, "CSEMap mismatch, InstrMapping has MIs without " - "corresponding Nodes in CSEMap"); + "corresponding Nodes in CSEMap:\n%s", + stringify(It.second->MI, S1)); } // For every node in the CSEMap, make sure that the InstrMapping @@ -282,11 +292,14 @@ Error GISelCSEInfo::verify() { for (const UniqueMachineInstr &UMI : CSEMap) { if (!InstrMapping.count(UMI.MI)) return createStringError(std::errc::not_supported, - "Node in CSE without InstrMapping", UMI.MI); + "Node in CSE without InstrMapping:\n%s", + stringify(UMI.MI, S1)); if (InstrMapping[UMI.MI] != &UMI) return createStringError(std::make_error_code(std::errc::not_supported), - "Mismatch in CSE mapping"); + "Mismatch in CSE mapping:\n%s\n%s", + stringify(InstrMapping[UMI.MI]->MI, S1), + stringify(UMI.MI, S2)); } #endif return Error::success(); diff --git a/lib/CodeGen/GlobalISel/Combiner.cpp b/lib/CodeGen/GlobalISel/Combiner.cpp index f1071d96e5a..6f103bca689 100644 --- a/lib/CodeGen/GlobalISel/Combiner.cpp +++ b/lib/CodeGen/GlobalISel/Combiner.cpp @@ -153,8 +153,14 @@ bool Combiner::combineMachineInstrs(MachineFunction &MF, MFChanged |= Changed; } while (Changed); - assert(!CSEInfo || (!errorToBool(CSEInfo->verify()) && - "CSEInfo is not consistent. Likely missing calls to " - "observer on mutations")); +#ifndef NDEBUG + if (CSEInfo) { + if (auto E = CSEInfo->verify()) { + errs() << E << '\n'; + assert(false && "CSEInfo is not consistent. Likely missing calls to " + "observer on mutations."); + } + } +#endif return MFChanged; }