[llvm] 14d64be - [GISel] Print better error messages for missing Combiner Observer calls

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 15:18:27 PDT 2021


Author: Jon Roelofs
Date: 2021-07-01T15:18:18-07:00
New Revision: 14d64be6e54a23e1a20216b6a42ae2ce5926d2ed

URL: https://github.com/llvm/llvm-project/commit/14d64be6e54a23e1a20216b6a42ae2ce5926d2ed
DIFF: https://github.com/llvm/llvm-project/commit/14d64be6e54a23e1a20216b6a42ae2ce5926d2ed.diff

LOG: [GISel] Print better error messages for missing Combiner Observer calls

Differential revision: https://reviews.llvm.org/D105290

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
    llvm/lib/CodeGen/GlobalISel/Combiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
index f146271718ee7..f9bfe8518083c 100644
--- a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
+++ b/llvm/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/llvm/lib/CodeGen/GlobalISel/Combiner.cpp b/llvm/lib/CodeGen/GlobalISel/Combiner.cpp
index f1071d96e5a36..6f103bca6892f 100644
--- a/llvm/lib/CodeGen/GlobalISel/Combiner.cpp
+++ b/llvm/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;
 }


        


More information about the llvm-commits mailing list