Add opt-bisect support to polly.
[polly-mirror.git] / lib / Transform / CodePreparation.cpp
blob081244da8104770adc0c0fda0c2ce0a8e7ceadd2
1 //===---- CodePreparation.cpp - Code preparation for Scop Detection -------===//
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 // The Polly code preparation pass is executed before SCoP detection. Its
11 // currently only splits the entry block of the SCoP to make room for alloc
12 // instructions as they are generated during code generation.
14 // XXX: In the future, we should remove the need for this pass entirely and
15 // instead add this spitting to the code generation pass.
17 //===----------------------------------------------------------------------===//
19 #include "polly/LinkAllPasses.h"
20 #include "polly/ScopDetection.h"
21 #include "polly/Support/ScopHelper.h"
22 #include "llvm/Analysis/DominanceFrontier.h"
23 #include "llvm/Analysis/LoopInfo.h"
24 #include "llvm/Analysis/RegionInfo.h"
25 #include "llvm/Analysis/ScalarEvolution.h"
26 #include "llvm/Transforms/Utils/Local.h"
28 using namespace llvm;
29 using namespace polly;
31 namespace {
33 /// Prepare the IR for the scop detection.
34 ///
35 class CodePreparation : public FunctionPass {
36 CodePreparation(const CodePreparation &) = delete;
37 const CodePreparation &operator=(const CodePreparation &) = delete;
39 LoopInfo *LI;
40 ScalarEvolution *SE;
42 void clear();
44 public:
45 static char ID;
47 explicit CodePreparation() : FunctionPass(ID) {}
48 ~CodePreparation();
50 /// @name FunctionPass interface.
51 //@{
52 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
53 virtual void releaseMemory();
54 virtual bool runOnFunction(Function &F);
55 virtual void print(raw_ostream &OS, const Module *) const;
56 //@}
58 } // namespace
60 void CodePreparation::clear() {}
62 CodePreparation::~CodePreparation() { clear(); }
64 void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
65 AU.addRequired<LoopInfoWrapperPass>();
66 AU.addRequired<ScalarEvolutionWrapperPass>();
68 AU.addPreserved<LoopInfoWrapperPass>();
69 AU.addPreserved<RegionInfoPass>();
70 AU.addPreserved<DominatorTreeWrapperPass>();
71 AU.addPreserved<DominanceFrontierWrapperPass>();
74 bool CodePreparation::runOnFunction(Function &F) {
75 if (skipFunction(F))
76 return false;
78 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
79 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
81 splitEntryBlockForAlloca(&F.getEntryBlock(), this);
83 return true;
86 void CodePreparation::releaseMemory() { clear(); }
88 void CodePreparation::print(raw_ostream &OS, const Module *) const {}
90 char CodePreparation::ID = 0;
91 char &polly::CodePreparationID = CodePreparation::ID;
93 Pass *polly::createCodePreparationPass() { return new CodePreparation(); }
95 INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
96 "Polly - Prepare code for polly", false, false)
97 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
98 INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
99 "Polly - Prepare code for polly", false, false)