Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1 | //===--------- ScopInfo.cpp - Create Scops from LLVM IR ------------------===// |
| 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 | // Create a polyhedral description for a static control flow region. |
| 11 | // |
| 12 | // The pass creates a polyhedral description of the Scops detected by the Scop |
| 13 | // detection derived from their LLVM-IR code. |
| 14 | // |
Tobias Grosser | a5605d3 | 2014-10-29 19:58:28 +0000 | [diff] [blame] | 15 | // This representation is shared among several tools in the polyhedral |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 16 | // community, which are e.g. Cloog, Pluto, Loopo, Graphite. |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 20 | #include "polly/LinkAllPasses.h" |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 21 | #include "polly/Options.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 22 | #include "polly/ScopInfo.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 23 | #include "polly/Support/GICHelper.h" |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 24 | #include "polly/Support/SCEVValidator.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 25 | #include "polly/Support/ScopHelper.h" |
Sebastian Pop | 27c10c6 | 2013-03-22 22:07:43 +0000 | [diff] [blame] | 26 | #include "polly/TempScopInfo.h" |
Tobias Grosser | f4c24b2 | 2015-04-05 13:11:54 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/MapVector.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SetVector.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/Statistic.h" |
Johannes Doerfert | ecff11d | 2015-05-22 23:43:58 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/STLExtras.h" |
Hongbin Zheng | 86a3774 | 2012-04-25 08:01:38 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringExtras.h" |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 32 | #include "llvm/Analysis/AliasAnalysis.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 33 | #include "llvm/Analysis/LoopInfo.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 34 | #include "llvm/Analysis/RegionIterator.h" |
| 35 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Debug.h" |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 37 | #include "isl/aff.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 38 | #include "isl/constraint.h" |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 39 | #include "isl/local_space.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 40 | #include "isl/map.h" |
Tobias Grosser | 4a8e356 | 2011-12-07 07:42:51 +0000 | [diff] [blame] | 41 | #include "isl/options.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 42 | #include "isl/printer.h" |
| 43 | #include "isl/set.h" |
| 44 | #include "isl/union_map.h" |
Tobias Grosser | cd524dc | 2015-05-09 09:36:38 +0000 | [diff] [blame] | 45 | #include "isl/union_set.h" |
Tobias Grosser | edab135 | 2013-06-21 06:41:31 +0000 | [diff] [blame] | 46 | #include "isl/val.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 47 | #include <sstream> |
| 48 | #include <string> |
| 49 | #include <vector> |
| 50 | |
| 51 | using namespace llvm; |
| 52 | using namespace polly; |
| 53 | |
Chandler Carruth | 95fef94 | 2014-04-22 03:30:19 +0000 | [diff] [blame] | 54 | #define DEBUG_TYPE "polly-scops" |
| 55 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 56 | STATISTIC(ScopFound, "Number of valid Scops"); |
| 57 | STATISTIC(RichScopFound, "Number of Scops containing a loop"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 58 | |
Johannes Doerfert | 9e7b17b | 2014-08-18 00:40:13 +0000 | [diff] [blame] | 59 | // Multiplicative reductions can be disabled separately as these kind of |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 60 | // operations can overflow easily. Additive reductions and bit operations |
| 61 | // are in contrast pretty stable. |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 62 | static cl::opt<bool> DisableMultiplicativeReductions( |
| 63 | "polly-disable-multiplicative-reductions", |
| 64 | cl::desc("Disable multiplicative reductions"), cl::Hidden, cl::ZeroOrMore, |
| 65 | cl::init(false), cl::cat(PollyCategory)); |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 66 | |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 67 | static cl::opt<unsigned> RunTimeChecksMaxParameters( |
| 68 | "polly-rtc-max-parameters", |
| 69 | cl::desc("The maximal number of parameters allowed in RTCs."), cl::Hidden, |
| 70 | cl::ZeroOrMore, cl::init(8), cl::cat(PollyCategory)); |
| 71 | |
Tobias Grosser | 7150072 | 2015-03-28 15:11:14 +0000 | [diff] [blame] | 72 | static cl::opt<unsigned> RunTimeChecksMaxArraysPerGroup( |
| 73 | "polly-rtc-max-arrays-per-group", |
| 74 | cl::desc("The maximal number of arrays to compare in each alias group."), |
| 75 | cl::Hidden, cl::ZeroOrMore, cl::init(20), cl::cat(PollyCategory)); |
| 76 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 77 | /// Translate a 'const SCEV *' expression in an isl_pw_aff. |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 78 | struct SCEVAffinator : public SCEVVisitor<SCEVAffinator, isl_pw_aff *> { |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 79 | public: |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 80 | /// @brief Translate a 'const SCEV *' to an isl_pw_aff. |
| 81 | /// |
| 82 | /// @param Stmt The location at which the scalar evolution expression |
| 83 | /// is evaluated. |
| 84 | /// @param Expr The expression that is translated. |
| 85 | static __isl_give isl_pw_aff *getPwAff(ScopStmt *Stmt, const SCEV *Expr); |
| 86 | |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 87 | private: |
Tobias Grosser | 3cc9974 | 2012-06-06 16:33:15 +0000 | [diff] [blame] | 88 | isl_ctx *Ctx; |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 89 | int NbLoopSpaces; |
Tobias Grosser | 3cc9974 | 2012-06-06 16:33:15 +0000 | [diff] [blame] | 90 | const Scop *S; |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 91 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 92 | SCEVAffinator(const ScopStmt *Stmt); |
| 93 | int getLoopDepth(const Loop *L); |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 94 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 95 | __isl_give isl_pw_aff *visit(const SCEV *Expr); |
| 96 | __isl_give isl_pw_aff *visitConstant(const SCEVConstant *Expr); |
| 97 | __isl_give isl_pw_aff *visitTruncateExpr(const SCEVTruncateExpr *Expr); |
| 98 | __isl_give isl_pw_aff *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr); |
| 99 | __isl_give isl_pw_aff *visitSignExtendExpr(const SCEVSignExtendExpr *Expr); |
| 100 | __isl_give isl_pw_aff *visitAddExpr(const SCEVAddExpr *Expr); |
| 101 | __isl_give isl_pw_aff *visitMulExpr(const SCEVMulExpr *Expr); |
| 102 | __isl_give isl_pw_aff *visitUDivExpr(const SCEVUDivExpr *Expr); |
| 103 | __isl_give isl_pw_aff *visitAddRecExpr(const SCEVAddRecExpr *Expr); |
| 104 | __isl_give isl_pw_aff *visitSMaxExpr(const SCEVSMaxExpr *Expr); |
| 105 | __isl_give isl_pw_aff *visitUMaxExpr(const SCEVUMaxExpr *Expr); |
| 106 | __isl_give isl_pw_aff *visitUnknown(const SCEVUnknown *Expr); |
Johannes Doerfert | b9d1888 | 2015-02-11 14:54:50 +0000 | [diff] [blame] | 107 | __isl_give isl_pw_aff *visitSDivInstruction(Instruction *SDiv); |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 108 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 109 | friend struct SCEVVisitor<SCEVAffinator, isl_pw_aff *>; |
| 110 | }; |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 111 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 112 | SCEVAffinator::SCEVAffinator(const ScopStmt *Stmt) |
| 113 | : Ctx(Stmt->getIslCtx()), NbLoopSpaces(Stmt->getNumIterators()), |
| 114 | S(Stmt->getParent()) {} |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 115 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 116 | __isl_give isl_pw_aff *SCEVAffinator::getPwAff(ScopStmt *Stmt, |
| 117 | const SCEV *Scev) { |
| 118 | Scop *S = Stmt->getParent(); |
| 119 | const Region *Reg = &S->getRegion(); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 120 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 121 | S->addParams(getParamsInAffineExpr(Reg, Scev, *S->getSE())); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 122 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 123 | SCEVAffinator Affinator(Stmt); |
| 124 | return Affinator.visit(Scev); |
| 125 | } |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 126 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 127 | __isl_give isl_pw_aff *SCEVAffinator::visit(const SCEV *Expr) { |
| 128 | // In case the scev is a valid parameter, we do not further analyze this |
| 129 | // expression, but create a new parameter in the isl_pw_aff. This allows us |
| 130 | // to treat subexpressions that we cannot translate into an piecewise affine |
| 131 | // expression, as constant parameters of the piecewise affine expression. |
| 132 | if (isl_id *Id = S->getIdForParam(Expr)) { |
| 133 | isl_space *Space = isl_space_set_alloc(Ctx, 1, NbLoopSpaces); |
| 134 | Space = isl_space_set_dim_id(Space, isl_dim_param, 0, Id); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 135 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 136 | isl_set *Domain = isl_set_universe(isl_space_copy(Space)); |
| 137 | isl_aff *Affine = isl_aff_zero_on_domain(isl_local_space_from_space(Space)); |
| 138 | Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 139 | |
| 140 | return isl_pw_aff_alloc(Domain, Affine); |
| 141 | } |
| 142 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 143 | return SCEVVisitor<SCEVAffinator, isl_pw_aff *>::visit(Expr); |
| 144 | } |
| 145 | |
Tobias Grosser | 0d17013 | 2013-10-03 13:09:19 +0000 | [diff] [blame] | 146 | __isl_give isl_pw_aff *SCEVAffinator::visitConstant(const SCEVConstant *Expr) { |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 147 | ConstantInt *Value = Expr->getValue(); |
| 148 | isl_val *v; |
| 149 | |
| 150 | // LLVM does not define if an integer value is interpreted as a signed or |
| 151 | // unsigned value. Hence, without further information, it is unknown how |
| 152 | // this value needs to be converted to GMP. At the moment, we only support |
| 153 | // signed operations. So we just interpret it as signed. Later, there are |
| 154 | // two options: |
| 155 | // |
| 156 | // 1. We always interpret any value as signed and convert the values on |
| 157 | // demand. |
| 158 | // 2. We pass down the signedness of the calculation and use it to interpret |
| 159 | // this constant correctly. |
| 160 | v = isl_valFromAPInt(Ctx, Value->getValue(), /* isSigned */ true); |
| 161 | |
| 162 | isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces); |
Johannes Doerfert | 9c14737 | 2014-11-19 15:36:59 +0000 | [diff] [blame] | 163 | isl_local_space *ls = isl_local_space_from_space(Space); |
| 164 | return isl_pw_aff_from_aff(isl_aff_val_on_domain(ls, v)); |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | __isl_give isl_pw_aff * |
| 168 | SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) { |
| 169 | llvm_unreachable("SCEVTruncateExpr not yet supported"); |
| 170 | } |
| 171 | |
| 172 | __isl_give isl_pw_aff * |
| 173 | SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) { |
| 174 | llvm_unreachable("SCEVZeroExtendExpr not yet supported"); |
| 175 | } |
| 176 | |
| 177 | __isl_give isl_pw_aff * |
| 178 | SCEVAffinator::visitSignExtendExpr(const SCEVSignExtendExpr *Expr) { |
| 179 | // Assuming the value is signed, a sign extension is basically a noop. |
| 180 | // TODO: Reconsider this as soon as we support unsigned values. |
| 181 | return visit(Expr->getOperand()); |
| 182 | } |
| 183 | |
| 184 | __isl_give isl_pw_aff *SCEVAffinator::visitAddExpr(const SCEVAddExpr *Expr) { |
| 185 | isl_pw_aff *Sum = visit(Expr->getOperand(0)); |
| 186 | |
| 187 | for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) { |
| 188 | isl_pw_aff *NextSummand = visit(Expr->getOperand(i)); |
| 189 | Sum = isl_pw_aff_add(Sum, NextSummand); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 192 | // TODO: Check for NSW and NUW. |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 193 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 194 | return Sum; |
| 195 | } |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 196 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 197 | __isl_give isl_pw_aff *SCEVAffinator::visitMulExpr(const SCEVMulExpr *Expr) { |
Johannes Doerfert | be40996 | 2015-03-29 20:45:09 +0000 | [diff] [blame] | 198 | // Divide Expr into a constant part and the rest. Then visit both and multiply |
| 199 | // the result to obtain the representation for Expr. While the second part of |
| 200 | // ConstantAndLeftOverPair might still be a SCEVMulExpr we will not get to |
| 201 | // this point again. The reason is that if it is a multiplication it consists |
| 202 | // only of parameters and we will stop in the visit(const SCEV *) function and |
| 203 | // return the isl_pw_aff for that parameter. |
| 204 | auto ConstantAndLeftOverPair = extractConstantFactor(Expr, *S->getSE()); |
| 205 | return isl_pw_aff_mul(visit(ConstantAndLeftOverPair.first), |
| 206 | visit(ConstantAndLeftOverPair.second)); |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 207 | } |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 208 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 209 | __isl_give isl_pw_aff *SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) { |
| 210 | llvm_unreachable("SCEVUDivExpr not yet supported"); |
| 211 | } |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 212 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 213 | __isl_give isl_pw_aff * |
| 214 | SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) { |
| 215 | assert(Expr->isAffine() && "Only affine AddRecurrences allowed"); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 216 | |
Johannes Doerfert | d5d8f67 | 2015-04-26 19:55:21 +0000 | [diff] [blame] | 217 | auto Flags = Expr->getNoWrapFlags(); |
| 218 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 219 | // Directly generate isl_pw_aff for Expr if 'start' is zero. |
| 220 | if (Expr->getStart()->isZero()) { |
| 221 | assert(S->getRegion().contains(Expr->getLoop()) && |
| 222 | "Scop does not contain the loop referenced in this AddRec"); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 223 | |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 224 | isl_pw_aff *Start = visit(Expr->getStart()); |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 225 | isl_pw_aff *Step = visit(Expr->getOperand(1)); |
| 226 | isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces); |
| 227 | isl_local_space *LocalSpace = isl_local_space_from_space(Space); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 228 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 229 | int loopDimension = getLoopDepth(Expr->getLoop()); |
| 230 | |
| 231 | isl_aff *LAff = isl_aff_set_coefficient_si( |
| 232 | isl_aff_zero_on_domain(LocalSpace), isl_dim_in, loopDimension, 1); |
| 233 | isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff); |
| 234 | |
| 235 | // TODO: Do we need to check for NSW and NUW? |
| 236 | return isl_pw_aff_add(Start, isl_pw_aff_mul(Step, LPwAff)); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 239 | // Translate AddRecExpr from '{start, +, inc}' into 'start + {0, +, inc}' |
| 240 | // if 'start' is not zero. |
Johannes Doerfert | d5d8f67 | 2015-04-26 19:55:21 +0000 | [diff] [blame] | 241 | // TODO: Using the original SCEV no-wrap flags is not always safe, however |
| 242 | // as our code generation is reordering the expression anyway it doesn't |
| 243 | // really matter. |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 244 | ScalarEvolution &SE = *S->getSE(); |
Johannes Doerfert | d5d8f67 | 2015-04-26 19:55:21 +0000 | [diff] [blame] | 245 | const SCEV *ZeroStartExpr = |
| 246 | SE.getAddRecExpr(SE.getConstant(Expr->getStart()->getType(), 0), |
| 247 | Expr->getStepRecurrence(SE), Expr->getLoop(), Flags); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 248 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 249 | isl_pw_aff *ZeroStartResult = visit(ZeroStartExpr); |
| 250 | isl_pw_aff *Start = visit(Expr->getStart()); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 251 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 252 | return isl_pw_aff_add(ZeroStartResult, Start); |
| 253 | } |
| 254 | |
| 255 | __isl_give isl_pw_aff *SCEVAffinator::visitSMaxExpr(const SCEVSMaxExpr *Expr) { |
| 256 | isl_pw_aff *Max = visit(Expr->getOperand(0)); |
| 257 | |
| 258 | for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) { |
| 259 | isl_pw_aff *NextOperand = visit(Expr->getOperand(i)); |
| 260 | Max = isl_pw_aff_max(Max, NextOperand); |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 263 | return Max; |
| 264 | } |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 265 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 266 | __isl_give isl_pw_aff *SCEVAffinator::visitUMaxExpr(const SCEVUMaxExpr *Expr) { |
| 267 | llvm_unreachable("SCEVUMaxExpr not yet supported"); |
| 268 | } |
| 269 | |
Johannes Doerfert | b9d1888 | 2015-02-11 14:54:50 +0000 | [diff] [blame] | 270 | __isl_give isl_pw_aff *SCEVAffinator::visitSDivInstruction(Instruction *SDiv) { |
| 271 | assert(SDiv->getOpcode() == Instruction::SDiv && "Assumed SDiv instruction!"); |
| 272 | auto *SE = S->getSE(); |
| 273 | |
| 274 | auto *Divisor = SDiv->getOperand(1); |
| 275 | auto *DivisorSCEV = SE->getSCEV(Divisor); |
| 276 | auto *DivisorPWA = visit(DivisorSCEV); |
| 277 | assert(isa<ConstantInt>(Divisor) && |
| 278 | "SDiv is no parameter but has a non-constant RHS."); |
| 279 | |
| 280 | auto *Dividend = SDiv->getOperand(0); |
| 281 | auto *DividendSCEV = SE->getSCEV(Dividend); |
| 282 | auto *DividendPWA = visit(DividendSCEV); |
| 283 | return isl_pw_aff_tdiv_q(DividendPWA, DivisorPWA); |
| 284 | } |
| 285 | |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 286 | __isl_give isl_pw_aff *SCEVAffinator::visitUnknown(const SCEVUnknown *Expr) { |
Johannes Doerfert | b9d1888 | 2015-02-11 14:54:50 +0000 | [diff] [blame] | 287 | if (Instruction *I = dyn_cast<Instruction>(Expr->getValue())) { |
| 288 | switch (I->getOpcode()) { |
| 289 | case Instruction::SDiv: |
| 290 | return visitSDivInstruction(I); |
| 291 | default: |
| 292 | break; // Fall through. |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | llvm_unreachable( |
| 297 | "Unknowns SCEV was neither parameter nor a valid instruction."); |
Tobias Grosser | 0695ee4 | 2013-09-17 03:30:31 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | int SCEVAffinator::getLoopDepth(const Loop *L) { |
| 301 | Loop *outerLoop = S->getRegion().outermostLoopInRegion(const_cast<Loop *>(L)); |
| 302 | assert(outerLoop && "Scop does not contain this loop"); |
| 303 | return L->getLoopDepth() - outerLoop->getLoopDepth(); |
| 304 | } |
Tobias Grosser | 33ba62ad | 2011-08-18 06:31:50 +0000 | [diff] [blame] | 305 | |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 306 | /// @brief Add the bounds of @p Range to the set @p S for dimension @p dim. |
| 307 | static __isl_give isl_set *addRangeBoundsToSet(__isl_take isl_set *S, |
| 308 | const ConstantRange &Range, |
| 309 | int dim, |
| 310 | enum isl_dim_type type) { |
| 311 | isl_val *V; |
| 312 | isl_ctx *ctx = isl_set_get_ctx(S); |
| 313 | |
Johannes Doerfert | 8f8af43 | 2015-04-26 20:07:21 +0000 | [diff] [blame] | 314 | bool useLowerUpperBound = Range.isSignWrappedSet() && !Range.isFullSet(); |
| 315 | const auto LB = useLowerUpperBound ? Range.getLower() : Range.getSignedMin(); |
Johannes Doerfert | e4bd53b | 2015-03-08 19:49:50 +0000 | [diff] [blame] | 316 | V = isl_valFromAPInt(ctx, LB, true); |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 317 | isl_set *SLB = isl_set_lower_bound_val(isl_set_copy(S), type, dim, V); |
| 318 | |
Johannes Doerfert | 8f8af43 | 2015-04-26 20:07:21 +0000 | [diff] [blame] | 319 | const auto UB = useLowerUpperBound ? Range.getUpper() : Range.getSignedMax(); |
Johannes Doerfert | e4bd53b | 2015-03-08 19:49:50 +0000 | [diff] [blame] | 320 | V = isl_valFromAPInt(ctx, UB, true); |
Johannes Doerfert | 8f8af43 | 2015-04-26 20:07:21 +0000 | [diff] [blame] | 321 | if (useLowerUpperBound) |
Johannes Doerfert | e4bd53b | 2015-03-08 19:49:50 +0000 | [diff] [blame] | 322 | V = isl_val_sub_ui(V, 1); |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 323 | isl_set *SUB = isl_set_upper_bound_val(S, type, dim, V); |
| 324 | |
Johannes Doerfert | 8f8af43 | 2015-04-26 20:07:21 +0000 | [diff] [blame] | 325 | if (useLowerUpperBound) |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 326 | return isl_set_union(SLB, SUB); |
| 327 | else |
| 328 | return isl_set_intersect(SLB, SUB); |
| 329 | } |
| 330 | |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 331 | ScopArrayInfo::ScopArrayInfo(Value *BasePtr, Type *ElementType, isl_ctx *Ctx, |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 332 | const SmallVector<const SCEV *, 4> &DimensionSizes) |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 333 | : BasePtr(BasePtr), ElementType(ElementType), |
| 334 | DimensionSizes(DimensionSizes) { |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 335 | const std::string BasePtrName = getIslCompatibleName("MemRef_", BasePtr, ""); |
| 336 | Id = isl_id_alloc(Ctx, BasePtrName.c_str(), this); |
| 337 | } |
| 338 | |
| 339 | ScopArrayInfo::~ScopArrayInfo() { isl_id_free(Id); } |
| 340 | |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 341 | std::string ScopArrayInfo::getName() const { return isl_id_get_name(Id); } |
| 342 | |
| 343 | int ScopArrayInfo::getElemSizeInBytes() const { |
| 344 | return ElementType->getPrimitiveSizeInBits() / 8; |
| 345 | } |
| 346 | |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 347 | isl_id *ScopArrayInfo::getBasePtrId() const { return isl_id_copy(Id); } |
| 348 | |
| 349 | void ScopArrayInfo::dump() const { print(errs()); } |
| 350 | |
| 351 | void ScopArrayInfo::print(raw_ostream &OS) const { |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 352 | OS.indent(8) << *getElementType() << " " << getName() << "[*]"; |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 353 | for (unsigned u = 0; u < getNumberOfDimensions(); u++) |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 354 | OS << "[" << *DimensionSizes[u] << "]"; |
| 355 | OS << " // Element size " << getElemSizeInBytes() << "\n"; |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | const ScopArrayInfo * |
| 359 | ScopArrayInfo::getFromAccessFunction(__isl_keep isl_pw_multi_aff *PMA) { |
| 360 | isl_id *Id = isl_pw_multi_aff_get_tuple_id(PMA, isl_dim_out); |
| 361 | assert(Id && "Output dimension didn't have an ID"); |
| 362 | return getFromId(Id); |
| 363 | } |
| 364 | |
| 365 | const ScopArrayInfo *ScopArrayInfo::getFromId(isl_id *Id) { |
| 366 | void *User = isl_id_get_user(Id); |
| 367 | const ScopArrayInfo *SAI = static_cast<ScopArrayInfo *>(User); |
| 368 | isl_id_free(Id); |
| 369 | return SAI; |
| 370 | } |
| 371 | |
Johannes Doerfert | 32868bf | 2014-08-01 08:13:25 +0000 | [diff] [blame] | 372 | const std::string |
| 373 | MemoryAccess::getReductionOperatorStr(MemoryAccess::ReductionType RT) { |
| 374 | switch (RT) { |
| 375 | case MemoryAccess::RT_NONE: |
| 376 | llvm_unreachable("Requested a reduction operator string for a memory " |
| 377 | "access which isn't a reduction"); |
| 378 | case MemoryAccess::RT_ADD: |
| 379 | return "+"; |
| 380 | case MemoryAccess::RT_MUL: |
| 381 | return "*"; |
| 382 | case MemoryAccess::RT_BOR: |
| 383 | return "|"; |
| 384 | case MemoryAccess::RT_BXOR: |
| 385 | return "^"; |
| 386 | case MemoryAccess::RT_BAND: |
| 387 | return "&"; |
| 388 | } |
| 389 | llvm_unreachable("Unknown reduction type"); |
| 390 | return ""; |
| 391 | } |
| 392 | |
Johannes Doerfert | f618339 | 2014-07-01 20:52:51 +0000 | [diff] [blame] | 393 | /// @brief Return the reduction type for a given binary operator |
| 394 | static MemoryAccess::ReductionType getReductionType(const BinaryOperator *BinOp, |
| 395 | const Instruction *Load) { |
| 396 | if (!BinOp) |
| 397 | return MemoryAccess::RT_NONE; |
| 398 | switch (BinOp->getOpcode()) { |
| 399 | case Instruction::FAdd: |
| 400 | if (!BinOp->hasUnsafeAlgebra()) |
| 401 | return MemoryAccess::RT_NONE; |
| 402 | // Fall through |
| 403 | case Instruction::Add: |
| 404 | return MemoryAccess::RT_ADD; |
| 405 | case Instruction::Or: |
| 406 | return MemoryAccess::RT_BOR; |
| 407 | case Instruction::Xor: |
| 408 | return MemoryAccess::RT_BXOR; |
| 409 | case Instruction::And: |
| 410 | return MemoryAccess::RT_BAND; |
| 411 | case Instruction::FMul: |
| 412 | if (!BinOp->hasUnsafeAlgebra()) |
| 413 | return MemoryAccess::RT_NONE; |
| 414 | // Fall through |
| 415 | case Instruction::Mul: |
| 416 | if (DisableMultiplicativeReductions) |
| 417 | return MemoryAccess::RT_NONE; |
| 418 | return MemoryAccess::RT_MUL; |
| 419 | default: |
| 420 | return MemoryAccess::RT_NONE; |
| 421 | } |
| 422 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 423 | //===----------------------------------------------------------------------===// |
| 424 | |
| 425 | MemoryAccess::~MemoryAccess() { |
Tobias Grosser | 6f48e0f | 2015-05-15 09:58:32 +0000 | [diff] [blame] | 426 | isl_id_free(Id); |
Tobias Grosser | 54a86e6 | 2011-08-18 06:31:46 +0000 | [diff] [blame] | 427 | isl_map_free(AccessRelation); |
Raghesh Aloor | 129e867 | 2011-08-15 02:33:39 +0000 | [diff] [blame] | 428 | isl_map_free(newAccessRelation); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Johannes Doerfert | 8f7124c | 2014-09-12 11:00:49 +0000 | [diff] [blame] | 431 | static MemoryAccess::AccessType getMemoryAccessType(const IRAccess &Access) { |
| 432 | switch (Access.getType()) { |
| 433 | case IRAccess::READ: |
| 434 | return MemoryAccess::READ; |
| 435 | case IRAccess::MUST_WRITE: |
| 436 | return MemoryAccess::MUST_WRITE; |
| 437 | case IRAccess::MAY_WRITE: |
| 438 | return MemoryAccess::MAY_WRITE; |
| 439 | } |
| 440 | llvm_unreachable("Unknown IRAccess type!"); |
| 441 | } |
| 442 | |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 443 | const ScopArrayInfo *MemoryAccess::getScopArrayInfo() const { |
| 444 | isl_id *ArrayId = getArrayId(); |
| 445 | void *User = isl_id_get_user(ArrayId); |
| 446 | const ScopArrayInfo *SAI = static_cast<ScopArrayInfo *>(User); |
| 447 | isl_id_free(ArrayId); |
| 448 | return SAI; |
| 449 | } |
| 450 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 451 | __isl_give isl_id *MemoryAccess::getArrayId() const { |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 452 | return isl_map_get_tuple_id(AccessRelation, isl_dim_out); |
| 453 | } |
| 454 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 455 | __isl_give isl_pw_multi_aff *MemoryAccess::applyScheduleToAccessRelation( |
| 456 | __isl_take isl_union_map *USchedule) const { |
Johannes Doerfert | a99130f | 2014-10-13 12:58:03 +0000 | [diff] [blame] | 457 | isl_map *Schedule, *ScheduledAccRel; |
| 458 | isl_union_set *UDomain; |
| 459 | |
| 460 | UDomain = isl_union_set_from_set(getStatement()->getDomain()); |
| 461 | USchedule = isl_union_map_intersect_domain(USchedule, UDomain); |
| 462 | Schedule = isl_map_from_union_map(USchedule); |
| 463 | ScheduledAccRel = isl_map_apply_domain(getAccessRelation(), Schedule); |
| 464 | return isl_pw_multi_aff_from_map(ScheduledAccRel); |
| 465 | } |
| 466 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 467 | __isl_give isl_map *MemoryAccess::getOriginalAccessRelation() const { |
Tobias Grosser | 5d45381 | 2011-10-06 00:04:11 +0000 | [diff] [blame] | 468 | return isl_map_copy(AccessRelation); |
| 469 | } |
| 470 | |
Johannes Doerfert | a99130f | 2014-10-13 12:58:03 +0000 | [diff] [blame] | 471 | std::string MemoryAccess::getOriginalAccessRelationStr() const { |
Tobias Grosser | 5d45381 | 2011-10-06 00:04:11 +0000 | [diff] [blame] | 472 | return stringFromIslObj(AccessRelation); |
| 473 | } |
| 474 | |
Johannes Doerfert | a99130f | 2014-10-13 12:58:03 +0000 | [diff] [blame] | 475 | __isl_give isl_space *MemoryAccess::getOriginalAccessRelationSpace() const { |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 476 | return isl_map_get_space(AccessRelation); |
| 477 | } |
| 478 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 479 | __isl_give isl_map *MemoryAccess::getNewAccessRelation() const { |
Tobias Grosser | 5d45381 | 2011-10-06 00:04:11 +0000 | [diff] [blame] | 480 | return isl_map_copy(newAccessRelation); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 483 | __isl_give isl_basic_map * |
| 484 | MemoryAccess::createBasicAccessMap(ScopStmt *Statement) { |
Tobias Grosser | 084d8f7 | 2012-05-29 09:29:44 +0000 | [diff] [blame] | 485 | isl_space *Space = isl_space_set_alloc(Statement->getIslCtx(), 0, 1); |
Tobias Grosser | ed29566 | 2012-09-11 13:50:21 +0000 | [diff] [blame] | 486 | Space = isl_space_align_params(Space, Statement->getDomainSpace()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 487 | |
Tobias Grosser | 084d8f7 | 2012-05-29 09:29:44 +0000 | [diff] [blame] | 488 | return isl_basic_map_from_domain_and_range( |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 489 | isl_basic_set_universe(Statement->getDomainSpace()), |
| 490 | isl_basic_set_universe(Space)); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 493 | // Formalize no out-of-bound access assumption |
| 494 | // |
| 495 | // When delinearizing array accesses we optimistically assume that the |
| 496 | // delinearized accesses do not access out of bound locations (the subscript |
| 497 | // expression of each array evaluates for each statement instance that is |
| 498 | // executed to a value that is larger than zero and strictly smaller than the |
| 499 | // size of the corresponding dimension). The only exception is the outermost |
Tobias Grosser | f57d63f | 2014-08-03 21:07:30 +0000 | [diff] [blame] | 500 | // dimension for which we do not need to assume any upper bound. At this point |
| 501 | // we formalize this assumption to ensure that at code generation time the |
| 502 | // relevant run-time checks can be generated. |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 503 | // |
| 504 | // To find the set of constraints necessary to avoid out of bound accesses, we |
| 505 | // first build the set of data locations that are not within array bounds. We |
| 506 | // then apply the reverse access relation to obtain the set of iterations that |
| 507 | // may contain invalid accesses and reduce this set of iterations to the ones |
| 508 | // that are actually executed by intersecting them with the domain of the |
| 509 | // statement. If we now project out all loop dimensions, we obtain a set of |
| 510 | // parameters that may cause statement instances to be executed that may |
| 511 | // possibly yield out of bound memory accesses. The complement of these |
| 512 | // constraints is the set of constraints that needs to be assumed to ensure such |
| 513 | // statement instances are never executed. |
| 514 | void MemoryAccess::assumeNoOutOfBound(const IRAccess &Access) { |
Johannes Doerfert | a99130f | 2014-10-13 12:58:03 +0000 | [diff] [blame] | 515 | isl_space *Space = isl_space_range(getOriginalAccessRelationSpace()); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 516 | isl_set *Outside = isl_set_empty(isl_space_copy(Space)); |
Tobias Grosser | f57d63f | 2014-08-03 21:07:30 +0000 | [diff] [blame] | 517 | for (int i = 1, Size = Access.Subscripts.size(); i < Size; ++i) { |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 518 | isl_local_space *LS = isl_local_space_from_space(isl_space_copy(Space)); |
| 519 | isl_pw_aff *Var = |
| 520 | isl_pw_aff_var_on_domain(isl_local_space_copy(LS), isl_dim_set, i); |
| 521 | isl_pw_aff *Zero = isl_pw_aff_zero_on_domain(LS); |
| 522 | |
| 523 | isl_set *DimOutside; |
| 524 | |
Tobias Grosser | f57d63f | 2014-08-03 21:07:30 +0000 | [diff] [blame] | 525 | DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero); |
| 526 | isl_pw_aff *SizeE = SCEVAffinator::getPwAff(Statement, Access.Sizes[i - 1]); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 527 | |
Tobias Grosser | f57d63f | 2014-08-03 21:07:30 +0000 | [diff] [blame] | 528 | SizeE = isl_pw_aff_drop_dims(SizeE, isl_dim_in, 0, |
| 529 | Statement->getNumIterators()); |
| 530 | SizeE = isl_pw_aff_add_dims(SizeE, isl_dim_in, |
| 531 | isl_space_dim(Space, isl_dim_set)); |
| 532 | SizeE = isl_pw_aff_set_tuple_id(SizeE, isl_dim_in, |
| 533 | isl_space_get_tuple_id(Space, isl_dim_set)); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 534 | |
Tobias Grosser | f57d63f | 2014-08-03 21:07:30 +0000 | [diff] [blame] | 535 | DimOutside = isl_set_union(DimOutside, isl_pw_aff_le_set(SizeE, Var)); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 536 | |
| 537 | Outside = isl_set_union(Outside, DimOutside); |
| 538 | } |
| 539 | |
| 540 | Outside = isl_set_apply(Outside, isl_map_reverse(getAccessRelation())); |
| 541 | Outside = isl_set_intersect(Outside, Statement->getDomain()); |
| 542 | Outside = isl_set_params(Outside); |
| 543 | Outside = isl_set_complement(Outside); |
| 544 | Statement->getParent()->addAssumption(Outside); |
| 545 | isl_space_free(Space); |
| 546 | } |
| 547 | |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 548 | void MemoryAccess::computeBoundsOnAccessRelation(unsigned ElementSize) { |
| 549 | ScalarEvolution *SE = Statement->getParent()->getSE(); |
| 550 | |
| 551 | Value *Ptr = getPointerOperand(*getAccessInstruction()); |
| 552 | if (!Ptr || !SE->isSCEVable(Ptr->getType())) |
| 553 | return; |
| 554 | |
| 555 | auto *PtrSCEV = SE->getSCEV(Ptr); |
| 556 | if (isa<SCEVCouldNotCompute>(PtrSCEV)) |
| 557 | return; |
| 558 | |
| 559 | auto *BasePtrSCEV = SE->getPointerBase(PtrSCEV); |
| 560 | if (BasePtrSCEV && !isa<SCEVCouldNotCompute>(BasePtrSCEV)) |
| 561 | PtrSCEV = SE->getMinusSCEV(PtrSCEV, BasePtrSCEV); |
| 562 | |
| 563 | const ConstantRange &Range = SE->getSignedRange(PtrSCEV); |
| 564 | if (Range.isFullSet()) |
| 565 | return; |
| 566 | |
Johannes Doerfert | e4bd53b | 2015-03-08 19:49:50 +0000 | [diff] [blame] | 567 | bool isWrapping = Range.isSignWrappedSet(); |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 568 | unsigned BW = Range.getBitWidth(); |
Johannes Doerfert | e4bd53b | 2015-03-08 19:49:50 +0000 | [diff] [blame] | 569 | const auto LB = isWrapping ? Range.getLower() : Range.getSignedMin(); |
| 570 | const auto UB = isWrapping ? Range.getUpper() : Range.getSignedMax(); |
| 571 | |
| 572 | auto Min = LB.sdiv(APInt(BW, ElementSize)); |
| 573 | auto Max = (UB - APInt(BW, 1)).sdiv(APInt(BW, ElementSize)); |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 574 | |
| 575 | isl_set *AccessRange = isl_map_range(isl_map_copy(AccessRelation)); |
| 576 | AccessRange = |
| 577 | addRangeBoundsToSet(AccessRange, ConstantRange(Min, Max), 0, isl_dim_set); |
| 578 | AccessRelation = isl_map_intersect_range(AccessRelation, AccessRange); |
| 579 | } |
| 580 | |
Tobias Grosser | 619190d | 2015-03-30 17:22:28 +0000 | [diff] [blame] | 581 | __isl_give isl_map *MemoryAccess::foldAccess(const IRAccess &Access, |
| 582 | __isl_take isl_map *AccessRelation, |
| 583 | ScopStmt *Statement) { |
| 584 | int Size = Access.Subscripts.size(); |
| 585 | |
| 586 | for (int i = Size - 2; i >= 0; --i) { |
| 587 | isl_space *Space; |
| 588 | isl_map *MapOne, *MapTwo; |
| 589 | isl_pw_aff *DimSize = SCEVAffinator::getPwAff(Statement, Access.Sizes[i]); |
| 590 | |
| 591 | isl_space *SpaceSize = isl_pw_aff_get_space(DimSize); |
| 592 | isl_pw_aff_free(DimSize); |
| 593 | isl_id *ParamId = isl_space_get_dim_id(SpaceSize, isl_dim_param, 0); |
| 594 | |
| 595 | Space = isl_map_get_space(AccessRelation); |
| 596 | Space = isl_space_map_from_set(isl_space_range(Space)); |
| 597 | Space = isl_space_align_params(Space, SpaceSize); |
| 598 | |
| 599 | int ParamLocation = isl_space_find_dim_by_id(Space, isl_dim_param, ParamId); |
| 600 | isl_id_free(ParamId); |
| 601 | |
| 602 | MapOne = isl_map_universe(isl_space_copy(Space)); |
| 603 | for (int j = 0; j < Size; ++j) |
| 604 | MapOne = isl_map_equate(MapOne, isl_dim_in, j, isl_dim_out, j); |
| 605 | MapOne = isl_map_lower_bound_si(MapOne, isl_dim_in, i + 1, 0); |
| 606 | |
| 607 | MapTwo = isl_map_universe(isl_space_copy(Space)); |
| 608 | for (int j = 0; j < Size; ++j) |
| 609 | if (j < i || j > i + 1) |
| 610 | MapTwo = isl_map_equate(MapTwo, isl_dim_in, j, isl_dim_out, j); |
| 611 | |
| 612 | isl_local_space *LS = isl_local_space_from_space(Space); |
| 613 | isl_constraint *C; |
| 614 | C = isl_equality_alloc(isl_local_space_copy(LS)); |
| 615 | C = isl_constraint_set_constant_si(C, -1); |
| 616 | C = isl_constraint_set_coefficient_si(C, isl_dim_in, i, 1); |
| 617 | C = isl_constraint_set_coefficient_si(C, isl_dim_out, i, -1); |
| 618 | MapTwo = isl_map_add_constraint(MapTwo, C); |
| 619 | C = isl_equality_alloc(LS); |
| 620 | C = isl_constraint_set_coefficient_si(C, isl_dim_in, i + 1, 1); |
| 621 | C = isl_constraint_set_coefficient_si(C, isl_dim_out, i + 1, -1); |
| 622 | C = isl_constraint_set_coefficient_si(C, isl_dim_param, ParamLocation, 1); |
| 623 | MapTwo = isl_map_add_constraint(MapTwo, C); |
| 624 | MapTwo = isl_map_upper_bound_si(MapTwo, isl_dim_in, i + 1, -1); |
| 625 | |
| 626 | MapOne = isl_map_union(MapOne, MapTwo); |
| 627 | AccessRelation = isl_map_apply_range(AccessRelation, MapOne); |
| 628 | } |
| 629 | return AccessRelation; |
| 630 | } |
| 631 | |
Johannes Doerfert | 13c8cf2 | 2014-08-10 08:09:38 +0000 | [diff] [blame] | 632 | MemoryAccess::MemoryAccess(const IRAccess &Access, Instruction *AccInst, |
Tobias Grosser | 6f48e0f | 2015-05-15 09:58:32 +0000 | [diff] [blame] | 633 | ScopStmt *Statement, const ScopArrayInfo *SAI, |
| 634 | int Identifier) |
Johannes Doerfert | 4c7ce47 | 2014-10-08 10:11:33 +0000 | [diff] [blame] | 635 | : AccType(getMemoryAccessType(Access)), Statement(Statement), Inst(AccInst), |
Johannes Doerfert | 8f7124c | 2014-09-12 11:00:49 +0000 | [diff] [blame] | 636 | newAccessRelation(nullptr) { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 637 | |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 638 | isl_ctx *Ctx = Statement->getIslCtx(); |
Tobias Grosser | 9759f85 | 2011-11-10 12:44:55 +0000 | [diff] [blame] | 639 | BaseAddr = Access.getBase(); |
Johannes Doerfert | 79fc23f | 2014-07-24 23:48:02 +0000 | [diff] [blame] | 640 | BaseName = getIslCompatibleName("MemRef_", getBaseAddr(), ""); |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 641 | |
| 642 | isl_id *BaseAddrId = SAI->getBasePtrId(); |
Tobias Grosser | 5683df4 | 2011-11-09 22:34:34 +0000 | [diff] [blame] | 643 | |
Tobias Grosser | e29d31c | 2015-05-15 12:24:09 +0000 | [diff] [blame] | 644 | auto IdName = "__polly_array_ref_ " + std::to_string(Identifier); |
| 645 | Id = isl_id_alloc(Ctx, IdName.c_str(), nullptr); |
Tobias Grosser | 6f48e0f | 2015-05-15 09:58:32 +0000 | [diff] [blame] | 646 | |
Tobias Grosser | a187964 | 2011-12-20 10:43:14 +0000 | [diff] [blame] | 647 | if (!Access.isAffine()) { |
Tobias Grosser | 4f96749 | 2013-06-23 05:21:18 +0000 | [diff] [blame] | 648 | // We overapproximate non-affine accesses with a possible access to the |
| 649 | // whole array. For read accesses it does not make a difference, if an |
| 650 | // access must or may happen. However, for write accesses it is important to |
| 651 | // differentiate between writes that must happen and writes that may happen. |
Tobias Grosser | 04d6ae6 | 2013-06-23 06:04:54 +0000 | [diff] [blame] | 652 | AccessRelation = isl_map_from_basic_map(createBasicAccessMap(Statement)); |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 653 | AccessRelation = |
| 654 | isl_map_set_tuple_id(AccessRelation, isl_dim_out, BaseAddrId); |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 655 | |
| 656 | computeBoundsOnAccessRelation(Access.getElemSizeInBytes()); |
Tobias Grosser | a187964 | 2011-12-20 10:43:14 +0000 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 660 | isl_space *Space = isl_space_alloc(Ctx, 0, Statement->getNumIterators(), 0); |
Tobias Grosser | 79baa21 | 2014-04-10 08:38:02 +0000 | [diff] [blame] | 661 | AccessRelation = isl_map_universe(Space); |
Tobias Grosser | a187964 | 2011-12-20 10:43:14 +0000 | [diff] [blame] | 662 | |
Tobias Grosser | 79baa21 | 2014-04-10 08:38:02 +0000 | [diff] [blame] | 663 | for (int i = 0, Size = Access.Subscripts.size(); i < Size; ++i) { |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 664 | isl_pw_aff *Affine = |
| 665 | SCEVAffinator::getPwAff(Statement, Access.Subscripts[i]); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 666 | |
Sebastian Pop | 422e33f | 2014-06-03 18:16:31 +0000 | [diff] [blame] | 667 | if (Size == 1) { |
| 668 | // For the non delinearized arrays, divide the access function of the last |
| 669 | // subscript by the size of the elements in the array. |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 670 | // |
| 671 | // A stride one array access in C expressed as A[i] is expressed in |
| 672 | // LLVM-IR as something like A[i * elementsize]. This hides the fact that |
| 673 | // two subsequent values of 'i' index two values that are stored next to |
| 674 | // each other in memory. By this division we make this characteristic |
| 675 | // obvious again. |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 676 | isl_val *v = isl_val_int_from_si(Ctx, Access.getElemSizeInBytes()); |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 677 | Affine = isl_pw_aff_scale_down_val(Affine, v); |
| 678 | } |
| 679 | |
| 680 | isl_map *SubscriptMap = isl_map_from_pw_aff(Affine); |
| 681 | |
Tobias Grosser | 79baa21 | 2014-04-10 08:38:02 +0000 | [diff] [blame] | 682 | AccessRelation = isl_map_flat_range_product(AccessRelation, SubscriptMap); |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Tobias Grosser | 619190d | 2015-03-30 17:22:28 +0000 | [diff] [blame] | 685 | AccessRelation = foldAccess(Access, AccessRelation, Statement); |
| 686 | |
Tobias Grosser | 79baa21 | 2014-04-10 08:38:02 +0000 | [diff] [blame] | 687 | Space = Statement->getDomainSpace(); |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 688 | AccessRelation = isl_map_set_tuple_id( |
| 689 | AccessRelation, isl_dim_in, isl_space_get_tuple_id(Space, isl_dim_set)); |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 690 | AccessRelation = |
| 691 | isl_map_set_tuple_id(AccessRelation, isl_dim_out, BaseAddrId); |
| 692 | |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 693 | assumeNoOutOfBound(Access); |
Tobias Grosser | aa660a9 | 2015-03-30 00:07:50 +0000 | [diff] [blame] | 694 | AccessRelation = isl_map_gist_domain(AccessRelation, Statement->getDomain()); |
Johannes Doerfert | 5d83f09 | 2014-07-29 08:37:55 +0000 | [diff] [blame] | 695 | isl_space_free(Space); |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 696 | } |
Tobias Grosser | 30b8a09 | 2011-08-18 07:51:37 +0000 | [diff] [blame] | 697 | |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 698 | void MemoryAccess::realignParams() { |
Tobias Grosser | 6defb5b | 2014-04-10 08:37:44 +0000 | [diff] [blame] | 699 | isl_space *ParamSpace = Statement->getParent()->getParamSpace(); |
Tobias Grosser | 3748705 | 2011-10-06 00:03:42 +0000 | [diff] [blame] | 700 | AccessRelation = isl_map_align_params(AccessRelation, ParamSpace); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Johannes Doerfert | 32868bf | 2014-08-01 08:13:25 +0000 | [diff] [blame] | 703 | const std::string MemoryAccess::getReductionOperatorStr() const { |
| 704 | return MemoryAccess::getReductionOperatorStr(getReductionType()); |
| 705 | } |
| 706 | |
Tobias Grosser | 6f48e0f | 2015-05-15 09:58:32 +0000 | [diff] [blame] | 707 | __isl_give isl_id *MemoryAccess::getId() const { return isl_id_copy(Id); } |
| 708 | |
Johannes Doerfert | f618339 | 2014-07-01 20:52:51 +0000 | [diff] [blame] | 709 | raw_ostream &polly::operator<<(raw_ostream &OS, |
| 710 | MemoryAccess::ReductionType RT) { |
Johannes Doerfert | 32868bf | 2014-08-01 08:13:25 +0000 | [diff] [blame] | 711 | if (RT == MemoryAccess::RT_NONE) |
Johannes Doerfert | f618339 | 2014-07-01 20:52:51 +0000 | [diff] [blame] | 712 | OS << "NONE"; |
Johannes Doerfert | 32868bf | 2014-08-01 08:13:25 +0000 | [diff] [blame] | 713 | else |
| 714 | OS << MemoryAccess::getReductionOperatorStr(RT); |
Johannes Doerfert | f618339 | 2014-07-01 20:52:51 +0000 | [diff] [blame] | 715 | return OS; |
| 716 | } |
| 717 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 718 | void MemoryAccess::print(raw_ostream &OS) const { |
Johannes Doerfert | 4c7ce47 | 2014-10-08 10:11:33 +0000 | [diff] [blame] | 719 | switch (AccType) { |
Tobias Grosser | b58f6a4 | 2013-07-13 20:41:24 +0000 | [diff] [blame] | 720 | case READ: |
Johannes Doerfert | 6780bc3 | 2014-06-26 18:47:03 +0000 | [diff] [blame] | 721 | OS.indent(12) << "ReadAccess :=\t"; |
Tobias Grosser | 4f96749 | 2013-06-23 05:21:18 +0000 | [diff] [blame] | 722 | break; |
Tobias Grosser | b58f6a4 | 2013-07-13 20:41:24 +0000 | [diff] [blame] | 723 | case MUST_WRITE: |
Johannes Doerfert | 6780bc3 | 2014-06-26 18:47:03 +0000 | [diff] [blame] | 724 | OS.indent(12) << "MustWriteAccess :=\t"; |
Tobias Grosser | 4f96749 | 2013-06-23 05:21:18 +0000 | [diff] [blame] | 725 | break; |
Tobias Grosser | b58f6a4 | 2013-07-13 20:41:24 +0000 | [diff] [blame] | 726 | case MAY_WRITE: |
Johannes Doerfert | 6780bc3 | 2014-06-26 18:47:03 +0000 | [diff] [blame] | 727 | OS.indent(12) << "MayWriteAccess :=\t"; |
Tobias Grosser | 4f96749 | 2013-06-23 05:21:18 +0000 | [diff] [blame] | 728 | break; |
| 729 | } |
Johannes Doerfert | 0ff23ec | 2015-02-06 20:13:15 +0000 | [diff] [blame] | 730 | OS << "[Reduction Type: " << getReductionType() << "] "; |
| 731 | OS << "[Scalar: " << isScalar() << "]\n"; |
Johannes Doerfert | a99130f | 2014-10-13 12:58:03 +0000 | [diff] [blame] | 732 | OS.indent(16) << getOriginalAccessRelationStr() << ";\n"; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 735 | void MemoryAccess::dump() const { print(errs()); } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 736 | |
| 737 | // Create a map in the size of the provided set domain, that maps from the |
| 738 | // one element of the provided set domain to another element of the provided |
| 739 | // set domain. |
| 740 | // The mapping is limited to all points that are equal in all but the last |
| 741 | // dimension and for which the last dimension of the input is strict smaller |
| 742 | // than the last dimension of the output. |
| 743 | // |
| 744 | // getEqualAndLarger(set[i0, i1, ..., iX]): |
| 745 | // |
| 746 | // set[i0, i1, ..., iX] -> set[o0, o1, ..., oX] |
| 747 | // : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1), iX < oX |
| 748 | // |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 749 | static isl_map *getEqualAndLarger(isl_space *setDomain) { |
Tobias Grosser | c327932c | 2012-02-01 14:23:36 +0000 | [diff] [blame] | 750 | isl_space *Space = isl_space_map_from_set(setDomain); |
Tobias Grosser | 1b6ea57 | 2015-05-21 19:02:44 +0000 | [diff] [blame] | 751 | isl_map *Map = isl_map_universe(Space); |
Sebastian Pop | 4040876 | 2013-10-04 17:14:53 +0000 | [diff] [blame] | 752 | unsigned lastDimension = isl_map_dim(Map, isl_dim_in) - 1; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 753 | |
| 754 | // Set all but the last dimension to be equal for the input and output |
| 755 | // |
| 756 | // input[i0, i1, ..., iX] -> output[o0, o1, ..., oX] |
| 757 | // : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1) |
Sebastian Pop | 4040876 | 2013-10-04 17:14:53 +0000 | [diff] [blame] | 758 | for (unsigned i = 0; i < lastDimension; ++i) |
Tobias Grosser | c327932c | 2012-02-01 14:23:36 +0000 | [diff] [blame] | 759 | Map = isl_map_equate(Map, isl_dim_in, i, isl_dim_out, i); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 760 | |
| 761 | // Set the last dimension of the input to be strict smaller than the |
| 762 | // last dimension of the output. |
| 763 | // |
| 764 | // input[?,?,?,...,iX] -> output[?,?,?,...,oX] : iX < oX |
Tobias Grosser | 1b6ea57 | 2015-05-21 19:02:44 +0000 | [diff] [blame] | 765 | Map = isl_map_order_lt(Map, isl_dim_in, lastDimension, isl_dim_out, |
| 766 | lastDimension); |
Tobias Grosser | c327932c | 2012-02-01 14:23:36 +0000 | [diff] [blame] | 767 | return Map; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 770 | __isl_give isl_set * |
| 771 | MemoryAccess::getStride(__isl_take const isl_map *Schedule) const { |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 772 | isl_map *S = const_cast<isl_map *>(Schedule); |
Johannes Doerfert | a99130f | 2014-10-13 12:58:03 +0000 | [diff] [blame] | 773 | isl_map *AccessRelation = getAccessRelation(); |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 774 | isl_space *Space = isl_space_range(isl_map_get_space(S)); |
| 775 | isl_map *NextScatt = getEqualAndLarger(Space); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 776 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 777 | S = isl_map_reverse(S); |
| 778 | NextScatt = isl_map_lexmin(NextScatt); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 779 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 780 | NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(S)); |
| 781 | NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(AccessRelation)); |
| 782 | NextScatt = isl_map_apply_domain(NextScatt, S); |
| 783 | NextScatt = isl_map_apply_domain(NextScatt, AccessRelation); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 784 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 785 | isl_set *Deltas = isl_map_deltas(NextScatt); |
| 786 | return Deltas; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 789 | bool MemoryAccess::isStrideX(__isl_take const isl_map *Schedule, |
Tobias Grosser | 28dd486 | 2012-01-24 16:42:16 +0000 | [diff] [blame] | 790 | int StrideWidth) const { |
| 791 | isl_set *Stride, *StrideX; |
| 792 | bool IsStrideX; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 793 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 794 | Stride = getStride(Schedule); |
Tobias Grosser | 28dd486 | 2012-01-24 16:42:16 +0000 | [diff] [blame] | 795 | StrideX = isl_set_universe(isl_set_get_space(Stride)); |
| 796 | StrideX = isl_set_fix_si(StrideX, isl_dim_set, 0, StrideWidth); |
| 797 | IsStrideX = isl_set_is_equal(Stride, StrideX); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 798 | |
Tobias Grosser | 28dd486 | 2012-01-24 16:42:16 +0000 | [diff] [blame] | 799 | isl_set_free(StrideX); |
Tobias Grosser | dea9823 | 2012-01-17 20:34:27 +0000 | [diff] [blame] | 800 | isl_set_free(Stride); |
Tobias Grosser | b76f3853 | 2011-08-20 11:11:25 +0000 | [diff] [blame] | 801 | |
Tobias Grosser | 28dd486 | 2012-01-24 16:42:16 +0000 | [diff] [blame] | 802 | return IsStrideX; |
| 803 | } |
| 804 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 805 | bool MemoryAccess::isStrideZero(const isl_map *Schedule) const { |
| 806 | return isStrideX(Schedule, 0); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Tobias Grosser | 79baa21 | 2014-04-10 08:38:02 +0000 | [diff] [blame] | 809 | bool MemoryAccess::isScalar() const { |
| 810 | return isl_map_n_out(AccessRelation) == 0; |
| 811 | } |
| 812 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 813 | bool MemoryAccess::isStrideOne(const isl_map *Schedule) const { |
| 814 | return isStrideX(Schedule, 1); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Tobias Grosser | 5d45381 | 2011-10-06 00:04:11 +0000 | [diff] [blame] | 817 | void MemoryAccess::setNewAccessRelation(isl_map *newAccess) { |
Tobias Grosser | b76f3853 | 2011-08-20 11:11:25 +0000 | [diff] [blame] | 818 | isl_map_free(newAccessRelation); |
Raghesh Aloor | 7a04f4f | 2011-08-03 13:47:59 +0000 | [diff] [blame] | 819 | newAccessRelation = newAccess; |
Raghesh Aloor | 3cb6628 | 2011-07-12 17:14:03 +0000 | [diff] [blame] | 820 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 821 | |
| 822 | //===----------------------------------------------------------------------===// |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 823 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 824 | isl_map *ScopStmt::getSchedule() const { return isl_map_copy(Schedule); } |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 825 | |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 826 | void ScopStmt::restrictDomain(__isl_take isl_set *NewDomain) { |
| 827 | assert(isl_set_is_subset(NewDomain, Domain) && |
| 828 | "New domain is not a subset of old domain!"); |
| 829 | isl_set_free(Domain); |
| 830 | Domain = NewDomain; |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 831 | Schedule = isl_map_intersect_domain(Schedule, isl_set_copy(Domain)); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 834 | void ScopStmt::setSchedule(__isl_take isl_map *NewSchedule) { |
| 835 | assert(NewSchedule && "New schedule is nullptr"); |
| 836 | isl_map_free(Schedule); |
| 837 | Schedule = NewSchedule; |
Tobias Grosser | b76f3853 | 2011-08-20 11:11:25 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 840 | void ScopStmt::buildSchedule(SmallVectorImpl<unsigned> &ScheduleVec) { |
Tobias Grosser | 78d8a3d | 2012-01-17 20:34:23 +0000 | [diff] [blame] | 841 | unsigned NbIterators = getNumIterators(); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 842 | unsigned NbScheduleDims = Parent.getMaxLoopDepth() * 2 + 1; |
Tobias Grosser | 78d8a3d | 2012-01-17 20:34:23 +0000 | [diff] [blame] | 843 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 844 | isl_space *Space = isl_space_set_alloc(getIslCtx(), 0, NbScheduleDims); |
Tobias Grosser | 78d8a3d | 2012-01-17 20:34:23 +0000 | [diff] [blame] | 845 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 846 | Schedule = isl_map_from_domain_and_range(isl_set_universe(getDomainSpace()), |
Tobias Grosser | 654af8f | 2015-04-21 11:42:01 +0000 | [diff] [blame] | 847 | isl_set_universe(Space)); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 848 | |
| 849 | // Loop dimensions. |
Tobias Grosser | 78d8a3d | 2012-01-17 20:34:23 +0000 | [diff] [blame] | 850 | for (unsigned i = 0; i < NbIterators; ++i) |
Tobias Grosser | 654af8f | 2015-04-21 11:42:01 +0000 | [diff] [blame] | 851 | Schedule = isl_map_equate(Schedule, isl_dim_out, 2 * i + 1, isl_dim_in, i); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 852 | |
| 853 | // Constant dimensions |
Tobias Grosser | 78d8a3d | 2012-01-17 20:34:23 +0000 | [diff] [blame] | 854 | for (unsigned i = 0; i < NbIterators + 1; ++i) |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 855 | Schedule = isl_map_fix_si(Schedule, isl_dim_out, 2 * i, ScheduleVec[i]); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 856 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 857 | // Fill schedule dimensions. |
| 858 | for (unsigned i = 2 * NbIterators + 1; i < NbScheduleDims; ++i) |
| 859 | Schedule = isl_map_fix_si(Schedule, isl_dim_out, i, 0); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 860 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 861 | Schedule = isl_map_align_params(Schedule, Parent.getParamSpace()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 864 | void ScopStmt::buildAccesses(TempScop &tempScop, BasicBlock *Block, |
| 865 | bool isApproximated) { |
| 866 | AccFuncSetType *AFS = tempScop.getAccessFunctions(Block); |
| 867 | if (!AFS) |
| 868 | return; |
| 869 | |
| 870 | for (auto &AccessPair : *AFS) { |
| 871 | IRAccess &Access = AccessPair.first; |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 872 | Instruction *AccessInst = AccessPair.second; |
| 873 | |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 874 | Type *ElementType = getAccessInstType(AccessInst); |
Johannes Doerfert | 80ef110 | 2014-11-07 08:31:31 +0000 | [diff] [blame] | 875 | const ScopArrayInfo *SAI = getParent()->getOrCreateScopArrayInfo( |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 876 | Access.getBase(), ElementType, Access.Sizes); |
Johannes Doerfert | 80ef110 | 2014-11-07 08:31:31 +0000 | [diff] [blame] | 877 | |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 878 | if (isApproximated && Access.isWrite()) |
| 879 | Access.setMayWrite(); |
| 880 | |
Johannes Doerfert | ecff11d | 2015-05-22 23:43:58 +0000 | [diff] [blame] | 881 | MemoryAccessList *&MAL = InstructionToAccess[AccessInst]; |
| 882 | if (!MAL) |
| 883 | MAL = new MemoryAccessList(); |
| 884 | MAL->emplace_front(Access, AccessInst, this, SAI, MemAccs.size()); |
| 885 | MemAccs.push_back(&MAL->front()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 889 | void ScopStmt::realignParams() { |
Johannes Doerfert | f675289 | 2014-06-13 18:01:45 +0000 | [diff] [blame] | 890 | for (MemoryAccess *MA : *this) |
| 891 | MA->realignParams(); |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 892 | |
| 893 | Domain = isl_set_align_params(Domain, Parent.getParamSpace()); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 894 | Schedule = isl_map_align_params(Schedule, Parent.getParamSpace()); |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Tobias Grosser | 65b0058 | 2011-11-08 15:41:19 +0000 | [diff] [blame] | 897 | __isl_give isl_set *ScopStmt::buildConditionSet(const Comparison &Comp) { |
Tobias Grosser | a601fbd | 2011-11-09 22:34:44 +0000 | [diff] [blame] | 898 | isl_pw_aff *L = SCEVAffinator::getPwAff(this, Comp.getLHS()); |
| 899 | isl_pw_aff *R = SCEVAffinator::getPwAff(this, Comp.getRHS()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 900 | |
Tobias Grosser | d2795d0 | 2011-08-18 07:51:40 +0000 | [diff] [blame] | 901 | switch (Comp.getPred()) { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 902 | case ICmpInst::ICMP_EQ: |
Tobias Grosser | 048c879 | 2011-10-23 20:59:20 +0000 | [diff] [blame] | 903 | return isl_pw_aff_eq_set(L, R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 904 | case ICmpInst::ICMP_NE: |
Tobias Grosser | 048c879 | 2011-10-23 20:59:20 +0000 | [diff] [blame] | 905 | return isl_pw_aff_ne_set(L, R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 906 | case ICmpInst::ICMP_SLT: |
Tobias Grosser | 048c879 | 2011-10-23 20:59:20 +0000 | [diff] [blame] | 907 | return isl_pw_aff_lt_set(L, R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 908 | case ICmpInst::ICMP_SLE: |
Tobias Grosser | 048c879 | 2011-10-23 20:59:20 +0000 | [diff] [blame] | 909 | return isl_pw_aff_le_set(L, R); |
Tobias Grosser | d2795d0 | 2011-08-18 07:51:40 +0000 | [diff] [blame] | 910 | case ICmpInst::ICMP_SGT: |
Tobias Grosser | 048c879 | 2011-10-23 20:59:20 +0000 | [diff] [blame] | 911 | return isl_pw_aff_gt_set(L, R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 912 | case ICmpInst::ICMP_SGE: |
Tobias Grosser | 048c879 | 2011-10-23 20:59:20 +0000 | [diff] [blame] | 913 | return isl_pw_aff_ge_set(L, R); |
Tobias Grosser | d2795d0 | 2011-08-18 07:51:40 +0000 | [diff] [blame] | 914 | case ICmpInst::ICMP_ULT: |
Tobias Grosser | bfbc369 | 2015-01-09 00:01:33 +0000 | [diff] [blame] | 915 | return isl_pw_aff_lt_set(L, R); |
Tobias Grosser | d2795d0 | 2011-08-18 07:51:40 +0000 | [diff] [blame] | 916 | case ICmpInst::ICMP_UGT: |
Tobias Grosser | bfbc369 | 2015-01-09 00:01:33 +0000 | [diff] [blame] | 917 | return isl_pw_aff_gt_set(L, R); |
Tobias Grosser | d2795d0 | 2011-08-18 07:51:40 +0000 | [diff] [blame] | 918 | case ICmpInst::ICMP_ULE: |
Tobias Grosser | bfbc369 | 2015-01-09 00:01:33 +0000 | [diff] [blame] | 919 | return isl_pw_aff_le_set(L, R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 920 | case ICmpInst::ICMP_UGE: |
Tobias Grosser | bfbc369 | 2015-01-09 00:01:33 +0000 | [diff] [blame] | 921 | return isl_pw_aff_ge_set(L, R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 922 | default: |
| 923 | llvm_unreachable("Non integer predicate not supported"); |
| 924 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 927 | __isl_give isl_set *ScopStmt::addLoopBoundsToDomain(__isl_take isl_set *Domain, |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 928 | TempScop &tempScop) { |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 929 | isl_space *Space; |
| 930 | isl_local_space *LocalSpace; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 931 | |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 932 | Space = isl_set_get_space(Domain); |
| 933 | LocalSpace = isl_local_space_from_space(Space); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 934 | |
Johannes Doerfert | 5ad8a6a | 2014-11-01 01:14:56 +0000 | [diff] [blame] | 935 | ScalarEvolution *SE = getParent()->getSE(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 936 | for (int i = 0, e = getNumIterators(); i != e; ++i) { |
Tobias Grosser | 9b13d3d | 2011-10-06 22:32:58 +0000 | [diff] [blame] | 937 | isl_aff *Zero = isl_aff_zero_on_domain(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 938 | isl_pw_aff *IV = |
| 939 | isl_pw_aff_from_aff(isl_aff_set_coefficient_si(Zero, isl_dim_in, i, 1)); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 940 | |
Tobias Grosser | 9b13d3d | 2011-10-06 22:32:58 +0000 | [diff] [blame] | 941 | // 0 <= IV. |
| 942 | isl_set *LowerBound = isl_pw_aff_nonneg_set(isl_pw_aff_copy(IV)); |
| 943 | Domain = isl_set_intersect(Domain, LowerBound); |
| 944 | |
| 945 | // IV <= LatchExecutions. |
Hongbin Zheng | 27f3afb | 2011-04-30 03:26:51 +0000 | [diff] [blame] | 946 | const Loop *L = getLoopForDimension(i); |
Johannes Doerfert | 5ad8a6a | 2014-11-01 01:14:56 +0000 | [diff] [blame] | 947 | const SCEV *LatchExecutions = SE->getBackedgeTakenCount(L); |
Tobias Grosser | 9b13d3d | 2011-10-06 22:32:58 +0000 | [diff] [blame] | 948 | isl_pw_aff *UpperBound = SCEVAffinator::getPwAff(this, LatchExecutions); |
| 949 | isl_set *UpperBoundSet = isl_pw_aff_le_set(IV, UpperBound); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 950 | Domain = isl_set_intersect(Domain, UpperBoundSet); |
| 951 | } |
| 952 | |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 953 | isl_local_space_free(LocalSpace); |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 954 | return Domain; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 957 | __isl_give isl_set *ScopStmt::addConditionsToDomain(__isl_take isl_set *Domain, |
| 958 | TempScop &tempScop, |
| 959 | const Region &CurRegion) { |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 960 | const Region *TopRegion = tempScop.getMaxRegion().getParent(), |
Tobias Grosser | d7e5864 | 2013-04-10 06:55:45 +0000 | [diff] [blame] | 961 | *CurrentRegion = &CurRegion; |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 962 | const BasicBlock *BranchingBB = BB ? BB : R->getEntry(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 963 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 964 | do { |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 965 | if (BranchingBB != CurrentRegion->getEntry()) { |
| 966 | if (const BBCond *Condition = tempScop.getBBCond(BranchingBB)) |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 967 | for (const auto &C : *Condition) { |
| 968 | isl_set *ConditionSet = buildConditionSet(C); |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 969 | Domain = isl_set_intersect(Domain, ConditionSet); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 970 | } |
| 971 | } |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 972 | BranchingBB = CurrentRegion->getEntry(); |
| 973 | CurrentRegion = CurrentRegion->getParent(); |
| 974 | } while (TopRegion != CurrentRegion); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 975 | |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 976 | return Domain; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 979 | __isl_give isl_set *ScopStmt::buildDomain(TempScop &tempScop, |
| 980 | const Region &CurRegion) { |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 981 | isl_space *Space; |
| 982 | isl_set *Domain; |
Tobias Grosser | 084d8f7 | 2012-05-29 09:29:44 +0000 | [diff] [blame] | 983 | isl_id *Id; |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 984 | |
| 985 | Space = isl_space_set_alloc(getIslCtx(), 0, getNumIterators()); |
| 986 | |
Tobias Grosser | 084d8f7 | 2012-05-29 09:29:44 +0000 | [diff] [blame] | 987 | Id = isl_id_alloc(getIslCtx(), getBaseName(), this); |
| 988 | |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 989 | Domain = isl_set_universe(Space); |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 990 | Domain = addLoopBoundsToDomain(Domain, tempScop); |
| 991 | Domain = addConditionsToDomain(Domain, tempScop, CurRegion); |
Tobias Grosser | 084d8f7 | 2012-05-29 09:29:44 +0000 | [diff] [blame] | 992 | Domain = isl_set_set_tuple_id(Domain, Id); |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 993 | |
| 994 | return Domain; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 995 | } |
| 996 | |
Tobias Grosser | 7b50bee | 2014-11-25 10:51:12 +0000 | [diff] [blame] | 997 | void ScopStmt::deriveAssumptionsFromGEP(GetElementPtrInst *GEP) { |
| 998 | int Dimension = 0; |
| 999 | isl_ctx *Ctx = Parent.getIslCtx(); |
| 1000 | isl_local_space *LSpace = isl_local_space_from_space(getDomainSpace()); |
| 1001 | Type *Ty = GEP->getPointerOperandType(); |
| 1002 | ScalarEvolution &SE = *Parent.getSE(); |
| 1003 | |
| 1004 | if (auto *PtrTy = dyn_cast<PointerType>(Ty)) { |
| 1005 | Dimension = 1; |
| 1006 | Ty = PtrTy->getElementType(); |
| 1007 | } |
| 1008 | |
| 1009 | while (auto ArrayTy = dyn_cast<ArrayType>(Ty)) { |
| 1010 | unsigned int Operand = 1 + Dimension; |
| 1011 | |
| 1012 | if (GEP->getNumOperands() <= Operand) |
| 1013 | break; |
| 1014 | |
| 1015 | const SCEV *Expr = SE.getSCEV(GEP->getOperand(Operand)); |
| 1016 | |
| 1017 | if (isAffineExpr(&Parent.getRegion(), Expr, SE)) { |
| 1018 | isl_pw_aff *AccessOffset = SCEVAffinator::getPwAff(this, Expr); |
| 1019 | AccessOffset = |
| 1020 | isl_pw_aff_set_tuple_id(AccessOffset, isl_dim_in, getDomainId()); |
| 1021 | |
| 1022 | isl_pw_aff *DimSize = isl_pw_aff_from_aff(isl_aff_val_on_domain( |
| 1023 | isl_local_space_copy(LSpace), |
| 1024 | isl_val_int_from_si(Ctx, ArrayTy->getNumElements()))); |
| 1025 | |
| 1026 | isl_set *OutOfBound = isl_pw_aff_ge_set(AccessOffset, DimSize); |
| 1027 | OutOfBound = isl_set_intersect(getDomain(), OutOfBound); |
| 1028 | OutOfBound = isl_set_params(OutOfBound); |
| 1029 | isl_set *InBound = isl_set_complement(OutOfBound); |
| 1030 | isl_set *Executed = isl_set_params(getDomain()); |
| 1031 | |
| 1032 | // A => B == !A or B |
| 1033 | isl_set *InBoundIfExecuted = |
| 1034 | isl_set_union(isl_set_complement(Executed), InBound); |
| 1035 | |
| 1036 | Parent.addAssumption(InBoundIfExecuted); |
| 1037 | } |
| 1038 | |
| 1039 | Dimension += 1; |
| 1040 | Ty = ArrayTy->getElementType(); |
| 1041 | } |
| 1042 | |
| 1043 | isl_local_space_free(LSpace); |
| 1044 | } |
| 1045 | |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1046 | void ScopStmt::deriveAssumptions(BasicBlock *Block) { |
| 1047 | for (Instruction &Inst : *Block) |
Tobias Grosser | 7b50bee | 2014-11-25 10:51:12 +0000 | [diff] [blame] | 1048 | if (auto *GEP = dyn_cast<GetElementPtrInst>(&Inst)) |
| 1049 | deriveAssumptionsFromGEP(GEP); |
| 1050 | } |
| 1051 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1052 | ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop, const Region &CurRegion, |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1053 | Region &R, SmallVectorImpl<Loop *> &Nest, |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1054 | SmallVectorImpl<unsigned> &ScheduleVec) |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1055 | : Parent(parent), BB(nullptr), R(&R), Build(nullptr), |
| 1056 | NestLoops(Nest.size()) { |
| 1057 | // Setup the induction variables. |
| 1058 | for (unsigned i = 0, e = Nest.size(); i < e; ++i) |
| 1059 | NestLoops[i] = Nest[i]; |
| 1060 | |
| 1061 | BaseName = getIslCompatibleName("Stmt_(", R.getNameStr(), ")"); |
| 1062 | |
| 1063 | Domain = buildDomain(tempScop, CurRegion); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1064 | buildSchedule(ScheduleVec); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1065 | |
| 1066 | BasicBlock *EntryBB = R.getEntry(); |
| 1067 | for (BasicBlock *Block : R.blocks()) { |
| 1068 | buildAccesses(tempScop, Block, Block != EntryBB); |
| 1069 | deriveAssumptions(Block); |
| 1070 | } |
| 1071 | checkForReductions(); |
| 1072 | } |
| 1073 | |
| 1074 | ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop, const Region &CurRegion, |
Sebastian Pop | 860e021 | 2013-02-15 21:26:44 +0000 | [diff] [blame] | 1075 | BasicBlock &bb, SmallVectorImpl<Loop *> &Nest, |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1076 | SmallVectorImpl<unsigned> &ScheduleVec) |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1077 | : Parent(parent), BB(&bb), R(nullptr), Build(nullptr), |
| 1078 | NestLoops(Nest.size()) { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1079 | // Setup the induction variables. |
Tobias Grosser | 683b8e4 | 2014-11-30 14:33:31 +0000 | [diff] [blame] | 1080 | for (unsigned i = 0, e = Nest.size(); i < e; ++i) |
Sebastian Pop | 860e021 | 2013-02-15 21:26:44 +0000 | [diff] [blame] | 1081 | NestLoops[i] = Nest[i]; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1082 | |
Johannes Doerfert | 79fc23f | 2014-07-24 23:48:02 +0000 | [diff] [blame] | 1083 | BaseName = getIslCompatibleName("Stmt_", &bb, ""); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1084 | |
Tobias Grosser | e19661e | 2011-10-07 08:46:57 +0000 | [diff] [blame] | 1085 | Domain = buildDomain(tempScop, CurRegion); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1086 | buildSchedule(ScheduleVec); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1087 | buildAccesses(tempScop, BB); |
| 1088 | deriveAssumptions(BB); |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1089 | checkForReductions(); |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1092 | /// @brief Collect loads which might form a reduction chain with @p StoreMA |
| 1093 | /// |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1094 | /// Check if the stored value for @p StoreMA is a binary operator with one or |
| 1095 | /// two loads as operands. If the binary operand is commutative & associative, |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1096 | /// used only once (by @p StoreMA) and its load operands are also used only |
| 1097 | /// once, we have found a possible reduction chain. It starts at an operand |
| 1098 | /// load and includes the binary operator and @p StoreMA. |
| 1099 | /// |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1100 | /// Note: We allow only one use to ensure the load and binary operator cannot |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1101 | /// escape this block or into any other store except @p StoreMA. |
| 1102 | void ScopStmt::collectCandiateReductionLoads( |
| 1103 | MemoryAccess *StoreMA, SmallVectorImpl<MemoryAccess *> &Loads) { |
| 1104 | auto *Store = dyn_cast<StoreInst>(StoreMA->getAccessInstruction()); |
| 1105 | if (!Store) |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 1106 | return; |
| 1107 | |
| 1108 | // Skip if there is not one binary operator between the load and the store |
| 1109 | auto *BinOp = dyn_cast<BinaryOperator>(Store->getValueOperand()); |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1110 | if (!BinOp) |
| 1111 | return; |
| 1112 | |
| 1113 | // Skip if the binary operators has multiple uses |
| 1114 | if (BinOp->getNumUses() != 1) |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 1115 | return; |
| 1116 | |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1117 | // Skip if the opcode of the binary operator is not commutative/associative |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 1118 | if (!BinOp->isCommutative() || !BinOp->isAssociative()) |
| 1119 | return; |
| 1120 | |
Johannes Doerfert | 9890a05 | 2014-07-01 00:32:29 +0000 | [diff] [blame] | 1121 | // Skip if the binary operator is outside the current SCoP |
| 1122 | if (BinOp->getParent() != Store->getParent()) |
| 1123 | return; |
| 1124 | |
Johannes Doerfert | 0ee1f21 | 2014-06-17 17:31:36 +0000 | [diff] [blame] | 1125 | // Skip if it is a multiplicative reduction and we disabled them |
| 1126 | if (DisableMultiplicativeReductions && |
| 1127 | (BinOp->getOpcode() == Instruction::Mul || |
| 1128 | BinOp->getOpcode() == Instruction::FMul)) |
| 1129 | return; |
| 1130 | |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1131 | // Check the binary operator operands for a candidate load |
| 1132 | auto *PossibleLoad0 = dyn_cast<LoadInst>(BinOp->getOperand(0)); |
| 1133 | auto *PossibleLoad1 = dyn_cast<LoadInst>(BinOp->getOperand(1)); |
| 1134 | if (!PossibleLoad0 && !PossibleLoad1) |
| 1135 | return; |
| 1136 | |
| 1137 | // A load is only a candidate if it cannot escape (thus has only this use) |
| 1138 | if (PossibleLoad0 && PossibleLoad0->getNumUses() == 1) |
Johannes Doerfert | 9890a05 | 2014-07-01 00:32:29 +0000 | [diff] [blame] | 1139 | if (PossibleLoad0->getParent() == Store->getParent()) |
| 1140 | Loads.push_back(lookupAccessFor(PossibleLoad0)); |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1141 | if (PossibleLoad1 && PossibleLoad1->getNumUses() == 1) |
Johannes Doerfert | 9890a05 | 2014-07-01 00:32:29 +0000 | [diff] [blame] | 1142 | if (PossibleLoad1->getParent() == Store->getParent()) |
| 1143 | Loads.push_back(lookupAccessFor(PossibleLoad1)); |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | /// @brief Check for reductions in this ScopStmt |
| 1147 | /// |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1148 | /// Iterate over all store memory accesses and check for valid binary reduction |
| 1149 | /// like chains. For all candidates we check if they have the same base address |
| 1150 | /// and there are no other accesses which overlap with them. The base address |
| 1151 | /// check rules out impossible reductions candidates early. The overlap check, |
| 1152 | /// together with the "only one user" check in collectCandiateReductionLoads, |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1153 | /// guarantees that none of the intermediate results will escape during |
| 1154 | /// execution of the loop nest. We basically check here that no other memory |
| 1155 | /// access can access the same memory as the potential reduction. |
| 1156 | void ScopStmt::checkForReductions() { |
| 1157 | SmallVector<MemoryAccess *, 2> Loads; |
| 1158 | SmallVector<std::pair<MemoryAccess *, MemoryAccess *>, 4> Candidates; |
| 1159 | |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1160 | // First collect candidate load-store reduction chains by iterating over all |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1161 | // stores and collecting possible reduction loads. |
| 1162 | for (MemoryAccess *StoreMA : MemAccs) { |
| 1163 | if (StoreMA->isRead()) |
| 1164 | continue; |
| 1165 | |
| 1166 | Loads.clear(); |
| 1167 | collectCandiateReductionLoads(StoreMA, Loads); |
| 1168 | for (MemoryAccess *LoadMA : Loads) |
| 1169 | Candidates.push_back(std::make_pair(LoadMA, StoreMA)); |
| 1170 | } |
| 1171 | |
| 1172 | // Then check each possible candidate pair. |
| 1173 | for (const auto &CandidatePair : Candidates) { |
| 1174 | bool Valid = true; |
| 1175 | isl_map *LoadAccs = CandidatePair.first->getAccessRelation(); |
| 1176 | isl_map *StoreAccs = CandidatePair.second->getAccessRelation(); |
| 1177 | |
| 1178 | // Skip those with obviously unequal base addresses. |
| 1179 | if (!isl_map_has_equal_space(LoadAccs, StoreAccs)) { |
| 1180 | isl_map_free(LoadAccs); |
| 1181 | isl_map_free(StoreAccs); |
| 1182 | continue; |
| 1183 | } |
| 1184 | |
| 1185 | // And check if the remaining for overlap with other memory accesses. |
| 1186 | isl_map *AllAccsRel = isl_map_union(LoadAccs, StoreAccs); |
| 1187 | AllAccsRel = isl_map_intersect_domain(AllAccsRel, getDomain()); |
| 1188 | isl_set *AllAccs = isl_map_range(AllAccsRel); |
| 1189 | |
| 1190 | for (MemoryAccess *MA : MemAccs) { |
| 1191 | if (MA == CandidatePair.first || MA == CandidatePair.second) |
| 1192 | continue; |
| 1193 | |
| 1194 | isl_map *AccRel = |
| 1195 | isl_map_intersect_domain(MA->getAccessRelation(), getDomain()); |
| 1196 | isl_set *Accs = isl_map_range(AccRel); |
| 1197 | |
| 1198 | if (isl_set_has_equal_space(AllAccs, Accs) || isl_set_free(Accs)) { |
| 1199 | isl_set *OverlapAccs = isl_set_intersect(Accs, isl_set_copy(AllAccs)); |
| 1200 | Valid = Valid && isl_set_is_empty(OverlapAccs); |
| 1201 | isl_set_free(OverlapAccs); |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | isl_set_free(AllAccs); |
| 1206 | if (!Valid) |
| 1207 | continue; |
| 1208 | |
Johannes Doerfert | f618339 | 2014-07-01 20:52:51 +0000 | [diff] [blame] | 1209 | const LoadInst *Load = |
| 1210 | dyn_cast<const LoadInst>(CandidatePair.first->getAccessInstruction()); |
| 1211 | MemoryAccess::ReductionType RT = |
| 1212 | getReductionType(dyn_cast<BinaryOperator>(Load->user_back()), Load); |
| 1213 | |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1214 | // If no overlapping access was found we mark the load and store as |
| 1215 | // reduction like. |
Johannes Doerfert | f618339 | 2014-07-01 20:52:51 +0000 | [diff] [blame] | 1216 | CandidatePair.first->markAsReductionLike(RT); |
| 1217 | CandidatePair.second->markAsReductionLike(RT); |
Johannes Doerfert | e58a012 | 2014-06-27 20:31:28 +0000 | [diff] [blame] | 1218 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1221 | std::string ScopStmt::getDomainStr() const { return stringFromIslObj(Domain); } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1222 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1223 | std::string ScopStmt::getScheduleStr() const { |
| 1224 | return stringFromIslObj(Schedule); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1227 | unsigned ScopStmt::getNumParams() const { return Parent.getNumParams(); } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1228 | |
Tobias Grosser | f567e1a | 2015-02-19 22:16:12 +0000 | [diff] [blame] | 1229 | unsigned ScopStmt::getNumIterators() const { return NestLoops.size(); } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1230 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1231 | unsigned ScopStmt::getNumSchedule() const { |
| 1232 | return isl_map_dim(Schedule, isl_dim_out); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | const char *ScopStmt::getBaseName() const { return BaseName.c_str(); } |
| 1236 | |
Hongbin Zheng | 27f3afb | 2011-04-30 03:26:51 +0000 | [diff] [blame] | 1237 | const Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const { |
Sebastian Pop | 860e021 | 2013-02-15 21:26:44 +0000 | [diff] [blame] | 1238 | return NestLoops[Dimension]; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1241 | isl_ctx *ScopStmt::getIslCtx() const { return Parent.getIslCtx(); } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1242 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 1243 | __isl_give isl_set *ScopStmt::getDomain() const { return isl_set_copy(Domain); } |
Tobias Grosser | d5a7bfc | 2011-05-06 19:52:19 +0000 | [diff] [blame] | 1244 | |
Tobias Grosser | 6e6c7e0 | 2015-03-30 12:22:39 +0000 | [diff] [blame] | 1245 | __isl_give isl_space *ScopStmt::getDomainSpace() const { |
Tobias Grosser | 78d8a3d | 2012-01-17 20:34:23 +0000 | [diff] [blame] | 1246 | return isl_set_get_space(Domain); |
| 1247 | } |
| 1248 | |
Tobias Grosser | 4f663aa | 2015-03-30 11:52:59 +0000 | [diff] [blame] | 1249 | __isl_give isl_id *ScopStmt::getDomainId() const { |
| 1250 | return isl_set_get_tuple_id(Domain); |
| 1251 | } |
Tobias Grosser | cd95b77 | 2012-08-30 11:49:38 +0000 | [diff] [blame] | 1252 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1253 | ScopStmt::~ScopStmt() { |
Johannes Doerfert | ecff11d | 2015-05-22 23:43:58 +0000 | [diff] [blame] | 1254 | DeleteContainerSeconds(InstructionToAccess); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1255 | isl_set_free(Domain); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1256 | isl_map_free(Schedule); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | void ScopStmt::print(raw_ostream &OS) const { |
| 1260 | OS << "\t" << getBaseName() << "\n"; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1261 | OS.indent(12) << "Domain :=\n"; |
| 1262 | |
| 1263 | if (Domain) { |
| 1264 | OS.indent(16) << getDomainStr() << ";\n"; |
| 1265 | } else |
| 1266 | OS.indent(16) << "n/a\n"; |
| 1267 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1268 | OS.indent(12) << "Schedule :=\n"; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1269 | |
| 1270 | if (Domain) { |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1271 | OS.indent(16) << getScheduleStr() << ";\n"; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1272 | } else |
| 1273 | OS.indent(16) << "n/a\n"; |
| 1274 | |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 1275 | for (MemoryAccess *Access : MemAccs) |
| 1276 | Access->print(OS); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | void ScopStmt::dump() const { print(dbgs()); } |
| 1280 | |
| 1281 | //===----------------------------------------------------------------------===// |
| 1282 | /// Scop class implement |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 1283 | |
Tobias Grosser | 7ffe4e8 | 2011-11-17 12:56:10 +0000 | [diff] [blame] | 1284 | void Scop::setContext(__isl_take isl_set *NewContext) { |
Tobias Grosser | ff9b54d | 2011-11-15 11:38:44 +0000 | [diff] [blame] | 1285 | NewContext = isl_set_align_params(NewContext, isl_set_get_space(Context)); |
| 1286 | isl_set_free(Context); |
| 1287 | Context = NewContext; |
| 1288 | } |
| 1289 | |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 1290 | void Scop::addParams(std::vector<const SCEV *> NewParameters) { |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 1291 | for (const SCEV *Parameter : NewParameters) { |
Johannes Doerfert | be40996 | 2015-03-29 20:45:09 +0000 | [diff] [blame] | 1292 | Parameter = extractConstantFactor(Parameter, *SE).second; |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 1293 | if (ParameterIds.find(Parameter) != ParameterIds.end()) |
| 1294 | continue; |
| 1295 | |
| 1296 | int dimension = Parameters.size(); |
| 1297 | |
| 1298 | Parameters.push_back(Parameter); |
| 1299 | ParameterIds[Parameter] = dimension; |
| 1300 | } |
| 1301 | } |
| 1302 | |
Tobias Grosser | 9a38ab8 | 2011-11-08 15:41:03 +0000 | [diff] [blame] | 1303 | __isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) const { |
| 1304 | ParamIdType::const_iterator IdIter = ParameterIds.find(Parameter); |
Tobias Grosser | 76c2e32 | 2011-11-07 12:58:59 +0000 | [diff] [blame] | 1305 | |
Tobias Grosser | 9a38ab8 | 2011-11-08 15:41:03 +0000 | [diff] [blame] | 1306 | if (IdIter == ParameterIds.end()) |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 1307 | return nullptr; |
Tobias Grosser | 76c2e32 | 2011-11-07 12:58:59 +0000 | [diff] [blame] | 1308 | |
Tobias Grosser | 8f99c16 | 2011-11-15 11:38:55 +0000 | [diff] [blame] | 1309 | std::string ParameterName; |
| 1310 | |
| 1311 | if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) { |
| 1312 | Value *Val = ValueParameter->getValue(); |
Tobias Grosser | 29ee0b1 | 2011-11-17 14:52:36 +0000 | [diff] [blame] | 1313 | ParameterName = Val->getName(); |
Tobias Grosser | 8f99c16 | 2011-11-15 11:38:55 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | if (ParameterName == "" || ParameterName.substr(0, 2) == "p_") |
Hongbin Zheng | 86a3774 | 2012-04-25 08:01:38 +0000 | [diff] [blame] | 1317 | ParameterName = "p_" + utostr_32(IdIter->second); |
Tobias Grosser | 8f99c16 | 2011-11-15 11:38:55 +0000 | [diff] [blame] | 1318 | |
Tobias Grosser | 20532b8 | 2014-04-11 17:56:49 +0000 | [diff] [blame] | 1319 | return isl_id_alloc(getIslCtx(), ParameterName.c_str(), |
| 1320 | const_cast<void *>((const void *)Parameter)); |
Tobias Grosser | 76c2e32 | 2011-11-07 12:58:59 +0000 | [diff] [blame] | 1321 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1322 | |
Tobias Grosser | 6be480c | 2011-11-08 15:41:13 +0000 | [diff] [blame] | 1323 | void Scop::buildContext() { |
| 1324 | isl_space *Space = isl_space_params_alloc(IslCtx, 0); |
Tobias Grosser | e86109f | 2013-10-29 21:05:49 +0000 | [diff] [blame] | 1325 | Context = isl_set_universe(isl_space_copy(Space)); |
| 1326 | AssumedContext = isl_set_universe(Space); |
Tobias Grosser | 0e27e24 | 2011-10-06 00:03:48 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Tobias Grosser | 18daaca | 2012-05-22 10:47:27 +0000 | [diff] [blame] | 1329 | void Scop::addParameterBounds() { |
Johannes Doerfert | 4f8ac3d | 2015-02-23 16:15:51 +0000 | [diff] [blame] | 1330 | for (const auto &ParamID : ParameterIds) { |
Johannes Doerfert | 4f8ac3d | 2015-02-23 16:15:51 +0000 | [diff] [blame] | 1331 | int dim = ParamID.second; |
Tobias Grosser | 18daaca | 2012-05-22 10:47:27 +0000 | [diff] [blame] | 1332 | |
Johannes Doerfert | 4f8ac3d | 2015-02-23 16:15:51 +0000 | [diff] [blame] | 1333 | ConstantRange SRange = SE->getSignedRange(ParamID.first); |
Tobias Grosser | 18daaca | 2012-05-22 10:47:27 +0000 | [diff] [blame] | 1334 | |
Johannes Doerfert | e704494 | 2015-02-24 11:58:30 +0000 | [diff] [blame] | 1335 | Context = addRangeBoundsToSet(Context, SRange, dim, isl_dim_param); |
Tobias Grosser | 18daaca | 2012-05-22 10:47:27 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 1339 | void Scop::realignParams() { |
Tobias Grosser | 6be480c | 2011-11-08 15:41:13 +0000 | [diff] [blame] | 1340 | // Add all parameters into a common model. |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 1341 | isl_space *Space = isl_space_params_alloc(IslCtx, ParameterIds.size()); |
Tobias Grosser | 6be480c | 2011-11-08 15:41:13 +0000 | [diff] [blame] | 1342 | |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 1343 | for (const auto &ParamID : ParameterIds) { |
| 1344 | const SCEV *Parameter = ParamID.first; |
Tobias Grosser | 6be480c | 2011-11-08 15:41:13 +0000 | [diff] [blame] | 1345 | isl_id *id = getIdForParam(Parameter); |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 1346 | Space = isl_space_set_dim_id(Space, isl_dim_param, ParamID.second, id); |
Tobias Grosser | 6be480c | 2011-11-08 15:41:13 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | // Align the parameters of all data structures to the model. |
| 1350 | Context = isl_set_align_params(Context, Space); |
| 1351 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1352 | for (ScopStmt &Stmt : *this) |
| 1353 | Stmt.realignParams(); |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1356 | void Scop::simplifyAssumedContext() { |
| 1357 | // The parameter constraints of the iteration domains give us a set of |
| 1358 | // constraints that need to hold for all cases where at least a single |
| 1359 | // statement iteration is executed in the whole scop. We now simplify the |
| 1360 | // assumed context under the assumption that such constraints hold and at |
| 1361 | // least a single statement iteration is executed. For cases where no |
| 1362 | // statement instances are executed, the assumptions we have taken about |
| 1363 | // the executed code do not matter and can be changed. |
| 1364 | // |
| 1365 | // WARNING: This only holds if the assumptions we have taken do not reduce |
| 1366 | // the set of statement instances that are executed. Otherwise we |
| 1367 | // may run into a case where the iteration domains suggest that |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1368 | // for a certain set of parameter constraints no code is executed, |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1369 | // but in the original program some computation would have been |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1370 | // performed. In such a case, modifying the run-time conditions and |
| 1371 | // possibly influencing the run-time check may cause certain scops |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1372 | // to not be executed. |
| 1373 | // |
| 1374 | // Example: |
| 1375 | // |
| 1376 | // When delinearizing the following code: |
| 1377 | // |
| 1378 | // for (long i = 0; i < 100; i++) |
| 1379 | // for (long j = 0; j < m; j++) |
| 1380 | // A[i+p][j] = 1.0; |
| 1381 | // |
| 1382 | // we assume that the condition m <= 0 or (m >= 1 and p >= 0) holds as |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1383 | // otherwise we would access out of bound data. Now, knowing that code is |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1384 | // only executed for the case m >= 0, it is sufficient to assume p >= 0. |
| 1385 | AssumedContext = |
| 1386 | isl_set_gist_params(AssumedContext, isl_union_set_params(getDomains())); |
Johannes Doerfert | 4f8ac3d | 2015-02-23 16:15:51 +0000 | [diff] [blame] | 1387 | AssumedContext = isl_set_gist_params(AssumedContext, getContext()); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1390 | /// @brief Add the minimal/maximal access in @p Set to @p User. |
| 1391 | static int buildMinMaxAccess(__isl_take isl_set *Set, void *User) { |
| 1392 | Scop::MinMaxVectorTy *MinMaxAccesses = (Scop::MinMaxVectorTy *)User; |
| 1393 | isl_pw_multi_aff *MinPMA, *MaxPMA; |
| 1394 | isl_pw_aff *LastDimAff; |
| 1395 | isl_aff *OneAff; |
| 1396 | unsigned Pos; |
| 1397 | |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 1398 | // Restrict the number of parameters involved in the access as the lexmin/ |
| 1399 | // lexmax computation will take too long if this number is high. |
| 1400 | // |
| 1401 | // Experiments with a simple test case using an i7 4800MQ: |
| 1402 | // |
| 1403 | // #Parameters involved | Time (in sec) |
| 1404 | // 6 | 0.01 |
| 1405 | // 7 | 0.04 |
| 1406 | // 8 | 0.12 |
| 1407 | // 9 | 0.40 |
| 1408 | // 10 | 1.54 |
| 1409 | // 11 | 6.78 |
| 1410 | // 12 | 30.38 |
| 1411 | // |
| 1412 | if (isl_set_n_param(Set) > RunTimeChecksMaxParameters) { |
| 1413 | unsigned InvolvedParams = 0; |
| 1414 | for (unsigned u = 0, e = isl_set_n_param(Set); u < e; u++) |
| 1415 | if (isl_set_involves_dims(Set, isl_dim_param, u, 1)) |
| 1416 | InvolvedParams++; |
| 1417 | |
| 1418 | if (InvolvedParams > RunTimeChecksMaxParameters) { |
| 1419 | isl_set_free(Set); |
| 1420 | return -1; |
| 1421 | } |
| 1422 | } |
| 1423 | |
Johannes Doerfert | b6755bb | 2015-02-14 12:00:06 +0000 | [diff] [blame] | 1424 | Set = isl_set_remove_divs(Set); |
| 1425 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1426 | MinPMA = isl_set_lexmin_pw_multi_aff(isl_set_copy(Set)); |
| 1427 | MaxPMA = isl_set_lexmax_pw_multi_aff(isl_set_copy(Set)); |
| 1428 | |
Johannes Doerfert | 219b20e | 2014-10-07 14:37:59 +0000 | [diff] [blame] | 1429 | MinPMA = isl_pw_multi_aff_coalesce(MinPMA); |
| 1430 | MaxPMA = isl_pw_multi_aff_coalesce(MaxPMA); |
| 1431 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1432 | // Adjust the last dimension of the maximal access by one as we want to |
| 1433 | // enclose the accessed memory region by MinPMA and MaxPMA. The pointer |
| 1434 | // we test during code generation might now point after the end of the |
| 1435 | // allocated array but we will never dereference it anyway. |
| 1436 | assert(isl_pw_multi_aff_dim(MaxPMA, isl_dim_out) && |
| 1437 | "Assumed at least one output dimension"); |
| 1438 | Pos = isl_pw_multi_aff_dim(MaxPMA, isl_dim_out) - 1; |
| 1439 | LastDimAff = isl_pw_multi_aff_get_pw_aff(MaxPMA, Pos); |
| 1440 | OneAff = isl_aff_zero_on_domain( |
| 1441 | isl_local_space_from_space(isl_pw_aff_get_domain_space(LastDimAff))); |
| 1442 | OneAff = isl_aff_add_constant_si(OneAff, 1); |
| 1443 | LastDimAff = isl_pw_aff_add(LastDimAff, isl_pw_aff_from_aff(OneAff)); |
| 1444 | MaxPMA = isl_pw_multi_aff_set_pw_aff(MaxPMA, Pos, LastDimAff); |
| 1445 | |
| 1446 | MinMaxAccesses->push_back(std::make_pair(MinPMA, MaxPMA)); |
| 1447 | |
| 1448 | isl_set_free(Set); |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
Johannes Doerfert | eeab05a | 2014-10-01 12:42:37 +0000 | [diff] [blame] | 1452 | static __isl_give isl_set *getAccessDomain(MemoryAccess *MA) { |
| 1453 | isl_set *Domain = MA->getStatement()->getDomain(); |
| 1454 | Domain = isl_set_project_out(Domain, isl_dim_set, 0, isl_set_n_dim(Domain)); |
| 1455 | return isl_set_reset_tuple_id(Domain); |
| 1456 | } |
| 1457 | |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 1458 | bool Scop::buildAliasGroups(AliasAnalysis &AA) { |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1459 | // To create sound alias checks we perform the following steps: |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1460 | // o) Use the alias analysis and an alias set tracker to build alias sets |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1461 | // for all memory accesses inside the SCoP. |
| 1462 | // o) For each alias set we then map the aliasing pointers back to the |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1463 | // memory accesses we know, thus obtain groups of memory accesses which |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1464 | // might alias. |
Johannes Doerfert | eeab05a | 2014-10-01 12:42:37 +0000 | [diff] [blame] | 1465 | // o) We divide each group based on the domains of the minimal/maximal |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1466 | // accesses. That means two minimal/maximal accesses are only in a group |
Johannes Doerfert | eeab05a | 2014-10-01 12:42:37 +0000 | [diff] [blame] | 1467 | // if their access domains intersect, otherwise they are in different |
| 1468 | // ones. |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1469 | // o) We split groups such that they contain at most one read only base |
| 1470 | // address. |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1471 | // o) For each group with more than one base pointer we then compute minimal |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1472 | // and maximal accesses to each array in this group. |
| 1473 | using AliasGroupTy = SmallVector<MemoryAccess *, 4>; |
| 1474 | |
| 1475 | AliasSetTracker AST(AA); |
| 1476 | |
| 1477 | DenseMap<Value *, MemoryAccess *> PtrToAcc; |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1478 | DenseSet<Value *> HasWriteAccess; |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1479 | for (ScopStmt &Stmt : *this) { |
Johannes Doerfert | f1ee262 | 2014-10-06 17:43:00 +0000 | [diff] [blame] | 1480 | |
| 1481 | // Skip statements with an empty domain as they will never be executed. |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1482 | isl_set *StmtDomain = Stmt.getDomain(); |
Johannes Doerfert | f1ee262 | 2014-10-06 17:43:00 +0000 | [diff] [blame] | 1483 | bool StmtDomainEmpty = isl_set_is_empty(StmtDomain); |
| 1484 | isl_set_free(StmtDomain); |
| 1485 | if (StmtDomainEmpty) |
| 1486 | continue; |
| 1487 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1488 | for (MemoryAccess *MA : Stmt) { |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1489 | if (MA->isScalar()) |
| 1490 | continue; |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1491 | if (!MA->isRead()) |
| 1492 | HasWriteAccess.insert(MA->getBaseAddr()); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1493 | Instruction *Acc = MA->getAccessInstruction(); |
| 1494 | PtrToAcc[getPointerOperand(*Acc)] = MA; |
| 1495 | AST.add(Acc); |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | SmallVector<AliasGroupTy, 4> AliasGroups; |
| 1500 | for (AliasSet &AS : AST) { |
Johannes Doerfert | 74f6869 | 2014-10-08 02:23:48 +0000 | [diff] [blame] | 1501 | if (AS.isMustAlias() || AS.isForwardingAliasSet()) |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1502 | continue; |
| 1503 | AliasGroupTy AG; |
| 1504 | for (auto PR : AS) |
| 1505 | AG.push_back(PtrToAcc[PR.getValue()]); |
| 1506 | assert(AG.size() > 1 && |
| 1507 | "Alias groups should contain at least two accesses"); |
| 1508 | AliasGroups.push_back(std::move(AG)); |
| 1509 | } |
| 1510 | |
Johannes Doerfert | eeab05a | 2014-10-01 12:42:37 +0000 | [diff] [blame] | 1511 | // Split the alias groups based on their domain. |
| 1512 | for (unsigned u = 0; u < AliasGroups.size(); u++) { |
| 1513 | AliasGroupTy NewAG; |
| 1514 | AliasGroupTy &AG = AliasGroups[u]; |
| 1515 | AliasGroupTy::iterator AGI = AG.begin(); |
| 1516 | isl_set *AGDomain = getAccessDomain(*AGI); |
| 1517 | while (AGI != AG.end()) { |
| 1518 | MemoryAccess *MA = *AGI; |
| 1519 | isl_set *MADomain = getAccessDomain(MA); |
| 1520 | if (isl_set_is_disjoint(AGDomain, MADomain)) { |
| 1521 | NewAG.push_back(MA); |
| 1522 | AGI = AG.erase(AGI); |
| 1523 | isl_set_free(MADomain); |
| 1524 | } else { |
| 1525 | AGDomain = isl_set_union(AGDomain, MADomain); |
| 1526 | AGI++; |
| 1527 | } |
| 1528 | } |
| 1529 | if (NewAG.size() > 1) |
| 1530 | AliasGroups.push_back(std::move(NewAG)); |
| 1531 | isl_set_free(AGDomain); |
| 1532 | } |
| 1533 | |
Tobias Grosser | f4c24b2 | 2015-04-05 13:11:54 +0000 | [diff] [blame] | 1534 | MapVector<const Value *, SmallPtrSet<MemoryAccess *, 8>> ReadOnlyPairs; |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1535 | SmallPtrSet<const Value *, 4> NonReadOnlyBaseValues; |
| 1536 | for (AliasGroupTy &AG : AliasGroups) { |
| 1537 | NonReadOnlyBaseValues.clear(); |
| 1538 | ReadOnlyPairs.clear(); |
| 1539 | |
Johannes Doerfert | eeab05a | 2014-10-01 12:42:37 +0000 | [diff] [blame] | 1540 | if (AG.size() < 2) { |
| 1541 | AG.clear(); |
| 1542 | continue; |
| 1543 | } |
| 1544 | |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1545 | for (auto II = AG.begin(); II != AG.end();) { |
| 1546 | Value *BaseAddr = (*II)->getBaseAddr(); |
| 1547 | if (HasWriteAccess.count(BaseAddr)) { |
| 1548 | NonReadOnlyBaseValues.insert(BaseAddr); |
| 1549 | II++; |
| 1550 | } else { |
| 1551 | ReadOnlyPairs[BaseAddr].insert(*II); |
| 1552 | II = AG.erase(II); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | // If we don't have read only pointers check if there are at least two |
| 1557 | // non read only pointers, otherwise clear the alias group. |
| 1558 | if (ReadOnlyPairs.empty()) { |
| 1559 | if (NonReadOnlyBaseValues.size() <= 1) |
| 1560 | AG.clear(); |
| 1561 | continue; |
| 1562 | } |
| 1563 | |
| 1564 | // If we don't have non read only pointers clear the alias group. |
| 1565 | if (NonReadOnlyBaseValues.empty()) { |
| 1566 | AG.clear(); |
| 1567 | continue; |
| 1568 | } |
| 1569 | |
| 1570 | // If we have both read only and non read only base pointers we combine |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 1571 | // the non read only ones with exactly one read only one at a time into a |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1572 | // new alias group and clear the old alias group in the end. |
| 1573 | for (const auto &ReadOnlyPair : ReadOnlyPairs) { |
| 1574 | AliasGroupTy AGNonReadOnly = AG; |
| 1575 | for (MemoryAccess *MA : ReadOnlyPair.second) |
| 1576 | AGNonReadOnly.push_back(MA); |
| 1577 | AliasGroups.push_back(std::move(AGNonReadOnly)); |
| 1578 | } |
| 1579 | AG.clear(); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | for (AliasGroupTy &AG : AliasGroups) { |
Johannes Doerfert | 1377173 | 2014-10-01 12:40:46 +0000 | [diff] [blame] | 1583 | if (AG.empty()) |
| 1584 | continue; |
| 1585 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1586 | MinMaxVectorTy *MinMaxAccesses = new MinMaxVectorTy(); |
| 1587 | MinMaxAccesses->reserve(AG.size()); |
| 1588 | |
| 1589 | isl_union_map *Accesses = isl_union_map_empty(getParamSpace()); |
| 1590 | for (MemoryAccess *MA : AG) |
| 1591 | Accesses = isl_union_map_add_map(Accesses, MA->getAccessRelation()); |
| 1592 | Accesses = isl_union_map_intersect_domain(Accesses, getDomains()); |
| 1593 | |
| 1594 | isl_union_set *Locations = isl_union_map_range(Accesses); |
| 1595 | Locations = isl_union_set_intersect_params(Locations, getAssumedContext()); |
| 1596 | Locations = isl_union_set_coalesce(Locations); |
| 1597 | Locations = isl_union_set_detect_equalities(Locations); |
Tobias Grosser | 50d4e2e | 2015-03-28 14:50:32 +0000 | [diff] [blame] | 1598 | bool Valid = (0 == isl_union_set_foreach_set(Locations, buildMinMaxAccess, |
| 1599 | MinMaxAccesses)); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1600 | isl_union_set_free(Locations); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1601 | MinMaxAliasGroups.push_back(MinMaxAccesses); |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 1602 | |
| 1603 | if (!Valid) |
Tobias Grosser | 50d4e2e | 2015-03-28 14:50:32 +0000 | [diff] [blame] | 1604 | return false; |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1605 | } |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 1606 | |
Tobias Grosser | 7150072 | 2015-03-28 15:11:14 +0000 | [diff] [blame] | 1607 | // Bail out if the number of values we need to compare is too large. |
| 1608 | // This is important as the number of comparisions grows quadratically with |
| 1609 | // the number of values we need to compare. |
| 1610 | for (const auto *Values : MinMaxAliasGroups) |
| 1611 | if (Values->size() > RunTimeChecksMaxArraysPerGroup) |
| 1612 | return false; |
| 1613 | |
Tobias Grosser | 50d4e2e | 2015-03-28 14:50:32 +0000 | [diff] [blame] | 1614 | return true; |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Johannes Doerfert | f8206cf | 2015-04-12 22:58:40 +0000 | [diff] [blame] | 1617 | static unsigned getMaxLoopDepthInRegion(const Region &R, LoopInfo &LI, |
| 1618 | ScopDetection &SD) { |
| 1619 | |
| 1620 | const ScopDetection::BoxedLoopsSetTy *BoxedLoops = SD.getBoxedLoops(&R); |
| 1621 | |
Johannes Doerfert | e3da05a | 2014-11-01 00:12:13 +0000 | [diff] [blame] | 1622 | unsigned MinLD = INT_MAX, MaxLD = 0; |
| 1623 | for (BasicBlock *BB : R.blocks()) { |
| 1624 | if (Loop *L = LI.getLoopFor(BB)) { |
David Peixotto | dc0a11c | 2015-01-13 18:31:55 +0000 | [diff] [blame] | 1625 | if (!R.contains(L)) |
| 1626 | continue; |
Johannes Doerfert | f8206cf | 2015-04-12 22:58:40 +0000 | [diff] [blame] | 1627 | if (BoxedLoops && BoxedLoops->count(L)) |
| 1628 | continue; |
Johannes Doerfert | e3da05a | 2014-11-01 00:12:13 +0000 | [diff] [blame] | 1629 | unsigned LD = L->getLoopDepth(); |
| 1630 | MinLD = std::min(MinLD, LD); |
| 1631 | MaxLD = std::max(MaxLD, LD); |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | // Handle the case that there is no loop in the SCoP first. |
| 1636 | if (MaxLD == 0) |
| 1637 | return 1; |
| 1638 | |
| 1639 | assert(MinLD >= 1 && "Minimal loop depth should be at least one"); |
| 1640 | assert(MaxLD >= MinLD && |
| 1641 | "Maximal loop depth was smaller than mininaml loop depth?"); |
| 1642 | return MaxLD - MinLD + 1; |
| 1643 | } |
| 1644 | |
Tobias Grosser | 3f29619 | 2015-01-01 23:01:11 +0000 | [diff] [blame] | 1645 | void Scop::dropConstantScheduleDims() { |
| 1646 | isl_union_map *FullSchedule = getSchedule(); |
| 1647 | |
| 1648 | if (isl_union_map_n_map(FullSchedule) == 0) { |
| 1649 | isl_union_map_free(FullSchedule); |
| 1650 | return; |
| 1651 | } |
| 1652 | |
| 1653 | isl_set *ScheduleSpace = |
| 1654 | isl_set_from_union_set(isl_union_map_range(FullSchedule)); |
| 1655 | isl_map *DropDimMap = isl_set_identity(isl_set_copy(ScheduleSpace)); |
| 1656 | |
| 1657 | int NumDimsDropped = 0; |
Johannes Doerfert | 3f21e27 | 2015-03-04 22:23:21 +0000 | [diff] [blame] | 1658 | for (unsigned i = 0; i < isl_set_dim(ScheduleSpace, isl_dim_set); i += 2) { |
| 1659 | isl_val *FixedVal = |
| 1660 | isl_set_plain_get_val_if_fixed(ScheduleSpace, isl_dim_set, i); |
| 1661 | if (isl_val_is_int(FixedVal)) { |
| 1662 | DropDimMap = |
| 1663 | isl_map_project_out(DropDimMap, isl_dim_out, i - NumDimsDropped, 1); |
| 1664 | NumDimsDropped++; |
Tobias Grosser | 3f29619 | 2015-01-01 23:01:11 +0000 | [diff] [blame] | 1665 | } |
Johannes Doerfert | 3f21e27 | 2015-03-04 22:23:21 +0000 | [diff] [blame] | 1666 | isl_val_free(FixedVal); |
| 1667 | } |
Tobias Grosser | 3f29619 | 2015-01-01 23:01:11 +0000 | [diff] [blame] | 1668 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1669 | for (ScopStmt &Stmt : *this) { |
| 1670 | isl_map *Schedule = Stmt.getSchedule(); |
Tobias Grosser | 3f29619 | 2015-01-01 23:01:11 +0000 | [diff] [blame] | 1671 | Schedule = isl_map_apply_range(Schedule, isl_map_copy(DropDimMap)); |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1672 | Stmt.setSchedule(Schedule); |
Tobias Grosser | 3f29619 | 2015-01-01 23:01:11 +0000 | [diff] [blame] | 1673 | } |
| 1674 | isl_set_free(ScheduleSpace); |
| 1675 | isl_map_free(DropDimMap); |
| 1676 | } |
| 1677 | |
Tobias Grosser | 0e27e24 | 2011-10-06 00:03:48 +0000 | [diff] [blame] | 1678 | Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution, |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1679 | ScopDetection &SD, isl_ctx *Context) |
Johannes Doerfert | 7ceb040 | 2015-02-11 17:25:09 +0000 | [diff] [blame] | 1680 | : SE(&ScalarEvolution), R(tempScop.getMaxRegion()), IsOptimized(false), |
Johannes Doerfert | f8206cf | 2015-04-12 22:58:40 +0000 | [diff] [blame] | 1681 | MaxLoopDepth(getMaxLoopDepthInRegion(tempScop.getMaxRegion(), LI, SD)) { |
Tobias Grosser | 9a38ab8 | 2011-11-08 15:41:03 +0000 | [diff] [blame] | 1682 | IslCtx = Context; |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1683 | |
Tobias Grosser | 6be480c | 2011-11-08 15:41:13 +0000 | [diff] [blame] | 1684 | buildContext(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1685 | |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 1686 | SmallVector<Loop *, 8> NestLoops; |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1687 | SmallVector<unsigned, 8> Schedule; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1688 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1689 | Schedule.assign(MaxLoopDepth + 1, 0); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1690 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1691 | // Build the iteration domain, access functions and schedule functions |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1692 | // traversing the region tree. |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1693 | buildScop(tempScop, getRegion(), NestLoops, Schedule, LI, SD); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1694 | |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 1695 | realignParams(); |
Tobias Grosser | 18daaca | 2012-05-22 10:47:27 +0000 | [diff] [blame] | 1696 | addParameterBounds(); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1697 | simplifyAssumedContext(); |
Tobias Grosser | 3f29619 | 2015-01-01 23:01:11 +0000 | [diff] [blame] | 1698 | dropConstantScheduleDims(); |
Tobias Grosser | 8cae72f | 2011-11-08 15:41:08 +0000 | [diff] [blame] | 1699 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1700 | assert(NestLoops.empty() && "NestLoops not empty at top level!"); |
| 1701 | } |
| 1702 | |
| 1703 | Scop::~Scop() { |
| 1704 | isl_set_free(Context); |
Tobias Grosser | e86109f | 2013-10-29 21:05:49 +0000 | [diff] [blame] | 1705 | isl_set_free(AssumedContext); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1706 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1707 | // Free the alias groups |
| 1708 | for (MinMaxVectorTy *MinMaxAccesses : MinMaxAliasGroups) { |
| 1709 | for (MinMaxAccessTy &MMA : *MinMaxAccesses) { |
| 1710 | isl_pw_multi_aff_free(MMA.first); |
| 1711 | isl_pw_multi_aff_free(MMA.second); |
| 1712 | } |
| 1713 | delete MinMaxAccesses; |
| 1714 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Johannes Doerfert | 80ef110 | 2014-11-07 08:31:31 +0000 | [diff] [blame] | 1717 | const ScopArrayInfo * |
| 1718 | Scop::getOrCreateScopArrayInfo(Value *BasePtr, Type *AccessType, |
| 1719 | const SmallVector<const SCEV *, 4> &Sizes) { |
Tobias Grosser | ab67144 | 2015-05-23 05:58:27 +0000 | [diff] [blame] | 1720 | auto &SAI = ScopArrayInfoMap[BasePtr]; |
Johannes Doerfert | 80ef110 | 2014-11-07 08:31:31 +0000 | [diff] [blame] | 1721 | if (!SAI) |
Tobias Grosser | ab67144 | 2015-05-23 05:58:27 +0000 | [diff] [blame] | 1722 | SAI.reset(new ScopArrayInfo(BasePtr, AccessType, getIslCtx(), Sizes)); |
| 1723 | return SAI.get(); |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | const ScopArrayInfo *Scop::getScopArrayInfo(Value *BasePtr) { |
Tobias Grosser | 2d7611f | 2015-05-23 05:58:30 +0000 | [diff] [blame] | 1727 | const ScopArrayInfo *SAI = ScopArrayInfoMap[BasePtr].get(); |
Johannes Doerfert | 1a28a89 | 2014-10-05 11:32:18 +0000 | [diff] [blame] | 1728 | assert(SAI && "No ScopArrayInfo available for this base pointer"); |
| 1729 | return SAI; |
| 1730 | } |
| 1731 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1732 | std::string Scop::getContextStr() const { return stringFromIslObj(Context); } |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1733 | std::string Scop::getAssumedContextStr() const { |
| 1734 | return stringFromIslObj(AssumedContext); |
| 1735 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1736 | |
| 1737 | std::string Scop::getNameStr() const { |
| 1738 | std::string ExitName, EntryName; |
| 1739 | raw_string_ostream ExitStr(ExitName); |
| 1740 | raw_string_ostream EntryStr(EntryName); |
| 1741 | |
Tobias Grosser | f240b48 | 2014-01-09 10:42:15 +0000 | [diff] [blame] | 1742 | R.getEntry()->printAsOperand(EntryStr, false); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1743 | EntryStr.str(); |
| 1744 | |
| 1745 | if (R.getExit()) { |
Tobias Grosser | f240b48 | 2014-01-09 10:42:15 +0000 | [diff] [blame] | 1746 | R.getExit()->printAsOperand(ExitStr, false); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1747 | ExitStr.str(); |
| 1748 | } else |
| 1749 | ExitName = "FunctionExit"; |
| 1750 | |
| 1751 | return EntryName + "---" + ExitName; |
| 1752 | } |
| 1753 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1754 | __isl_give isl_set *Scop::getContext() const { return isl_set_copy(Context); } |
Tobias Grosser | 3748705 | 2011-10-06 00:03:42 +0000 | [diff] [blame] | 1755 | __isl_give isl_space *Scop::getParamSpace() const { |
Tobias Grosser | eeb9f3c | 2015-05-26 21:37:31 +0000 | [diff] [blame] | 1756 | return isl_set_get_space(Context); |
Tobias Grosser | 3748705 | 2011-10-06 00:03:42 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
Tobias Grosser | e86109f | 2013-10-29 21:05:49 +0000 | [diff] [blame] | 1759 | __isl_give isl_set *Scop::getAssumedContext() const { |
| 1760 | return isl_set_copy(AssumedContext); |
| 1761 | } |
| 1762 | |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1763 | void Scop::addAssumption(__isl_take isl_set *Set) { |
| 1764 | AssumedContext = isl_set_intersect(AssumedContext, Set); |
Tobias Grosser | 7b50bee | 2014-11-25 10:51:12 +0000 | [diff] [blame] | 1765 | AssumedContext = isl_set_coalesce(AssumedContext); |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1768 | void Scop::printContext(raw_ostream &OS) const { |
| 1769 | OS << "Context:\n"; |
| 1770 | |
| 1771 | if (!Context) { |
| 1772 | OS.indent(4) << "n/a\n\n"; |
| 1773 | return; |
| 1774 | } |
| 1775 | |
| 1776 | OS.indent(4) << getContextStr() << "\n"; |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 1777 | |
Tobias Grosser | 5e6813d | 2014-07-02 17:47:48 +0000 | [diff] [blame] | 1778 | OS.indent(4) << "Assumed Context:\n"; |
| 1779 | if (!AssumedContext) { |
| 1780 | OS.indent(4) << "n/a\n\n"; |
| 1781 | return; |
| 1782 | } |
| 1783 | |
| 1784 | OS.indent(4) << getAssumedContextStr() << "\n"; |
| 1785 | |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 1786 | for (const SCEV *Parameter : Parameters) { |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 1787 | int Dim = ParameterIds.find(Parameter)->second; |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 1788 | OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n"; |
| 1789 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1792 | void Scop::printAliasAssumptions(raw_ostream &OS) const { |
| 1793 | OS.indent(4) << "Alias Groups (" << MinMaxAliasGroups.size() << "):\n"; |
| 1794 | if (MinMaxAliasGroups.empty()) { |
| 1795 | OS.indent(8) << "n/a\n"; |
| 1796 | return; |
| 1797 | } |
| 1798 | for (MinMaxVectorTy *MinMaxAccesses : MinMaxAliasGroups) { |
| 1799 | OS.indent(8) << "[["; |
| 1800 | for (MinMaxAccessTy &MinMacAccess : *MinMaxAccesses) |
| 1801 | OS << " <" << MinMacAccess.first << ", " << MinMacAccess.second << ">"; |
| 1802 | OS << " ]]\n"; |
| 1803 | } |
| 1804 | } |
| 1805 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1806 | void Scop::printStatements(raw_ostream &OS) const { |
| 1807 | OS << "Statements {\n"; |
| 1808 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1809 | for (const ScopStmt &Stmt : *this) |
| 1810 | OS.indent(4) << Stmt; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1811 | |
| 1812 | OS.indent(4) << "}\n"; |
| 1813 | } |
| 1814 | |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 1815 | void Scop::printArrayInfo(raw_ostream &OS) const { |
| 1816 | OS << "Arrays {\n"; |
| 1817 | |
Tobias Grosser | ab67144 | 2015-05-23 05:58:27 +0000 | [diff] [blame] | 1818 | for (auto &Array : arrays()) |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 1819 | Array.second->print(OS); |
| 1820 | |
| 1821 | OS.indent(4) << "}\n"; |
| 1822 | } |
| 1823 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1824 | void Scop::print(raw_ostream &OS) const { |
Tobias Grosser | 4eb7ddb | 2014-03-18 18:51:11 +0000 | [diff] [blame] | 1825 | OS.indent(4) << "Function: " << getRegion().getEntry()->getParent()->getName() |
| 1826 | << "\n"; |
Tobias Grosser | 483fdd4 | 2014-03-18 18:05:38 +0000 | [diff] [blame] | 1827 | OS.indent(4) << "Region: " << getNameStr() << "\n"; |
David Peixotto | dc0a11c | 2015-01-13 18:31:55 +0000 | [diff] [blame] | 1828 | OS.indent(4) << "Max Loop Depth: " << getMaxLoopDepth() << "\n"; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1829 | printContext(OS.indent(4)); |
Tobias Grosser | 49ad36c | 2015-05-20 08:05:31 +0000 | [diff] [blame] | 1830 | printArrayInfo(OS.indent(4)); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 1831 | printAliasAssumptions(OS); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1832 | printStatements(OS.indent(4)); |
| 1833 | } |
| 1834 | |
| 1835 | void Scop::dump() const { print(dbgs()); } |
| 1836 | |
Tobias Grosser | 9a38ab8 | 2011-11-08 15:41:03 +0000 | [diff] [blame] | 1837 | isl_ctx *Scop::getIslCtx() const { return IslCtx; } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1838 | |
Tobias Grosser | 5f9a762 | 2012-02-14 14:02:40 +0000 | [diff] [blame] | 1839 | __isl_give isl_union_set *Scop::getDomains() { |
Tobias Grosser | bc4ef90 | 2014-06-28 08:59:38 +0000 | [diff] [blame] | 1840 | isl_union_set *Domain = isl_union_set_empty(getParamSpace()); |
Tobias Grosser | 5f9a762 | 2012-02-14 14:02:40 +0000 | [diff] [blame] | 1841 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1842 | for (ScopStmt &Stmt : *this) |
| 1843 | Domain = isl_union_set_add_set(Domain, Stmt.getDomain()); |
Tobias Grosser | 5f9a762 | 2012-02-14 14:02:40 +0000 | [diff] [blame] | 1844 | |
| 1845 | return Domain; |
| 1846 | } |
| 1847 | |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1848 | __isl_give isl_union_map *Scop::getMustWrites() { |
Tobias Grosser | eeb9f3c | 2015-05-26 21:37:31 +0000 | [diff] [blame] | 1849 | isl_union_map *Write = isl_union_map_empty(getParamSpace()); |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1850 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1851 | for (ScopStmt &Stmt : *this) { |
| 1852 | for (MemoryAccess *MA : Stmt) { |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1853 | if (!MA->isMustWrite()) |
| 1854 | continue; |
| 1855 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1856 | isl_set *Domain = Stmt.getDomain(); |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1857 | isl_map *AccessDomain = MA->getAccessRelation(); |
| 1858 | AccessDomain = isl_map_intersect_domain(AccessDomain, Domain); |
| 1859 | Write = isl_union_map_add_map(Write, AccessDomain); |
| 1860 | } |
| 1861 | } |
| 1862 | return isl_union_map_coalesce(Write); |
| 1863 | } |
| 1864 | |
| 1865 | __isl_give isl_union_map *Scop::getMayWrites() { |
Tobias Grosser | eeb9f3c | 2015-05-26 21:37:31 +0000 | [diff] [blame] | 1866 | isl_union_map *Write = isl_union_map_empty(getParamSpace()); |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1867 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1868 | for (ScopStmt &Stmt : *this) { |
| 1869 | for (MemoryAccess *MA : Stmt) { |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1870 | if (!MA->isMayWrite()) |
| 1871 | continue; |
| 1872 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1873 | isl_set *Domain = Stmt.getDomain(); |
Tobias Grosser | 780ce0f | 2014-07-11 07:12:10 +0000 | [diff] [blame] | 1874 | isl_map *AccessDomain = MA->getAccessRelation(); |
| 1875 | AccessDomain = isl_map_intersect_domain(AccessDomain, Domain); |
| 1876 | Write = isl_union_map_add_map(Write, AccessDomain); |
| 1877 | } |
| 1878 | } |
| 1879 | return isl_union_map_coalesce(Write); |
| 1880 | } |
| 1881 | |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1882 | __isl_give isl_union_map *Scop::getWrites() { |
Tobias Grosser | eeb9f3c | 2015-05-26 21:37:31 +0000 | [diff] [blame] | 1883 | isl_union_map *Write = isl_union_map_empty(getParamSpace()); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1884 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1885 | for (ScopStmt &Stmt : *this) { |
| 1886 | for (MemoryAccess *MA : Stmt) { |
Johannes Doerfert | f675289 | 2014-06-13 18:01:45 +0000 | [diff] [blame] | 1887 | if (!MA->isWrite()) |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1888 | continue; |
| 1889 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1890 | isl_set *Domain = Stmt.getDomain(); |
Johannes Doerfert | f675289 | 2014-06-13 18:01:45 +0000 | [diff] [blame] | 1891 | isl_map *AccessDomain = MA->getAccessRelation(); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1892 | AccessDomain = isl_map_intersect_domain(AccessDomain, Domain); |
| 1893 | Write = isl_union_map_add_map(Write, AccessDomain); |
| 1894 | } |
| 1895 | } |
| 1896 | return isl_union_map_coalesce(Write); |
| 1897 | } |
| 1898 | |
| 1899 | __isl_give isl_union_map *Scop::getReads() { |
Tobias Grosser | bc4ef90 | 2014-06-28 08:59:38 +0000 | [diff] [blame] | 1900 | isl_union_map *Read = isl_union_map_empty(getParamSpace()); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1901 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1902 | for (ScopStmt &Stmt : *this) { |
| 1903 | for (MemoryAccess *MA : Stmt) { |
Johannes Doerfert | f675289 | 2014-06-13 18:01:45 +0000 | [diff] [blame] | 1904 | if (!MA->isRead()) |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1905 | continue; |
| 1906 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1907 | isl_set *Domain = Stmt.getDomain(); |
Johannes Doerfert | f675289 | 2014-06-13 18:01:45 +0000 | [diff] [blame] | 1908 | isl_map *AccessDomain = MA->getAccessRelation(); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1909 | |
| 1910 | AccessDomain = isl_map_intersect_domain(AccessDomain, Domain); |
| 1911 | Read = isl_union_map_add_map(Read, AccessDomain); |
| 1912 | } |
| 1913 | } |
| 1914 | return isl_union_map_coalesce(Read); |
| 1915 | } |
| 1916 | |
| 1917 | __isl_give isl_union_map *Scop::getSchedule() { |
Tobias Grosser | bc4ef90 | 2014-06-28 08:59:38 +0000 | [diff] [blame] | 1918 | isl_union_map *Schedule = isl_union_map_empty(getParamSpace()); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1919 | |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1920 | for (ScopStmt &Stmt : *this) |
| 1921 | Schedule = isl_union_map_add_map(Schedule, Stmt.getSchedule()); |
Tobias Grosser | bc4ef90 | 2014-06-28 08:59:38 +0000 | [diff] [blame] | 1922 | |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1923 | return isl_union_map_coalesce(Schedule); |
| 1924 | } |
| 1925 | |
| 1926 | bool Scop::restrictDomains(__isl_take isl_union_set *Domain) { |
| 1927 | bool Changed = false; |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1928 | for (ScopStmt &Stmt : *this) { |
| 1929 | isl_union_set *StmtDomain = isl_union_set_from_set(Stmt.getDomain()); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1930 | isl_union_set *NewStmtDomain = isl_union_set_intersect( |
| 1931 | isl_union_set_copy(StmtDomain), isl_union_set_copy(Domain)); |
| 1932 | |
| 1933 | if (isl_union_set_is_subset(StmtDomain, NewStmtDomain)) { |
| 1934 | isl_union_set_free(StmtDomain); |
| 1935 | isl_union_set_free(NewStmtDomain); |
| 1936 | continue; |
| 1937 | } |
| 1938 | |
| 1939 | Changed = true; |
| 1940 | |
| 1941 | isl_union_set_free(StmtDomain); |
| 1942 | NewStmtDomain = isl_union_set_coalesce(NewStmtDomain); |
| 1943 | |
| 1944 | if (isl_union_set_is_empty(NewStmtDomain)) { |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1945 | Stmt.restrictDomain(isl_set_empty(Stmt.getDomainSpace())); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1946 | isl_union_set_free(NewStmtDomain); |
| 1947 | } else |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1948 | Stmt.restrictDomain(isl_set_from_union_set(NewStmtDomain)); |
Tobias Grosser | 37eb422 | 2014-02-20 21:43:54 +0000 | [diff] [blame] | 1949 | } |
| 1950 | isl_union_set_free(Domain); |
| 1951 | return Changed; |
| 1952 | } |
| 1953 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1954 | ScalarEvolution *Scop::getSE() const { return SE; } |
| 1955 | |
| 1956 | bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) { |
| 1957 | if (tempScop.getAccessFunctions(BB)) |
| 1958 | return false; |
| 1959 | |
| 1960 | return true; |
| 1961 | } |
| 1962 | |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1963 | void Scop::addScopStmt(BasicBlock *BB, Region *R, TempScop &tempScop, |
| 1964 | const Region &CurRegion, |
| 1965 | SmallVectorImpl<Loop *> &NestLoops, |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1966 | SmallVectorImpl<unsigned> &ScheduleVec) { |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1967 | if (BB) { |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1968 | Stmts.emplace_back(*this, tempScop, CurRegion, *BB, NestLoops, ScheduleVec); |
| 1969 | StmtMap[BB] = &Stmts.back(); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1970 | } else { |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1971 | assert(R && "Either basic block or a region expected."); |
| 1972 | Stmts.emplace_back(*this, tempScop, CurRegion, *R, NestLoops, ScheduleVec); |
| 1973 | auto *Ptr = &Stmts.back(); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1974 | for (BasicBlock *BB : R->blocks()) |
Tobias Grosser | 7c3bad5 | 2015-05-27 05:16:57 +0000 | [diff] [blame] | 1975 | StmtMap[BB] = Ptr; |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1978 | // Increasing the Schedule function is OK for the moment, because |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1979 | // we are using a depth first iterator and the program is well structured. |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1980 | ++ScheduleVec[NestLoops.size()]; |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 1983 | void Scop::buildScop(TempScop &tempScop, const Region &CurRegion, |
| 1984 | SmallVectorImpl<Loop *> &NestLoops, |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1985 | SmallVectorImpl<unsigned> &ScheduleVec, LoopInfo &LI, |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1986 | ScopDetection &SD) { |
| 1987 | if (SD.isNonAffineSubRegion(&CurRegion, &getRegion())) |
| 1988 | return addScopStmt(nullptr, const_cast<Region *>(&CurRegion), tempScop, |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1989 | CurRegion, NestLoops, ScheduleVec); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 1990 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1991 | Loop *L = castToLoop(CurRegion, LI); |
| 1992 | |
| 1993 | if (L) |
| 1994 | NestLoops.push_back(L); |
| 1995 | |
| 1996 | unsigned loopDepth = NestLoops.size(); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 1997 | assert(ScheduleVec.size() > loopDepth && "Schedule not big enough!"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1998 | |
| 1999 | for (Region::const_element_iterator I = CurRegion.element_begin(), |
Tobias Grosser | abfbe63 | 2013-02-05 12:09:06 +0000 | [diff] [blame] | 2000 | E = CurRegion.element_end(); |
| 2001 | I != E; ++I) |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 2002 | if (I->isSubRegion()) { |
Tobias Grosser | 654af8f | 2015-04-21 11:42:01 +0000 | [diff] [blame] | 2003 | buildScop(tempScop, *I->getNodeAs<Region>(), NestLoops, ScheduleVec, LI, |
| 2004 | SD); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 2005 | } else { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2006 | BasicBlock *BB = I->getNodeAs<BasicBlock>(); |
| 2007 | |
| 2008 | if (isTrivialBB(BB, tempScop)) |
| 2009 | continue; |
| 2010 | |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 2011 | addScopStmt(BB, nullptr, tempScop, CurRegion, NestLoops, ScheduleVec); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | if (!L) |
| 2015 | return; |
| 2016 | |
| 2017 | // Exiting a loop region. |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 2018 | ScheduleVec[loopDepth] = 0; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2019 | NestLoops.pop_back(); |
Tobias Grosser | 5483931 | 2015-04-21 11:37:25 +0000 | [diff] [blame] | 2020 | ++ScheduleVec[loopDepth - 1]; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Johannes Doerfert | 7c49421 | 2014-10-31 23:13:39 +0000 | [diff] [blame] | 2023 | ScopStmt *Scop::getStmtForBasicBlock(BasicBlock *BB) const { |
Tobias Grosser | 57411e3 | 2015-05-27 06:51:34 +0000 | [diff] [blame^] | 2024 | auto StmtMapIt = StmtMap.find(BB); |
Johannes Doerfert | 7c49421 | 2014-10-31 23:13:39 +0000 | [diff] [blame] | 2025 | if (StmtMapIt == StmtMap.end()) |
| 2026 | return nullptr; |
| 2027 | return StmtMapIt->second; |
| 2028 | } |
| 2029 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2030 | //===----------------------------------------------------------------------===// |
Tobias Grosser | b76f3853 | 2011-08-20 11:11:25 +0000 | [diff] [blame] | 2031 | ScopInfo::ScopInfo() : RegionPass(ID), scop(0) { |
| 2032 | ctx = isl_ctx_alloc(); |
Tobias Grosser | 4a8e356 | 2011-12-07 07:42:51 +0000 | [diff] [blame] | 2033 | isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT); |
Tobias Grosser | b76f3853 | 2011-08-20 11:11:25 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | ScopInfo::~ScopInfo() { |
| 2037 | clear(); |
| 2038 | isl_ctx_free(ctx); |
| 2039 | } |
| 2040 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2041 | void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const { |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 2042 | AU.addRequired<LoopInfoWrapperPass>(); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 2043 | AU.addRequired<RegionInfoPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2044 | AU.addRequired<ScalarEvolution>(); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 2045 | AU.addRequired<ScopDetection>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2046 | AU.addRequired<TempScopInfo>(); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 2047 | AU.addRequired<AliasAnalysis>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2048 | AU.setPreservesAll(); |
| 2049 | } |
| 2050 | |
| 2051 | bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) { |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 2052 | LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 2053 | AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 2054 | ScopDetection &SD = getAnalysis<ScopDetection>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2055 | ScalarEvolution &SE = getAnalysis<ScalarEvolution>(); |
| 2056 | |
| 2057 | TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R); |
| 2058 | |
| 2059 | // This region is no Scop. |
| 2060 | if (!tempScop) { |
Tobias Grosser | c98a8fc | 2014-11-14 11:12:31 +0000 | [diff] [blame] | 2061 | scop = nullptr; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2062 | return false; |
| 2063 | } |
| 2064 | |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 2065 | scop = new Scop(*tempScop, LI, SE, SD, ctx); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2066 | |
Johannes Doerfert | 21aa3dc | 2014-11-01 01:30:11 +0000 | [diff] [blame] | 2067 | if (!PollyUseRuntimeAliasChecks) { |
| 2068 | // Statistics. |
| 2069 | ++ScopFound; |
| 2070 | if (scop->getMaxLoopDepth() > 0) |
| 2071 | ++RichScopFound; |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 2072 | return false; |
Johannes Doerfert | 21aa3dc | 2014-11-01 01:30:11 +0000 | [diff] [blame] | 2073 | } |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 2074 | |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 2075 | // If a problem occurs while building the alias groups we need to delete |
| 2076 | // this SCoP and pretend it wasn't valid in the first place. |
Johannes Doerfert | 21aa3dc | 2014-11-01 01:30:11 +0000 | [diff] [blame] | 2077 | if (scop->buildAliasGroups(AA)) { |
| 2078 | // Statistics. |
| 2079 | ++ScopFound; |
| 2080 | if (scop->getMaxLoopDepth() > 0) |
| 2081 | ++RichScopFound; |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 2082 | return false; |
Johannes Doerfert | 21aa3dc | 2014-11-01 01:30:11 +0000 | [diff] [blame] | 2083 | } |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 2084 | |
| 2085 | DEBUG(dbgs() |
| 2086 | << "\n\nNOTE: Run time checks for " << scop->getNameStr() |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 2087 | << " could not be created as the number of parameters involved is too " |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 2088 | "high. The SCoP will be " |
| 2089 | "dismissed.\nUse:\n\t--polly-rtc-max-parameters=X\nto adjust the " |
Johannes Doerfert | 6cad9c4 | 2015-02-24 16:00:29 +0000 | [diff] [blame] | 2090 | "maximal number of parameters but be advised that the compile time " |
Johannes Doerfert | 9143d67 | 2014-09-27 11:02:39 +0000 | [diff] [blame] | 2091 | "might increase exponentially.\n\n"); |
| 2092 | |
| 2093 | delete scop; |
| 2094 | scop = nullptr; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 2095 | return false; |
| 2096 | } |
| 2097 | |
| 2098 | char ScopInfo::ID = 0; |
| 2099 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 2100 | Pass *polly::createScopInfoPass() { return new ScopInfo(); } |
| 2101 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 2102 | INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops", |
| 2103 | "Polly - Create polyhedral description of Scops", false, |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 2104 | false); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 2105 | INITIALIZE_AG_DEPENDENCY(AliasAnalysis); |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 2106 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 2107 | INITIALIZE_PASS_DEPENDENCY(RegionInfoPass); |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 2108 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolution); |
Johannes Doerfert | ff9d198 | 2015-02-24 12:00:50 +0000 | [diff] [blame] | 2109 | INITIALIZE_PASS_DEPENDENCY(ScopDetection); |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 2110 | INITIALIZE_PASS_DEPENDENCY(TempScopInfo); |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 2111 | INITIALIZE_PASS_END(ScopInfo, "polly-scops", |
| 2112 | "Polly - Create polyhedral description of Scops", false, |
| 2113 | false) |