Coverage Report

Created: 2019-02-20 07:29

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