From: Chandler Carruth Date: Thu, 13 Aug 2015 01:03:26 +0000 (+0000) Subject: [LIR] Make the LoopIdiomRecognize pass get analyses essentially the same X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=27df06a97035fe087ec0fca3520dd259a2797fa3;hp=118bc241c3553eecb303c7fa2b91e97245749f5f [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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244853 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 8ccbf9dcb1a..e431609c474 100644 --- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -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(); } - DominatorTree *getDominatorTree() { - return DT ? DT - : (DT = &getAnalysis().getDomTree()); - } - - ScalarEvolution *getScalarEvolution() { - return SE ? SE : (SE = &getAnalysis()); - } - - TargetLibraryInfo *getTargetLibraryInfo() { - if (!TLI) - TLI = &getAnalysis().getTLI(); - - return TLI; - } - - const TargetTransformInfo *getTargetTransformInfo() { - return TTI ? TTI - : (TTI = &getAnalysis().getTTI( - *CurLoop->getHeader()->getParent())); - } - - Loop *getLoop() const { return CurLoop; } - private: /// \name Countable Loop Idiom Handling /// @{ @@ -205,7 +177,6 @@ bool LoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) { 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 *L, LPPassManager &LPM) { if (Name == "memset" || Name == "memcpy") return false; + DT = &getAnalysis().getDomTree(); SE = &getAnalysis(); + TLI = &getAnalysis().getTLI(); + TTI = &getAnalysis().getTTI( + *CurLoop->getHeader()->getParent()); + if (SE->hasLoopInvariantBackedgeTakenCount(L)) return runOnCountableLoop(); + return runOnNoncountableLoop(); } @@ -234,14 +211,7 @@ bool LoopIdiomRecognize::runOnCountableLoop() { if (BECst->getValue()->getValue() == 0) return false; - // set DT - (void)getDominatorTree(); - LoopInfo &LI = getAnalysis().getLoopInfo(); - TLI = &getAnalysis().getTLI(); - - // set TLI - (void)getTargetLibraryInfo(); SmallVector ExitBlocks; CurLoop->getUniqueExitBlocks(ExitBlocks); @@ -852,10 +822,6 @@ static bool detectPopcountIdiom(Loop *CurLoop, BasicBlock *PreCondBB, /// 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;