[LIR] Move all the helpers to be private and re-order the methods in
authorChandler Carruth <chandlerc@gmail.com>
Thu, 13 Aug 2015 00:10:03 +0000 (00:10 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 13 Aug 2015 00:10:03 +0000 (00:10 +0000)
a way that groups things logically. No functionality changed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244845 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopIdiomRecognize.cpp

index 33633ae073f959bcdec203cff4492c15d291f26a..95aadb190751d0a8faff984cc355a7f61c3d35a9 100644 (file)
@@ -129,20 +129,6 @@ public:
   }
 
   bool runOnLoop(Loop *L, LPPassManager &LPM) override;
-  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
-                      SmallVectorImpl<BasicBlock *> &ExitBlocks);
-
-  bool processLoopStore(StoreInst *SI, const SCEV *BECount);
-  bool processLoopMemSet(MemSetInst *MSI, const SCEV *BECount);
-
-  bool processLoopStridedStore(Value *DestPtr, unsigned StoreSize,
-                               unsigned StoreAlignment, Value *SplatValue,
-                               Instruction *TheStore, const SCEVAddRecExpr *Ev,
-                               const SCEV *BECount);
-  bool processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize,
-                                  const SCEVAddRecExpr *StoreEv,
-                                  const SCEVAddRecExpr *LoadEv,
-                                  const SCEV *BECount);
 
   /// This transformation requires natural loop information & requires that
   /// loop preheaders be inserted into the CFG.
@@ -189,8 +175,32 @@ public:
   Loop *getLoop() const { return CurLoop; }
 
 private:
-  bool runOnNoncountableLoop();
+  /// \name Countable Loop Idiom Handling
+  /// @{
+
   bool runOnCountableLoop();
+  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
+                      SmallVectorImpl<BasicBlock *> &ExitBlocks);
+
+  bool processLoopStore(StoreInst *SI, const SCEV *BECount);
+  bool processLoopMemSet(MemSetInst *MSI, const SCEV *BECount);
+
+  bool processLoopStridedStore(Value *DestPtr, unsigned StoreSize,
+                               unsigned StoreAlignment, Value *SplatValue,
+                               Instruction *TheStore, const SCEVAddRecExpr *Ev,
+                               const SCEV *BECount);
+  bool processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize,
+                                  const SCEVAddRecExpr *StoreEv,
+                                  const SCEVAddRecExpr *LoadEv,
+                                  const SCEV *BECount);
+
+  /// @}
+  /// \name Noncountable Loop Idiom Handling
+  /// @{
+
+  bool runOnNoncountableLoop();
+
+  /// @}
 };
 
 } // End anonymous namespace.
@@ -552,7 +562,6 @@ CallInst *NclPopcountRecognize::createPopcntIntrinsic(IRBuilderTy &IRBuilder,
 ///   detected, transform the relevant code to popcount intrinsic function
 ///   call, and return true; otherwise, return false.
 bool NclPopcountRecognize::recognize() {
-
   if (!LIR.getTargetTransformInfo())
     return false;
 
@@ -577,6 +586,28 @@ bool NclPopcountRecognize::recognize() {
 //
 //===----------------------------------------------------------------------===//
 
+bool LoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) {
+  if (skipOptnoneFunction(L))
+    return false;
+
+  CurLoop = L;
+
+  // If the loop could not be converted to canonical form, it must have an
+  // indirectbr in it, just give up.
+  if (!L->getLoopPreheader())
+    return false;
+
+  // Disable loop idiom recognition if the function's name is a common idiom.
+  StringRef Name = L->getHeader()->getParent()->getName();
+  if (Name == "memset" || Name == "memcpy")
+    return false;
+
+  SE = &getAnalysis<ScalarEvolution>();
+  if (SE->hasLoopInvariantBackedgeTakenCount(L))
+    return runOnCountableLoop();
+  return runOnNoncountableLoop();
+}
+
 bool LoopIdiomRecognize::runOnCountableLoop() {
   const SCEV *BECount = SE->getBackedgeTakenCount(CurLoop);
   assert(!isa<SCEVCouldNotCompute>(BECount) &&
@@ -617,36 +648,6 @@ bool LoopIdiomRecognize::runOnCountableLoop() {
   return MadeChange;
 }
 
-bool LoopIdiomRecognize::runOnNoncountableLoop() {
-  NclPopcountRecognize Popcount(*this);
-  if (Popcount.recognize())
-    return true;
-
-  return false;
-}
-
-bool LoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) {
-  if (skipOptnoneFunction(L))
-    return false;
-
-  CurLoop = L;
-
-  // If the loop could not be converted to canonical form, it must have an
-  // indirectbr in it, just give up.
-  if (!L->getLoopPreheader())
-    return false;
-
-  // Disable loop idiom recognition if the function's name is a common idiom.
-  StringRef Name = L->getHeader()->getParent()->getName();
-  if (Name == "memset" || Name == "memcpy")
-    return false;
-
-  SE = &getAnalysis<ScalarEvolution>();
-  if (SE->hasLoopInvariantBackedgeTakenCount(L))
-    return runOnCountableLoop();
-  return runOnNoncountableLoop();
-}
-
 /// runOnLoopBlock - Process the specified block, which lives in a counted loop
 /// with the specified backedge count.  This block is known to be in the current
 /// loop and not in any subloops.
@@ -1062,3 +1063,11 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(
   ++NumMemCpy;
   return true;
 }
+
+bool LoopIdiomRecognize::runOnNoncountableLoop() {
+  NclPopcountRecognize Popcount(*this);
+  if (Popcount.recognize())
+    return true;
+
+  return false;
+}