Polly 22.0.0git
IslAst.h
Go to the documentation of this file.
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
25#include "llvm/ADT/SmallPtrSet.h"
26#include "isl/ctx.h"
27
28namespace polly {
29using llvm::raw_ostream;
30using llvm::SmallPtrSet;
31
32class Dependences;
33
34class IslAst final {
35public:
36 IslAst(const IslAst &) = delete;
37 IslAst &operator=(const IslAst &) = delete;
38 IslAst(IslAst &&);
39 IslAst &operator=(IslAst &&) = delete;
40
41 static IslAst create(Scop &Scop, const Dependences &D);
42
44
45 const std::shared_ptr<isl_ctx> getSharedIslCtx() const { return Ctx; }
46
47 /// Get the run-time conditions for the Scop.
49
50 /// Build run-time condition for scop.
51 ///
52 /// @param S The scop to build the condition for.
53 /// @param Build The isl_build object to use to build the condition.
54 ///
55 /// @returns An ast expression that describes the necessary run-time check.
57
58private:
60 std::shared_ptr<isl_ctx> Ctx;
63
65
66 void init(const Dependences &D);
67};
68
70public:
71 using MemoryAccessSet = SmallPtrSet<MemoryAccess *, 4>;
72
73 /// Payload information used to annotate an AST node.
75 /// Construct and initialize the payload.
76 IslAstUserPayload() = default;
77
78 /// Does the dependence analysis determine that there are no loop-carried
79 /// dependencies?
80 bool IsParallel = false;
81
82 /// Flag to mark innermost loops.
83 bool IsInnermost = false;
84
85 /// Flag to mark innermost parallel loops.
86 bool IsInnermostParallel = false;
87
88 /// Flag to mark outermost parallel loops.
89 bool IsOutermostParallel = false;
90
91 /// Flag to mark parallel loops which break reductions.
92 bool IsReductionParallel = false;
93
94 /// The minimal dependence distance for non parallel loops.
96
97 /// The build environment at the time this node was constructed.
99
100 /// Set of accesses which break reduction dependences.
102 };
103
104private:
107
108public:
109 IslAstInfo(Scop &S, const Dependences &D) : S(S), Ast(IslAst::create(S, D)) {}
110
111 /// Return the isl AST computed by this IslAstInfo.
112 IslAst &getIslAst() { return Ast; }
113
114 /// Return a copy of the AST root node.
116
117 /// Get the run condition.
118 ///
119 /// Only if the run condition evaluates at run-time to a non-zero value, the
120 /// assumptions that have been taken hold. If the run condition evaluates to
121 /// zero/false some assumptions do not hold and the original code needs to
122 /// be executed.
124
125 void print(raw_ostream &O);
126
127 /// @name Extract information attached to an isl ast (for) node.
128 ///
129 ///{
130 /// Get the complete payload attached to @p Node.
132
133 /// Is this loop an innermost loop?
134 static bool isInnermost(const isl::ast_node &Node);
135
136 /// Is this loop a parallel loop?
137 static bool isParallel(const isl::ast_node &Node);
138
139 /// Is this loop an outermost parallel loop?
140 static bool isOutermostParallel(const isl::ast_node &Node);
141
142 /// Is this loop an innermost parallel loop?
143 static bool isInnermostParallel(const isl::ast_node &Node);
144
145 /// Is this loop a reduction parallel loop?
146 static bool isReductionParallel(const isl::ast_node &Node);
147
148 /// Will the loop be run as thread parallel?
149 static bool isExecutedInParallel(const isl::ast_node &Node);
150
151 /// Get the nodes schedule or a nullptr if not available.
152 static isl::union_map getSchedule(const isl::ast_node &Node);
153
154 /// Get minimal dependence distance or nullptr if not available.
156
157 /// Get the nodes broken reductions or a nullptr if not available.
159
160 /// Get the nodes build context or a nullptr if not available.
161 static isl::ast_build getBuild(const isl::ast_node &Node);
162
163 ///}
164};
165
166std::unique_ptr<IslAstInfo> runIslAstGen(Scop &S,
167 DependenceAnalysis::Result &DA);
168} // namespace polly
169
170#endif // POLLY_ISLAST_H
IslAstInfo::IslAstUserPayload IslAstUserPayload
Definition IslAst.cpp:59
The accumulated dependence information for a SCoP.
static bool isOutermostParallel(const isl::ast_node &Node)
Is this loop an outermost parallel loop?
Definition IslAst.cpp:591
static MemoryAccessSet * getBrokenReductions(const isl::ast_node &Node)
Get the nodes broken reductions or a nullptr if not available.
Definition IslAst.cpp:632
static bool isParallel(const isl::ast_node &Node)
Is this loop a parallel loop?
Definition IslAst.cpp:581
static isl::pw_aff getMinimalDependenceDistance(const isl::ast_node &Node)
Get minimal dependence distance or nullptr if not available.
Definition IslAst.cpp:626
static bool isInnermostParallel(const isl::ast_node &Node)
Is this loop an innermost parallel loop?
Definition IslAst.cpp:586
isl::ast_node getAst()
Return a copy of the AST root node.
Definition IslAst.cpp:565
SmallPtrSet< MemoryAccess *, 4 > MemoryAccessSet
Definition IslAst.h:71
static bool isExecutedInParallel(const isl::ast_node &Node)
Will the loop be run as thread parallel?
Definition IslAst.cpp:601
isl::ast_expr getRunCondition()
Get the run condition.
Definition IslAst.cpp:566
static bool isInnermost(const isl::ast_node &Node)
Is this loop an innermost loop?
Definition IslAst.cpp:576
static IslAstUserPayload * getNodePayload(const isl::ast_node &Node)
Definition IslAst.cpp:568
static isl::union_map getSchedule(const isl::ast_node &Node)
Get the nodes schedule or a nullptr if not available.
Definition IslAst.cpp:620
void print(raw_ostream &O)
Definition IslAst.cpp:713
IslAstInfo(Scop &S, const Dependences &D)
Definition IslAst.h:109
IslAst & getIslAst()
Return the isl AST computed by this IslAstInfo.
Definition IslAst.h:112
static isl::ast_build getBuild(const isl::ast_node &Node)
Get the nodes build context or a nullptr if not available.
Definition IslAst.cpp:637
static bool isReductionParallel(const isl::ast_node &Node)
Is this loop a reduction parallel loop?
Definition IslAst.cpp:596
const std::shared_ptr< isl_ctx > getSharedIslCtx() const
Definition IslAst.h:45
static isl::ast_expr buildRunCondition(Scop &S, const isl::ast_build &Build)
Build run-time condition for scop.
Definition IslAst.cpp:398
Scop & S
Definition IslAst.h:59
isl::ast_node Root
Definition IslAst.h:62
IslAst & operator=(const IslAst &)=delete
isl::ast_expr getRunCondition()
Get the run-time conditions for the Scop.
Definition IslAst.cpp:563
IslAst(const IslAst &)=delete
std::shared_ptr< isl_ctx > Ctx
Definition IslAst.h:60
static IslAst create(Scop &Scop, const Dependences &D)
Definition IslAst.cpp:556
IslAst & operator=(IslAst &&)=delete
isl::ast_expr RunCondition
Definition IslAst.h:61
isl::ast_node getAst()
Definition IslAst.cpp:562
void init(const Dependences &D)
Definition IslAst.cpp:502
Static Control Part.
Definition ScopInfo.h:1625
#define S(TYPE, NAME)
std::unique_ptr< IslAstInfo > runIslAstGen(Scop &S, DependenceAnalysis::Result &DA)
Definition IslAst.cpp:765
bool IsInnermost
Flag to mark innermost loops.
Definition IslAst.h:83
bool IsOutermostParallel
Flag to mark outermost parallel loops.
Definition IslAst.h:89
bool IsParallel
Does the dependence analysis determine that there are no loop-carried dependencies?
Definition IslAst.h:80
MemoryAccessSet BrokenReductions
Set of accesses which break reduction dependences.
Definition IslAst.h:101
isl::pw_aff MinimalDependenceDistance
The minimal dependence distance for non parallel loops.
Definition IslAst.h:95
bool IsReductionParallel
Flag to mark parallel loops which break reductions.
Definition IslAst.h:92
IslAstUserPayload()=default
Construct and initialize the payload.
bool IsInnermostParallel
Flag to mark innermost parallel loops.
Definition IslAst.h:86
isl::ast_build Build
The build environment at the time this node was constructed.
Definition IslAst.h:98