[llvm] r244853 - [LIR] Make the LoopIdiomRecognize pass get analyses essentially the same

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 18:03:26 PDT 2015


Author: chandlerc
Date: Wed Aug 12 20:03:26 2015
New Revision: 244853

URL: http://llvm.org/viewvc/llvm-project?rev=244853&view=rev
Log:
[LIR] Make the LoopIdiomRecognize pass get analyses essentially the same
way as every other pass. This simplifies the code quite a bit and is
also more idiomatic! <ba-dum!>

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp?rev=244853&r1=244852&r2=244853&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp Wed Aug 12 20:03:26 2015
@@ -78,10 +78,6 @@ public:
   static char ID;
   explicit LoopIdiomRecognize() : LoopPass(ID) {
     initializeLoopIdiomRecognizePass(*PassRegistry::getPassRegistry());
-    DT = nullptr;
-    SE = nullptr;
-    TLI = nullptr;
-    TTI = nullptr;
   }
 
   bool runOnLoop(Loop *L, LPPassManager &LPM) override;
@@ -106,30 +102,6 @@ public:
     AU.addRequired<TargetTransformInfoWrapperPass>();
   }
 
-  DominatorTree *getDominatorTree() {
-    return DT ? DT
-              : (DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree());
-  }
-
-  ScalarEvolution *getScalarEvolution() {
-    return SE ? SE : (SE = &getAnalysis<ScalarEvolution>());
-  }
-
-  TargetLibraryInfo *getTargetLibraryInfo() {
-    if (!TLI)
-      TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
-
-    return TLI;
-  }
-
-  const TargetTransformInfo *getTargetTransformInfo() {
-    return TTI ? TTI
-               : (TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
-                      *CurLoop->getHeader()->getParent()));
-  }
-
-  Loop *getLoop() const { return CurLoop; }
-
 private:
   /// \name Countable Loop Idiom Handling
   /// @{
@@ -205,7 +177,6 @@ bool LoopIdiomRecognize::runOnLoop(Loop
     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())
@@ -216,9 +187,15 @@ bool LoopIdiomRecognize::runOnLoop(Loop
   if (Name == "memset" || Name == "memcpy")
     return false;
 
+  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
   SE = &getAnalysis<ScalarEvolution>();
+  TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
+  TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
+      *CurLoop->getHeader()->getParent());
+
   if (SE->hasLoopInvariantBackedgeTakenCount(L))
     return runOnCountableLoop();
+
   return runOnNoncountableLoop();
 }
 
@@ -234,14 +211,7 @@ bool LoopIdiomRecognize::runOnCountableL
     if (BECst->getValue()->getValue() == 0)
       return false;
 
-  // set DT
-  (void)getDominatorTree();
-
   LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
-  TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
-
-  // set TLI
-  (void)getTargetLibraryInfo();
 
   SmallVector<BasicBlock *, 8> ExitBlocks;
   CurLoop->getUniqueExitBlocks(ExitBlocks);
@@ -852,10 +822,6 @@ static bool detectPopcountIdiom(Loop *Cu
 /// If detected, transforms the relevant code to issue the popcount intrinsic
 /// function call, and returns true; otherwise, returns false.
 bool LoopIdiomRecognize::recognizePopcount() {
-  (void)getScalarEvolution();
-  (void)getTargetLibraryInfo();
-  (void)getTargetTransformInfo();
-
   if (TTI->getPopcntSupport(32) != TargetTransformInfo::PSK_FastHardware)
     return false;
 




More information about the llvm-commits mailing list