/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/Transform/CodePreparation.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===---- CodePreparation.cpp - Code preparation for Scop Detection -------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // The Polly code preparation pass is executed before SCoP detection. Its |
10 | | // currently only splits the entry block of the SCoP to make room for alloc |
11 | | // instructions as they are generated during code generation. |
12 | | // |
13 | | // XXX: In the future, we should remove the need for this pass entirely and |
14 | | // instead add this spitting to the code generation pass. |
15 | | // |
16 | | //===----------------------------------------------------------------------===// |
17 | | |
18 | | #include "polly/CodePreparation.h" |
19 | | #include "polly/LinkAllPasses.h" |
20 | | #include "polly/Support/ScopHelper.h" |
21 | | #include "llvm/Analysis/DominanceFrontier.h" |
22 | | #include "llvm/Analysis/LoopInfo.h" |
23 | | #include "llvm/Analysis/RegionInfo.h" |
24 | | #include "llvm/Analysis/ScalarEvolution.h" |
25 | | |
26 | | using namespace llvm; |
27 | | using namespace polly; |
28 | | |
29 | | namespace { |
30 | | |
31 | | /// Prepare the IR for the scop detection. |
32 | | /// |
33 | | class CodePreparation : public FunctionPass { |
34 | | CodePreparation(const CodePreparation &) = delete; |
35 | | const CodePreparation &operator=(const CodePreparation &) = delete; |
36 | | |
37 | | LoopInfo *LI; |
38 | | ScalarEvolution *SE; |
39 | | |
40 | | void clear(); |
41 | | |
42 | | public: |
43 | | static char ID; |
44 | | |
45 | 12 | explicit CodePreparation() : FunctionPass(ID) {} |
46 | | ~CodePreparation(); |
47 | | |
48 | | /// @name FunctionPass interface. |
49 | | //@{ |
50 | | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
51 | | virtual void releaseMemory(); |
52 | | virtual bool runOnFunction(Function &F); |
53 | | virtual void print(raw_ostream &OS, const Module *) const; |
54 | | //@} |
55 | | }; |
56 | | } // namespace |
57 | | |
58 | | PreservedAnalyses CodePreparationPass::run(Function &F, |
59 | 1 | FunctionAnalysisManager &FAM) { |
60 | 1 | |
61 | 1 | // Find first non-alloca instruction. Every basic block has a non-alloca |
62 | 1 | // instruction, as every well formed basic block has a terminator. |
63 | 1 | auto &EntryBlock = F.getEntryBlock(); |
64 | 1 | BasicBlock::iterator I = EntryBlock.begin(); |
65 | 1 | while (isa<AllocaInst>(I)) |
66 | 0 | ++I; |
67 | 1 | |
68 | 1 | auto &DT = FAM.getResult<DominatorTreeAnalysis>(F); |
69 | 1 | auto &LI = FAM.getResult<LoopAnalysis>(F); |
70 | 1 | |
71 | 1 | // splitBlock updates DT, LI and RI. |
72 | 1 | splitEntryBlockForAlloca(&EntryBlock, &DT, &LI, nullptr); |
73 | 1 | |
74 | 1 | PreservedAnalyses PA; |
75 | 1 | PA.preserve<DominatorTreeAnalysis>(); |
76 | 1 | PA.preserve<LoopAnalysis>(); |
77 | 1 | return PA; |
78 | 1 | } |
79 | | |
80 | 25 | void CodePreparation::clear() {} |
81 | | |
82 | 12 | CodePreparation::~CodePreparation() { clear(); } |
83 | | |
84 | 12 | void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const { |
85 | 12 | AU.addRequired<LoopInfoWrapperPass>(); |
86 | 12 | AU.addRequired<ScalarEvolutionWrapperPass>(); |
87 | 12 | |
88 | 12 | AU.addPreserved<LoopInfoWrapperPass>(); |
89 | 12 | AU.addPreserved<RegionInfoPass>(); |
90 | 12 | AU.addPreserved<DominatorTreeWrapperPass>(); |
91 | 12 | AU.addPreserved<DominanceFrontierWrapperPass>(); |
92 | 12 | } |
93 | | |
94 | 13 | bool CodePreparation::runOnFunction(Function &F) { |
95 | 13 | if (skipFunction(F)) |
96 | 0 | return false; |
97 | 13 | |
98 | 13 | LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
99 | 13 | SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); |
100 | 13 | |
101 | 13 | splitEntryBlockForAlloca(&F.getEntryBlock(), this); |
102 | 13 | |
103 | 13 | return true; |
104 | 13 | } |
105 | | |
106 | 13 | void CodePreparation::releaseMemory() { clear(); } |
107 | | |
108 | 12 | void CodePreparation::print(raw_ostream &OS, const Module *) const {} |
109 | | |
110 | | char CodePreparation::ID = 0; |
111 | | char &polly::CodePreparationID = CodePreparation::ID; |
112 | | |
113 | 1 | Pass *polly::createCodePreparationPass() { return new CodePreparation(); } |
114 | | |
115 | 48.2k | INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare", |
116 | 48.2k | "Polly - Prepare code for polly", false, false) |
117 | 48.2k | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
118 | 48.2k | INITIALIZE_PASS_END(CodePreparation, "polly-prepare", |
119 | | "Polly - Prepare code for polly", false, false) |