Polly 19.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
24#include "polly/ScopPass.h"
25#include "llvm/ADT/SmallPtrSet.h"
26#include "llvm/IR/PassManager.h"
27#include "isl/ctx.h"
28
29namespace polly {
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
166struct IslAstAnalysis : AnalysisInfoMixin<IslAstAnalysis> {
167 static AnalysisKey Key;
168
170
173};
174
175class IslAstInfoWrapperPass final : public ScopPass {
176 std::unique_ptr<IslAstInfo> Ast;
177
178public:
179 static char ID;
180
182
183 IslAstInfo &getAI() { return *Ast; }
184 const IslAstInfo &getAI() const { return *Ast; }
185
186 /// Build the AST for the given SCoP @p S.
187 bool runOnScop(Scop &S) override;
188
189 /// Register all analyses and transformation required.
190 void getAnalysisUsage(AnalysisUsage &AU) const override;
191
192 /// Release the internal memory.
193 void releaseMemory() override;
194
195 /// Print a source code representation of the program.
196 void printScop(raw_ostream &OS, Scop &S) const override;
197};
198
200llvm::Pass *createIslAstInfoPrinterLegacyPass(llvm::raw_ostream &OS);
201
202struct IslAstPrinterPass final : PassInfoMixin<IslAstPrinterPass> {
203 IslAstPrinterPass(raw_ostream &OS) : OS(OS) {}
204
205 PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
207
208 raw_ostream &OS;
209};
210} // namespace polly
211
212namespace llvm {
213void initializeIslAstInfoWrapperPassPass(llvm::PassRegistry &);
215} // namespace llvm
216
217#endif // POLLY_ISLAST_H
IslAstInfo::IslAstUserPayload IslAstUserPayload
Definition: IslAst.cpp:61
The accumulated dependence information for a SCoP.
void printScop(raw_ostream &OS, Scop &S) const override
Print a source code representation of the program.
Definition: IslAst.cpp:800
void getAnalysisUsage(AnalysisUsage &AU) const override
Register all analyses and transformation required.
Definition: IslAst.cpp:791
IslAstInfo & getAI()
Definition: IslAst.h:183
const IslAstInfo & getAI() const
Definition: IslAst.h:184
void releaseMemory() override
Release the internal memory.
Definition: IslAst.cpp:779
bool runOnScop(Scop &S) override
Build the AST for the given SCoP S.
Definition: IslAst.cpp:781
std::unique_ptr< IslAstInfo > Ast
Definition: IslAst.h:176
static bool isOutermostParallel(const isl::ast_node &Node)
Is this loop an outermost parallel loop?
Definition: IslAst.cpp:588
static MemoryAccessSet * getBrokenReductions(const isl::ast_node &Node)
Get the nodes broken reductions or a nullptr if not available.
Definition: IslAst.cpp:629
static bool isParallel(const isl::ast_node &Node)
Is this loop a parallel loop?
Definition: IslAst.cpp:578
static isl::pw_aff getMinimalDependenceDistance(const isl::ast_node &Node)
Get minimal dependence distance or nullptr if not available.
Definition: IslAst.cpp:623
static bool isInnermostParallel(const isl::ast_node &Node)
Is this loop an innermost parallel loop?
Definition: IslAst.cpp:583
isl::ast_node getAst()
Return a copy of the AST root node.
Definition: IslAst.cpp:562
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:598
isl::ast_expr getRunCondition()
Get the run condition.
Definition: IslAst.cpp:563
static bool isInnermost(const isl::ast_node &Node)
Is this loop an innermost loop?
Definition: IslAst.cpp:573
static IslAstUserPayload * getNodePayload(const isl::ast_node &Node)
Definition: IslAst.cpp:565
static isl::union_map getSchedule(const isl::ast_node &Node)
Get the nodes schedule or a nullptr if not available.
Definition: IslAst.cpp:617
void print(raw_ostream &O)
Definition: IslAst.cpp:719
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:634
static bool isReductionParallel(const isl::ast_node &Node)
Is this loop a reduction parallel loop?
Definition: IslAst.cpp:593
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:395
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:560
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:553
IslAst & operator=(IslAst &&)=delete
isl::ast_expr RunCondition
Definition: IslAst.h:61
isl::ast_node getAst()
Definition: IslAst.cpp:559
void init(const Dependences &D)
Definition: IslAst.cpp:499
ScopPass - This class adapts the RegionPass interface to allow convenient creation of passes that ope...
Definition: ScopPass.h:161
Static Control Part.
Definition: ScopInfo.h:1628
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
void initializeIslAstInfoPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeIslAstInfoWrapperPassPass(llvm::PassRegistry &)
llvm::Pass * createIslAstInfoPrinterLegacyPass(llvm::raw_ostream &OS)
AnalysisManager< Scop, ScopStandardAnalysisResults & > ScopAnalysisManager
Definition: ScopPass.h:46
llvm::Pass * createIslAstInfoWrapperPassPass()
Definition: IslAst.cpp:809
IslAstInfo run(Scop &S, ScopAnalysisManager &SAM, ScopStandardAnalysisResults &SAR)
Definition: IslAst.cpp:662
static AnalysisKey Key
Definition: IslAst.h:167
Payload information used to annotate an AST node.
Definition: IslAst.h:74
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
raw_ostream & OS
Definition: IslAst.h:208
IslAstPrinterPass(raw_ostream &OS)
Definition: IslAst.h:203
PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM, ScopStandardAnalysisResults &, SPMUpdater &U)
Definition: IslAst.cpp:771