<div dir="ltr">I swear there was a more generic debug counting proposal a few months ago.<div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 3, 2016 at 1:10 PM, Sebastian Pop <span dir="ltr"><<a href="mailto:sebpop@gmail.com" target="_blank">sebpop@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">sebpop created this revision.<br>
sebpop added reviewers: dberlin, majnemer.<br>
sebpop added a subscriber: llvm-commits.<br>
sebpop set the repository for this revision to rL LLVM.<br>
<br>
This patch adds -licm-max-hoist and -licm-max-sink to debug the LICM pass.<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D20984" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20984</a><br>
<br>
Files:<br>
  llvm/lib/Transforms/Scalar/LICM.cpp<br>
<br>
Index: llvm/lib/Transforms/Scalar/LICM.cpp<br>
===================================================================<br>
--- llvm/lib/Transforms/Scalar/LICM.cpp<br>
+++ llvm/lib/Transforms/Scalar/LICM.cpp<br>
@@ -77,6 +77,16 @@<br>
 static cl::opt<bool><br>
     DisablePromotion("disable-licm-promotion", cl::Hidden,<br>
                      cl::desc("Disable memory promotion in LICM pass"));<br>
+static cl::opt<int><br>
+    LICMMaxHoist("licm-max-hoist", cl::Hidden, cl::init(-1),<br>
+                 cl::desc("Max number of instructions to hoist "<br>
+                          "(default unlimited = -1)"));<br>
+static cl::opt<int><br>
+    LICMMaxSink("licm-max-sink", cl::Hidden, cl::init(-1),<br>
+                cl::desc("Max number of instructions to sink "<br>
+                         "(default unlimited = -1)"));<br>
+static int HoistCtr = 0;<br>
+static int SinkCtr = 0;<br>
<br>
 static bool inSubLoop(BasicBlock *BB, Loop *CurLoop, LoopInfo *LI);<br>
 static bool isNotUsedInLoop(const Instruction &I, const Loop *CurLoop,<br>
@@ -628,14 +638,18 @@<br>
 static bool sink(Instruction &I, const LoopInfo *LI, const DominatorTree *DT,<br>
                  const Loop *CurLoop, AliasSetTracker *CurAST,<br>
                  const LICMSafetyInfo *SafetyInfo) {<br>
+  if (LICMMaxSink != -1) {<br>
+    if (SinkCtr >= LICMMaxSink)<br>
+      return false;<br>
+    ++SinkCtr;<br>
+  }<br>
+<br>
   DEBUG(dbgs() << "LICM sinking instruction: " << I << "\n");<br>
-  bool Changed = false;<br>
   if (isa<LoadInst>(I))<br>
     ++NumMovedLoads;<br>
   else if (isa<CallInst>(I))<br>
     ++NumMovedCalls;<br>
   ++NumSunk;<br>
-  Changed = true;<br>
<br>
 #ifndef NDEBUG<br>
   SmallVector<BasicBlock *, 32> ExitBlocks;<br>
@@ -688,14 +702,20 @@<br>
<br>
   CurAST->deleteValue(&I);<br>
   I.eraseFromParent();<br>
-  return Changed;<br>
+  return true;<br>
 }<br>
<br>
-/// When an instruction is found to only use loop invariant operands that<br>
-/// is safe to hoist, this instruction is called to do the dirty work.<br>
+/// When an instruction is found to only use loop invariant operands that is<br>
+/// safe to hoist, this function is called to do the dirty work.<br>
 ///<br>
 static bool hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,<br>
                   const LICMSafetyInfo *SafetyInfo) {<br>
+  if (LICMMaxHoist != -1) {<br>
+    if (HoistCtr >= LICMMaxHoist)<br>
+      return false;<br>
+    ++HoistCtr;<br>
+  }<br>
+<br>
   auto *Preheader = CurLoop->getLoopPreheader();<br>
   DEBUG(dbgs() << "LICM hoisting to " << Preheader->getName() << ": " << I<br>
                << "\n");<br>
<br>
<br>
</blockquote></div><br></div>