blob: 78d5789e63b48e63c1ef1669ece95c19664220f2 [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);
714
715 IsReduction = tempScop.is_Reduction(*BB);
716}
717
718ScopStmt::ScopStmt(Scop &parent, SmallVectorImpl<unsigned> &Scatter)
719 : Parent(parent), BB(NULL), IVS(0) {
720
721 BaseName = "FinalRead";
722
723 // Build iteration domain.
724 std::string IterationDomainString = "{[i0] : i0 = 0}";
725 Domain = isl_set_read_from_str(Parent.getCtx(), IterationDomainString.c_str(),
726 -1);
Tobias Grosser75805372011-04-29 06:27:02 +0000727 Domain = isl_set_set_tuple_name(Domain, getBaseName());
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000728 isl_dim *Model = isl_set_get_dim(getParent()->getContext());
729 Domain = isl_set_align_params(Domain, isl_dim_copy(Model));
Tobias Grosser75805372011-04-29 06:27:02 +0000730
731 // Build scattering.
732 unsigned ScatDim = Parent.getMaxLoopDepth() * 2 + 1;
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000733 isl_dim *dim = isl_dim_alloc(Parent.getCtx(), 0, 1, ScatDim);
Tobias Grosser75805372011-04-29 06:27:02 +0000734 dim = isl_dim_set_tuple_name(dim, isl_dim_out, "scattering");
735 dim = isl_dim_set_tuple_name(dim, isl_dim_in, getBaseName());
736 isl_basic_map *bmap = isl_basic_map_universe(isl_dim_copy(dim));
737 isl_int v;
738 isl_int_init(v);
739
740 isl_constraint *c = isl_equality_alloc(dim);
741 isl_int_set_si(v, -1);
742 isl_constraint_set_coefficient(c, isl_dim_out, 0, v);
743
744 // TODO: This is incorrect. We should not use a very large number to ensure
745 // that this statement is executed last.
746 isl_int_set_si(v, 200000000);
747 isl_constraint_set_constant(c, v);
748
749 bmap = isl_basic_map_add_constraint(bmap, c);
750 isl_int_clear(v);
751 Scattering = isl_map_from_basic_map(bmap);
Tobias Grosserfa7bc2f2011-08-20 00:03:28 +0000752 Scattering = isl_map_align_params(Scattering, Model);
Tobias Grosser75805372011-04-29 06:27:02 +0000753
754 // Build memory accesses, use SetVector to keep the order of memory accesses
755 // and prevent the same memory access inserted more than once.
756 SetVector<const Value*> BaseAddressSet;
757
758 for (Scop::const_iterator SI = Parent.begin(), SE = Parent.end(); SI != SE;
759 ++SI) {
760 ScopStmt *Stmt = *SI;
761
762 for (MemoryAccessVec::const_iterator I = Stmt->memacc_begin(),
763 E = Stmt->memacc_end(); I != E; ++I)
764 BaseAddressSet.insert((*I)->getBaseAddr());
765 }
766
767 for (SetVector<const Value*>::iterator BI = BaseAddressSet.begin(),
768 BE = BaseAddressSet.end(); BI != BE; ++BI)
769 MemAccs.push_back(new MemoryAccess(*BI, this));
770
771 IsReduction = false;
772}
773
774std::string ScopStmt::getDomainStr() const {
Tobias Grosserd5a7bfc2011-05-06 19:52:19 +0000775 isl_set *domain = getDomain();
776 std::string string = stringFromIslObj(domain);
777 isl_set_free(domain);
778 return string;
Tobias Grosser75805372011-04-29 06:27:02 +0000779}
780
781std::string ScopStmt::getScatteringStr() const {
782 return stringFromIslObj(getScattering());
783}
784
785unsigned ScopStmt::getNumParams() const {
786 return Parent.getNumParams();
787}
788
789unsigned ScopStmt::getNumIterators() const {
790 // The final read has one dimension with one element.
791 if (!BB)
792 return 1;
793
794 return IVS.size();
795}
796
797unsigned ScopStmt::getNumScattering() const {
798 return isl_map_dim(Scattering, isl_dim_out);
799}
800
801const char *ScopStmt::getBaseName() const { return BaseName.c_str(); }
802
803const PHINode *ScopStmt::getInductionVariableForDimension(unsigned Dimension)
804 const {
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000805 return IVS[Dimension].first;
806}
807
808const Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const {
809 return IVS[Dimension].second;
Tobias Grosser75805372011-04-29 06:27:02 +0000810}
811
812const SCEVAddRecExpr *ScopStmt::getSCEVForDimension(unsigned Dimension)
813 const {
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000814 PHINode *PN =
815 const_cast<PHINode*>(getInductionVariableForDimension(Dimension));
Tobias Grosser75805372011-04-29 06:27:02 +0000816 return cast<SCEVAddRecExpr>(getParent()->getSE()->getSCEV(PN));
817}
818
819isl_ctx *ScopStmt::getIslContext() {
820 return Parent.getCtx();
821}
822
Tobias Grosserd5a7bfc2011-05-06 19:52:19 +0000823isl_set *ScopStmt::getDomain() const {
824 return isl_set_copy(Domain);
825}
826
Tobias Grosser75805372011-04-29 06:27:02 +0000827ScopStmt::~ScopStmt() {
828 while (!MemAccs.empty()) {
829 delete MemAccs.back();
830 MemAccs.pop_back();
831 }
832
833 isl_set_free(Domain);
834 isl_map_free(Scattering);
835}
836
837void ScopStmt::print(raw_ostream &OS) const {
838 OS << "\t" << getBaseName() << "\n";
839
840 OS.indent(12) << "Domain :=\n";
841
842 if (Domain) {
843 OS.indent(16) << getDomainStr() << ";\n";
844 } else
845 OS.indent(16) << "n/a\n";
846
847 OS.indent(12) << "Scattering :=\n";
848
849 if (Domain) {
850 OS.indent(16) << getScatteringStr() << ";\n";
851 } else
852 OS.indent(16) << "n/a\n";
853
854 for (MemoryAccessVec::const_iterator I = MemAccs.begin(), E = MemAccs.end();
855 I != E; ++I)
856 (*I)->print(OS);
857}
858
859void ScopStmt::dump() const { print(dbgs()); }
860
861//===----------------------------------------------------------------------===//
862/// Scop class implement
Tobias Grosserb76f38532011-08-20 11:11:25 +0000863Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution,
864 isl_ctx *ctx)
Tobias Grosser75805372011-04-29 06:27:02 +0000865 : SE(&ScalarEvolution), R(tempScop.getMaxRegion()),
866 MaxLoopDepth(tempScop.getMaxLoopDepth()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000867 ParamSetType &Params = tempScop.getParamSet();
868 Parameters.insert(Parameters.begin(), Params.begin(), Params.end());
869
870 isl_dim *dim = isl_dim_set_alloc(ctx, getNumParams(), 0);
871
Tobias Grosser30b8a092011-08-18 07:51:37 +0000872 int i = 0;
873 for (ParamSetType::iterator PI = Params.begin(), PE = Params.end();
874 PI != PE; ++PI) {
875 const SCEV *scev = *PI;
876 isl_id *id = isl_id_alloc(ctx,
877 ("p" + convertInt(i)).c_str(),
878 (void *) scev);
879 dim = isl_dim_set_dim_id(dim, isl_dim_param, i, id);
880 i++;
881 }
882
Tobias Grosser75805372011-04-29 06:27:02 +0000883 // TODO: Insert relations between parameters.
884 // TODO: Insert constraints on parameters.
885 Context = isl_set_universe (dim);
886
887 SmallVector<Loop*, 8> NestLoops;
888 SmallVector<unsigned, 8> Scatter;
889
890 Scatter.assign(MaxLoopDepth + 1, 0);
891
892 // Build the iteration domain, access functions and scattering functions
893 // traversing the region tree.
894 buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
895 Stmts.push_back(new ScopStmt(*this, Scatter));
896
Tobias Grosser75805372011-04-29 06:27:02 +0000897 assert(NestLoops.empty() && "NestLoops not empty at top level!");
898}
899
900Scop::~Scop() {
901 isl_set_free(Context);
902
903 // Free the statements;
904 for (iterator I = begin(), E = end(); I != E; ++I)
905 delete *I;
Tobias Grosser75805372011-04-29 06:27:02 +0000906}
907
908std::string Scop::getContextStr() const {
909 return stringFromIslObj(getContext());
910}
911
912std::string Scop::getNameStr() const {
913 std::string ExitName, EntryName;
914 raw_string_ostream ExitStr(ExitName);
915 raw_string_ostream EntryStr(EntryName);
916
917 WriteAsOperand(EntryStr, R.getEntry(), false);
918 EntryStr.str();
919
920 if (R.getExit()) {
921 WriteAsOperand(ExitStr, R.getExit(), false);
922 ExitStr.str();
923 } else
924 ExitName = "FunctionExit";
925
926 return EntryName + "---" + ExitName;
927}
928
929void Scop::printContext(raw_ostream &OS) const {
930 OS << "Context:\n";
931
932 if (!Context) {
933 OS.indent(4) << "n/a\n\n";
934 return;
935 }
936
937 OS.indent(4) << getContextStr() << "\n";
938}
939
940void Scop::printStatements(raw_ostream &OS) const {
941 OS << "Statements {\n";
942
943 for (const_iterator SI = begin(), SE = end();SI != SE; ++SI)
944 OS.indent(4) << (**SI);
945
946 OS.indent(4) << "}\n";
947}
948
949
950void Scop::print(raw_ostream &OS) const {
951 printContext(OS.indent(4));
952 printStatements(OS.indent(4));
953}
954
955void Scop::dump() const { print(dbgs()); }
956
957isl_ctx *Scop::getCtx() const { return isl_set_get_ctx(Context); }
958
959ScalarEvolution *Scop::getSE() const { return SE; }
960
961bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) {
962 if (tempScop.getAccessFunctions(BB))
963 return false;
964
965 return true;
966}
967
968void Scop::buildScop(TempScop &tempScop,
969 const Region &CurRegion,
970 SmallVectorImpl<Loop*> &NestLoops,
971 SmallVectorImpl<unsigned> &Scatter,
972 LoopInfo &LI) {
973 Loop *L = castToLoop(CurRegion, LI);
974
975 if (L)
976 NestLoops.push_back(L);
977
978 unsigned loopDepth = NestLoops.size();
979 assert(Scatter.size() > loopDepth && "Scatter not big enough!");
980
981 for (Region::const_element_iterator I = CurRegion.element_begin(),
982 E = CurRegion.element_end(); I != E; ++I)
983 if (I->isSubRegion())
984 buildScop(tempScop, *(I->getNodeAs<Region>()), NestLoops, Scatter, LI);
985 else {
986 BasicBlock *BB = I->getNodeAs<BasicBlock>();
987
988 if (isTrivialBB(BB, tempScop))
989 continue;
990
991 Stmts.push_back(new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops,
992 Scatter));
993
994 // Increasing the Scattering function is OK for the moment, because
995 // we are using a depth first iterator and the program is well structured.
996 ++Scatter[loopDepth];
997 }
998
999 if (!L)
1000 return;
1001
1002 // Exiting a loop region.
1003 Scatter[loopDepth] = 0;
1004 NestLoops.pop_back();
1005 ++Scatter[loopDepth-1];
1006}
1007
1008//===----------------------------------------------------------------------===//
Tobias Grosserb76f38532011-08-20 11:11:25 +00001009ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
1010 ctx = isl_ctx_alloc();
1011}
1012
1013ScopInfo::~ScopInfo() {
1014 clear();
1015 isl_ctx_free(ctx);
1016}
1017
1018
Tobias Grosser75805372011-04-29 06:27:02 +00001019
1020void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
1021 AU.addRequired<LoopInfo>();
1022 AU.addRequired<RegionInfo>();
1023 AU.addRequired<ScalarEvolution>();
1024 AU.addRequired<TempScopInfo>();
1025 AU.setPreservesAll();
1026}
1027
1028bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
1029 LoopInfo &LI = getAnalysis<LoopInfo>();
1030 ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
1031
1032 TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
1033
1034 // This region is no Scop.
1035 if (!tempScop) {
1036 scop = 0;
1037 return false;
1038 }
1039
1040 // Statistics.
1041 ++ScopFound;
1042 if (tempScop->getMaxLoopDepth() > 0) ++RichScopFound;
1043
Tobias Grosserb76f38532011-08-20 11:11:25 +00001044 scop = new Scop(*tempScop, LI, SE, ctx);
Tobias Grosser75805372011-04-29 06:27:02 +00001045
1046 return false;
1047}
1048
1049char ScopInfo::ID = 0;
1050
1051
1052static RegisterPass<ScopInfo>
1053X("polly-scops", "Polly - Create polyhedral description of Scops");
1054
1055Pass *polly::createScopInfoPass() {
1056 return new ScopInfo();
1057}