LLVM  7.0.0svn
LoopRotation.cpp
Go to the documentation of this file.
1 //===- LoopRotation.cpp - Loop Rotation Pass ------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements Loop Rotation Pass.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Analysis/LoopPass.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Transforms/Scalar.h"
25 using namespace llvm;
26 
27 #define DEBUG_TYPE "loop-rotate"
28 
30  "rotation-max-header-size", cl::init(16), cl::Hidden,
31  cl::desc("The default maximum header size for automatic loop rotation"));
32 
33 LoopRotatePass::LoopRotatePass(bool EnableHeaderDuplication)
34  : EnableHeaderDuplication(EnableHeaderDuplication) {}
35 
38  LPMUpdater &) {
39  int Threshold = EnableHeaderDuplication ? DefaultRotationThreshold : 0;
40  const DataLayout &DL = L.getHeader()->getModule()->getDataLayout();
41  const SimplifyQuery SQ = getBestSimplifyQuery(AR, DL);
42 
43  bool Changed = LoopRotation(&L, &AR.LI, &AR.TTI, &AR.AC, &AR.DT, &AR.SE, SQ,
44  false, Threshold, false);
45 
46  if (!Changed)
47  return PreservedAnalyses::all();
48 
50 }
51 
52 namespace {
53 
54 class LoopRotateLegacyPass : public LoopPass {
55  unsigned MaxHeaderSize;
56 
57 public:
58  static char ID; // Pass ID, replacement for typeid
59  LoopRotateLegacyPass(int SpecifiedMaxHeaderSize = -1) : LoopPass(ID) {
61  if (SpecifiedMaxHeaderSize == -1)
62  MaxHeaderSize = DefaultRotationThreshold;
63  else
64  MaxHeaderSize = unsigned(SpecifiedMaxHeaderSize);
65  }
66 
67  // LCSSA form makes instruction renaming easier.
68  void getAnalysisUsage(AnalysisUsage &AU) const override {
72  }
73 
74  bool runOnLoop(Loop *L, LPPassManager &LPM) override {
75  if (skipLoop(L))
76  return false;
77  Function &F = *L->getHeader()->getParent();
78 
79  auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
80  const auto *TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
81  auto *AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
82  auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
83  auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
84  auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
85  auto *SE = SEWP ? &SEWP->getSE() : nullptr;
86  const SimplifyQuery SQ = getBestSimplifyQuery(*this, F);
87  return LoopRotation(L, LI, TTI, AC, DT, SE, SQ, false, MaxHeaderSize,
88  false);
89  }
90 };
91 }
92 
94 INITIALIZE_PASS_BEGIN(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops",
95  false, false)
99 INITIALIZE_PASS_END(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops", false,
100  false)
101 
102 Pass *llvm::createLoopRotatePass(int MaxHeaderSize) {
103  return new LoopRotateLegacyPass(MaxHeaderSize);
104 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
An immutable pass that tracks lazily created AssumptionCache objects.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
F(f)
const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:134
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
INITIALIZE_PASS_BEGIN(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops", false, false) INITIALIZE_PASS_END(LoopRotateLegacyPass
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:361
BlockT * getHeader() const
Definition: LoopInfo.h:100
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
Wrapper pass for TargetTransformInfo.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
bool LoopRotation(Loop *L, LoopInfo *LI, const TargetTransformInfo *TTI, AssumptionCache *AC, DominatorTree *DT, ScalarEvolution *SE, const SimplifyQuery &SQ, bool RotationOnly, unsigned Threshold, bool IsUtilMode)
Convert a loop into a loop with bottom test.
Represent the analysis usage information of a pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
void initializeLoopRotateLegacyPassPass(PassRegistry &)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
loop Rotate Loops
loop rotate
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:459
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass&#39;s AnalysisUsage.
Definition: LoopUtils.cpp:1226
LoopRotatePass(bool EnableHeaderDuplication=true)
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
A container for analyses that lazily runs them and caches their results.
This pass exposes codegen information to IR-level passes.
Pass * createLoopRotatePass(int MaxHeaderSize=-1)
static cl::opt< unsigned > DefaultRotationThreshold("rotation-max-header-size", cl::init(16), cl::Hidden, cl::desc("The default maximum header size for automatic loop rotation"))