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/CodeGen/BlockGenerators.h" 21 #include "polly/ScopDetection.h" 22 #include "polly/Support/ScopHelper.h" 23 #include "llvm/Analysis/DominanceFrontier.h" 24 #include "llvm/Analysis/LoopInfo.h" 25 #include "llvm/Analysis/RegionInfo.h" 26 #include "llvm/Analysis/ScalarEvolution.h" 27 #include "llvm/Transforms/Utils/Local.h" 28 29 using namespace llvm; 30 using namespace polly; 31 32 namespace { 33 34 /// @brief Prepare the IR for the scop detection. 35 /// 36 class CodePreparation : public FunctionPass { 37 CodePreparation(const CodePreparation &) = delete; 38 const CodePreparation &operator=(const CodePreparation &) = delete; 39 40 LoopInfo *LI; 41 ScalarEvolution *SE; 42 43 void clear(); 44 45 bool eliminatePHINodes(Function &F); 46 47 public: 48 static char ID; 49 50 explicit CodePreparation() : FunctionPass(ID) {} 51 ~CodePreparation(); 52 53 /// @name FunctionPass interface. 54 //@{ 55 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 56 virtual void releaseMemory(); 57 virtual bool runOnFunction(Function &F); 58 virtual void print(raw_ostream &OS, const Module *) const; 59 //@} 60 }; 61 } 62 63 void CodePreparation::clear() {} 64 65 CodePreparation::~CodePreparation() { clear(); } 66 67 void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const { 68 AU.addRequired<LoopInfoWrapperPass>(); 69 AU.addRequired<ScalarEvolutionWrapperPass>(); 70 71 AU.addPreserved<LoopInfoWrapperPass>(); 72 AU.addPreserved<RegionInfoPass>(); 73 AU.addPreserved<DominatorTreeWrapperPass>(); 74 AU.addPreserved<DominanceFrontier>(); 75 } 76 77 bool CodePreparation::runOnFunction(Function &F) { 78 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); 79 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); 80 81 splitEntryBlockForAlloca(&F.getEntryBlock(), this); 82 83 return false; 84 } 85 86 void CodePreparation::releaseMemory() { clear(); } 87 88 void CodePreparation::print(raw_ostream &OS, const Module *) const {} 89 90 char CodePreparation::ID = 0; 91 char &polly::CodePreparationID = CodePreparation::ID; 92 93 Pass *polly::createCodePreparationPass() { return new CodePreparation(); } 94 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) 100