diff options
Diffstat (limited to 'contrib/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp')
-rw-r--r-- | contrib/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/contrib/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp b/contrib/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp index f29228c..8fb5801 100644 --- a/contrib/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp +++ b/contrib/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp @@ -20,17 +20,37 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DepthFirstIterator.h" +#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/LoopAccessAnalysis.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpander.h" +#include "llvm/Analysis/ScalarEvolutionExpressions.h" +#include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/LoopVersioning.h" #include <forward_list> +#include <cassert> +#include <algorithm> +#include <set> +#include <tuple> +#include <utility> #define LLE_OPTION "loop-load-elim" #define DEBUG_TYPE LLE_OPTION @@ -47,7 +67,6 @@ static cl::opt<unsigned> LoadElimSCEVCheckThreshold( cl::desc("The maximum number of SCEV checks allowed for Loop " "Load Elimination")); - STATISTIC(NumLoopLoadEliminted, "Number of loads eliminated by LLE"); namespace { @@ -113,10 +132,9 @@ bool doesStoreDominatesAllLatches(BasicBlock *StoreBlock, Loop *L, DominatorTree *DT) { SmallVector<BasicBlock *, 8> Latches; L->getLoopLatches(Latches); - return std::all_of(Latches.begin(), Latches.end(), - [&](const BasicBlock *Latch) { - return DT->dominates(StoreBlock, Latch); - }); + return llvm::all_of(Latches, [&](const BasicBlock *Latch) { + return DT->dominates(StoreBlock, Latch); + }); } /// \brief Return true if the load is not executed on all paths in the loop. @@ -348,7 +366,7 @@ public: // Collect the pointers of the candidate loads. // FIXME: SmallSet does not work with std::inserter. std::set<Value *> CandLoadPtrs; - std::transform(Candidates.begin(), Candidates.end(), + transform(Candidates, std::inserter(CandLoadPtrs, CandLoadPtrs.begin()), std::mem_fn(&StoreToLoadForwardingCandidate::getLoadPtr)); @@ -397,7 +415,9 @@ public: Value *InitialPtr = SEE.expandCodeFor(PtrSCEV->getStart(), Ptr->getType(), PH->getTerminator()); Value *Initial = - new LoadInst(InitialPtr, "load_initial", PH->getTerminator()); + new LoadInst(InitialPtr, "load_initial", /* isVolatile */ false, + Cand.Load->getAlignment(), PH->getTerminator()); + PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded", &L->getHeader()->front()); PHI->addIncoming(Initial, PH); @@ -499,6 +519,11 @@ public: return false; } + if (!L->isLoopSimplifyForm()) { + DEBUG(dbgs() << "Loop is not is loop-simplify form"); + return false; + } + // Point of no-return, start the transformation. First, version the loop // if necessary. @@ -581,11 +606,13 @@ public: AU.addRequired<ScalarEvolutionWrapperPass>(); AU.addRequired<DominatorTreeWrapperPass>(); AU.addPreserved<DominatorTreeWrapperPass>(); + AU.addPreserved<GlobalsAAWrapperPass>(); } static char ID; }; -} + +} // end anonymous namespace char LoopLoadElimination::ID; static const char LLE_name[] = "Loop Load Elimination"; @@ -599,7 +626,9 @@ INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_END(LoopLoadElimination, LLE_OPTION, LLE_name, false, false) namespace llvm { + FunctionPass *createLoopLoadEliminationPass() { return new LoopLoadElimination(); } -} + +} // end namespace llvm |