blob: 9b3b618de296da3ea7a0f83161f3de5292cb44e8 [file] [log] [blame]
Sebastian Pop082cea82012-05-07 16:20:07 +00001//===------ IslCodeGeneration.cpp - Code generate the Scops using ISL. ----===//
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// The IslCodeGeneration pass takes a Scop created by ScopInfo and translates it
11// back to LLVM-IR using the ISL code generator.
12//
13// The Scop describes the high level memory behaviour of a control flow region.
14// Transformation passes can update the schedule (execution order) of statements
15// in the Scop. ISL is used to generate an abstract syntax tree that reflects
16// the updated execution order. This clast is used to create new LLVM-IR that is
17// computationally equivalent to the original control flow region, but executes
18// its code in the new execution order defined by the changed scattering.
19//
20//===----------------------------------------------------------------------===//
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +000021#include "polly/Config/config.h"
Sebastian Pop082cea82012-05-07 16:20:07 +000022
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +000023#include "polly/Dependences.h"
24#include "polly/LinkAllPasses.h"
25#include "polly/ScopInfo.h"
26#include "polly/TempScopInfo.h"
27#include "polly/CodeGen/IslAst.h"
28#include "polly/CodeGen/BlockGenerators.h"
Sebastian Pop04c4ce32012-12-18 07:46:13 +000029#include "polly/CodeGen/CodeGeneration.h"
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +000030#include "polly/CodeGen/LoopGenerators.h"
31#include "polly/CodeGen/Utils.h"
32#include "polly/Support/GICHelper.h"
33
Chandler Carruth535d52c2013-01-02 11:47:44 +000034#include "llvm/IR/Module.h"
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +000035#include "llvm/Analysis/LoopInfo.h"
36#include "llvm/Analysis/ScalarEvolutionExpander.h"
37#define DEBUG_TYPE "polly-codegen-isl"
38#include "llvm/Support/CommandLine.h"
39#include "llvm/Support/Debug.h"
Chandler Carruth535d52c2013-01-02 11:47:44 +000040#include "llvm/IR/DataLayout.h"
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +000041#include "llvm/Transforms/Utils/BasicBlockUtils.h"
42
43#include "isl/union_map.h"
44#include "isl/list.h"
45#include "isl/ast.h"
46#include "isl/ast_build.h"
47#include "isl/set.h"
48#include "isl/map.h"
49#include "isl/aff.h"
50
51#include <map>
52
53using namespace polly;
54using namespace llvm;
55
56/// @brief Insert function calls that print certain LLVM values at run time.
57///
58/// This class inserts libc function calls to print certain LLVM values at
59/// run time.
60class RuntimeDebugBuilder {
61public:
62 RuntimeDebugBuilder(IRBuilder<> &Builder) : Builder(Builder) {}
63
64 /// @brief Print a string to stdout.
65 ///
66 /// @param String The string to print.
67 void createStrPrinter(std::string String);
68
69 /// @brief Print an integer value to stdout.
70 ///
71 /// @param V The value to print.
72 void createIntPrinter(Value *V);
73
74private:
75 IRBuilder<> &Builder;
76
77 /// @brief Add a call to the fflush function with no file pointer given.
78 ///
79 /// This call will flush all opened file pointers including stdout and stderr.
80 void createFlush();
81
82 /// @brief Get a reference to the 'printf' function.
83 ///
84 /// If the current module does not yet contain a reference to printf, we
85 /// insert a reference to it. Otherwise the existing reference is returned.
86 Function *getPrintF();
87};
88
89Function *RuntimeDebugBuilder::getPrintF() {
90 Module *M = Builder.GetInsertBlock()->getParent()->getParent();
91 const char *Name = "printf";
92 Function *F = M->getFunction(Name);
93
94 if (!F) {
95 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
96 FunctionType *Ty = FunctionType::get(Builder.getInt32Ty(),
97 Builder.getInt8PtrTy(), true);
98 F = Function::Create(Ty, Linkage, Name, M);
99 }
100
101 return F;
102}
103
104void RuntimeDebugBuilder::createFlush() {
105 Module *M = Builder.GetInsertBlock()->getParent()->getParent();
106 const char *Name = "fflush";
107 Function *F = M->getFunction(Name);
108
109 if (!F) {
110 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
111 FunctionType *Ty = FunctionType::get(Builder.getInt32Ty(),
112 Builder.getInt8PtrTy(), false);
113 F = Function::Create(Ty, Linkage, Name, M);
114 }
115
116 Builder.CreateCall(F, Constant::getNullValue(Builder.getInt8PtrTy()));
117}
118
119void RuntimeDebugBuilder::createStrPrinter(std::string String) {
120 Function *F = getPrintF();
121 Value *StringValue = Builder.CreateGlobalStringPtr(String);
122 Builder.CreateCall(F, StringValue);
123
124 createFlush();
125}
126
127void RuntimeDebugBuilder::createIntPrinter(Value *V) {
128 IntegerType *Ty = dyn_cast<IntegerType>(V->getType());
129 assert(Ty && Ty->getBitWidth() == 64 &&
130 "Cannot insert printer for this type.");
131
132 Function *F = getPrintF();
133 Value *String = Builder.CreateGlobalStringPtr("%ld");
134 Builder.CreateCall2(F, String, V);
135 createFlush();
136}
137
138/// @brief Calculate the Value of a certain isl_ast_expr
139class IslExprBuilder {
140public:
141 IslExprBuilder(IRBuilder<> &Builder,
142 std::map<isl_id *, Value*> &IDToValue, Pass *P)
143 : Builder(Builder), IDToValue(IDToValue) { }
144
145 Value *create(__isl_take isl_ast_expr *Expr);
146 Type *getWidestType(Type *T1, Type *T2);
147 IntegerType *getType(__isl_keep isl_ast_expr *Expr);
148
149private:
150 IRBuilder<> &Builder;
151 std::map<isl_id *, Value*> &IDToValue;
152
153 Value *createOp(__isl_take isl_ast_expr *Expr);
154 Value *createOpUnary(__isl_take isl_ast_expr *Expr);
155 Value *createOpBin(__isl_take isl_ast_expr *Expr);
156 Value *createOpNAry(__isl_take isl_ast_expr *Expr);
157 Value *createOpSelect(__isl_take isl_ast_expr *Expr);
158 Value *createOpICmp(__isl_take isl_ast_expr *Expr);
159 Value *createOpBoolean(__isl_take isl_ast_expr *Expr);
160 Value *createId(__isl_take isl_ast_expr *Expr);
161 Value *createInt(__isl_take isl_ast_expr *Expr);
162};
163
164Type *IslExprBuilder::getWidestType(Type *T1, Type *T2) {
165 assert(isa<IntegerType>(T1) && isa<IntegerType>(T2));
166
167 if (T1->getPrimitiveSizeInBits() < T2->getPrimitiveSizeInBits())
168 return T2;
169 else
170 return T1;
171}
172
173Value *IslExprBuilder::createOpUnary(__isl_take isl_ast_expr *Expr) {
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000174 assert(isl_ast_expr_get_op_type(Expr) == isl_ast_op_minus &&
175 "Unsupported unary operation");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000176
177 Value *V;
178 Type *MaxType = getType(Expr);
179
180 V = create(isl_ast_expr_get_op_arg(Expr, 0));
181 MaxType = getWidestType(MaxType, V->getType());
182
183 if (MaxType != V->getType())
184 V = Builder.CreateSExt(V, MaxType);
185
186 isl_ast_expr_free(Expr);
187 return Builder.CreateNSWNeg(V);
188}
189
190Value *IslExprBuilder::createOpNAry(__isl_take isl_ast_expr *Expr) {
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000191 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
192 "isl ast expression not of type isl_ast_op");
193 assert(isl_ast_expr_get_op_n_arg(Expr) >= 2 &&
194 "We need at least two operands in an n-ary operation");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000195
196 Value *V;
197
198 V = create(isl_ast_expr_get_op_arg(Expr, 0));
199
200 for (int i = 0; i < isl_ast_expr_get_op_n_arg(Expr); ++i) {
201 Value *OpV;
202 OpV = create(isl_ast_expr_get_op_arg(Expr, i));
203
204 Type *Ty = getWidestType(V->getType(), OpV->getType());
205
206 if (Ty != OpV->getType())
207 OpV = Builder.CreateSExt(OpV, Ty);
208
209 if (Ty != V->getType())
210 V = Builder.CreateSExt(V, Ty);
211
212 switch (isl_ast_expr_get_op_type(Expr)) {
213 default:
214 llvm_unreachable("This is no n-ary isl ast expression");
215
216 case isl_ast_op_max:
217 {
218 Value *Cmp = Builder.CreateICmpSGT(V, OpV);
219 V = Builder.CreateSelect(Cmp, V, OpV);
220 continue;
221 }
222 case isl_ast_op_min:
223 {
224 Value *Cmp = Builder.CreateICmpSLT(V, OpV);
225 V = Builder.CreateSelect(Cmp, V, OpV);
226 continue;
227 }
228 }
229 }
230
231 // TODO: We can truncate the result, if it fits into a smaller type. This can
232 // help in cases where we have larger operands (e.g. i67) but the result is
233 // known to fit into i64. Without the truncation, the larger i67 type may
234 // force all subsequent operations to be performed on a non-native type.
235 isl_ast_expr_free(Expr);
236 return V;
237}
238
239Value *IslExprBuilder::createOpBin(__isl_take isl_ast_expr *Expr) {
240 Value *LHS, *RHS, *Res;
241 Type *MaxType;
242 isl_ast_op_type OpType;
243
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000244 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
245 "isl ast expression not of type isl_ast_op");
246 assert(isl_ast_expr_get_op_n_arg(Expr) == 2 &&
247 "not a binary isl ast expression");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000248
249 OpType = isl_ast_expr_get_op_type(Expr);
250
251 LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
252 RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
253
254 MaxType = LHS->getType();
255 MaxType = getWidestType(MaxType, RHS->getType());
256
257 // Take the result into account when calculating the widest type.
258 //
259 // For operations such as '+' the result may require a type larger than
260 // the type of the individual operands. For other operations such as '/', the
261 // result type cannot be larger than the type of the individual operand. isl
262 // does not calculate correct types for these operations and we consequently
263 // exclude those operations here.
Tobias Grosser1bb59b02012-12-29 23:47:38 +0000264 switch (OpType) {
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000265 case isl_ast_op_pdiv_q:
266 case isl_ast_op_pdiv_r:
267 case isl_ast_op_div:
268 case isl_ast_op_fdiv_q:
269 // Do nothing
270 break;
271 case isl_ast_op_add:
272 case isl_ast_op_sub:
273 case isl_ast_op_mul:
274 MaxType = getWidestType(MaxType, getType(Expr));
275 break;
276 default:
277 llvm_unreachable("This is no binary isl ast expression");
278 }
279
280 if (MaxType != RHS->getType())
281 RHS = Builder.CreateSExt(RHS, MaxType);
282
283 if (MaxType != LHS->getType())
284 LHS = Builder.CreateSExt(LHS, MaxType);
285
286 switch (OpType) {
287 default:
288 llvm_unreachable("This is no binary isl ast expression");
289 case isl_ast_op_add:
290 Res = Builder.CreateNSWAdd(LHS, RHS);
291 break;
292 case isl_ast_op_sub:
293 Res = Builder.CreateNSWSub(LHS, RHS);
294 break;
295 case isl_ast_op_mul:
296 Res = Builder.CreateNSWMul(LHS, RHS);
297 break;
298 case isl_ast_op_div:
299 case isl_ast_op_pdiv_q: // Dividend is non-negative
300 Res = Builder.CreateSDiv(LHS, RHS);
301 break;
302 case isl_ast_op_fdiv_q: // Round towards -infty
303 {
304 // TODO: Review code and check that this calculation does not yield
305 // incorrect overflow in some bordercases.
306 //
307 // floord(n,d) ((n < 0) ? (n - d + 1) : n) / d
308 Value *One = ConstantInt::get(MaxType, 1);
309 Value *Zero = ConstantInt::get(MaxType, 0);
310 Value *Sum1 = Builder.CreateSub(LHS, RHS);
311 Value *Sum2 = Builder.CreateAdd(Sum1, One);
312 Value *isNegative = Builder.CreateICmpSLT(LHS, Zero);
313 Value *Dividend = Builder.CreateSelect(isNegative, Sum2, LHS);
314 Res = Builder.CreateSDiv(Dividend, RHS);
315 break;
316 }
317 case isl_ast_op_pdiv_r: // Dividend is non-negative
318 Res = Builder.CreateSRem(LHS, RHS);
319 break;
320 }
321
322 // TODO: We can truncate the result, if it fits into a smaller type. This can
323 // help in cases where we have larger operands (e.g. i67) but the result is
324 // known to fit into i64. Without the truncation, the larger i67 type may
325 // force all subsequent operations to be performed on a non-native type.
326 isl_ast_expr_free(Expr);
327 return Res;
328}
329
330Value *IslExprBuilder::createOpSelect(__isl_take isl_ast_expr *Expr) {
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000331 assert(isl_ast_expr_get_op_type(Expr) == isl_ast_op_select &&
332 "Unsupported unary isl ast expression");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000333 Value *LHS, *RHS, *Cond;
334 Type *MaxType = getType(Expr);
335
336 Cond = create(isl_ast_expr_get_op_arg(Expr, 0));
337
338 LHS = create(isl_ast_expr_get_op_arg(Expr, 1));
339 RHS = create(isl_ast_expr_get_op_arg(Expr, 2));
340
341 MaxType = getWidestType(MaxType, LHS->getType());
342 MaxType = getWidestType(MaxType, RHS->getType());
343
344 if (MaxType != RHS->getType())
345 RHS = Builder.CreateSExt(RHS, MaxType);
346
347 if (MaxType != LHS->getType())
348 LHS = Builder.CreateSExt(LHS, MaxType);
349
350 // TODO: Do we want to truncate the result?
351 isl_ast_expr_free(Expr);
352 return Builder.CreateSelect(Cond, LHS, RHS);
353}
354
355Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
356 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
357 "Expected an isl_ast_expr_op expression");
358
359 Value *LHS, *RHS, *Res;
360
361 LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
362 RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
363
364 Type *MaxType = LHS->getType();
365 MaxType = getWidestType(MaxType, RHS->getType());
366
367 if (MaxType != RHS->getType())
368 RHS = Builder.CreateSExt(RHS, MaxType);
369
370 if (MaxType != LHS->getType())
371 LHS = Builder.CreateSExt(LHS, MaxType);
372
373 switch (isl_ast_expr_get_op_type(Expr)) {
374 default:
375 llvm_unreachable("Unsupported ICmp isl ast expression");
376 case isl_ast_op_eq:
377 Res = Builder.CreateICmpEQ(LHS, RHS);
378 break;
379 case isl_ast_op_le:
380 Res = Builder.CreateICmpSLE(LHS, RHS);
381 break;
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000382 case isl_ast_op_lt:
383 Res = Builder.CreateICmpSLT(LHS, RHS);
384 break;
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000385 case isl_ast_op_ge:
386 Res = Builder.CreateICmpSGE(LHS, RHS);
387 break;
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000388 case isl_ast_op_gt:
389 Res = Builder.CreateICmpSGT(LHS, RHS);
390 break;
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000391 }
392
393 isl_ast_expr_free(Expr);
394 return Res;
395}
396
397Value *IslExprBuilder::createOpBoolean(__isl_take isl_ast_expr *Expr) {
398 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
399 "Expected an isl_ast_expr_op expression");
400
401 Value *LHS, *RHS, *Res;
402 isl_ast_op_type OpType;
403
404 OpType = isl_ast_expr_get_op_type(Expr);
405
406 assert((OpType == isl_ast_op_and || OpType == isl_ast_op_or) &&
407 "Unsupported isl_ast_op_type");
408
409 LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
410 RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
411
412 // Even though the isl pretty printer prints the expressions as 'exp && exp'
413 // or 'exp || exp', we actually code generate the bitwise expressions
414 // 'exp & exp' or 'exp | exp'. This forces the evaluation of both branches,
415 // but it is, due to the use of i1 types, otherwise equivalent. The reason
416 // to go for bitwise operations is, that we assume the reduced control flow
417 // will outweight the overhead introduced by evaluating unneeded expressions.
418 // The isl code generation currently does not take advantage of the fact that
419 // the expression after an '||' or '&&' is in some cases not evaluated.
420 // Evaluating it anyways does not cause any undefined behaviour.
421 //
422 // TODO: Document in isl itself, that the unconditionally evaluating the
423 // second part of '||' or '&&' expressions is safe.
424 assert(LHS->getType() == Builder.getInt1Ty() && "Expected i1 type");
425 assert(RHS->getType() == Builder.getInt1Ty() && "Expected i1 type");
426
427 switch (OpType) {
428 default:
429 llvm_unreachable("Unsupported boolean expression");
430 case isl_ast_op_and:
431 Res = Builder.CreateAnd(LHS, RHS);
432 break;
433 case isl_ast_op_or:
434 Res = Builder.CreateOr(LHS, RHS);
435 break;
436 }
437
438 isl_ast_expr_free(Expr);
439 return Res;
440}
441
442Value *IslExprBuilder::createOp(__isl_take isl_ast_expr *Expr) {
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000443 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
444 "Expression not of type isl_ast_expr_op");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000445 switch (isl_ast_expr_get_op_type(Expr)) {
446 case isl_ast_op_error:
447 case isl_ast_op_cond:
448 case isl_ast_op_and_then:
449 case isl_ast_op_or_else:
450 case isl_ast_op_call:
451 llvm_unreachable("Unsupported isl ast expression");
452 case isl_ast_op_max:
453 case isl_ast_op_min:
454 return createOpNAry(Expr);
455 case isl_ast_op_add:
456 case isl_ast_op_sub:
457 case isl_ast_op_mul:
458 case isl_ast_op_div:
459 case isl_ast_op_fdiv_q: // Round towards -infty
460 case isl_ast_op_pdiv_q: // Dividend is non-negative
461 case isl_ast_op_pdiv_r: // Dividend is non-negative
462 return createOpBin(Expr);
463 case isl_ast_op_minus:
464 return createOpUnary(Expr);
465 case isl_ast_op_select:
466 return createOpSelect(Expr);
467 case isl_ast_op_and:
468 case isl_ast_op_or:
469 return createOpBoolean(Expr);
470 case isl_ast_op_eq:
471 case isl_ast_op_le:
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000472 case isl_ast_op_lt:
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000473 case isl_ast_op_ge:
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000474 case isl_ast_op_gt:
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000475 return createOpICmp(Expr);
476 }
477
478 llvm_unreachable("Unsupported isl_ast_expr_op kind.");
479}
480
481Value *IslExprBuilder::createId(__isl_take isl_ast_expr *Expr) {
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000482 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_id &&
483 "Expression not of type isl_ast_expr_ident");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000484
485 isl_id *Id;
486 Value *V;
487
488 Id = isl_ast_expr_get_id(Expr);
489
490 assert(IDToValue.count(Id) && "Identifier not found");
491
492 V = IDToValue[Id];
493
494 isl_id_free(Id);
495 isl_ast_expr_free(Expr);
496
497 return V;
498}
499
500IntegerType *IslExprBuilder::getType(__isl_keep isl_ast_expr *Expr) {
501 // XXX: We assume i64 is large enough. This is often true, but in general
502 // incorrect. Also, on 32bit architectures, it would be beneficial to
503 // use a smaller type. We can and should directly derive this information
504 // during code generation.
505 return IntegerType::get(Builder.getContext(), 64);
506}
507
508Value *IslExprBuilder::createInt(__isl_take isl_ast_expr *Expr) {
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000509 assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_int &&
510 "Expression not of type isl_ast_expr_int");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000511 isl_int Int;
512 Value *V;
513 APInt APValue;
514 IntegerType *T;
515
516 isl_int_init(Int);
517 isl_ast_expr_get_int(Expr, &Int);
518 APValue = APInt_from_MPZ(Int);
519 T = getType(Expr);
520 APValue = APValue.sextOrSelf(T->getBitWidth());
521 V = ConstantInt::get(T, APValue);
522
523 isl_ast_expr_free(Expr);
524 isl_int_clear(Int);
525 return V;
526}
527
528Value *IslExprBuilder::create(__isl_take isl_ast_expr *Expr) {
529 switch (isl_ast_expr_get_type(Expr)) {
530 case isl_ast_expr_error:
531 llvm_unreachable("Code generation error");
532 case isl_ast_expr_op:
533 return createOp(Expr);
534 case isl_ast_expr_id:
535 return createId(Expr);
536 case isl_ast_expr_int:
537 return createInt(Expr);
538 }
539
540 llvm_unreachable("Unexpected enum value");
541}
542
543class IslNodeBuilder {
544public:
545 IslNodeBuilder(IRBuilder<> &Builder, Pass *P):
546 Builder(Builder), ExprBuilder(Builder, IDToValue, P), P(P) {}
547
548 void addParameters(__isl_take isl_set *Context);
549 void create(__isl_take isl_ast_node *Node);
550
551private:
552 IRBuilder<> &Builder;
553 IslExprBuilder ExprBuilder;
554 Pass *P;
555
556 // This maps an isl_id* to the Value* it has in the generated program. For now
557 // on, the only isl_ids that are stored here are the newly calculated loop
558 // ivs.
559 std::map<isl_id *, Value*> IDToValue;
560
561 // Extract the upper bound of this loop
562 //
563 // The isl code generation can generate arbitrary expressions to check if the
564 // upper bound of a loop is reached, but it provides an option to enforce
565 // 'atomic' upper bounds. An 'atomic upper bound is always of the form
566 // iv <= expr, where expr is an (arbitrary) expression not containing iv.
567 //
568 // This function extracts 'atomic' upper bounds. Polly, in general, requires
569 // atomic upper bounds for the following reasons:
570 //
571 // 1. An atomic upper bound is loop invariant
572 //
573 // It must not be calculated at each loop iteration and can often even be
574 // hoisted out further by the loop invariant code motion.
575 //
576 // 2. OpenMP needs a loop invarient upper bound to calculate the number
577 // of loop iterations.
578 //
579 // 3. With the existing code, upper bounds have been easier to implement.
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000580 __isl_give isl_ast_expr *getUpperBound(__isl_keep isl_ast_node *For,
581 CmpInst::Predicate &Predicate);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000582
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000583 unsigned getNumberOfIterations(__isl_keep isl_ast_node *For);
584
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000585 void createFor(__isl_take isl_ast_node *For);
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000586 void createForVector(__isl_take isl_ast_node *For, int VectorWidth);
587 void createForSequential(__isl_take isl_ast_node *For);
588 void createSubstitutions(__isl_take isl_pw_multi_aff *PMA,
589 __isl_take isl_ast_build *Context,
590 ScopStmt *Stmt, ValueMapT &VMap);
591 void createSubstitutionsVector(__isl_take isl_pw_multi_aff *PMA,
592 __isl_take isl_ast_build *Context,
593 ScopStmt *Stmt, VectorValueMapT &VMap,
594 std::vector<Value*> &IVS,
595 __isl_take isl_id *IteratorID);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000596 void createIf(__isl_take isl_ast_node *If);
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000597 void createUserVector(__isl_take isl_ast_node *User,
598 std::vector<Value*> &IVS, __isl_take isl_id *IteratorID,
599 __isl_take isl_union_map *Schedule);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000600 void createUser(__isl_take isl_ast_node *User);
601 void createBlock(__isl_take isl_ast_node *Block);
602};
603
604__isl_give isl_ast_expr *IslNodeBuilder::getUpperBound(
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000605 __isl_keep isl_ast_node *For, ICmpInst::Predicate &Predicate) {
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000606 isl_id *UBID, *IteratorID;
607 isl_ast_expr *Cond, *Iterator, *UB, *Arg0;
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000608 isl_ast_op_type Type;
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000609
610 Cond = isl_ast_node_for_get_cond(For);
611 Iterator = isl_ast_node_for_get_iterator(For);
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000612 Type = isl_ast_expr_get_op_type(Cond);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000613
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000614 assert(isl_ast_expr_get_type(Cond) == isl_ast_expr_op &&
615 "conditional expression is not an atomic upper bound");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000616
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000617 switch (Type) {
618 case isl_ast_op_le:
619 Predicate = ICmpInst::ICMP_SLE;
620 break;
621 case isl_ast_op_lt:
622 Predicate = ICmpInst::ICMP_SLT;
623 break;
624 default:
625 llvm_unreachable("Unexpected comparision type in loop conditon");
626 }
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000627
628 Arg0 = isl_ast_expr_get_op_arg(Cond, 0);
629
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000630 assert(isl_ast_expr_get_type(Arg0) == isl_ast_expr_id &&
631 "conditional expression is not an atomic upper bound");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000632
633 UBID = isl_ast_expr_get_id(Arg0);
634
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000635 assert(isl_ast_expr_get_type(Iterator) == isl_ast_expr_id &&
636 "Could not get the iterator");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000637
638 IteratorID = isl_ast_expr_get_id(Iterator);
639
Tobias Grosserae2d83e2012-12-29 23:57:18 +0000640 assert(UBID == IteratorID &&
641 "conditional expression is not an atomic upper bound");
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000642
643 UB = isl_ast_expr_get_op_arg(Cond, 1);
644
645 isl_ast_expr_free(Cond);
646 isl_ast_expr_free(Iterator);
647 isl_ast_expr_free(Arg0);
648 isl_id_free(IteratorID);
649 isl_id_free(UBID);
650
651 return UB;
652}
653
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000654unsigned IslNodeBuilder::getNumberOfIterations(__isl_keep isl_ast_node *For) {
655 isl_id *Annotation = isl_ast_node_get_annotation(For);
656 if (!Annotation)
657 return -1;
658
659 struct IslAstUser *Info = (struct IslAstUser *) isl_id_get_user(Annotation);
660 if (!Info) {
661 isl_id_free(Annotation);
662 return -1;
663 }
664
665 isl_union_map *Schedule = isl_ast_build_get_schedule(Info->Context);
666 isl_set *LoopDomain = isl_set_from_union_set(isl_union_map_range(Schedule));
667 isl_id_free(Annotation);
Sebastian Pop2aa5c242012-12-18 08:56:51 +0000668 int NumberOfIterations = polly::getNumberOfIterations(LoopDomain);
669 if (NumberOfIterations == -1)
670 return -1;
671 return NumberOfIterations + 1;
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000672}
673
674void IslNodeBuilder::createUserVector(__isl_take isl_ast_node *User,
675 std::vector<Value*> &IVS,
676 __isl_take isl_id *IteratorID,
677 __isl_take isl_union_map *Schedule) {
678 isl_id *Annotation = isl_ast_node_get_annotation(User);
679 assert(Annotation && "Vector user statement is not annotated");
680
681 struct IslAstUser *Info = (struct IslAstUser *) isl_id_get_user(Annotation);
682 assert(Info && "Vector user statement annotation does not contain info");
683
684 isl_id *Id = isl_pw_multi_aff_get_tuple_id(Info->PMA, isl_dim_out);
685 ScopStmt *Stmt = (ScopStmt *) isl_id_get_user(Id);
686 VectorValueMapT VectorMap(IVS.size());
687
688 isl_union_set *Domain = isl_union_set_from_set(Stmt->getDomain());
689 Schedule = isl_union_map_intersect_domain(Schedule, Domain);
690 isl_map *S = isl_map_from_union_map(Schedule);
691
692 createSubstitutionsVector(isl_pw_multi_aff_copy(Info->PMA),
Tobias Grosser1bb59b02012-12-29 23:47:38 +0000693 isl_ast_build_copy(Info->Context), Stmt, VectorMap,
694 IVS, IteratorID);
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000695 VectorBlockGenerator::generate(Builder, *Stmt, VectorMap, S, P);
696
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000697 isl_map_free(S);
698 isl_id_free(Annotation);
699 isl_id_free(Id);
700 isl_ast_node_free(User);
701}
702
703void IslNodeBuilder::createForVector(__isl_take isl_ast_node *For,
704 int VectorWidth) {
705 isl_ast_node *Body = isl_ast_node_for_get_body(For);
706 isl_ast_expr *Init = isl_ast_node_for_get_init(For);
707 isl_ast_expr *Inc = isl_ast_node_for_get_inc(For);
708 isl_ast_expr *Iterator = isl_ast_node_for_get_iterator(For);
709 isl_id *IteratorID = isl_ast_expr_get_id(Iterator);
710 CmpInst::Predicate Predicate;
711 isl_ast_expr *UB = getUpperBound(For, Predicate);
712
713 Value *ValueLB = ExprBuilder.create(Init);
714 Value *ValueUB = ExprBuilder.create(UB);
715 Value *ValueInc = ExprBuilder.create(Inc);
716
717 Type *MaxType = ExprBuilder.getType(Iterator);
718 MaxType = ExprBuilder.getWidestType(MaxType, ValueLB->getType());
719 MaxType = ExprBuilder.getWidestType(MaxType, ValueUB->getType());
720 MaxType = ExprBuilder.getWidestType(MaxType, ValueInc->getType());
721
722 if (MaxType != ValueLB->getType())
723 ValueLB = Builder.CreateSExt(ValueLB, MaxType);
724 if (MaxType != ValueUB->getType())
725 ValueUB = Builder.CreateSExt(ValueUB, MaxType);
726 if (MaxType != ValueInc->getType())
727 ValueInc = Builder.CreateSExt(ValueInc, MaxType);
728
729 std::vector<Value*> IVS(VectorWidth);
730 IVS[0] = ValueLB;
731
732 for (int i = 1; i < VectorWidth; i++)
733 IVS[i] = Builder.CreateAdd(IVS[i-1], ValueInc, "p_vector_iv");
734
735 isl_id *Annotation = isl_ast_node_get_annotation(For);
736 assert(Annotation && "For statement is not annotated");
737
738 struct IslAstUser *Info = (struct IslAstUser *) isl_id_get_user(Annotation);
739 assert(Info && "For statement annotation does not contain info");
740
741 isl_union_map *Schedule = isl_ast_build_get_schedule(Info->Context);
742 assert(Schedule && "For statement annotation does not contain its schedule");
743
744 IDToValue[IteratorID] = ValueLB;
745
746 switch (isl_ast_node_get_type(Body)) {
747 case isl_ast_node_user:
748 createUserVector(Body, IVS, isl_id_copy(IteratorID),
749 isl_union_map_copy(Schedule));
750 break;
751 case isl_ast_node_block: {
752 isl_ast_node_list *List = isl_ast_node_block_get_children(Body);
753
754 for (int i = 0; i < isl_ast_node_list_n_ast_node(List); ++i)
755 createUserVector(isl_ast_node_list_get_ast_node(List, i), IVS,
Tobias Grosser1bb59b02012-12-29 23:47:38 +0000756 isl_id_copy(IteratorID), isl_union_map_copy(Schedule));
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000757
758 isl_ast_node_free(Body);
759 isl_ast_node_list_free(List);
760 break;
761 }
762 default:
763 isl_ast_node_dump(Body);
764 llvm_unreachable("Unhandled isl_ast_node in vectorizer");
765 }
766
767 IDToValue.erase(IteratorID);
768 isl_id_free(IteratorID);
769 isl_id_free(Annotation);
770 isl_union_map_free(Schedule);
771
772 isl_ast_node_free(For);
773 isl_ast_expr_free(Iterator);
774}
775
776void IslNodeBuilder::createForSequential(__isl_take isl_ast_node *For) {
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000777 isl_ast_node *Body;
778 isl_ast_expr *Init, *Inc, *Iterator, *UB;
779 isl_id *IteratorID;
780 Value *ValueLB, *ValueUB, *ValueInc;
781 Type *MaxType;
782 BasicBlock *AfterBlock;
783 Value *IV;
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000784 CmpInst::Predicate Predicate;
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000785
786 Body = isl_ast_node_for_get_body(For);
787
788 // isl_ast_node_for_is_degenerate(For)
789 //
790 // TODO: For degenerated loops we could generate a plain assignment.
791 // However, for now we just reuse the logic for normal loops, which will
792 // create a loop with a single iteration.
793
794 Init = isl_ast_node_for_get_init(For);
795 Inc = isl_ast_node_for_get_inc(For);
796 Iterator = isl_ast_node_for_get_iterator(For);
797 IteratorID = isl_ast_expr_get_id(Iterator);
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000798 UB = getUpperBound(For, Predicate);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000799
800 ValueLB = ExprBuilder.create(Init);
801 ValueUB = ExprBuilder.create(UB);
802 ValueInc = ExprBuilder.create(Inc);
803
804 MaxType = ExprBuilder.getType(Iterator);
805 MaxType = ExprBuilder.getWidestType(MaxType, ValueLB->getType());
806 MaxType = ExprBuilder.getWidestType(MaxType, ValueUB->getType());
807 MaxType = ExprBuilder.getWidestType(MaxType, ValueInc->getType());
808
809 if (MaxType != ValueLB->getType())
810 ValueLB = Builder.CreateSExt(ValueLB, MaxType);
811 if (MaxType != ValueUB->getType())
812 ValueUB = Builder.CreateSExt(ValueUB, MaxType);
813 if (MaxType != ValueInc->getType())
814 ValueInc = Builder.CreateSExt(ValueInc, MaxType);
815
816 // TODO: In case we can proof a loop is executed at least once, we can
817 // generate the condition iv != UB + stride (consider possible
818 // overflow). This condition will allow LLVM to prove the loop is
819 // executed at least once, which will enable a lot of loop invariant
820 // code motion.
821
Tobias Grosserc967d8e2012-10-16 07:29:13 +0000822 IV = createLoop(ValueLB, ValueUB, ValueInc, Builder, P, AfterBlock,
823 Predicate);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000824 IDToValue[IteratorID] = IV;
825
826 create(Body);
827
828 IDToValue.erase(IteratorID);
829
830 Builder.SetInsertPoint(AfterBlock->begin());
831
832 isl_ast_node_free(For);
833 isl_ast_expr_free(Iterator);
834 isl_id_free(IteratorID);
835}
836
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000837void IslNodeBuilder::createFor(__isl_take isl_ast_node *For) {
838 bool Vector = PollyVectorizerChoice != VECTORIZER_NONE;
839
840 if (Vector && isInnermostParallel(For)) {
841 int VectorWidth = getNumberOfIterations(For);
842 if (1 < VectorWidth && VectorWidth <= 16) {
843 createForVector(For, VectorWidth);
844 return;
845 }
846 }
847 createForSequential(For);
848}
849
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000850void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) {
851 isl_ast_expr *Cond = isl_ast_node_if_get_cond(If);
852
853 Function *F = Builder.GetInsertBlock()->getParent();
854 LLVMContext &Context = F->getContext();
855
856 BasicBlock *CondBB = SplitBlock(Builder.GetInsertBlock(),
857 Builder.GetInsertPoint(), P);
858 CondBB->setName("polly.cond");
859 BasicBlock *MergeBB = SplitBlock(CondBB, CondBB->begin(), P);
860 MergeBB->setName("polly.merge");
861 BasicBlock *ThenBB = BasicBlock::Create(Context, "polly.then", F);
862 BasicBlock *ElseBB = BasicBlock::Create(Context, "polly.else", F);
863
864 DominatorTree &DT = P->getAnalysis<DominatorTree>();
865 DT.addNewBlock(ThenBB, CondBB);
866 DT.addNewBlock(ElseBB, CondBB);
867 DT.changeImmediateDominator(MergeBB, CondBB);
868
869 CondBB->getTerminator()->eraseFromParent();
870
871 Builder.SetInsertPoint(CondBB);
872 Value *Predicate = ExprBuilder.create(Cond);
873 Builder.CreateCondBr(Predicate, ThenBB, ElseBB);
874 Builder.SetInsertPoint(ThenBB);
875 Builder.CreateBr(MergeBB);
876 Builder.SetInsertPoint(ElseBB);
877 Builder.CreateBr(MergeBB);
878 Builder.SetInsertPoint(ThenBB->begin());
879
880 create(isl_ast_node_if_get_then(If));
881
882 Builder.SetInsertPoint(ElseBB->begin());
883
884 if (isl_ast_node_if_has_else(If))
885 create(isl_ast_node_if_get_else(If));
886
887 Builder.SetInsertPoint(MergeBB->begin());
888
889 isl_ast_node_free(If);
890}
891
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000892void IslNodeBuilder::createSubstitutions(__isl_take isl_pw_multi_aff *PMA,
Tobias Grosser1bb59b02012-12-29 23:47:38 +0000893 __isl_take isl_ast_build *Context,
894 ScopStmt *Stmt, ValueMapT &VMap) {
895 for (unsigned i = 0; i < isl_pw_multi_aff_dim(PMA, isl_dim_out); ++i) {
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000896 isl_pw_aff *Aff;
897 isl_ast_expr *Expr;
898 const Value *OldIV;
899 Value *V;
900
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000901 Aff = isl_pw_multi_aff_get_pw_aff(PMA, i);
902 Expr = isl_ast_build_expr_from_pw_aff(Context, Aff);
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000903 OldIV = Stmt->getInductionVariableForDimension(i);
904 V = ExprBuilder.create(Expr);
905
906 // CreateIntCast can introduce trunc expressions. This is correct, as the
907 // result will always fit into the type of the original induction variable
908 // (because we calculate a value of the original induction variable).
909 V = Builder.CreateIntCast(V, OldIV->getType(), true);
910 VMap[OldIV] = V;
911 }
912
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000913 isl_pw_multi_aff_free(PMA);
914 isl_ast_build_free(Context);
915}
916
917void IslNodeBuilder::createSubstitutionsVector(__isl_take isl_pw_multi_aff *PMA,
918 __isl_take isl_ast_build *Context, ScopStmt *Stmt, VectorValueMapT &VMap,
919 std::vector<Value*> &IVS, __isl_take isl_id *IteratorID) {
920 int i = 0;
921
922 Value *OldValue = IDToValue[IteratorID];
923 for (std::vector<Value*>::iterator II = IVS.begin(), IE = IVS.end();
924 II != IE; ++II) {
925 IDToValue[IteratorID] = *II;
Tobias Grosser1bb59b02012-12-29 23:47:38 +0000926 createSubstitutions(isl_pw_multi_aff_copy(PMA), isl_ast_build_copy(Context),
927 Stmt, VMap[i]);
Sebastian Pop04c4ce32012-12-18 07:46:13 +0000928 i++;
929 }
930
931 IDToValue[IteratorID] = OldValue;
932 isl_id_free(IteratorID);
933 isl_pw_multi_aff_free(PMA);
934 isl_ast_build_free(Context);
935}
936
937void IslNodeBuilder::createUser(__isl_take isl_ast_node *User) {
938 ValueMapT VMap;
939 struct IslAstUser *Info;
940 isl_id *Annotation, *Id;
941 ScopStmt *Stmt;
942
943 Annotation = isl_ast_node_get_annotation(User);
944 assert(Annotation && "Scalar user statement is not annotated");
945
946 Info = (struct IslAstUser *) isl_id_get_user(Annotation);
947 assert(Info && "Scalar user statement annotation does not contain info");
948
949 Id = isl_pw_multi_aff_get_tuple_id(Info->PMA, isl_dim_out);
950 Stmt = (ScopStmt *) isl_id_get_user(Id);
951
952 createSubstitutions(isl_pw_multi_aff_copy(Info->PMA),
953 isl_ast_build_copy(Info->Context), Stmt, VMap);
954
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +0000955 BlockGenerator::generate(Builder, *Stmt, VMap, P);
956
957 isl_ast_node_free(User);
958 isl_id_free(Annotation);
959 isl_id_free(Id);
960}
961
962void IslNodeBuilder::createBlock(__isl_take isl_ast_node *Block) {
963 isl_ast_node_list *List = isl_ast_node_block_get_children(Block);
964
965 for (int i = 0; i < isl_ast_node_list_n_ast_node(List); ++i)
966 create(isl_ast_node_list_get_ast_node(List, i));
967
968 isl_ast_node_free(Block);
969 isl_ast_node_list_free(List);
970}
971
972void IslNodeBuilder::create(__isl_take isl_ast_node *Node) {
973 switch (isl_ast_node_get_type(Node)) {
974 case isl_ast_node_error:
975 llvm_unreachable("code generation error");
976 case isl_ast_node_for:
977 createFor(Node);
978 return;
979 case isl_ast_node_if:
980 createIf(Node);
981 return;
982 case isl_ast_node_user:
983 createUser(Node);
984 return;
985 case isl_ast_node_block:
986 createBlock(Node);
987 return;
988 }
989
990 llvm_unreachable("Unknown isl_ast_node type");
991}
992
993void IslNodeBuilder::addParameters(__isl_take isl_set *Context) {
994 SCEVExpander Rewriter(P->getAnalysis<ScalarEvolution>(), "polly");
995
996 for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
997 isl_id *Id;
998 const SCEV *Scev;
999 IntegerType *T;
1000 Instruction *InsertLocation;
1001
1002 Id = isl_set_get_dim_id(Context, isl_dim_param, i);
1003 Scev = (const SCEV*) isl_id_get_user(Id);
1004 T = dyn_cast<IntegerType>(Scev->getType());
1005 InsertLocation = --(Builder.GetInsertBlock()->end());
1006 Value *V = Rewriter.expandCodeFor(Scev, T, InsertLocation);
1007 IDToValue[Id] = V;
1008
1009 isl_id_free(Id);
1010 }
1011
1012 isl_set_free(Context);
1013}
1014
1015namespace {
1016class IslCodeGeneration : public ScopPass {
Tobias Grosser1bb59b02012-12-29 23:47:38 +00001017public:
Tobias Grosser8a5bc6e2012-10-02 19:50:43 +00001018 static char ID;
1019
1020 IslCodeGeneration() : ScopPass(ID) {}
1021
1022 bool runOnScop(Scop &S) {
1023 IslAstInfo &AstInfo = getAnalysis<IslAstInfo>();
1024 assert(S.getRegion().isSimple() && "Only simple regions are supported");
1025
1026 BasicBlock *StartBlock = executeScopConditionally(S, this);
1027 isl_ast_node *Ast = AstInfo.getAst();
1028 IRBuilder<> Builder(StartBlock->begin());
1029
1030 IslNodeBuilder NodeBuilder(Builder, this);
1031 NodeBuilder.addParameters(S.getContext());
1032 NodeBuilder.create(Ast);
1033 return true;
1034 }
1035
1036 virtual void printScop(raw_ostream &OS) const {
1037 }
1038
1039 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
1040 AU.addRequired<DominatorTree>();
1041 AU.addRequired<IslAstInfo>();
1042 AU.addRequired<RegionInfo>();
1043 AU.addRequired<ScalarEvolution>();
1044 AU.addRequired<ScopDetection>();
1045 AU.addRequired<ScopInfo>();
1046
1047 AU.addPreserved<Dependences>();
1048
1049 // FIXME: We do not create LoopInfo for the newly generated loops.
1050 AU.addPreserved<LoopInfo>();
1051 AU.addPreserved<DominatorTree>();
1052 AU.addPreserved<IslAstInfo>();
1053 AU.addPreserved<ScopDetection>();
1054 AU.addPreserved<ScalarEvolution>();
1055
1056 // FIXME: We do not yet add regions for the newly generated code to the
1057 // region tree.
1058 AU.addPreserved<RegionInfo>();
1059 AU.addPreserved<TempScopInfo>();
1060 AU.addPreserved<ScopInfo>();
1061 AU.addPreservedID(IndependentBlocksID);
1062 }
1063};
1064}
1065
1066char IslCodeGeneration::ID = 1;
1067
1068INITIALIZE_PASS_BEGIN(IslCodeGeneration, "polly-codegen-isl",
1069 "Polly - Create LLVM-IR from SCoPs", false, false)
1070INITIALIZE_PASS_DEPENDENCY(Dependences)
1071INITIALIZE_PASS_DEPENDENCY(DominatorTree)
1072INITIALIZE_PASS_DEPENDENCY(LoopInfo)
1073INITIALIZE_PASS_DEPENDENCY(RegionInfo)
1074INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
1075INITIALIZE_PASS_DEPENDENCY(ScopDetection)
1076INITIALIZE_PASS_END(IslCodeGeneration, "polly-codegen-isl",
1077 "Polly - Create LLVM-IR from SCoPs", false, false)
1078
1079Pass *polly::createIslCodeGenerationPass() {
1080 return new IslCodeGeneration();
1081}