blob: f46b155e228f6dec5c4defd8d8786514b8efdbf1 [file] [log] [blame]
Tobias Grosser75805372011-04-29 06:27:02 +00001//===--------- 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//
15// This represantation is shared among several tools in the polyhedral
16// community, which are e.g. Cloog, Pluto, Loopo, Graphite.
17//
18//===----------------------------------------------------------------------===//
19
20#include "polly/ScopInfo.h"
21
22#include "polly/TempScopInfo.h"
23#include "polly/LinkAllPasses.h"
24#include "polly/Support/GICHelper.h"
25#include "polly/Support/ScopHelper.h"
26
27#include "llvm/Analysis/LoopInfo.h"
28#include "llvm/Analysis/ScalarEvolutionExpressions.h"
29#include "llvm/Analysis/RegionIterator.h"
30#include "llvm/Assembly/Writer.h"
31#include "llvm/ADT/Statistic.h"
32#include "llvm/ADT/SetVector.h"
33#include "llvm/Support/CommandLine.h"
34
35#define DEBUG_TYPE "polly-scops"
36#include "llvm/Support/Debug.h"
37
38#include "isl/constraint.h"
39#include "isl/set.h"
40#include "isl/map.h"
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000041#include "isl/aff.h"
42#include "isl/printer.h"
Tobias Grosser75805372011-04-29 06:27:02 +000043#include <sstream>
44#include <string>
45#include <vector>
46
47using namespace llvm;
48using namespace polly;
49
50STATISTIC(ScopFound, "Number of valid Scops");
51STATISTIC(RichScopFound, "Number of Scops containing a loop");
52
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000053/// Convert an int into a string.
54static std::string convertInt(int number)
55{
56 if (number == 0)
57 return "0";
58 std::string temp = "";
59 std::string returnvalue = "";
60 while (number > 0)
61 {
62 temp += number % 10 + 48;
63 number /= 10;
64 }
65 for (unsigned i = 0; i < temp.length(); i++)
66 returnvalue+=temp[temp.length() - i - 1];
67 return returnvalue;
Tobias Grosser75805372011-04-29 06:27:02 +000068}
69
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000070/// Translate a SCEVExpression into an isl_pw_aff object.
71struct SCEVAffinator : public SCEVVisitor<SCEVAffinator, isl_pw_aff*> {
72private:
73 isl_ctx *ctx;
74 int NbLoopDims;
75 const Scop *scop;
76
77 /// baseAdress is set if we analyze a memory access. It holds the base address
78 /// of this memory access.
79 const Value *baseAddress;
80
81public:
82 static isl_pw_aff *getPwAff(const ScopStmt *stmt, const SCEV *scev,
83 const Value *baseAddress) {
84 SCEVAffinator Affinator(stmt, baseAddress);
85 return Affinator.visit(scev);
86 }
87
88 isl_pw_aff *visit(const SCEV *scev) {
89 // In case the scev is contained in our list of parameters, we do not
90 // further analyze this expression, but create a new parameter in the
91 // isl_pw_aff. This allows us to treat subexpressions that we cannot
92 // translate into an piecewise affine expression, as constant parameters of
93 // the piecewise affine expression.
94 int i = 0;
95 for (Scop::const_param_iterator PI = scop->param_begin(),
96 PE = scop->param_end(); PI != PE; ++PI) {
97 if (*PI == scev) {
98 isl_id *ID = isl_id_alloc(ctx, ("p" + convertInt(i)).c_str(),
99 (void *) scev);
100 isl_dim *Dim = isl_dim_set_alloc(ctx, 1, NbLoopDims);
101 Dim = isl_dim_set_dim_id(Dim, isl_dim_param, 0, ID);
102
103 isl_set *Domain = isl_set_universe(isl_dim_copy(Dim));
104 isl_aff *Affine = isl_aff_zero(isl_local_space_from_dim(Dim));
105 Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
106
107 return isl_pw_aff_alloc(Domain, Affine);
108 }
109 i++;
110 }
111
112 return SCEVVisitor<SCEVAffinator, isl_pw_aff*>::visit(scev);
113 }
114
115 SCEVAffinator(const ScopStmt *stmt, const Value *baseAddress) :
116 ctx(stmt->getParent()->getCtx()),
117 NbLoopDims(stmt->getNumIterators()),
118 scop(stmt->getParent()),
119 baseAddress(baseAddress) {};
120
121 __isl_give isl_pw_aff *visitConstant(const SCEVConstant *Constant) {
122 ConstantInt *Value = Constant->getValue();
123 isl_int v;
124 isl_int_init(v);
125
126 // LLVM does not define if an integer value is interpreted as a signed or
127 // unsigned value. Hence, without further information, it is unknown how
128 // this value needs to be converted to GMP. At the moment, we only support
129 // signed operations. So we just interpret it as signed. Later, there are
130 // two options:
131 //
132 // 1. We always interpret any value as signed and convert the values on
133 // demand.
134 // 2. We pass down the signedness of the calculation and use it to interpret
135 // this constant correctly.
136 MPZ_from_APInt(v, Value->getValue(), /* isSigned */ true);
137
138 isl_dim *dim = isl_dim_set_alloc(ctx, 0, NbLoopDims);
139 isl_local_space *ls = isl_local_space_from_dim(isl_dim_copy(dim));
140 isl_aff *Affine = isl_aff_zero(ls);
141 isl_set *Domain = isl_set_universe(dim);
142
143 Affine = isl_aff_add_constant(Affine, v);
144 isl_int_clear(v);
145
146 return isl_pw_aff_alloc(Domain, Affine);
147 }
148
149 __isl_give isl_pw_aff *visitTruncateExpr(const SCEVTruncateExpr* Expr) {
150 assert(0 && "Not yet supported");
151 }
152
153 __isl_give isl_pw_aff *visitZeroExtendExpr(const SCEVZeroExtendExpr * Expr) {
154 assert(0 && "Not yet supported");
155 }
156
157 __isl_give isl_pw_aff *visitSignExtendExpr(const SCEVSignExtendExpr* Expr) {
158 // Assuming the value is signed, a sign extension is basically a noop.
159 // TODO: Reconsider this as soon as we support unsigned values.
160 return visit(Expr->getOperand());
161 }
162
163 __isl_give isl_pw_aff *visitAddExpr(const SCEVAddExpr* Expr) {
164 isl_pw_aff *Sum = visit(Expr->getOperand(0));
165
166 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
167 isl_pw_aff *NextSummand = visit(Expr->getOperand(i));
168 Sum = isl_pw_aff_add(Sum, NextSummand);
169 }
170
171 // TODO: Check for NSW and NUW.
172
173 return Sum;
174 }
175
176 __isl_give isl_pw_aff *visitMulExpr(const SCEVMulExpr* Expr) {
177 isl_pw_aff *Product = visit(Expr->getOperand(0));
178
179 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
180 isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
181
182 if (!isl_pw_aff_is_cst(Product) && !isl_pw_aff_is_cst(NextOperand)) {
183 isl_pw_aff_free(Product);
184 isl_pw_aff_free(NextOperand);
185 return NULL;
186 }
187
188 Product = isl_pw_aff_mul(Product, NextOperand);
189 }
190
191 // TODO: Check for NSW and NUW.
192 return Product;
193 }
194
195 __isl_give isl_pw_aff *visitUDivExpr(const SCEVUDivExpr* Expr) {
196 assert(0 && "Not yet supported");
197 }
198
199 int getLoopDepth(const Loop *L) {
200 Loop *outerLoop =
201 scop->getRegion().outermostLoopInRegion(const_cast<Loop*>(L));
202 return L->getLoopDepth() - outerLoop->getLoopDepth();
203 }
204
205 __isl_give isl_pw_aff *visitAddRecExpr(const SCEVAddRecExpr* Expr) {
206 assert(Expr->isAffine() && "Only affine AddRecurrences allowed");
207
208 isl_pw_aff *Start = visit(Expr->getStart());
209 isl_pw_aff *Step = visit(Expr->getOperand(1));
210 isl_dim *Dim = isl_dim_set_alloc (ctx, 0, NbLoopDims);
211 isl_local_space *LocalSpace = isl_local_space_from_dim (Dim);
212
213 int loopDimension = getLoopDepth(Expr->getLoop());
214
215 isl_aff *LAff = isl_aff_set_coefficient_si (isl_aff_zero (LocalSpace),
216 isl_dim_set, loopDimension, 1);
217 isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff);
218
219 // TODO: Do we need to check for NSW and NUW?
220 return isl_pw_aff_add(Start, isl_pw_aff_mul(Step, LPwAff));
221 }
222
223 __isl_give isl_pw_aff *visitSMaxExpr(const SCEVSMaxExpr* Expr) {
224 isl_pw_aff *Max = visit(Expr->getOperand(0));
225
226 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
227 isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
228 Max = isl_pw_aff_max(Max, NextOperand);
229 }
230
231 return Max;
232 }
233
234 __isl_give isl_pw_aff *visitUMaxExpr(const SCEVUMaxExpr* Expr) {
235 assert(0 && "Not yet supported");
236 }
237
238 __isl_give isl_pw_aff *visitUnknown(const SCEVUnknown* Expr) {
239 Value *Value = Expr->getValue();
240
241 isl_dim *Dim;
242
243 /// If baseAddress is set, we ignore its Value object in the scev and do not
244 /// add it to the isl_pw_aff. This is because it is regarded as defining the
245 /// name of an array, in contrast to its array subscript.
246 if (baseAddress != Value) {
247 isl_id *ID = isl_id_alloc(ctx, Value->getNameStr().c_str(), Value);
248 Dim = isl_dim_set_alloc(ctx, 1, NbLoopDims);
249 Dim = isl_dim_set_dim_id(Dim, isl_dim_param, 0, ID);
250 } else {
251 Dim = isl_dim_set_alloc(ctx, 0, NbLoopDims);
252 }
253
254 isl_set *Domain = isl_set_universe(isl_dim_copy(Dim));
255 isl_aff *Affine = isl_aff_zero(isl_local_space_from_dim(Dim));
256
257 if (baseAddress != Value)
258 Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
259
260 return isl_pw_aff_alloc(Domain, Affine);
261 }
262};
263
Tobias Grosser75805372011-04-29 06:27:02 +0000264//===----------------------------------------------------------------------===//
265
266MemoryAccess::~MemoryAccess() {
Tobias Grosser54a86e62011-08-18 06:31:46 +0000267 isl_map_free(AccessRelation);
Raghesh Aloor129e8672011-08-15 02:33:39 +0000268 isl_map_free(newAccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000269}
270
271static void replace(std::string& str, const std::string& find,
272 const std::string& replace) {
273 size_t pos = 0;
274 while((pos = str.find(find, pos)) != std::string::npos)
275 {
276 str.replace(pos, find.length(), replace);
277 pos += replace.length();
278 }
279}
280
281static void makeIslCompatible(std::string& str) {
Tobias Grossereec4d56e2011-08-20 11:11:14 +0000282 str.erase(0, 1);
Tobias Grosser75805372011-04-29 06:27:02 +0000283 replace(str, ".", "_");
Tobias Grosser3b660f82011-08-03 00:12:11 +0000284 replace(str, "\"", "_");
Tobias Grosser75805372011-04-29 06:27:02 +0000285}
286
287void MemoryAccess::setBaseName() {
288 raw_string_ostream OS(BaseName);
289 WriteAsOperand(OS, getBaseAddr(), false);
290 BaseName = OS.str();
291
Tobias Grosser75805372011-04-29 06:27:02 +0000292 makeIslCompatible(BaseName);
293 BaseName = "MemRef_" + BaseName;
294}
295
296std::string MemoryAccess::getAccessFunctionStr() const {
297 return stringFromIslObj(getAccessFunction());
298}
299
300isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000301 isl_dim *dim = isl_dim_alloc(Statement->getIslContext(), 0,
Tobias Grosser75805372011-04-29 06:27:02 +0000302 Statement->getNumIterators(), 1);
303 setBaseName();
304
305 dim = isl_dim_set_tuple_name(dim, isl_dim_out, getBaseName().c_str());
306 dim = isl_dim_set_tuple_name(dim, isl_dim_in, Statement->getBaseName());
307
308 return isl_basic_map_universe(dim);
309}
310
311MemoryAccess::MemoryAccess(const SCEVAffFunc &AffFunc, ScopStmt *Statement) {
Raghesh Aloor3cb66282011-07-12 17:14:03 +0000312 newAccessRelation = NULL;
Tobias Grosser75805372011-04-29 06:27:02 +0000313 BaseAddr = AffFunc.getBaseAddr();
314 Type = AffFunc.isRead() ? Read : Write;
315 statement = Statement;
316
317 setBaseName();
318
Tobias Grosser7d4cee42011-08-19 23:34:28 +0000319 isl_pw_aff *Affine = SCEVAffinator::getPwAff(Statement, AffFunc.OriginalSCEV,
320 AffFunc.getBaseAddr());
Tobias Grosser75805372011-04-29 06:27:02 +0000321
Tobias Grosser7d4cee42011-08-19 23:34:28 +0000322 // Devide the access function by the size of the elements in the array.
323 //
324 // A stride one array access in C expressed as A[i] is expressed in LLVM-IR
325 // as something like A[i * elementsize]. This hides the fact that two
326 // subsequent values of 'i' index two values that are stored next to each
327 // other in memory. By this devision we make this characteristic obvious
328 // again.
Tobias Grosser75805372011-04-29 06:27:02 +0000329 isl_int v;
330 isl_int_init(v);
Tobias Grosser75805372011-04-29 06:27:02 +0000331 isl_int_set_si(v, AffFunc.getElemSizeInBytes());
Tobias Grosser7d4cee42011-08-19 23:34:28 +0000332 Affine = isl_pw_aff_scale_down(Affine, v);
333 isl_int_clear(v);
Tobias Grosser75805372011-04-29 06:27:02 +0000334
Tobias Grosser7d4cee42011-08-19 23:34:28 +0000335 AccessRelation = isl_map_from_pw_aff(Affine);
336 AccessRelation = isl_map_set_tuple_name(AccessRelation, isl_dim_in,
337 Statement->getBaseName());
Tobias Grosser75805372011-04-29 06:27:02 +0000338 AccessRelation = isl_map_set_tuple_name(AccessRelation, isl_dim_out,
339 getBaseName().c_str());
Tobias Grosser30b8a092011-08-18 07:51:37 +0000340
Tobias Grosser7d4cee42011-08-19 23:34:28 +0000341 isl_dim *Model = isl_set_get_dim(Statement->getParent()->getContext());
342 AccessRelation = isl_map_align_params(AccessRelation, Model);
Tobias Grosser75805372011-04-29 06:27:02 +0000343}
344
345MemoryAccess::MemoryAccess(const Value *BaseAddress, ScopStmt *Statement) {
Raghesh Aloor3cb66282011-07-12 17:14:03 +0000346 newAccessRelation = NULL;
Tobias Grosser75805372011-04-29 06:27:02 +0000347 BaseAddr = BaseAddress;
348 Type = Read;
349 statement = Statement;
350
351 isl_basic_map *BasicAccessMap = createBasicAccessMap(Statement);
352 AccessRelation = isl_map_from_basic_map(BasicAccessMap);
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000353 isl_dim *Model = isl_set_get_dim(Statement->getParent()->getContext());
354 AccessRelation = isl_map_align_params(AccessRelation, Model);
Tobias Grosser75805372011-04-29 06:27:02 +0000355}
356
357void MemoryAccess::print(raw_ostream &OS) const {
358 OS.indent(12) << (isRead() ? "Read" : "Write") << "Access := \n";
359 OS.indent(16) << getAccessFunctionStr() << ";\n";
360}
361
362void MemoryAccess::dump() const {
363 print(errs());
364}
365
366// Create a map in the size of the provided set domain, that maps from the
367// one element of the provided set domain to another element of the provided
368// set domain.
369// The mapping is limited to all points that are equal in all but the last
370// dimension and for which the last dimension of the input is strict smaller
371// than the last dimension of the output.
372//
373// getEqualAndLarger(set[i0, i1, ..., iX]):
374//
375// set[i0, i1, ..., iX] -> set[o0, o1, ..., oX]
376// : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1), iX < oX
377//
378static isl_map *getEqualAndLarger(isl_dim *setDomain) {
379 isl_dim *mapDomain = isl_dim_map_from_set(setDomain);
380 isl_basic_map *bmap = isl_basic_map_universe(mapDomain);
381
382 // Set all but the last dimension to be equal for the input and output
383 //
384 // input[i0, i1, ..., iX] -> output[o0, o1, ..., oX]
385 // : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1)
386 for (unsigned i = 0; i < isl_basic_map_n_in(bmap) - 1; ++i) {
387 isl_int v;
388 isl_int_init(v);
389 isl_constraint *c = isl_equality_alloc(isl_basic_map_get_dim(bmap));
390
391 isl_int_set_si(v, 1);
392 isl_constraint_set_coefficient(c, isl_dim_in, i, v);
393 isl_int_set_si(v, -1);
394 isl_constraint_set_coefficient(c, isl_dim_out, i, v);
395
396 bmap = isl_basic_map_add_constraint(bmap, c);
397
398 isl_int_clear(v);
399 }
400
401 // Set the last dimension of the input to be strict smaller than the
402 // last dimension of the output.
403 //
404 // input[?,?,?,...,iX] -> output[?,?,?,...,oX] : iX < oX
405 //
406 unsigned lastDimension = isl_basic_map_n_in(bmap) - 1;
407 isl_int v;
408 isl_int_init(v);
409 isl_constraint *c = isl_inequality_alloc(isl_basic_map_get_dim(bmap));
410 isl_int_set_si(v, -1);
411 isl_constraint_set_coefficient(c, isl_dim_in, lastDimension, v);
412 isl_int_set_si(v, 1);
413 isl_constraint_set_coefficient(c, isl_dim_out, lastDimension, v);
414 isl_int_set_si(v, -1);
415 isl_constraint_set_constant(c, v);
416 isl_int_clear(v);
417
418 bmap = isl_basic_map_add_constraint(bmap, c);
419
420 return isl_map_from_basic_map(bmap);
421}
422
423isl_set *MemoryAccess::getStride(const isl_set *domainSubset) const {
424 isl_map *accessRelation = isl_map_copy(getAccessFunction());
425 isl_set *scatteringDomain = isl_set_copy(const_cast<isl_set*>(domainSubset));
426 isl_map *scattering = isl_map_copy(getStatement()->getScattering());
427
428 scattering = isl_map_reverse(scattering);
429 int difference = isl_map_n_in(scattering) - isl_set_n_dim(scatteringDomain);
430 scattering = isl_map_project_out(scattering, isl_dim_in,
431 isl_set_n_dim(scatteringDomain),
432 difference);
433
434 // Remove all names of the scattering dimensions, as the names may be lost
435 // anyways during the project. This leads to consistent results.
436 scattering = isl_map_set_tuple_name(scattering, isl_dim_in, "");
437 scatteringDomain = isl_set_set_tuple_name(scatteringDomain, "");
438
439 isl_map *nextScatt = getEqualAndLarger(isl_set_get_dim(scatteringDomain));
440 nextScatt = isl_map_lexmin(nextScatt);
441
442 scattering = isl_map_intersect_domain(scattering, scatteringDomain);
443
444 nextScatt = isl_map_apply_range(nextScatt, isl_map_copy(scattering));
445 nextScatt = isl_map_apply_range(nextScatt, isl_map_copy(accessRelation));
446 nextScatt = isl_map_apply_domain(nextScatt, scattering);
447 nextScatt = isl_map_apply_domain(nextScatt, accessRelation);
448
449 return isl_map_deltas(nextScatt);
450}
451
452bool MemoryAccess::isStrideZero(const isl_set *domainSubset) const {
453 isl_set *stride = getStride(domainSubset);
454 isl_constraint *c = isl_equality_alloc(isl_set_get_dim(stride));
455
456 isl_int v;
457 isl_int_init(v);
458 isl_int_set_si(v, 1);
459 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
460 isl_int_set_si(v, 0);
461 isl_constraint_set_constant(c, v);
462 isl_int_clear(v);
463
464 isl_basic_set *bset = isl_basic_set_universe(isl_set_get_dim(stride));
465
466 bset = isl_basic_set_add_constraint(bset, c);
467 isl_set *strideZero = isl_set_from_basic_set(bset);
468
Tobias Grosserb76f38532011-08-20 11:11:25 +0000469 bool isStrideZero = isl_set_is_equal(stride, strideZero);
470
471 isl_set_free(strideZero);
472 isl_set_free(stride);
473
474 return isStrideZero;
Tobias Grosser75805372011-04-29 06:27:02 +0000475}
476
477bool MemoryAccess::isStrideOne(const isl_set *domainSubset) const {
478 isl_set *stride = getStride(domainSubset);
479 isl_constraint *c = isl_equality_alloc(isl_set_get_dim(stride));
480
481 isl_int v;
482 isl_int_init(v);
483 isl_int_set_si(v, 1);
484 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
485 isl_int_set_si(v, -1);
486 isl_constraint_set_constant(c, v);
487 isl_int_clear(v);
488
489 isl_basic_set *bset = isl_basic_set_universe(isl_set_get_dim(stride));
490
491 bset = isl_basic_set_add_constraint(bset, c);
Tobias Grosserb76f38532011-08-20 11:11:25 +0000492 isl_set *strideOne = isl_set_from_basic_set(bset);
Tobias Grosser75805372011-04-29 06:27:02 +0000493
Tobias Grosserb76f38532011-08-20 11:11:25 +0000494 bool isStrideOne = isl_set_is_equal(stride, strideOne);
495
496 isl_set_free(strideOne);
497 isl_set_free(stride);
498
499 return isStrideOne;
Tobias Grosser75805372011-04-29 06:27:02 +0000500}
501
Raghesh Aloor7a04f4f2011-08-03 13:47:59 +0000502void MemoryAccess::setNewAccessFunction(isl_map *newAccess) {
Tobias Grosserb76f38532011-08-20 11:11:25 +0000503 isl_map_free(newAccessRelation);
Raghesh Aloor7a04f4f2011-08-03 13:47:59 +0000504 newAccessRelation = newAccess;
Raghesh Aloor3cb66282011-07-12 17:14:03 +0000505}
Tobias Grosser75805372011-04-29 06:27:02 +0000506
507//===----------------------------------------------------------------------===//
Tobias Grosserb76f38532011-08-20 11:11:25 +0000508void ScopStmt::setScattering(isl_map *scattering) {
509 isl_map_free(Scattering);
510 Scattering = scattering;
511}
512
Tobias Grosser75805372011-04-29 06:27:02 +0000513void ScopStmt::buildScattering(SmallVectorImpl<unsigned> &Scatter) {
514 unsigned NumberOfIterators = getNumIterators();
515 unsigned ScatDim = Parent.getMaxLoopDepth() * 2 + 1;
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000516 isl_dim *dim = isl_dim_alloc(Parent.getCtx(), 0, NumberOfIterators, ScatDim);
Tobias Grosser75805372011-04-29 06:27:02 +0000517 dim = isl_dim_set_tuple_name(dim, isl_dim_out, "scattering");
518 dim = isl_dim_set_tuple_name(dim, isl_dim_in, getBaseName());
519 isl_basic_map *bmap = isl_basic_map_universe(isl_dim_copy(dim));
520 isl_int v;
521 isl_int_init(v);
522
523 // Loop dimensions.
524 for (unsigned i = 0; i < NumberOfIterators; ++i) {
525 isl_constraint *c = isl_equality_alloc(isl_dim_copy(dim));
526 isl_int_set_si(v, 1);
527 isl_constraint_set_coefficient(c, isl_dim_out, 2 * i + 1, v);
528 isl_int_set_si(v, -1);
529 isl_constraint_set_coefficient(c, isl_dim_in, i, v);
530
531 bmap = isl_basic_map_add_constraint(bmap, c);
532 }
533
534 // Constant dimensions
535 for (unsigned i = 0; i < NumberOfIterators + 1; ++i) {
536 isl_constraint *c = isl_equality_alloc(isl_dim_copy(dim));
537 isl_int_set_si(v, -1);
538 isl_constraint_set_coefficient(c, isl_dim_out, 2 * i, v);
539 isl_int_set_si(v, Scatter[i]);
540 isl_constraint_set_constant(c, v);
541
542 bmap = isl_basic_map_add_constraint(bmap, c);
543 }
544
545 // Fill scattering dimensions.
546 for (unsigned i = 2 * NumberOfIterators + 1; i < ScatDim ; ++i) {
547 isl_constraint *c = isl_equality_alloc(isl_dim_copy(dim));
548 isl_int_set_si(v, 1);
549 isl_constraint_set_coefficient(c, isl_dim_out, i, v);
550 isl_int_set_si(v, 0);
551 isl_constraint_set_constant(c, v);
552
553 bmap = isl_basic_map_add_constraint(bmap, c);
554 }
555
556 isl_int_clear(v);
557 isl_dim_free(dim);
558 Scattering = isl_map_from_basic_map(bmap);
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000559 isl_dim *Model = isl_set_get_dim(getParent()->getContext());
560 Scattering = isl_map_align_params(Scattering, Model);
Tobias Grosser75805372011-04-29 06:27:02 +0000561}
562
563void ScopStmt::buildAccesses(TempScop &tempScop, const Region &CurRegion) {
564 const AccFuncSetType *AccFuncs = tempScop.getAccessFunctions(BB);
565
566 for (AccFuncSetType::const_iterator I = AccFuncs->begin(),
567 E = AccFuncs->end(); I != E; ++I) {
568 MemAccs.push_back(new MemoryAccess(I->first, this));
569 InstructionToAccess[I->second] = MemAccs.back();
570 }
571}
572
Tobias Grosserd2795d02011-08-18 07:51:40 +0000573isl_set *ScopStmt::toConditionSet(const Comparison &Comp, isl_dim *dim) const {
574 isl_pw_aff *LHS = SCEVAffinator::getPwAff(this, Comp.getLHS()->OriginalSCEV,
575 0);
576 isl_pw_aff *RHS = SCEVAffinator::getPwAff(this, Comp.getRHS()->OriginalSCEV,
577 0);
Tobias Grosser75805372011-04-29 06:27:02 +0000578
Tobias Grosserd2795d02011-08-18 07:51:40 +0000579 isl_set *set;
Tobias Grosser75805372011-04-29 06:27:02 +0000580
Tobias Grosserd2795d02011-08-18 07:51:40 +0000581 switch (Comp.getPred()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000582 case ICmpInst::ICMP_EQ:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000583 set = isl_pw_aff_eq_set(LHS, RHS);
Tobias Grosser75805372011-04-29 06:27:02 +0000584 break;
585 case ICmpInst::ICMP_NE:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000586 set = isl_pw_aff_ne_set(LHS, RHS);
Tobias Grosser75805372011-04-29 06:27:02 +0000587 break;
588 case ICmpInst::ICMP_SLT:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000589 set = isl_pw_aff_lt_set(LHS, RHS);
Tobias Grosser75805372011-04-29 06:27:02 +0000590 break;
591 case ICmpInst::ICMP_SLE:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000592 set = isl_pw_aff_le_set(LHS, RHS);
Tobias Grosser75805372011-04-29 06:27:02 +0000593 break;
Tobias Grosserd2795d02011-08-18 07:51:40 +0000594 case ICmpInst::ICMP_SGT:
595 set = isl_pw_aff_gt_set(LHS, RHS);
Tobias Grosser75805372011-04-29 06:27:02 +0000596 break;
597 case ICmpInst::ICMP_SGE:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000598 set = isl_pw_aff_ge_set(LHS, RHS);
Tobias Grosser75805372011-04-29 06:27:02 +0000599 break;
Tobias Grosserd2795d02011-08-18 07:51:40 +0000600 case ICmpInst::ICMP_ULT:
601 case ICmpInst::ICMP_UGT:
602 case ICmpInst::ICMP_ULE:
Tobias Grosser75805372011-04-29 06:27:02 +0000603 case ICmpInst::ICMP_UGE:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000604 llvm_unreachable("Unsigned comparisons not yet supported");
Tobias Grosser75805372011-04-29 06:27:02 +0000605 default:
606 llvm_unreachable("Non integer predicate not supported");
607 }
608
Tobias Grosserd2795d02011-08-18 07:51:40 +0000609 set = isl_set_set_tuple_name(set, isl_dim_get_tuple_name(dim, isl_dim_set));
610
611 return set;
Tobias Grosser75805372011-04-29 06:27:02 +0000612}
613
Tobias Grosserd2795d02011-08-18 07:51:40 +0000614isl_set *ScopStmt::toUpperLoopBound(const SCEVAffFunc &UpperBound, isl_dim *Dim,
Tobias Grosser75805372011-04-29 06:27:02 +0000615 unsigned BoundedDimension) const {
Tobias Grosserd2795d02011-08-18 07:51:40 +0000616 // FIXME: We should choose a consistent scheme of when to name the dimensions.
617 isl_dim *UnnamedDim = isl_dim_copy(Dim);
618 UnnamedDim = isl_dim_set_tuple_name(UnnamedDim, isl_dim_set, 0);
619 isl_local_space *LocalSpace = isl_local_space_from_dim (UnnamedDim);
620 isl_aff *LAff = isl_aff_set_coefficient_si (isl_aff_zero (LocalSpace),
621 isl_dim_set, BoundedDimension, 1);
622 isl_pw_aff *BoundedDim = isl_pw_aff_from_aff(LAff);
623 isl_pw_aff *Bound = SCEVAffinator::getPwAff(this, UpperBound.OriginalSCEV, 0);
624 isl_set *set = isl_pw_aff_le_set(BoundedDim, Bound);
625 set = isl_set_set_tuple_name(set, isl_dim_get_tuple_name(Dim, isl_dim_set));
Tobias Grosserb76f38532011-08-20 11:11:25 +0000626 isl_dim_free(Dim);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000627 return set;
Tobias Grosser75805372011-04-29 06:27:02 +0000628}
629
630void ScopStmt::buildIterationDomainFromLoops(TempScop &tempScop) {
Tobias Grosserb76f38532011-08-20 11:11:25 +0000631 isl_dim *dim = isl_dim_set_alloc(getIslContext(), 0, getNumIterators());
Tobias Grosser75805372011-04-29 06:27:02 +0000632 dim = isl_dim_set_tuple_name(dim, isl_dim_set, getBaseName());
633
634 Domain = isl_set_universe(isl_dim_copy(dim));
Tobias Grosser30b8a092011-08-18 07:51:37 +0000635 Domain = isl_set_align_params(Domain, isl_set_get_dim(Parent.getContext()));
Tobias Grosser75805372011-04-29 06:27:02 +0000636
637 isl_int v;
638 isl_int_init(v);
639
640 for (int i = 0, e = getNumIterators(); i != e; ++i) {
641 // Lower bound: IV >= 0.
642 isl_basic_set *bset = isl_basic_set_universe(isl_dim_copy(dim));
643 isl_constraint *c = isl_inequality_alloc(isl_dim_copy(dim));
644 isl_int_set_si(v, 1);
645 isl_constraint_set_coefficient(c, isl_dim_set, i, v);
646 bset = isl_basic_set_add_constraint(bset, c);
647 Domain = isl_set_intersect(Domain, isl_set_from_basic_set(bset));
648
649 // Upper bound: IV <= NumberOfIterations.
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000650 const Loop *L = getLoopForDimension(i);
Tobias Grosser75805372011-04-29 06:27:02 +0000651 const SCEVAffFunc &UpperBound = tempScop.getLoopBound(L);
652 isl_set *UpperBoundSet = toUpperLoopBound(UpperBound, isl_dim_copy(dim), i);
653 Domain = isl_set_intersect(Domain, UpperBoundSet);
654 }
655
Tobias Grosserb76f38532011-08-20 11:11:25 +0000656 isl_dim_free(dim);
Tobias Grosser75805372011-04-29 06:27:02 +0000657 isl_int_clear(v);
658}
659
660void ScopStmt::addConditionsToDomain(TempScop &tempScop,
661 const Region &CurRegion) {
662 isl_dim *dim = isl_set_get_dim(Domain);
663 const Region *TopR = tempScop.getMaxRegion().getParent(),
664 *CurR = &CurRegion;
665 const BasicBlock *CurEntry = BB;
666
667 // Build BB condition constrains, by traveling up the region tree.
668 do {
669 assert(CurR && "We exceed the top region?");
670 // Skip when multiple regions share the same entry.
671 if (CurEntry != CurR->getEntry()) {
672 if (const BBCond *Cnd = tempScop.getBBCond(CurEntry))
673 for (BBCond::const_iterator I = Cnd->begin(), E = Cnd->end();
674 I != E; ++I) {
675 isl_set *c = toConditionSet(*I, dim);
676 Domain = isl_set_intersect(Domain, c);
677 }
678 }
679 CurEntry = CurR->getEntry();
680 CurR = CurR->getParent();
681 } while (TopR != CurR);
682
683 isl_dim_free(dim);
684}
685
686void ScopStmt::buildIterationDomain(TempScop &tempScop, const Region &CurRegion)
687{
688 buildIterationDomainFromLoops(tempScop);
689 addConditionsToDomain(tempScop, CurRegion);
690}
691
692ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop,
693 const Region &CurRegion, BasicBlock &bb,
694 SmallVectorImpl<Loop*> &NestLoops,
695 SmallVectorImpl<unsigned> &Scatter)
696 : Parent(parent), BB(&bb), IVS(NestLoops.size()) {
697 // Setup the induction variables.
698 for (unsigned i = 0, e = NestLoops.size(); i < e; ++i) {
699 PHINode *PN = NestLoops[i]->getCanonicalInductionVariable();
700 assert(PN && "Non canonical IV in Scop!");
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000701 IVS[i] = std::make_pair(PN, NestLoops[i]);
Tobias Grosser75805372011-04-29 06:27:02 +0000702 }
703
704 raw_string_ostream OS(BaseName);
705 WriteAsOperand(OS, &bb, false);
706 BaseName = OS.str();
707
Tobias Grosser75805372011-04-29 06:27:02 +0000708 makeIslCompatible(BaseName);
709 BaseName = "Stmt_" + BaseName;
710
711 buildIterationDomain(tempScop, CurRegion);
712 buildScattering(Scatter);
713 buildAccesses(tempScop, CurRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000714}
715
716ScopStmt::ScopStmt(Scop &parent, SmallVectorImpl<unsigned> &Scatter)
717 : Parent(parent), BB(NULL), IVS(0) {
718
719 BaseName = "FinalRead";
720
721 // Build iteration domain.
722 std::string IterationDomainString = "{[i0] : i0 = 0}";
723 Domain = isl_set_read_from_str(Parent.getCtx(), IterationDomainString.c_str(),
724 -1);
Tobias Grosser75805372011-04-29 06:27:02 +0000725 Domain = isl_set_set_tuple_name(Domain, getBaseName());
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000726 isl_dim *Model = isl_set_get_dim(getParent()->getContext());
727 Domain = isl_set_align_params(Domain, isl_dim_copy(Model));
Tobias Grosser75805372011-04-29 06:27:02 +0000728
729 // Build scattering.
730 unsigned ScatDim = Parent.getMaxLoopDepth() * 2 + 1;
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000731 isl_dim *dim = isl_dim_alloc(Parent.getCtx(), 0, 1, ScatDim);
Tobias Grosser75805372011-04-29 06:27:02 +0000732 dim = isl_dim_set_tuple_name(dim, isl_dim_out, "scattering");
733 dim = isl_dim_set_tuple_name(dim, isl_dim_in, getBaseName());
734 isl_basic_map *bmap = isl_basic_map_universe(isl_dim_copy(dim));
735 isl_int v;
736 isl_int_init(v);
737
738 isl_constraint *c = isl_equality_alloc(dim);
739 isl_int_set_si(v, -1);
740 isl_constraint_set_coefficient(c, isl_dim_out, 0, v);
741
742 // TODO: This is incorrect. We should not use a very large number to ensure
743 // that this statement is executed last.
744 isl_int_set_si(v, 200000000);
745 isl_constraint_set_constant(c, v);
746
747 bmap = isl_basic_map_add_constraint(bmap, c);
748 isl_int_clear(v);
749 Scattering = isl_map_from_basic_map(bmap);
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000750 Scattering = isl_map_align_params(Scattering, Model);
Tobias Grosser75805372011-04-29 06:27:02 +0000751
752 // Build memory accesses, use SetVector to keep the order of memory accesses
753 // and prevent the same memory access inserted more than once.
754 SetVector<const Value*> BaseAddressSet;
755
756 for (Scop::const_iterator SI = Parent.begin(), SE = Parent.end(); SI != SE;
757 ++SI) {
758 ScopStmt *Stmt = *SI;
759
760 for (MemoryAccessVec::const_iterator I = Stmt->memacc_begin(),
761 E = Stmt->memacc_end(); I != E; ++I)
762 BaseAddressSet.insert((*I)->getBaseAddr());
763 }
764
765 for (SetVector<const Value*>::iterator BI = BaseAddressSet.begin(),
766 BE = BaseAddressSet.end(); BI != BE; ++BI)
767 MemAccs.push_back(new MemoryAccess(*BI, this));
Tobias Grosser75805372011-04-29 06:27:02 +0000768}
769
770std::string ScopStmt::getDomainStr() const {
Tobias Grosserd5a7bfc2011-05-06 19:52:19 +0000771 isl_set *domain = getDomain();
772 std::string string = stringFromIslObj(domain);
773 isl_set_free(domain);
774 return string;
Tobias Grosser75805372011-04-29 06:27:02 +0000775}
776
777std::string ScopStmt::getScatteringStr() const {
778 return stringFromIslObj(getScattering());
779}
780
781unsigned ScopStmt::getNumParams() const {
782 return Parent.getNumParams();
783}
784
785unsigned ScopStmt::getNumIterators() const {
786 // The final read has one dimension with one element.
787 if (!BB)
788 return 1;
789
790 return IVS.size();
791}
792
793unsigned ScopStmt::getNumScattering() const {
794 return isl_map_dim(Scattering, isl_dim_out);
795}
796
797const char *ScopStmt::getBaseName() const { return BaseName.c_str(); }
798
799const PHINode *ScopStmt::getInductionVariableForDimension(unsigned Dimension)
800 const {
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000801 return IVS[Dimension].first;
802}
803
804const Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const {
805 return IVS[Dimension].second;
Tobias Grosser75805372011-04-29 06:27:02 +0000806}
807
808const SCEVAddRecExpr *ScopStmt::getSCEVForDimension(unsigned Dimension)
809 const {
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000810 PHINode *PN =
811 const_cast<PHINode*>(getInductionVariableForDimension(Dimension));
Tobias Grosser75805372011-04-29 06:27:02 +0000812 return cast<SCEVAddRecExpr>(getParent()->getSE()->getSCEV(PN));
813}
814
815isl_ctx *ScopStmt::getIslContext() {
816 return Parent.getCtx();
817}
818
Tobias Grosserd5a7bfc2011-05-06 19:52:19 +0000819isl_set *ScopStmt::getDomain() const {
820 return isl_set_copy(Domain);
821}
822
Tobias Grosser75805372011-04-29 06:27:02 +0000823ScopStmt::~ScopStmt() {
824 while (!MemAccs.empty()) {
825 delete MemAccs.back();
826 MemAccs.pop_back();
827 }
828
829 isl_set_free(Domain);
830 isl_map_free(Scattering);
831}
832
833void ScopStmt::print(raw_ostream &OS) const {
834 OS << "\t" << getBaseName() << "\n";
835
836 OS.indent(12) << "Domain :=\n";
837
838 if (Domain) {
839 OS.indent(16) << getDomainStr() << ";\n";
840 } else
841 OS.indent(16) << "n/a\n";
842
843 OS.indent(12) << "Scattering :=\n";
844
845 if (Domain) {
846 OS.indent(16) << getScatteringStr() << ";\n";
847 } else
848 OS.indent(16) << "n/a\n";
849
850 for (MemoryAccessVec::const_iterator I = MemAccs.begin(), E = MemAccs.end();
851 I != E; ++I)
852 (*I)->print(OS);
853}
854
855void ScopStmt::dump() const { print(dbgs()); }
856
857//===----------------------------------------------------------------------===//
858/// Scop class implement
Tobias Grosserb76f38532011-08-20 11:11:25 +0000859Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution,
860 isl_ctx *ctx)
Tobias Grosser75805372011-04-29 06:27:02 +0000861 : SE(&ScalarEvolution), R(tempScop.getMaxRegion()),
862 MaxLoopDepth(tempScop.getMaxLoopDepth()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000863 ParamSetType &Params = tempScop.getParamSet();
864 Parameters.insert(Parameters.begin(), Params.begin(), Params.end());
865
866 isl_dim *dim = isl_dim_set_alloc(ctx, getNumParams(), 0);
867
Tobias Grosser30b8a092011-08-18 07:51:37 +0000868 int i = 0;
869 for (ParamSetType::iterator PI = Params.begin(), PE = Params.end();
870 PI != PE; ++PI) {
871 const SCEV *scev = *PI;
872 isl_id *id = isl_id_alloc(ctx,
873 ("p" + convertInt(i)).c_str(),
874 (void *) scev);
875 dim = isl_dim_set_dim_id(dim, isl_dim_param, i, id);
876 i++;
877 }
878
Tobias Grosser75805372011-04-29 06:27:02 +0000879 // TODO: Insert relations between parameters.
880 // TODO: Insert constraints on parameters.
881 Context = isl_set_universe (dim);
882
883 SmallVector<Loop*, 8> NestLoops;
884 SmallVector<unsigned, 8> Scatter;
885
886 Scatter.assign(MaxLoopDepth + 1, 0);
887
888 // Build the iteration domain, access functions and scattering functions
889 // traversing the region tree.
890 buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
891 Stmts.push_back(new ScopStmt(*this, Scatter));
892
Tobias Grosser75805372011-04-29 06:27:02 +0000893 assert(NestLoops.empty() && "NestLoops not empty at top level!");
894}
895
896Scop::~Scop() {
897 isl_set_free(Context);
898
899 // Free the statements;
900 for (iterator I = begin(), E = end(); I != E; ++I)
901 delete *I;
Tobias Grosser75805372011-04-29 06:27:02 +0000902}
903
904std::string Scop::getContextStr() const {
905 return stringFromIslObj(getContext());
906}
907
908std::string Scop::getNameStr() const {
909 std::string ExitName, EntryName;
910 raw_string_ostream ExitStr(ExitName);
911 raw_string_ostream EntryStr(EntryName);
912
913 WriteAsOperand(EntryStr, R.getEntry(), false);
914 EntryStr.str();
915
916 if (R.getExit()) {
917 WriteAsOperand(ExitStr, R.getExit(), false);
918 ExitStr.str();
919 } else
920 ExitName = "FunctionExit";
921
922 return EntryName + "---" + ExitName;
923}
924
925void Scop::printContext(raw_ostream &OS) const {
926 OS << "Context:\n";
927
928 if (!Context) {
929 OS.indent(4) << "n/a\n\n";
930 return;
931 }
932
933 OS.indent(4) << getContextStr() << "\n";
934}
935
936void Scop::printStatements(raw_ostream &OS) const {
937 OS << "Statements {\n";
938
939 for (const_iterator SI = begin(), SE = end();SI != SE; ++SI)
940 OS.indent(4) << (**SI);
941
942 OS.indent(4) << "}\n";
943}
944
945
946void Scop::print(raw_ostream &OS) const {
947 printContext(OS.indent(4));
948 printStatements(OS.indent(4));
949}
950
951void Scop::dump() const { print(dbgs()); }
952
953isl_ctx *Scop::getCtx() const { return isl_set_get_ctx(Context); }
954
955ScalarEvolution *Scop::getSE() const { return SE; }
956
957bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) {
958 if (tempScop.getAccessFunctions(BB))
959 return false;
960
961 return true;
962}
963
964void Scop::buildScop(TempScop &tempScop,
965 const Region &CurRegion,
966 SmallVectorImpl<Loop*> &NestLoops,
967 SmallVectorImpl<unsigned> &Scatter,
968 LoopInfo &LI) {
969 Loop *L = castToLoop(CurRegion, LI);
970
971 if (L)
972 NestLoops.push_back(L);
973
974 unsigned loopDepth = NestLoops.size();
975 assert(Scatter.size() > loopDepth && "Scatter not big enough!");
976
977 for (Region::const_element_iterator I = CurRegion.element_begin(),
978 E = CurRegion.element_end(); I != E; ++I)
979 if (I->isSubRegion())
980 buildScop(tempScop, *(I->getNodeAs<Region>()), NestLoops, Scatter, LI);
981 else {
982 BasicBlock *BB = I->getNodeAs<BasicBlock>();
983
984 if (isTrivialBB(BB, tempScop))
985 continue;
986
987 Stmts.push_back(new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops,
988 Scatter));
989
990 // Increasing the Scattering function is OK for the moment, because
991 // we are using a depth first iterator and the program is well structured.
992 ++Scatter[loopDepth];
993 }
994
995 if (!L)
996 return;
997
998 // Exiting a loop region.
999 Scatter[loopDepth] = 0;
1000 NestLoops.pop_back();
1001 ++Scatter[loopDepth-1];
1002}
1003
1004//===----------------------------------------------------------------------===//
Tobias Grosserb76f38532011-08-20 11:11:25 +00001005ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
1006 ctx = isl_ctx_alloc();
1007}
1008
1009ScopInfo::~ScopInfo() {
1010 clear();
1011 isl_ctx_free(ctx);
1012}
1013
1014
Tobias Grosser75805372011-04-29 06:27:02 +00001015
1016void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
1017 AU.addRequired<LoopInfo>();
1018 AU.addRequired<RegionInfo>();
1019 AU.addRequired<ScalarEvolution>();
1020 AU.addRequired<TempScopInfo>();
1021 AU.setPreservesAll();
1022}
1023
1024bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
1025 LoopInfo &LI = getAnalysis<LoopInfo>();
1026 ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
1027
1028 TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
1029
1030 // This region is no Scop.
1031 if (!tempScop) {
1032 scop = 0;
1033 return false;
1034 }
1035
1036 // Statistics.
1037 ++ScopFound;
1038 if (tempScop->getMaxLoopDepth() > 0) ++RichScopFound;
1039
Tobias Grosserb76f38532011-08-20 11:11:25 +00001040 scop = new Scop(*tempScop, LI, SE, ctx);
Tobias Grosser75805372011-04-29 06:27:02 +00001041
1042 return false;
1043}
1044
1045char ScopInfo::ID = 0;
1046
1047
1048static RegisterPass<ScopInfo>
1049X("polly-scops", "Polly - Create polyhedral description of Scops");
1050
1051Pass *polly::createScopInfoPass() {
1052 return new ScopInfo();
1053}