File indexing completed on 2026-05-10 08:48:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef POLLY_ISLAST_H
0022 #define POLLY_ISLAST_H
0023
0024 #include "polly/ScopPass.h"
0025 #include "llvm/ADT/SmallPtrSet.h"
0026 #include "llvm/IR/PassManager.h"
0027 #include "isl/ctx.h"
0028
0029 namespace polly {
0030 using llvm::SmallPtrSet;
0031
0032 class Dependences;
0033
0034 class IslAst final {
0035 public:
0036 IslAst(const IslAst &) = delete;
0037 IslAst &operator=(const IslAst &) = delete;
0038 IslAst(IslAst &&);
0039 IslAst &operator=(IslAst &&) = delete;
0040
0041 static IslAst create(Scop &Scop, const Dependences &D);
0042
0043 isl::ast_node getAst();
0044
0045 const std::shared_ptr<isl_ctx> getSharedIslCtx() const { return Ctx; }
0046
0047
0048 isl::ast_expr getRunCondition();
0049
0050
0051
0052
0053
0054
0055
0056 static isl::ast_expr buildRunCondition(Scop &S, const isl::ast_build &Build);
0057
0058 private:
0059 Scop &S;
0060 std::shared_ptr<isl_ctx> Ctx;
0061 isl::ast_expr RunCondition;
0062 isl::ast_node Root;
0063
0064 IslAst(Scop &Scop);
0065
0066 void init(const Dependences &D);
0067 };
0068
0069 class IslAstInfo {
0070 public:
0071 using MemoryAccessSet = SmallPtrSet<MemoryAccess *, 4>;
0072
0073
0074 struct IslAstUserPayload {
0075
0076 IslAstUserPayload() = default;
0077
0078
0079
0080 bool IsParallel = false;
0081
0082
0083 bool IsInnermost = false;
0084
0085
0086 bool IsInnermostParallel = false;
0087
0088
0089 bool IsOutermostParallel = false;
0090
0091
0092 bool IsReductionParallel = false;
0093
0094
0095 isl::pw_aff MinimalDependenceDistance;
0096
0097
0098 isl::ast_build Build;
0099
0100
0101 MemoryAccessSet BrokenReductions;
0102 };
0103
0104 private:
0105 Scop &S;
0106 IslAst Ast;
0107
0108 public:
0109 IslAstInfo(Scop &S, const Dependences &D) : S(S), Ast(IslAst::create(S, D)) {}
0110
0111
0112 IslAst &getIslAst() { return Ast; }
0113
0114
0115 isl::ast_node getAst();
0116
0117
0118
0119
0120
0121
0122
0123 isl::ast_expr getRunCondition();
0124
0125 void print(raw_ostream &O);
0126
0127
0128
0129
0130
0131 static IslAstUserPayload *getNodePayload(const isl::ast_node &Node);
0132
0133
0134 static bool isInnermost(const isl::ast_node &Node);
0135
0136
0137 static bool isParallel(const isl::ast_node &Node);
0138
0139
0140 static bool isOutermostParallel(const isl::ast_node &Node);
0141
0142
0143 static bool isInnermostParallel(const isl::ast_node &Node);
0144
0145
0146 static bool isReductionParallel(const isl::ast_node &Node);
0147
0148
0149 static bool isExecutedInParallel(const isl::ast_node &Node);
0150
0151
0152 static isl::union_map getSchedule(const isl::ast_node &Node);
0153
0154
0155 static isl::pw_aff getMinimalDependenceDistance(const isl::ast_node &Node);
0156
0157
0158 static MemoryAccessSet *getBrokenReductions(const isl::ast_node &Node);
0159
0160
0161 static isl::ast_build getBuild(const isl::ast_node &Node);
0162
0163
0164 };
0165
0166 struct IslAstAnalysis : AnalysisInfoMixin<IslAstAnalysis> {
0167 static AnalysisKey Key;
0168
0169 using Result = IslAstInfo;
0170
0171 IslAstInfo run(Scop &S, ScopAnalysisManager &SAM,
0172 ScopStandardAnalysisResults &SAR);
0173 };
0174
0175 class IslAstInfoWrapperPass final : public ScopPass {
0176 std::unique_ptr<IslAstInfo> Ast;
0177
0178 public:
0179 static char ID;
0180
0181 IslAstInfoWrapperPass() : ScopPass(ID) {}
0182
0183 IslAstInfo &getAI() { return *Ast; }
0184 const IslAstInfo &getAI() const { return *Ast; }
0185
0186
0187 bool runOnScop(Scop &S) override;
0188
0189
0190 void getAnalysisUsage(AnalysisUsage &AU) const override;
0191
0192
0193 void releaseMemory() override;
0194
0195
0196 void printScop(raw_ostream &OS, Scop &S) const override;
0197 };
0198
0199 llvm::Pass *createIslAstInfoWrapperPassPass();
0200 llvm::Pass *createIslAstInfoPrinterLegacyPass(llvm::raw_ostream &OS);
0201
0202 struct IslAstPrinterPass final : PassInfoMixin<IslAstPrinterPass> {
0203 IslAstPrinterPass(raw_ostream &OS) : OS(OS) {}
0204
0205 PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
0206 ScopStandardAnalysisResults &, SPMUpdater &U);
0207
0208 raw_ostream &OS;
0209 };
0210 }
0211
0212 namespace llvm {
0213 void initializeIslAstInfoWrapperPassPass(llvm::PassRegistry &);
0214 void initializeIslAstInfoPrinterLegacyPassPass(llvm::PassRegistry &);
0215 }
0216
0217 #endif