Coverage Report

Created: 2017-11-23 03:11

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/include/polly/CodeGen/IslAst.h
Line
Count
Source (jump to first uncovered line)
1
//===- IslAst.h - Interface to the isl code generator -----------*- 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
// The isl code generator interface takes a Scop and generates a isl_ast. This
11
// ist_ast can either be returned directly or it can be pretty printed to
12
// stdout.
13
//
14
// A typical isl_ast output looks like this:
15
//
16
// for (c2 = max(0, ceild(n + m, 2); c2 <= min(511, floord(5 * n, 3)); c2++) {
17
//   bb2(c2);
18
// }
19
//
20
//===----------------------------------------------------------------------===//
21
22
#ifndef POLLY_ISLAST_H
23
#define POLLY_ISLAST_H
24
25
#include "polly/Config/config.h"
26
#include "polly/ScopPass.h"
27
#include "llvm/ADT/SmallPtrSet.h"
28
#include "llvm/IR/PassManager.h"
29
#include "isl/ast.h"
30
#include "isl/ctx.h"
31
#include <memory>
32
33
namespace llvm {
34
35
class PassRegistry;
36
class raw_ostream;
37
38
void initializeIslAstInfoWrapperPassPass(PassRegistry &);
39
40
} // namespace llvm
41
42
struct isl_ast_build;
43
struct isl_ast_expr;
44
struct isl_ast_node;
45
struct isl_pw_aff;
46
struct isl_pw_multi_aff;
47
struct isl_union_map;
48
49
namespace polly {
50
51
struct Dependences;
52
class MemoryAccess;
53
class Scop;
54
55
class IslAst {
56
public:
57
  IslAst(const IslAst &) = delete;
58
  IslAst &operator=(const IslAst &) = delete;
59
  IslAst(IslAst &&);
60
  IslAst &operator=(IslAst &&) = delete;
61
  ~IslAst();
62
63
  static IslAst create(Scop &Scop, const Dependences &D);
64
65
  /// Print a source code representation of the program.
66
  void pprint(raw_ostream &OS);
67
68
  __isl_give isl_ast_node *getAst();
69
70
291
  const std::shared_ptr<isl_ctx> getSharedIslCtx() const { return Ctx; }
71
72
  /// Get the run-time conditions for the Scop.
73
  __isl_give isl_ast_expr *getRunCondition();
74
75
  /// Build run-time condition for scop.
76
  ///
77
  /// @param S     The scop to build the condition for.
78
  /// @param Build The isl_build object to use to build the condition.
79
  ///
80
  /// @returns An ast expression that describes the necessary run-time check.
81
  static isl_ast_expr *buildRunCondition(Scop &S,
82
                                         __isl_keep isl_ast_build *Build);
83
84
private:
85
  Scop &S;
86
  isl_ast_node *Root = nullptr;
87
  isl_ast_expr *RunCondition = nullptr;
88
  std::shared_ptr<isl_ctx> Ctx;
89
90
  IslAst(Scop &Scop);
91
92
  void init(const Dependences &D);
93
};
94
95
class IslAstInfo {
96
public:
97
  using MemoryAccessSet = SmallPtrSet<MemoryAccess *, 4>;
98
99
  /// Payload information used to annotate an AST node.
100
  struct IslAstUserPayload {
101
    /// Construct and initialize the payload.
102
2.31k
    IslAstUserPayload() = default;
103
104
    /// Cleanup all isl structs on destruction.
105
    ~IslAstUserPayload();
106
107
    /// Flag to mark innermost loops.
108
    bool IsInnermost = false;
109
110
    /// Flag to mark innermost parallel loops.
111
    bool IsInnermostParallel = false;
112
113
    /// Flag to mark outermost parallel loops.
114
    bool IsOutermostParallel = false;
115
116
    /// Flag to mark parallel loops which break reductions.
117
    bool IsReductionParallel = false;
118
119
    /// The minimal dependence distance for non parallel loops.
120
    isl_pw_aff *MinimalDependenceDistance = nullptr;
121
122
    /// The build environment at the time this node was constructed.
123
    isl_ast_build *Build = nullptr;
124
125
    /// Set of accesses which break reduction dependences.
126
    MemoryAccessSet BrokenReductions;
127
  };
128
129
private:
130
  Scop &S;
131
  IslAst Ast;
132
133
public:
134
443
  IslAstInfo(Scop &S, const Dependences &D) : S(S), Ast(IslAst::create(S, D)) {}
135
136
  /// Return the isl AST computed by this IslAstInfo.
137
291
  IslAst &getIslAst() { return Ast; }
138
139
  /// Return a copy of the AST root node.
140
  __isl_give isl_ast_node *getAst();
141
142
  /// Get the run condition.
143
  ///
144
  /// Only if the run condition evaluates at run-time to a non-zero value, the
145
  /// assumptions that have been taken hold. If the run condition evaluates to
146
  /// zero/false some assumptions do not hold and the original code needs to
147
  /// be executed.
148
  __isl_give isl_ast_expr *getRunCondition();
149
150
  void print(raw_ostream &O);
151
152
  /// @name Extract information attached to an isl ast (for) node.
153
  ///
154
  ///{
155
  /// Get the complete payload attached to @p Node.
156
  static IslAstUserPayload *getNodePayload(__isl_keep isl_ast_node *Node);
157
158
  /// Is this loop an innermost loop?
159
  static bool isInnermost(__isl_keep isl_ast_node *Node);
160
161
  /// Is this loop a parallel loop?
162
  static bool isParallel(__isl_keep isl_ast_node *Node);
163
164
  /// Is this loop an outermost parallel loop?
165
  static bool isOutermostParallel(__isl_keep isl_ast_node *Node);
166
167
  /// Is this loop an innermost parallel loop?
168
  static bool isInnermostParallel(__isl_keep isl_ast_node *Node);
169
170
  /// Is this loop a reduction parallel loop?
171
  static bool isReductionParallel(__isl_keep isl_ast_node *Node);
172
173
  /// Will the loop be run as thread parallel?
174
  static bool isExecutedInParallel(__isl_keep isl_ast_node *Node);
175
176
  /// Get the nodes schedule or a nullptr if not available.
177
  static __isl_give isl_union_map *getSchedule(__isl_keep isl_ast_node *Node);
178
179
  /// Get minimal dependence distance or nullptr if not available.
180
  static __isl_give isl_pw_aff *
181
  getMinimalDependenceDistance(__isl_keep isl_ast_node *Node);
182
183
  /// Get the nodes broken reductions or a nullptr if not available.
184
  static MemoryAccessSet *getBrokenReductions(__isl_keep isl_ast_node *Node);
185
186
  /// Get the nodes build context or a nullptr if not available.
187
  static __isl_give isl_ast_build *getBuild(__isl_keep isl_ast_node *Node);
188
189
  ///}
190
};
191
192
struct IslAstAnalysis : public AnalysisInfoMixin<IslAstAnalysis> {
193
  static AnalysisKey Key;
194
195
  using Result = IslAstInfo;
196
197
  IslAstInfo run(Scop &S, ScopAnalysisManager &SAM,
198
                 ScopStandardAnalysisResults &SAR);
199
};
200
201
class IslAstInfoWrapperPass : public ScopPass {
202
  std::unique_ptr<IslAstInfo> Ast;
203
204
public:
205
  static char ID;
206
207
481
  IslAstInfoWrapperPass() : ScopPass(ID) {}
208
209
291
  IslAstInfo &getAI() { return *Ast; }
210
0
  const IslAstInfo &getAI() const { return *Ast; }
211
212
  /// Build the AST for the given SCoP @p S.
213
  bool runOnScop(Scop &S) override;
214
215
  /// Register all analyses and transformation required.
216
  void getAnalysisUsage(AnalysisUsage &AU) const override;
217
218
  /// Release the internal memory.
219
  void releaseMemory() override;
220
221
  /// Print a source code representation of the program.
222
  void printScop(raw_ostream &OS, Scop &S) const override;
223
};
224
225
struct IslAstPrinterPass : public PassInfoMixin<IslAstPrinterPass> {
226
0
  IslAstPrinterPass(raw_ostream &OS) : OS(OS) {}
227
228
  PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
229
                        ScopStandardAnalysisResults &, SPMUpdater &U);
230
231
  raw_ostream &OS;
232
};
233
234
} // namespace polly
235
236
#endif // POLLY_ISLAST_H