Coverage Report

Created: 2017-04-27 19:33

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/include/polly/CodeGen/IslAst.h
Line
Count
Source
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
private:
69
  Scop *S;
70
  isl_ast_node *Root;
71
  isl_ast_expr *RunCondition;
72
  std::shared_ptr<isl_ctx> Ctx;
73
74
  IslAst(Scop *Scop);
75
  void init(const Dependences &D);
76
};
77
78
class IslAstInfo : public ScopPass {
79
public:
80
  using MemoryAccessSet = SmallPtrSet<MemoryAccess *, 4>;
81
82
  /// Payload information used to annotate an AST node.
83
  struct IslAstUserPayload {
84
    /// Construct and initialize the payload.
85
    IslAstUserPayload()
86
        : IsInnermost(false), IsInnermostParallel(false),
87
          IsOutermostParallel(false), IsReductionParallel(false),
88
1.48k
          MinimalDependenceDistance(nullptr), Build(nullptr) {}
89
90
    /// Cleanup all isl structs on destruction.
91
    ~IslAstUserPayload();
92
93
    /// Flag to mark innermost loops.
94
    bool IsInnermost;
95
96
    /// Flag to mark innermost parallel loops.
97
    bool IsInnermostParallel;
98
99
    /// Flag to mark outermost parallel loops.
100
    bool IsOutermostParallel;
101
102
    /// Flag to mark parallel loops which break reductions.
103
    bool IsReductionParallel;
104
105
    /// The minimal dependence distance for non parallel loops.
106
    isl_pw_aff *MinimalDependenceDistance;
107
108
    /// The build environment at the time this node was constructed.
109
    isl_ast_build *Build;
110
111
    /// Set of accesses which break reduction dependences.
112
    MemoryAccessSet BrokenReductions;
113
  };
114
115
private:
116
  Scop *S;
117
  IslAst *Ast;
118
119
public:
120
  static char ID;
121
435
  IslAstInfo() : ScopPass(ID), S(nullptr), Ast(nullptr) {}
122
123
  /// Build the AST for the given SCoP @p S.
124
  bool runOnScop(Scop &S) override;
125
126
  /// Register all analyses and transformation required.
127
  void getAnalysisUsage(AnalysisUsage &AU) const override;
128
129
  /// Release the internal memory.
130
  void releaseMemory() override;
131
132
  /// Print a source code representation of the program.
133
  void printScop(llvm::raw_ostream &OS, Scop &S) const override;
134
135
  /// Return a copy of the AST root node.
136
  __isl_give isl_ast_node *getAst() const;
137
138
  /// Get the run condition.
139
  ///
140
  /// Only if the run condition evaluates at run-time to a non-zero value, the
141
  /// assumptions that have been taken hold. If the run condition evaluates to
142
  /// zero/false some assumptions do not hold and the original code needs to
143
  /// be executed.
144
  __isl_give isl_ast_expr *getRunCondition() const;
145
146
  /// @name Extract information attached to an isl ast (for) node.
147
  ///
148
  ///{
149
150
  /// Get the complete payload attached to @p Node.
151
  static IslAstUserPayload *getNodePayload(__isl_keep isl_ast_node *Node);
152
153
  /// Is this loop an innermost loop?
154
  static bool isInnermost(__isl_keep isl_ast_node *Node);
155
156
  /// Is this loop a parallel loop?
157
  static bool isParallel(__isl_keep isl_ast_node *Node);
158
159
  /// Is this loop an outermost parallel loop?
160
  static bool isOutermostParallel(__isl_keep isl_ast_node *Node);
161
162
  /// Is this loop an innermost parallel loop?
163
  static bool isInnermostParallel(__isl_keep isl_ast_node *Node);
164
165
  /// Is this loop a reduction parallel loop?
166
  static bool isReductionParallel(__isl_keep isl_ast_node *Node);
167
168
  /// Will the loop be run as thread parallel?
169
  static bool isExecutedInParallel(__isl_keep isl_ast_node *Node);
170
171
  /// Get the nodes schedule or a nullptr if not available.
172
  static __isl_give isl_union_map *getSchedule(__isl_keep isl_ast_node *Node);
173
174
  /// Get minimal dependence distance or nullptr if not available.
175
  static __isl_give isl_pw_aff *
176
  getMinimalDependenceDistance(__isl_keep isl_ast_node *Node);
177
178
  /// Get the nodes broken reductions or a nullptr if not available.
179
  static MemoryAccessSet *getBrokenReductions(__isl_keep isl_ast_node *Node);
180
181
  /// Get the nodes build context or a nullptr if not available.
182
  static __isl_give isl_ast_build *getBuild(__isl_keep isl_ast_node *Node);
183
184
  ///}
185
};
186
} // namespace polly
187
188
namespace llvm {
189
class PassRegistry;
190
void initializeIslAstInfoPass(llvm::PassRegistry &);
191
} // namespace llvm
192
#endif /* POLLY_ISL_AST_H */