diff options
author | Jinsong Ji <jji@us.ibm.com> | 2019-07-09 17:53:09 +0000 |
---|---|---|
committer | Jinsong Ji <jji@us.ibm.com> | 2019-07-09 17:53:09 +0000 |
commit | 06fef0b359b1b932b4d09d630175d9243394d062 (patch) | |
tree | e7047f5663c6a9e32127d28725d0112796b362a7 /llvm/lib/CodeGen/HardwareLoops.cpp | |
parent | 65f964c23eb13ee592f4adfe7a9628b4ee1de286 (diff) | |
download | bcm5719-llvm-06fef0b359b1b932b4d09d630175d9243394d062.tar.gz bcm5719-llvm-06fef0b359b1b932b4d09d630175d9243394d062.zip |
Revert "[HardwareLoops] NFC - move hardware loop checking code to isHardwareLoopProfitable()"
This reverts commit d95557306585404893d610784edb3e32f1bfce18.
llvm-svn: 365520
Diffstat (limited to 'llvm/lib/CodeGen/HardwareLoops.cpp')
-rw-r--r-- | llvm/lib/CodeGen/HardwareLoops.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp index c1e9604d98b..5f57cabbe86 100644 --- a/llvm/lib/CodeGen/HardwareLoops.cpp +++ b/llvm/lib/CodeGen/HardwareLoops.cpp @@ -15,6 +15,7 @@ /// //===----------------------------------------------------------------------===// +#include "llvm/Pass.h" #include "llvm/PassRegistry.h" #include "llvm/PassSupport.h" #include "llvm/ADT/Statistic.h" @@ -35,8 +36,10 @@ #include "llvm/IR/Value.h" #include "llvm/Support/Debug.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Local.h" +#include "llvm/Transforms/Utils/LoopUtils.h" #define DEBUG_TYPE "hardware-loops" @@ -109,6 +112,7 @@ namespace { const DataLayout *DL = nullptr; const TargetTransformInfo *TTI = nullptr; DominatorTree *DT = nullptr; + bool PreserveLCSSA = false; AssumptionCache *AC = nullptr; TargetLibraryInfo *LibInfo = nullptr; Module *M = nullptr; @@ -180,6 +184,7 @@ bool HardwareLoops::runOnFunction(Function &F) { DL = &F.getParent()->getDataLayout(); auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>(); LibInfo = TLIP ? &TLIP->getTLI() : nullptr; + PreserveLCSSA = mustPreserveAnalysisID(LCSSAID); AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); M = F.getParent(); @@ -225,19 +230,25 @@ bool HardwareLoops::TryConvertLoop(Loop *L) { bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) { - LLVM_DEBUG(dbgs() << "HWLoops: Try to convert profitable loop: " - << *HWLoopInfo.L); + Loop *L = HWLoopInfo.L; + LLVM_DEBUG(dbgs() << "HWLoops: Try to convert profitable loop: " << *L); if (!HWLoopInfo.isHardwareLoopCandidate(*SE, *LI, *DT, ForceNestedLoop, - ForceHardwareLoopPHI, - ForceGuardLoopEntry)) + ForceHardwareLoopPHI)) return false; assert( (HWLoopInfo.ExitBlock && HWLoopInfo.ExitBranch && HWLoopInfo.ExitCount) && "Hardware Loop must have set exit info."); - // Now start to converting... + BasicBlock *Preheader = L->getLoopPreheader(); + + // If we don't have a preheader, then insert one. + if (!Preheader) + Preheader = InsertPreheaderForLoop(L, DT, LI, nullptr, PreserveLCSSA); + if (!Preheader) + return false; + HardwareLoop HWLoop(HWLoopInfo, *SE, *DL); HWLoop.Create(); ++NumHWLoops; @@ -246,10 +257,10 @@ bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) { void HardwareLoop::Create() { LLVM_DEBUG(dbgs() << "HWLoops: Converting loop..\n"); - + Value *LoopCountInit = InitLoopCount(); - - assert(LoopCountInit && "Hardware Loop must have a loop count"); + if (!LoopCountInit) + return; InsertIterationSetup(LoopCountInit); @@ -309,22 +320,32 @@ Value *HardwareLoop::InitLoopCount() { // loop counter and tests that is not zero? SCEVExpander SCEVE(SE, DL, "loopcnt"); + if (!ExitCount->getType()->isPointerTy() && + ExitCount->getType() != CountType) + ExitCount = SE.getZeroExtendExpr(ExitCount, CountType); + + ExitCount = SE.getAddExpr(ExitCount, SE.getOne(CountType)); // If we're trying to use the 'test and set' form of the intrinsic, we need // to replace a conditional branch that is controlling entry to the loop. It // is likely (guaranteed?) that the preheader has an unconditional branch to // the loop header, so also check if it has a single predecessor. if (SE.isLoopEntryGuardedByCond(L, ICmpInst::ICMP_NE, ExitCount, - SE.getZero(ExitCount->getType()))) + SE.getZero(ExitCount->getType()))) { + LLVM_DEBUG(dbgs() << " - Attempting to use test.set counter.\n"); UseLoopGuard |= ForceGuardLoopEntry; - else + } else UseLoopGuard = false; BasicBlock *BB = L->getLoopPreheader(); if (UseLoopGuard && BB->getSinglePredecessor() && - cast<BranchInst>(BB->getTerminator())->isUnconditional()) { - LLVM_DEBUG(dbgs() << " - Attempting to use test.set counter.\n"); + cast<BranchInst>(BB->getTerminator())->isUnconditional()) BB = BB->getSinglePredecessor(); + + if (!isSafeToExpandAt(ExitCount, BB->getTerminator(), SE)) { + LLVM_DEBUG(dbgs() << "- Bailing, unsafe to expand ExitCount " + << *ExitCount << "\n"); + return nullptr; } Value *Count = SCEVE.expandCodeFor(ExitCount, CountType, |