Coverage Report

Created: 2019-04-21 11:35

/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
4
  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
0
                                           FunctionAnalysisManager &FAM) {
60
0
61
0
  // Find first non-alloca instruction. Every basic block has a non-alloca
62
0
  // instruction, as every well formed basic block has a terminator.
63
0
  auto &EntryBlock = F.getEntryBlock();
64
0
  BasicBlock::iterator I = EntryBlock.begin();
65
0
  while (isa<AllocaInst>(I))
66
0
    ++I;
67
0
68
0
  auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
69
0
  auto &LI = FAM.getResult<LoopAnalysis>(F);
70
0
71
0
  // splitBlock updates DT, LI and RI.
72
0
  splitEntryBlockForAlloca(&EntryBlock, &DT, &LI, nullptr);
73
0
74
0
  PreservedAnalyses PA;
75
0
  PA.preserve<DominatorTreeAnalysis>();
76
0
  PA.preserve<LoopAnalysis>();
77
0
  return PA;
78
0
}
79
80
8
void CodePreparation::clear() {}
81
82
4
CodePreparation::~CodePreparation() { clear(); }
83
84
4
void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
85
4
  AU.addRequired<LoopInfoWrapperPass>();
86
4
  AU.addRequired<ScalarEvolutionWrapperPass>();
87
4
88
4
  AU.addPreserved<LoopInfoWrapperPass>();
89
4
  AU.addPreserved<RegionInfoPass>();
90
4
  AU.addPreserved<DominatorTreeWrapperPass>();
91
4
  AU.addPreserved<DominanceFrontierWrapperPass>();
92
4
}
93
94
4
bool CodePreparation::runOnFunction(Function &F) {
95
4
  if (skipFunction(F))
96
0
    return false;
97
4
98
4
  LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
99
4
  SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
100
4
101
4
  splitEntryBlockForAlloca(&F.getEntryBlock(), this);
102
4
103
4
  return true;
104
4
}
105
106
4
void CodePreparation::releaseMemory() { clear(); }
107
108
4
void CodePreparation::print(raw_ostream &OS, const Module *) const {}
109
110
char CodePreparation::ID = 0;
111
char &polly::CodePreparationID = CodePreparation::ID;
112
113
0
Pass *polly::createCodePreparationPass() { return new CodePreparation(); }
114
115
9.54k
INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
116
9.54k
                      "Polly - Prepare code for polly", false, false)
117
9.54k
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
118
9.54k
INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
119
                    "Polly - Prepare code for polly", false, false)