Coverage Report

Created: 2017-06-23 12:40

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/include/polly/ScopPass.h
Line
Count
Source (jump to first uncovered line)
1
//===--------- ScopPass.h - Pass for Static Control Parts --------*-C++ -*-===//
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
// This file defines the ScopPass class.  ScopPasses are just RegionPasses,
11
// except they operate on Polly IR (Scop and ScopStmt) built by ScopInfo Pass.
12
// Because they operate on Polly IR, not the LLVM IR, ScopPasses are not allowed
13
// to modify the LLVM IR. Due to this limitation, the ScopPass class takes
14
// care of declaring that no LLVM passes are invalidated.
15
//
16
//===----------------------------------------------------------------------===//
17
18
#ifndef POLLY_SCOP_PASS_H
19
#define POLLY_SCOP_PASS_H
20
21
#include "polly/ScopInfo.h"
22
#include "llvm/ADT/PriorityWorklist.h"
23
#include "llvm/Analysis/RegionPass.h"
24
#include "llvm/IR/PassManager.h"
25
26
using namespace llvm;
27
28
namespace polly {
29
class Scop;
30
class SPMUpdater;
31
struct ScopStandardAnalysisResults;
32
33
using ScopAnalysisManager =
34
    AnalysisManager<Scop, ScopStandardAnalysisResults &>;
35
using ScopAnalysisManagerFunctionProxy =
36
    InnerAnalysisManagerProxy<ScopAnalysisManager, Function>;
37
using FunctionAnalysisManagerScopProxy =
38
    OuterAnalysisManagerProxy<FunctionAnalysisManager, Scop,
39
                              ScopStandardAnalysisResults &>;
40
} // namespace polly
41
42
namespace llvm {
43
using polly::Scop;
44
using polly::ScopInfo;
45
using polly::ScopAnalysisManager;
46
using polly::ScopStandardAnalysisResults;
47
using polly::ScopAnalysisManagerFunctionProxy;
48
using polly::SPMUpdater;
49
50
template <>
51
class InnerAnalysisManagerProxy<ScopAnalysisManager, Function>::Result {
52
public:
53
  explicit Result(ScopAnalysisManager &InnerAM, ScopInfo &SI)
54
0
      : InnerAM(&InnerAM), SI(&SI) {}
55
0
  Result(Result &&R) : InnerAM(std::move(R.InnerAM)), SI(R.SI) {
56
0
    R.InnerAM = nullptr;
57
0
  }
58
0
  Result &operator=(Result &&RHS) {
59
0
    InnerAM = RHS.InnerAM;
60
0
    SI = RHS.SI;
61
0
    RHS.InnerAM = nullptr;
62
0
    return *this;
63
0
  }
64
0
  ~Result() {
65
0
    if (!InnerAM)
66
0
      return;
67
0
    InnerAM->clear();
68
0
  }
69
70
0
  ScopAnalysisManager &getManager() { return *InnerAM; }
71
72
  bool invalidate(Function &F, const PreservedAnalyses &PA,
73
                  FunctionAnalysisManager::Invalidator &Inv);
74
75
private:
76
  ScopAnalysisManager *InnerAM;
77
  ScopInfo *SI;
78
};
79
80
template <>
81
InnerAnalysisManagerProxy<ScopAnalysisManager, Function>::Result
82
InnerAnalysisManagerProxy<ScopAnalysisManager, Function>::run(
83
    Function &F, FunctionAnalysisManager &FAM);
84
85
template <>
86
PreservedAnalyses
87
PassManager<Scop, ScopAnalysisManager, ScopStandardAnalysisResults &,
88
            SPMUpdater &>::run(Scop &InitialS, ScopAnalysisManager &AM,
89
                               ScopStandardAnalysisResults &, SPMUpdater &);
90
extern template class PassManager<Scop, ScopAnalysisManager,
91
                                  ScopStandardAnalysisResults &, SPMUpdater &>;
92
extern template class InnerAnalysisManagerProxy<ScopAnalysisManager, Function>;
93
extern template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Scop,
94
                                                ScopStandardAnalysisResults &>;
95
} // namespace llvm
96
97
namespace polly {
98
using ScopPassManager =
99
    PassManager<Scop, ScopAnalysisManager, ScopStandardAnalysisResults &,
100
                SPMUpdater &>;
101
102
/// ScopPass - This class adapts the RegionPass interface to allow convenient
103
/// creation of passes that operate on the Polly IR. Instead of overriding
104
/// runOnRegion, subclasses override runOnScop.
105
class ScopPass : public RegionPass {
106
  Scop *S;
107
108
protected:
109
1.45k
  explicit ScopPass(char &ID) : RegionPass(ID), S(0) {}
110
111
  /// runOnScop - This method must be overloaded to perform the
112
  /// desired Polyhedral transformation or analysis.
113
  ///
114
  virtual bool runOnScop(Scop &S) = 0;
115
116
  /// Print method for SCoPs.
117
27
  virtual void printScop(raw_ostream &OS, Scop &S) const {}
118
119
  /// getAnalysisUsage - Subclasses that override getAnalysisUsage
120
  /// must call this.
121
  ///
122
  virtual void getAnalysisUsage(AnalysisUsage &AU) const override;
123
124
private:
125
  bool runOnRegion(Region *R, RGPassManager &RGM) override;
126
  void print(raw_ostream &OS, const Module *) const override;
127
};
128
129
struct ScopStandardAnalysisResults {
130
  DominatorTree &DT;
131
  ScalarEvolution &SE;
132
  LoopInfo &LI;
133
  RegionInfo &RI;
134
};
135
136
class SPMUpdater {
137
public:
138
  SPMUpdater(SmallPriorityWorklist<Scop *, 4> &Worklist,
139
             ScopAnalysisManager &SAM)
140
0
      : Worklist(Worklist), SAM(SAM) {}
141
142
0
  void SkipScop(Scop &S) {
143
0
    if (Worklist.erase(&S))
144
0
      SAM.clear(S);
145
0
  }
146
147
private:
148
  SmallPriorityWorklist<Scop *, 4> &Worklist;
149
  ScopAnalysisManager &SAM;
150
};
151
152
template <typename ScopPassT>
153
class FunctionToScopPassAdaptor
154
    : public PassInfoMixin<FunctionToScopPassAdaptor<ScopPassT>> {
155
public:
156
  explicit FunctionToScopPassAdaptor(ScopPassT Pass) : Pass(std::move(Pass)) {}
157
158
  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
159
    PreservedAnalyses PA = PreservedAnalyses::all();
160
    auto &Scops = AM.getResult<ScopInfoAnalysis>(F);
161
    if (Scops.empty())
162
      return PA;
163
164
    ScopAnalysisManager &SAM =
165
        AM.getResult<ScopAnalysisManagerFunctionProxy>(F).getManager();
166
167
    ScopStandardAnalysisResults AR = {AM.getResult<DominatorTreeAnalysis>(F),
168
                                      AM.getResult<ScalarEvolutionAnalysis>(F),
169
                                      AM.getResult<LoopAnalysis>(F),
170
                                      AM.getResult<RegionInfoAnalysis>(F)};
171
172
    SmallPriorityWorklist<Scop *, 4> Worklist;
173
    SPMUpdater Updater{Worklist, SAM};
174
175
    for (auto &S : Scops)
176
      if (auto *scop = S.second.get())
177
        Worklist.insert(scop);
178
179
    while (!Worklist.empty()) {
180
      Scop *scop = Worklist.pop_back_val();
181
      PreservedAnalyses PassPA = Pass.run(*scop, SAM, AR, Updater);
182
183
      SAM.invalidate(*scop, PassPA);
184
      PA.intersect(std::move(PassPA));
185
    };
186
187
    PA.preserveSet<AllAnalysesOn<Scop>>();
188
    PA.preserve<ScopAnalysisManagerFunctionProxy>();
189
    return PA;
190
  }
191
192
private:
193
  ScopPassT Pass;
194
}; // namespace polly
195
196
template <typename ScopPassT>
197
FunctionToScopPassAdaptor<ScopPassT>
198
createFunctionToScopPassAdaptor(ScopPassT Pass) {
199
  return FunctionToScopPassAdaptor<ScopPassT>(std::move(Pass));
200
}
201
202
} // namespace polly
203
204
#endif