Coverage Report

Created: 2017-08-18 19:41

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