[PATCH] D31750: [globalisel] Enable tracing the legalizer with --debug-only=legalize-mir

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 6 03:31:49 PDT 2017


dsanders created this revision.
Herald added subscribers: igorb, dberris.

https://reviews.llvm.org/D31750

Files:
  lib/CodeGen/GlobalISel/LegalizerHelper.cpp


Index: lib/CodeGen/GlobalISel/LegalizerHelper.cpp
===================================================================
--- lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -35,33 +35,46 @@
 
 LegalizerHelper::LegalizeResult
 LegalizerHelper::legalizeInstrStep(MachineInstr &MI) {
+  DEBUG(dbgs() << "Legalizing: "; MI.print(dbgs()));
+
   auto Action = LI.getAction(MI, MRI);
   switch (std::get<0>(Action)) {
   case LegalizerInfo::Legal:
+    DEBUG(dbgs() << ".. Already legal\n");
     return AlreadyLegal;
   case LegalizerInfo::Libcall:
+    DEBUG(dbgs() << ".. Convert to libcall\n");
     return libcall(MI);
   case LegalizerInfo::NarrowScalar:
+    DEBUG(dbgs() << ".. Narrow scalar\n");
     return narrowScalar(MI, std::get<1>(Action), std::get<2>(Action));
   case LegalizerInfo::WidenScalar:
+    DEBUG(dbgs() << ".. Widen scalar\n");
     return widenScalar(MI, std::get<1>(Action), std::get<2>(Action));
   case LegalizerInfo::Lower:
+    DEBUG(dbgs() << ".. Lower\n");
     return lower(MI, std::get<1>(Action), std::get<2>(Action));
   case LegalizerInfo::FewerElements:
+    DEBUG(dbgs() << ".. Reduce number of elements\n");
     return fewerElementsVector(MI, std::get<1>(Action), std::get<2>(Action));
   case LegalizerInfo::Custom:
+    DEBUG(dbgs() << ".. Custom legalization\n");
     return LI.legalizeCustom(MI, MRI, MIRBuilder) ? Legalized
                                                   : UnableToLegalize;
   default:
+    DEBUG(dbgs() << ".. Unable to legalize\n");
     return UnableToLegalize;
   }
 }
 
 LegalizerHelper::LegalizeResult
 LegalizerHelper::legalizeInstr(MachineInstr &MI) {
+  SmallVector<MachineInstr *, 4> DebugReportList LLVM_ATTRIBUTE_UNUSED;
   SmallVector<MachineInstr *, 4> WorkList;
-  MIRBuilder.recordInsertions(
-      [&](MachineInstr *MI) { WorkList.push_back(MI); });
+  MIRBuilder.recordInsertions([&](MachineInstr *MI) {
+    DEBUG(DebugReportList.push_back(MI));
+    WorkList.push_back(MI);
+  });
   WorkList.push_back(&MI);
 
   bool Changed = false;
@@ -75,6 +88,12 @@
     }
     Changed |= Res == Legalized;
     ++Idx;
+
+#ifndef NDEBUG
+    for (const auto *MI: DebugReportList)
+      DEBUG(dbgs() << ".. .. New MI: "; MI->print(dbgs()));
+    DebugReportList.clear();
+#endif
   } while (Idx < WorkList.size());
 
   MIRBuilder.stopRecordingInsertions();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31750.94343.patch
Type: text/x-patch
Size: 2375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170406/e07dab26/attachment.bin>


More information about the llvm-commits mailing list