Coverage Report

Created: 2018-10-23 09:19

/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
} // namespace llvm
40
41
struct isl_ast_build;
42
struct isl_ast_expr;
43
struct isl_ast_node;
44
struct isl_pw_aff;
45
struct isl_pw_multi_aff;
46
struct isl_union_map;
47
48
namespace polly {
49
50
struct Dependences;
51
class MemoryAccess;
52
class Scop;
53
54
class IslAst {
55
public:
56
  IslAst(const IslAst &) = delete;
57
  IslAst &operator=(const IslAst &) = delete;
58
  IslAst(IslAst &&);
59
  IslAst &operator=(IslAst &&) = delete;
60
  ~IslAst();
61
62
  static IslAst create(Scop &Scop, const Dependences &D);
63
64
  /// Print a source code representation of the program.
65
  void pprint(raw_ostream &OS);
66
67
  __isl_give isl_ast_node *getAst();
68
69
294
  const std::shared_ptr<isl_ctx> getSharedIslCtx() const { return Ctx; }
70
71
  /// Get the run-time conditions for the Scop.
72
  __isl_give isl_ast_expr *getRunCondition();
73
74
  /// Build run-time condition for scop.
75
  ///
76
  /// @param S     The scop to build the condition for.
77
  /// @param Build The isl_build object to use to build the condition.
78
  ///
79
  /// @returns An ast expression that describes the necessary run-time check.
80
  static isl_ast_expr *buildRunCondition(Scop &S,
81
                                         __isl_keep isl_ast_build *Build);
82
83
private:
84
  Scop &S;
85
  isl_ast_node *Root = nullptr;
86
  isl_ast_expr *RunCondition = nullptr;
87
  std::shared_ptr<isl_ctx> Ctx;
88
89
  IslAst(Scop &Scop);
90
91
  void init(const Dependences &D);
92
};
93
94
class IslAstInfo {
95
public:
96
  using MemoryAccessSet = SmallPtrSet<MemoryAccess *, 4>;
97
98
  /// Payload information used to annotate an AST node.
99
  struct IslAstUserPayload {
100
    /// Construct and initialize the payload.
101
2.42k
    IslAstUserPayload() = default;
102
103
    /// Cleanup all isl structs on destruction.
104
    ~IslAstUserPayload();
105
106
    /// Does the dependence analysis determine that there are no loop-carried
107
    /// dependencies?
108
    bool IsParallel = false;
109
110
    /// Flag to mark innermost loops.
111
    bool IsInnermost = false;
112
113
    /// Flag to mark innermost parallel loops.
114
    bool IsInnermostParallel = false;
115
116
    /// Flag to mark outermost parallel loops.
117
    bool IsOutermostParallel = false;
118
119
    /// Flag to mark parallel loops which break reductions.
120
    bool IsReductionParallel = false;
121
122
    /// The minimal dependence distance for non parallel loops.
123
    isl::pw_aff MinimalDependenceDistance;
124
125
    /// The build environment at the time this node was constructed.
126
    isl_ast_build *Build = nullptr;
127
128
    /// Set of accesses which break reduction dependences.
129
    MemoryAccessSet BrokenReductions;
130
  };
131
132
private:
133
  Scop &S;
134
  IslAst Ast;
135
136
public:
137
446
  IslAstInfo(Scop &S, const Dependences &D) : S(S), Ast(IslAst::create(S, D)) {}
138
139
  /// Return the isl AST computed by this IslAstInfo.
140
294
  IslAst &getIslAst() { return Ast; }
141
142
  /// Return a copy of the AST root node.
143
  __isl_give isl_ast_node *getAst();
144
145
  /// Get the run condition.
146
  ///
147
  /// Only if the run condition evaluates at run-time to a non-zero value, the
148
  /// assumptions that have been taken hold. If the run condition evaluates to
149
  /// zero/false some assumptions do not hold and the original code needs to
150
  /// be executed.
151
  __isl_give isl_ast_expr *getRunCondition();
152
153
  void print(raw_ostream &O);
154
155
  /// @name Extract information attached to an isl ast (for) node.
156
  ///
157
  ///{
158
  /// Get the complete payload attached to @p Node.
159
  static IslAstUserPayload *getNodePayload(__isl_keep isl_ast_node *Node);
160
161
  /// Is this loop an innermost loop?
162
  static bool isInnermost(__isl_keep isl_ast_node *Node);
163
164
  /// Is this loop a parallel loop?
165
  static bool isParallel(__isl_keep isl_ast_node *Node);
166
167
  /// Is this loop an outermost parallel loop?
168
  static bool isOutermostParallel(__isl_keep isl_ast_node *Node);
169
170
  /// Is this loop an innermost parallel loop?
171
  static bool isInnermostParallel(__isl_keep isl_ast_node *Node);
172
173
  /// Is this loop a reduction parallel loop?
174
  static bool isReductionParallel(__isl_keep isl_ast_node *Node);
175
176
  /// Will the loop be run as thread parallel?
177
  static bool isExecutedInParallel(__isl_keep isl_ast_node *Node);
178
179
  /// Get the nodes schedule or a nullptr if not available.
180
  static __isl_give isl_union_map *getSchedule(__isl_keep isl_ast_node *Node);
181
182
  /// Get minimal dependence distance or nullptr if not available.
183
  static __isl_give isl_pw_aff *
184
  getMinimalDependenceDistance(__isl_keep isl_ast_node *Node);
185
186
  /// Get the nodes broken reductions or a nullptr if not available.
187
  static MemoryAccessSet *getBrokenReductions(__isl_keep isl_ast_node *Node);
188
189
  /// Get the nodes build context or a nullptr if not available.
190
  static __isl_give isl_ast_build *getBuild(__isl_keep isl_ast_node *Node);
191
192
  ///}
193
};
194
195
struct IslAstAnalysis : public AnalysisInfoMixin<IslAstAnalysis> {
196
  static AnalysisKey Key;
197
198
  using Result = IslAstInfo;
199
200
  IslAstInfo run(Scop &S, ScopAnalysisManager &SAM,
201
                 ScopStandardAnalysisResults &SAR);
202
};
203
204
class IslAstInfoWrapperPass : public ScopPass {
205
  std::unique_ptr<IslAstInfo> Ast;
206
207
public:
208
  static char ID;
209
210
484
  IslAstInfoWrapperPass() : ScopPass(ID) {}
211
212
294
  IslAstInfo &getAI() { return *Ast; }
213
0
  const IslAstInfo &getAI() const { return *Ast; }
214
215
  /// Build the AST for the given SCoP @p S.
216
  bool runOnScop(Scop &S) override;
217
218
  /// Register all analyses and transformation required.
219
  void getAnalysisUsage(AnalysisUsage &AU) const override;
220
221
  /// Release the internal memory.
222
  void releaseMemory() override;
223
224
  /// Print a source code representation of the program.
225
  void printScop(raw_ostream &OS, Scop &S) const override;
226
};
227
228
struct IslAstPrinterPass : public PassInfoMixin<IslAstPrinterPass> {
229
1
  IslAstPrinterPass(raw_ostream &OS) : OS(OS) {}
230
231
  PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
232
                        ScopStandardAnalysisResults &, SPMUpdater &U);
233
234
  raw_ostream &OS;
235
};
236
} // namespace polly
237
238
#endif // POLLY_ISLAST_H