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

Jon Roelofs via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 08:24:51 PDT 2021


jroelofs created this revision.
jroelofs added a reviewer: aemerson.
Herald added a subscriber: hiraditya.
jroelofs requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105290

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


Index: llvm/lib/CodeGen/GlobalISel/Combiner.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Combiner.cpp
+++ llvm/lib/CodeGen/GlobalISel/Combiner.cpp
@@ -153,8 +153,14 @@
     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;
 }
Index: llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
+++ llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
@@ -260,8 +260,18 @@
 #endif
 }
 
+#ifndef NDEBUG
+template<typename T>
+static const char *stringify(T &t, std::string &S) {
+  raw_string_ostream OS(S);
+  OS << t;
+  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 +284,8 @@
     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 +293,14 @@
   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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105290.355895.patch
Type: text/x-patch
Size: 2625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210701/ce026cb5/attachment.bin>


More information about the llvm-commits mailing list