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 public: 45 static char ID; 46 47 explicit CodePreparation() : FunctionPass(ID) {} 48 ~CodePreparation(); 49 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 //@} 57 }; 58 } // namespace 59 60 void CodePreparation::clear() {} 61 62 CodePreparation::~CodePreparation() { clear(); } 63 64 void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const { 65 AU.addRequired<LoopInfoWrapperPass>(); 66 AU.addRequired<ScalarEvolutionWrapperPass>(); 67 68 AU.addPreserved<LoopInfoWrapperPass>(); 69 AU.addPreserved<RegionInfoPass>(); 70 AU.addPreserved<DominatorTreeWrapperPass>(); 71 AU.addPreserved<DominanceFrontierWrapperPass>(); 72 } 73 74 bool CodePreparation::runOnFunction(Function &F) { 75 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); 76 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); 77 78 splitEntryBlockForAlloca(&F.getEntryBlock(), this); 79 80 return false; 81 } 82 83 void CodePreparation::releaseMemory() { clear(); } 84 85 void CodePreparation::print(raw_ostream &OS, const Module *) const {} 86 87 char CodePreparation::ID = 0; 88 char &polly::CodePreparationID = CodePreparation::ID; 89 90 Pass *polly::createCodePreparationPass() { return new CodePreparation(); } 91 92 INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare", 93 "Polly - Prepare code for polly", false, false) 94 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) 95 INITIALIZE_PASS_END(CodePreparation, "polly-prepare", 96 "Polly - Prepare code for polly", false, false) 97