Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 1 | |
| 2 | #include "polly/Support/SCEVValidator.h" |
| 3 | |
| 4 | #include "llvm/Analysis/ScalarEvolution.h" |
| 5 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
| 6 | #include "llvm/Analysis/RegionInfo.h" |
| 7 | |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 10 | using namespace llvm; |
| 11 | |
| 12 | namespace SCEVType { |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 13 | /// @brief The type of a SCEV |
| 14 | /// |
| 15 | /// To check for the validity of a SCEV we assign to each SCEV a type. The |
| 16 | /// possible types are INT, PARAM, IV and INVALID. The order of the types is |
| 17 | /// important. The subexpressions of SCEV with a type X can only have a type |
| 18 | /// that is smaller or equal than X. |
| 19 | enum TYPE { |
| 20 | // An integer value. |
| 21 | INT, |
| 22 | |
| 23 | // An expression that is constant during the execution of the Scop, |
| 24 | // but that may depend on parameters unknown at compile time. |
| 25 | PARAM, |
| 26 | |
| 27 | // An expression that may change during the execution of the SCoP. |
| 28 | IV, |
| 29 | |
| 30 | // An invalid expression. |
| 31 | INVALID |
| 32 | }; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 35 | /// @brief The result the validator returns for a SCEV expression. |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 36 | class ValidatorResult { |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 37 | /// @brief The type of the expression |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 38 | SCEVType::TYPE Type; |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 39 | |
| 40 | /// @brief The set of Parameters in the expression. |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 41 | std::vector<const SCEV*> Parameters; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 42 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 43 | public: |
| 44 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 45 | /// @brief Create an invalid result. |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 46 | ValidatorResult() : Type(SCEVType::INVALID) {}; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 47 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 48 | /// @brief The copy constructor |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 49 | ValidatorResult(const ValidatorResult &Source) { |
| 50 | Type = Source.Type; |
| 51 | Parameters = Source.Parameters; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 54 | /// @brief Construct a result with a certain type and no parameters. |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 55 | ValidatorResult(SCEVType::TYPE Type) : Type(Type) {}; |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 56 | |
| 57 | /// @brief Construct a result with a certain type and a single parameter. |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 58 | ValidatorResult(SCEVType::TYPE Type, const SCEV *Expr) : Type(Type) { |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 59 | Parameters.push_back(Expr); |
| 60 | }; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 61 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 62 | /// @brief Is the analyzed SCEV constant during the execution of the SCoP. |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 63 | bool isConstant() { |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 64 | return Type == SCEVType::INT || Type == SCEVType::PARAM; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 67 | /// @brief Is the analyzed SCEV valid. |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 68 | bool isValid() { |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 69 | return Type != SCEVType::INVALID; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 72 | /// @brief Is the analyzed SCEV of Type IV. |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 73 | bool isIV() { |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 74 | return Type == SCEVType::IV; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 77 | /// @brief Is the analyzed SCEV of Type INT. |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 78 | bool isINT() { |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 79 | return Type == SCEVType::INT; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 80 | } |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 81 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 82 | /// @brief Get the parameters of this validator result. |
| 83 | std::vector<const SCEV*> getParameters() { |
| 84 | return Parameters; |
| 85 | } |
| 86 | |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 87 | /// @brief Add the parameters of Source to this result. |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 88 | void addParamsFrom(class ValidatorResult &Source) { |
Tobias Grosser | b1f07c5 | 2011-11-17 12:56:17 +0000 | [diff] [blame] | 89 | Parameters.insert(Parameters.end(), |
| 90 | Source.Parameters.begin(), |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 91 | Source.Parameters.end()); |
| 92 | } |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 93 | |
| 94 | /// @brief Merge a result. |
| 95 | /// |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 96 | /// This means to merge the parameters and to set the Type to the most |
| 97 | /// specific Type that matches both. |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 98 | void merge(class ValidatorResult &ToMerge) { |
Tobias Grosser | edb8a28 | 2011-11-17 12:56:21 +0000 | [diff] [blame^] | 99 | Type = std::max(Type, ToMerge.Type); |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 100 | addParamsFrom(ToMerge); |
| 101 | } |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /// Check if a SCEV is valid in a SCoP. |
| 105 | struct SCEVValidator |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 106 | : public SCEVVisitor<SCEVValidator, class ValidatorResult> { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 107 | private: |
| 108 | const Region *R; |
| 109 | ScalarEvolution &SE; |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 110 | const Value *BaseAddress; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 111 | |
| 112 | public: |
| 113 | SCEVValidator(const Region *R, ScalarEvolution &SE, |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 114 | const Value *BaseAddress) : R(R), SE(SE), |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 115 | BaseAddress(BaseAddress) {}; |
| 116 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 117 | class ValidatorResult visitConstant(const SCEVConstant *Constant) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 118 | return ValidatorResult(SCEVType::INT); |
| 119 | } |
| 120 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 121 | class ValidatorResult visitTruncateExpr(const SCEVTruncateExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 122 | ValidatorResult Op = visit(Expr->getOperand()); |
| 123 | |
| 124 | // We currently do not represent a truncate expression as an affine |
| 125 | // expression. If it is constant during Scop execution, we treat it as a |
| 126 | // parameter, otherwise we bail out. |
| 127 | if (Op.isConstant()) |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 128 | return ValidatorResult(SCEVType::PARAM, Expr); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 129 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 130 | return ValidatorResult(SCEVType::INVALID); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 133 | class ValidatorResult visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 134 | ValidatorResult Op = visit(Expr->getOperand()); |
| 135 | |
| 136 | // We currently do not represent a zero extend expression as an affine |
| 137 | // expression. If it is constant during Scop execution, we treat it as a |
| 138 | // parameter, otherwise we bail out. |
| 139 | if (Op.isConstant()) |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 140 | return ValidatorResult(SCEVType::PARAM, Expr); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 141 | |
| 142 | return ValidatorResult(SCEVType::INVALID); |
| 143 | } |
| 144 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 145 | class ValidatorResult visitSignExtendExpr(const SCEVSignExtendExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 146 | // We currently allow only signed SCEV expressions. In the case of a |
| 147 | // signed value, a sign extend is a noop. |
| 148 | // |
| 149 | // TODO: Reconsider this when we add support for unsigned values. |
| 150 | return visit(Expr->getOperand()); |
| 151 | } |
| 152 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 153 | class ValidatorResult visitAddExpr(const SCEVAddExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 154 | ValidatorResult Return(SCEVType::INT); |
| 155 | |
| 156 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 157 | ValidatorResult Op = visit(Expr->getOperand(i)); |
| 158 | |
| 159 | if (!Op.isValid()) |
| 160 | return ValidatorResult(SCEVType::INVALID); |
| 161 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 162 | Return.merge(Op); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | // TODO: Check for NSW and NUW. |
| 166 | return Return; |
| 167 | } |
| 168 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 169 | class ValidatorResult visitMulExpr(const SCEVMulExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 170 | ValidatorResult Return(SCEVType::INT); |
| 171 | |
| 172 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 173 | ValidatorResult Op = visit(Expr->getOperand(i)); |
| 174 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 175 | if (Op.isINT()) |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 176 | continue; |
| 177 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 178 | if (!Op.isValid() || !Return.isINT()) |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 179 | return ValidatorResult(SCEVType::INVALID); |
| 180 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 181 | Return.merge(Op); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // TODO: Check for NSW and NUW. |
| 185 | return Return; |
| 186 | } |
| 187 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 188 | class ValidatorResult visitUDivExpr(const SCEVUDivExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 189 | ValidatorResult LHS = visit(Expr->getLHS()); |
| 190 | ValidatorResult RHS = visit(Expr->getRHS()); |
| 191 | |
Tobias Grosser | 2a7cd94 | 2011-11-17 12:56:12 +0000 | [diff] [blame] | 192 | // We currently do not represent an unsigned devision as an affine |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 193 | // expression. If the division is constant during Scop execution we treat it |
| 194 | // as a parameter, otherwise we bail out. |
| 195 | if (LHS.isConstant() && RHS.isConstant()) |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 196 | return ValidatorResult(SCEVType::PARAM, Expr); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 197 | |
| 198 | return ValidatorResult(SCEVType::INVALID); |
| 199 | } |
| 200 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 201 | class ValidatorResult visitAddRecExpr(const SCEVAddRecExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 202 | if (!Expr->isAffine()) |
| 203 | return ValidatorResult(SCEVType::INVALID); |
| 204 | |
| 205 | ValidatorResult Start = visit(Expr->getStart()); |
| 206 | ValidatorResult Recurrence = visit(Expr->getStepRecurrence(SE)); |
| 207 | |
Tobias Grosser | bcc0a0d | 2011-11-17 12:56:14 +0000 | [diff] [blame] | 208 | if (!Start.isValid() || !Recurrence.isConstant()) |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 209 | return ValidatorResult(SCEVType::INVALID); |
| 210 | |
Tobias Grosser | bcc0a0d | 2011-11-17 12:56:14 +0000 | [diff] [blame] | 211 | if (R->contains(Expr->getLoop())) { |
| 212 | if (Recurrence.isINT()) { |
| 213 | ValidatorResult Result(SCEVType::IV); |
| 214 | Result.addParamsFrom(Start); |
| 215 | return Result; |
| 216 | } |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 217 | |
Tobias Grosser | bcc0a0d | 2011-11-17 12:56:14 +0000 | [diff] [blame] | 218 | return ValidatorResult(SCEVType::INVALID); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Tobias Grosser | bcc0a0d | 2011-11-17 12:56:14 +0000 | [diff] [blame] | 221 | if (Start.isConstant()) |
| 222 | return ValidatorResult(SCEVType::PARAM, Expr); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 223 | |
Tobias Grosser | bcc0a0d | 2011-11-17 12:56:14 +0000 | [diff] [blame] | 224 | return ValidatorResult(SCEVType::INVALID); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 227 | class ValidatorResult visitSMaxExpr(const SCEVSMaxExpr *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 228 | ValidatorResult Return(SCEVType::INT); |
| 229 | |
| 230 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 231 | ValidatorResult Op = visit(Expr->getOperand(i)); |
| 232 | |
| 233 | if (!Op.isValid()) |
| 234 | return ValidatorResult(SCEVType::INVALID); |
| 235 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 236 | Return.merge(Op); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | return Return; |
| 240 | } |
| 241 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 242 | class ValidatorResult visitUMaxExpr(const SCEVUMaxExpr *Expr) { |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 243 | ValidatorResult Return(SCEVType::PARAM); |
| 244 | |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 245 | // We do not support unsigned operations. If 'Expr' is constant during Scop |
| 246 | // execution we treat this as a parameter, otherwise we bail out. |
| 247 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 248 | ValidatorResult Op = visit(Expr->getOperand(i)); |
| 249 | |
| 250 | if (!Op.isConstant()) |
| 251 | return ValidatorResult(SCEVType::INVALID); |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 252 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 253 | Return.merge(Op); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 256 | return Return; |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Tobias Grosser | 7ffe4e8 | 2011-11-17 12:56:10 +0000 | [diff] [blame] | 259 | ValidatorResult visitUnknown(const SCEVUnknown *Expr) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 260 | Value *V = Expr->getValue(); |
| 261 | |
| 262 | if (isa<UndefValue>(V)) |
| 263 | return ValidatorResult(SCEVType::INVALID); |
| 264 | |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 265 | if (Instruction *I = dyn_cast<Instruction>(Expr->getValue())) |
| 266 | if (R->contains(I)) |
| 267 | return ValidatorResult(SCEVType::INVALID); |
| 268 | |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 269 | if (BaseAddress == V) |
| 270 | return ValidatorResult(SCEVType::INVALID); |
| 271 | |
| 272 | return ValidatorResult(SCEVType::PARAM, Expr); |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 273 | } |
| 274 | }; |
| 275 | |
| 276 | namespace polly { |
| 277 | bool isAffineExpr(const Region *R, const SCEV *Expr, ScalarEvolution &SE, |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 278 | const Value *BaseAddress) { |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 279 | if (isa<SCEVCouldNotCompute>(Expr)) |
| 280 | return false; |
| 281 | |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 282 | SCEVValidator Validator(R, SE, BaseAddress); |
| 283 | ValidatorResult Result = Validator.visit(Expr); |
| 284 | |
| 285 | return Result.isValid(); |
| 286 | } |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 287 | |
| 288 | std::vector<const SCEV*> getParamsInAffineExpr(const Region *R, |
| 289 | const SCEV *Expr, |
| 290 | ScalarEvolution &SE, |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 291 | const Value *BaseAddress) { |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 292 | if (isa<SCEVCouldNotCompute>(Expr)) |
| 293 | return std::vector<const SCEV*>(); |
| 294 | |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 295 | SCEVValidator Validator(R, SE, BaseAddress); |
| 296 | ValidatorResult Result = Validator.visit(Expr); |
| 297 | |
Tobias Grosser | fa043f0 | 2011-11-17 12:56:19 +0000 | [diff] [blame] | 298 | return Result.getParameters(); |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 299 | } |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | |