Coverage Report

Created: 2018-06-24 14:39

/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
293
  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.37k
    IslAstUserPayload() = default;
102
103
    /// Cleanup all isl structs on destruction.
104
    ~IslAstUserPayload();
105
106
    /// Flag to mark innermost loops.
107
    bool IsInnermost = false;
108
109
    /// Flag to mark innermost parallel loops.
110
    bool IsInnermostParallel = false;
111
112
    /// Flag to mark outermost parallel loops.
113
    bool IsOutermostParallel = false;
114
115
    /// Flag to mark parallel loops which break reductions.
116
    bool IsReductionParallel = false;
117
118
    /// The minimal dependence distance for non parallel loops.
119
    isl_pw_aff *MinimalDependenceDistance = nullptr;
120
121
    /// The build environment at the time this node was constructed.
122
    isl_ast_build *Build = nullptr;
123
124
    /// Set of accesses which break reduction dependences.
125
    MemoryAccessSet BrokenReductions;
126
  };
127
128
private:
129
  Scop &S;
130
  IslAst Ast;
131
132
public:
133
445
  IslAstInfo(Scop &S, const Dependences &D) : S(S), Ast(IslAst::create(S, D)) {}
134
135
  /// Return the isl AST computed by this IslAstInfo.
136
293
  IslAst &getIslAst() { return Ast; }
137
138
  /// Return a copy of the AST root node.
139
  __isl_give isl_ast_node *getAst();
140
141
  /// Get the run condition.
142
  ///
143
  /// Only if the run condition evaluates at run-time to a non-zero value, the
144
  /// assumptions that have been taken hold. If the run condition evaluates to
145
  /// zero/false some assumptions do not hold and the original code needs to
146
  /// be executed.
147
  __isl_give isl_ast_expr *getRunCondition();
148
149
  void print(raw_ostream &O);
150
151
  /// @name Extract information attached to an isl ast (for) node.
152
  ///
153
  ///{
154
  /// Get the complete payload attached to @p Node.
155
  static IslAstUserPayload *getNodePayload(__isl_keep isl_ast_node *Node);
156
157
  /// Is this loop an innermost loop?
158
  static bool isInnermost(__isl_keep isl_ast_node *Node);
159
160
  /// Is this loop a parallel loop?
161
  static bool isParallel(__isl_keep isl_ast_node *Node);
162
163
  /// Is this loop an outermost parallel loop?
164
  static bool isOutermostParallel(__isl_keep isl_ast_node *Node);
165
166
  /// Is this loop an innermost parallel loop?
167
  static bool isInnermostParallel(__isl_keep isl_ast_node *Node);
168
169
  /// Is this loop a reduction parallel loop?
170
  static bool isReductionParallel(__isl_keep isl_ast_node *Node);
171
172
  /// Will the loop be run as thread parallel?
173
  static bool isExecutedInParallel(__isl_keep isl_ast_node *Node);
174
175
  /// Get the nodes schedule or a nullptr if not available.
176
  static __isl_give isl_union_map *getSchedule(__isl_keep isl_ast_node *Node);
177
178
  /// Get minimal dependence distance or nullptr if not available.
179
  static __isl_give isl_pw_aff *
180
  getMinimalDependenceDistance(__isl_keep isl_ast_node *Node);
181
182
  /// Get the nodes broken reductions or a nullptr if not available.
183
  static MemoryAccessSet *getBrokenReductions(__isl_keep isl_ast_node *Node);
184
185
  /// Get the nodes build context or a nullptr if not available.
186
  static __isl_give isl_ast_build *getBuild(__isl_keep isl_ast_node *Node);
187
188
  ///}
189
};
190
191
struct IslAstAnalysis : public AnalysisInfoMixin<IslAstAnalysis> {
192
  static AnalysisKey Key;
193
194
  using Result = IslAstInfo;
195
196
  IslAstInfo run(Scop &S, ScopAnalysisManager &SAM,
197
                 ScopStandardAnalysisResults &SAR);
198
};
199
200
class IslAstInfoWrapperPass : public ScopPass {
201
  std::unique_ptr<IslAstInfo> Ast;
202
203
public:
204
  static char ID;
205
206
483
  IslAstInfoWrapperPass() : ScopPass(ID) {}
207
208
293
  IslAstInfo &getAI() { return *Ast; }
209
0
  const IslAstInfo &getAI() const { return *Ast; }
210
211
  /// Build the AST for the given SCoP @p S.
212
  bool runOnScop(Scop &S) override;
213
214
  /// Register all analyses and transformation required.
215
  void getAnalysisUsage(AnalysisUsage &AU) const override;
216
217
  /// Release the internal memory.
218
  void releaseMemory() override;
219
220
  /// Print a source code representation of the program.
221
  void printScop(raw_ostream &OS, Scop &S) const override;
222
};
223
224
struct IslAstPrinterPass : public PassInfoMixin<IslAstPrinterPass> {
225
1
  IslAstPrinterPass(raw_ostream &OS) : OS(OS) {}
226
227
  PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
228
                        ScopStandardAnalysisResults &, SPMUpdater &U);
229
230
  raw_ostream &OS;
231
};
232
} // namespace polly
233
234
#endif // POLLY_ISLAST_H