[PATCH] D93577: [NFC][LICM] Minor improvements to debug output

Xiaoqing Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 18 20:52:17 PST 2020


xiaoqing_wu updated this revision to Diff 312916.
xiaoqing_wu added a comment.

Remve "\ No newline at end of file" at the end of the file.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93577/new/

https://reviews.llvm.org/D93577

Files:
  llvm/lib/Transforms/Scalar/LICM.cpp


Index: llvm/lib/Transforms/Scalar/LICM.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LICM.cpp
+++ llvm/lib/Transforms/Scalar/LICM.cpp
@@ -184,6 +184,9 @@
 static void moveInstructionBefore(Instruction &I, Instruction &Dest,
                                   ICFLoopSafetyInfo &SafetyInfo,
                                   MemorySSAUpdater *MSSAU, ScalarEvolution *SE);
+#ifndef NDEBUG                                  
+static std::string getBlockName(const BasicBlock *BB);
+#endif
 
 namespace {
 struct LoopInvariantCodeMotion {
@@ -221,6 +224,9 @@
     if (skipLoop(L))
       return false;
 
+    LLVM_DEBUG(dbgs() << "Perform LICM on Loop with header at block "
+                      << getBlockName(L->getHeader()) << "\n");
+
     auto *SE = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
     MemorySSA *MSSA = EnableMSSALoopDependency
                           ? (&getAnalysis<MemorySSAWrapperPass>().getMSSA())
@@ -698,8 +704,8 @@
     // If not involved in a pending branch, hoist to preheader
     BasicBlock *InitialPreheader = CurLoop->getLoopPreheader();
     if (It == HoistableBranches.end()) {
-      LLVM_DEBUG(dbgs() << "LICM using " << InitialPreheader->getName()
-                        << " as hoist destination for " << BB->getName()
+      LLVM_DEBUG(dbgs() << "LICM using " << getBlockName(InitialPreheader)
+                        << " as hoist destination for " << getBlockName(BB)
                         << "\n");
       HoistDestinationMap[BB] = InitialPreheader;
       return InitialPreheader;
@@ -979,8 +985,8 @@
           HoistPoint = Dominator->getTerminator();
         }
         LLVM_DEBUG(dbgs() << "LICM rehoisting to "
-                          << HoistPoint->getParent()->getName()
-                          << ": " << *I << "\n");
+                          << getBlockName(HoistPoint->getParent()) << ": " << *I
+                          << "\n");
         moveInstructionBefore(*I, *HoistPoint, *SafetyInfo, MSSAU, SE);
         HoistPoint = I;
         Changed = true;
@@ -1738,7 +1744,7 @@
                   BasicBlock *Dest, ICFLoopSafetyInfo *SafetyInfo,
                   MemorySSAUpdater *MSSAU, ScalarEvolution *SE,
                   OptimizationRemarkEmitter *ORE) {
-  LLVM_DEBUG(dbgs() << "LICM hoisting to " << Dest->getName() << ": " << I
+  LLVM_DEBUG(dbgs() << "LICM hoisting to " << getBlockName(Dest) << ": " << I
                     << "\n");
   ORE->emit([&]() {
     return OptimizationRemark(DEBUG_TYPE, "Hoisted", &I) << "hoisting "
@@ -2354,3 +2360,16 @@
   assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop");
   return LI->getLoopFor(BB) != CurLoop;
 }
+
+#ifndef NDEBUG
+/// Return block name, for unnamed block, return its label.
+static std::string getBlockName(const BasicBlock *BB) {
+  if (!BB->getName().empty())
+    return std::string(BB->getName());
+
+  std::string BBName;
+  raw_string_ostream OS(BBName);
+  BB->printAsOperand(OS, false);
+  return OS.str();
+}
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93577.312916.patch
Type: text/x-patch
Size: 3050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201219/6ef72dfb/attachment.bin>


More information about the llvm-commits mailing list