1 //===---- CodePreparation.cpp - Code preparation for Scop Detection -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
29 using namespace polly
;
33 /// Prepare the IR for the scop detection.
35 class CodePreparation
: public FunctionPass
{
36 CodePreparation(const CodePreparation
&) = delete;
37 const CodePreparation
&operator=(const CodePreparation
&) = delete;
47 explicit CodePreparation() : FunctionPass(ID
) {}
50 /// @name FunctionPass interface.
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;
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
) {
78 LI
= &getAnalysis
<LoopInfoWrapperPass
>().getLoopInfo();
79 SE
= &getAnalysis
<ScalarEvolutionWrapperPass
>().getSE();
81 splitEntryBlockForAlloca(&F
.getEntryBlock(), this);
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)