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.
13 //
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.
16 //
17 //===----------------------------------------------------------------------===//
18 
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"
27 
28 using namespace llvm;
29 using namespace polly;
30 
31 namespace {
32 
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;
38 
39   LoopInfo *LI;
40   ScalarEvolution *SE;
41 
42   void clear();
43 
44   bool eliminatePHINodes(Function &F);
45 
46 public:
47   static char ID;
48 
49   explicit CodePreparation() : FunctionPass(ID) {}
50   ~CodePreparation();
51 
52   /// @name FunctionPass interface.
53   //@{
54   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
55   virtual void releaseMemory();
56   virtual bool runOnFunction(Function &F);
57   virtual void print(raw_ostream &OS, const Module *) const;
58   //@}
59 };
60 } // namespace
61 
62 void CodePreparation::clear() {}
63 
64 CodePreparation::~CodePreparation() { clear(); }
65 
66 void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
67   AU.addRequired<LoopInfoWrapperPass>();
68   AU.addRequired<ScalarEvolutionWrapperPass>();
69 
70   AU.addPreserved<LoopInfoWrapperPass>();
71   AU.addPreserved<RegionInfoPass>();
72   AU.addPreserved<DominatorTreeWrapperPass>();
73   AU.addPreserved<DominanceFrontierWrapperPass>();
74 }
75 
76 bool CodePreparation::runOnFunction(Function &F) {
77   LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
78   SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
79 
80   splitEntryBlockForAlloca(&F.getEntryBlock(), this);
81 
82   return false;
83 }
84 
85 void CodePreparation::releaseMemory() { clear(); }
86 
87 void CodePreparation::print(raw_ostream &OS, const Module *) const {}
88 
89 char CodePreparation::ID = 0;
90 char &polly::CodePreparationID = CodePreparation::ID;
91 
92 Pass *polly::createCodePreparationPass() { return new CodePreparation(); }
93 
94 INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
95                       "Polly - Prepare code for polly", false, false)
96 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
97 INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
98                     "Polly - Prepare code for polly", false, false)
99