1 //===- IslAst.cpp - isl code generator interface --------------------------===//
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 isl code generator interface takes a Scop and generates an isl_ast. This
11 // ist_ast can either be returned directly or it can be pretty printed to
12 // stdout.
13 //
14 // A typical isl_ast output looks like this:
15 //
16 // for (c2 = max(0, ceild(n + m, 2); c2 <= min(511, floord(5 * n, 3)); c2++) {
17 //   bb2(c2);
18 // }
19 //
20 // An in-depth discussion of our AST generation approach can be found in:
21 //
22 // Polyhedral AST generation is more than scanning polyhedra
23 // Tobias Grosser, Sven Verdoolaege, Albert Cohen
24 // ACM Transations on Programming Languages and Systems (TOPLAS),
25 // 37(4), July 2015
26 // http://www.grosser.es/#pub-polyhedral-AST-generation
27 //
28 //===----------------------------------------------------------------------===//
29 
30 #include "polly/CodeGen/CodeGeneration.h"
31 #include "polly/CodeGen/IslAst.h"
32 #include "polly/DependenceInfo.h"
33 #include "polly/LinkAllPasses.h"
34 #include "polly/Options.h"
35 #include "polly/ScopInfo.h"
36 #include "polly/Support/GICHelper.h"
37 #include "llvm/Analysis/RegionInfo.h"
38 #include "llvm/Support/Debug.h"
39 #include "isl/aff.h"
40 #include "isl/ast_build.h"
41 #include "isl/list.h"
42 #include "isl/map.h"
43 #include "isl/set.h"
44 #include "isl/union_map.h"
45 
46 #define DEBUG_TYPE "polly-ast"
47 
48 using namespace llvm;
49 using namespace polly;
50 
51 using IslAstUserPayload = IslAstInfo::IslAstUserPayload;
52 
53 static cl::opt<bool>
54     PollyParallel("polly-parallel",
55                   cl::desc("Generate thread parallel code (isl codegen only)"),
56                   cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
57 
58 static cl::opt<bool> PollyParallelForce(
59     "polly-parallel-force",
60     cl::desc(
61         "Force generation of thread parallel code ignoring any cost model"),
62     cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
63 
64 static cl::opt<bool> UseContext("polly-ast-use-context",
65                                 cl::desc("Use context"), cl::Hidden,
66                                 cl::init(false), cl::ZeroOrMore,
67                                 cl::cat(PollyCategory));
68 
69 static cl::opt<bool> DetectParallel("polly-ast-detect-parallel",
70                                     cl::desc("Detect parallelism"), cl::Hidden,
71                                     cl::init(false), cl::ZeroOrMore,
72                                     cl::cat(PollyCategory));
73 
74 static cl::opt<bool> NoEarlyExit(
75     "polly-no-early-exit",
76     cl::desc("Do not exit early if no benefit of the Polly version was found."),
77     cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
78 
79 namespace polly {
80 class IslAst {
81 public:
82   static IslAst *create(Scop *Scop, const Dependences &D);
83   ~IslAst();
84 
85   /// Print a source code representation of the program.
86   void pprint(llvm::raw_ostream &OS);
87 
88   __isl_give isl_ast_node *getAst();
89 
90   /// @brief Get the run-time conditions for the Scop.
91   __isl_give isl_ast_expr *getRunCondition();
92 
93 private:
94   Scop *S;
95   isl_ast_node *Root;
96   isl_ast_expr *RunCondition;
97 
98   IslAst(Scop *Scop);
99   void init(const Dependences &D);
100 
101   void buildRunCondition(__isl_keep isl_ast_build *Build);
102 };
103 } // End namespace polly.
104 
105 /// @brief Free an IslAstUserPayload object pointed to by @p Ptr
106 static void freeIslAstUserPayload(void *Ptr) {
107   delete ((IslAstInfo::IslAstUserPayload *)Ptr);
108 }
109 
110 IslAstInfo::IslAstUserPayload::~IslAstUserPayload() {
111   isl_ast_build_free(Build);
112   isl_pw_aff_free(MinimalDependenceDistance);
113 }
114 
115 /// @brief Temporary information used when building the ast.
116 struct AstBuildUserInfo {
117   /// @brief Construct and initialize the helper struct for AST creation.
118   AstBuildUserInfo()
119       : Deps(nullptr), InParallelFor(false), LastForNodeId(nullptr) {}
120 
121   /// @brief The dependence information used for the parallelism check.
122   const Dependences *Deps;
123 
124   /// @brief Flag to indicate that we are inside a parallel for node.
125   bool InParallelFor;
126 
127   /// @brief The last iterator id created for the current SCoP.
128   isl_id *LastForNodeId;
129 };
130 
131 /// @brief Print a string @p str in a single line using @p Printer.
132 static isl_printer *printLine(__isl_take isl_printer *Printer,
133                               const std::string &str,
134                               __isl_keep isl_pw_aff *PWA = nullptr) {
135   Printer = isl_printer_start_line(Printer);
136   Printer = isl_printer_print_str(Printer, str.c_str());
137   if (PWA)
138     Printer = isl_printer_print_pw_aff(Printer, PWA);
139   return isl_printer_end_line(Printer);
140 }
141 
142 /// @brief Return all broken reductions as a string of clauses (OpenMP style).
143 static const std::string getBrokenReductionsStr(__isl_keep isl_ast_node *Node) {
144   IslAstInfo::MemoryAccessSet *BrokenReductions;
145   std::string str;
146 
147   BrokenReductions = IslAstInfo::getBrokenReductions(Node);
148   if (!BrokenReductions || BrokenReductions->empty())
149     return "";
150 
151   // Map each type of reduction to a comma separated list of the base addresses.
152   std::map<MemoryAccess::ReductionType, std::string> Clauses;
153   for (MemoryAccess *MA : *BrokenReductions)
154     if (MA->isWrite())
155       Clauses[MA->getReductionType()] +=
156           ", " + MA->getBaseAddr()->getName().str();
157 
158   // Now print the reductions sorted by type. Each type will cause a clause
159   // like:  reduction (+ : sum0, sum1, sum2)
160   for (const auto &ReductionClause : Clauses) {
161     str += " reduction (";
162     str += MemoryAccess::getReductionOperatorStr(ReductionClause.first);
163     // Remove the first two symbols (", ") to make the output look pretty.
164     str += " : " + ReductionClause.second.substr(2) + ")";
165   }
166 
167   return str;
168 }
169 
170 /// @brief Callback executed for each for node in the ast in order to print it.
171 static isl_printer *cbPrintFor(__isl_take isl_printer *Printer,
172                                __isl_take isl_ast_print_options *Options,
173                                __isl_keep isl_ast_node *Node, void *) {
174 
175   isl_pw_aff *DD = IslAstInfo::getMinimalDependenceDistance(Node);
176   const std::string BrokenReductionsStr = getBrokenReductionsStr(Node);
177   const std::string KnownParallelStr = "#pragma known-parallel";
178   const std::string DepDisPragmaStr = "#pragma minimal dependence distance: ";
179   const std::string SimdPragmaStr = "#pragma simd";
180   const std::string OmpPragmaStr = "#pragma omp parallel for";
181 
182   if (DD)
183     Printer = printLine(Printer, DepDisPragmaStr, DD);
184 
185   if (IslAstInfo::isInnermostParallel(Node))
186     Printer = printLine(Printer, SimdPragmaStr + BrokenReductionsStr);
187 
188   if (IslAstInfo::isExecutedInParallel(Node))
189     Printer = printLine(Printer, OmpPragmaStr);
190   else if (IslAstInfo::isOutermostParallel(Node))
191     Printer = printLine(Printer, KnownParallelStr + BrokenReductionsStr);
192 
193   isl_pw_aff_free(DD);
194   return isl_ast_node_for_print(Node, Printer, Options);
195 }
196 
197 /// @brief Check if the current scheduling dimension is parallel
198 ///
199 /// In case the dimension is parallel we also check if any reduction
200 /// dependences is broken when we exploit this parallelism. If so,
201 /// @p IsReductionParallel will be set to true. The reduction dependences we use
202 /// to check are actually the union of the transitive closure of the initial
203 /// reduction dependences together with their reveresal. Even though these
204 /// dependences connect all iterations with each other (thus they are cyclic)
205 /// we can perform the parallelism check as we are only interested in a zero
206 /// (or non-zero) dependence distance on the dimension in question.
207 static bool astScheduleDimIsParallel(__isl_keep isl_ast_build *Build,
208                                      const Dependences *D,
209                                      IslAstUserPayload *NodeInfo) {
210   if (!D->hasValidDependences())
211     return false;
212 
213   isl_union_map *Schedule = isl_ast_build_get_schedule(Build);
214   isl_union_map *Deps = D->getDependences(
215       Dependences::TYPE_RAW | Dependences::TYPE_WAW | Dependences::TYPE_WAR);
216 
217   if (!D->isParallel(Schedule, Deps, &NodeInfo->MinimalDependenceDistance) &&
218       !isl_union_map_free(Schedule))
219     return false;
220 
221   isl_union_map *RedDeps = D->getDependences(Dependences::TYPE_TC_RED);
222   if (!D->isParallel(Schedule, RedDeps))
223     NodeInfo->IsReductionParallel = true;
224 
225   if (!NodeInfo->IsReductionParallel && !isl_union_map_free(Schedule))
226     return true;
227 
228   // Annotate reduction parallel nodes with the memory accesses which caused the
229   // reduction dependences parallel execution of the node conflicts with.
230   for (const auto &MaRedPair : D->getReductionDependences()) {
231     if (!MaRedPair.second)
232       continue;
233     RedDeps = isl_union_map_from_map(isl_map_copy(MaRedPair.second));
234     if (!D->isParallel(Schedule, RedDeps))
235       NodeInfo->BrokenReductions.insert(MaRedPair.first);
236   }
237 
238   isl_union_map_free(Schedule);
239   return true;
240 }
241 
242 // This method is executed before the construction of a for node. It creates
243 // an isl_id that is used to annotate the subsequently generated ast for nodes.
244 //
245 // In this function we also run the following analyses:
246 //
247 // - Detection of openmp parallel loops
248 //
249 static __isl_give isl_id *astBuildBeforeFor(__isl_keep isl_ast_build *Build,
250                                             void *User) {
251   AstBuildUserInfo *BuildInfo = (AstBuildUserInfo *)User;
252   IslAstUserPayload *Payload = new IslAstUserPayload();
253   isl_id *Id = isl_id_alloc(isl_ast_build_get_ctx(Build), "", Payload);
254   Id = isl_id_set_free_user(Id, freeIslAstUserPayload);
255   BuildInfo->LastForNodeId = Id;
256 
257   // Test for parallelism only if we are not already inside a parallel loop
258   if (!BuildInfo->InParallelFor)
259     BuildInfo->InParallelFor = Payload->IsOutermostParallel =
260         astScheduleDimIsParallel(Build, BuildInfo->Deps, Payload);
261 
262   return Id;
263 }
264 
265 // This method is executed after the construction of a for node.
266 //
267 // It performs the following actions:
268 //
269 // - Reset the 'InParallelFor' flag, as soon as we leave a for node,
270 //   that is marked as openmp parallel.
271 //
272 static __isl_give isl_ast_node *
273 astBuildAfterFor(__isl_take isl_ast_node *Node, __isl_keep isl_ast_build *Build,
274                  void *User) {
275   isl_id *Id = isl_ast_node_get_annotation(Node);
276   assert(Id && "Post order visit assumes annotated for nodes");
277   IslAstUserPayload *Payload = (IslAstUserPayload *)isl_id_get_user(Id);
278   assert(Payload && "Post order visit assumes annotated for nodes");
279 
280   AstBuildUserInfo *BuildInfo = (AstBuildUserInfo *)User;
281   assert(!Payload->Build && "Build environment already set");
282   Payload->Build = isl_ast_build_copy(Build);
283   Payload->IsInnermost = (Id == BuildInfo->LastForNodeId);
284 
285   // Innermost loops that are surrounded by parallel loops have not yet been
286   // tested for parallelism. Test them here to ensure we check all innermost
287   // loops for parallelism.
288   if (Payload->IsInnermost && BuildInfo->InParallelFor) {
289     if (Payload->IsOutermostParallel)
290       Payload->IsInnermostParallel = true;
291     else
292       Payload->IsInnermostParallel =
293           astScheduleDimIsParallel(Build, BuildInfo->Deps, Payload);
294   }
295   if (Payload->IsOutermostParallel)
296     BuildInfo->InParallelFor = false;
297 
298   isl_id_free(Id);
299   return Node;
300 }
301 
302 static __isl_give isl_ast_node *AtEachDomain(__isl_take isl_ast_node *Node,
303                                              __isl_keep isl_ast_build *Build,
304                                              void *User) {
305   assert(!isl_ast_node_get_annotation(Node) && "Node already annotated");
306 
307   IslAstUserPayload *Payload = new IslAstUserPayload();
308   isl_id *Id = isl_id_alloc(isl_ast_build_get_ctx(Build), "", Payload);
309   Id = isl_id_set_free_user(Id, freeIslAstUserPayload);
310 
311   Payload->Build = isl_ast_build_copy(Build);
312 
313   return isl_ast_node_set_annotation(Node, Id);
314 }
315 
316 // Build alias check condition given a pair of minimal/maximal access.
317 static __isl_give isl_ast_expr *
318 buildCondition(__isl_keep isl_ast_build *Build, const Scop::MinMaxAccessTy *It0,
319                const Scop::MinMaxAccessTy *It1) {
320   isl_ast_expr *NonAliasGroup, *MinExpr, *MaxExpr;
321   MinExpr = isl_ast_expr_address_of(isl_ast_build_access_from_pw_multi_aff(
322       Build, isl_pw_multi_aff_copy(It0->first)));
323   MaxExpr = isl_ast_expr_address_of(isl_ast_build_access_from_pw_multi_aff(
324       Build, isl_pw_multi_aff_copy(It1->second)));
325   NonAliasGroup = isl_ast_expr_le(MaxExpr, MinExpr);
326   MinExpr = isl_ast_expr_address_of(isl_ast_build_access_from_pw_multi_aff(
327       Build, isl_pw_multi_aff_copy(It1->first)));
328   MaxExpr = isl_ast_expr_address_of(isl_ast_build_access_from_pw_multi_aff(
329       Build, isl_pw_multi_aff_copy(It0->second)));
330   NonAliasGroup =
331       isl_ast_expr_or(NonAliasGroup, isl_ast_expr_le(MaxExpr, MinExpr));
332 
333   return NonAliasGroup;
334 }
335 
336 void IslAst::buildRunCondition(__isl_keep isl_ast_build *Build) {
337   // The conditions that need to be checked at run-time for this scop are
338   // available as an isl_set in the runtime check context from which we can
339   // directly derive a run-time condition.
340   RunCondition =
341       isl_ast_build_expr_from_set(Build, S->getRuntimeCheckContext());
342 
343   // Create the alias checks from the minimal/maximal accesses in each alias
344   // group which consists of read only and non read only (read write) accesses.
345   // This operation is by construction quadratic in the read-write pointers and
346   // linear int the read only pointers in each alias group.
347   for (const Scop::MinMaxVectorPairTy &MinMaxAccessPair : S->getAliasGroups()) {
348     auto &MinMaxReadWrite = MinMaxAccessPair.first;
349     auto &MinMaxReadOnly = MinMaxAccessPair.second;
350     auto RWAccEnd = MinMaxReadWrite.end();
351 
352     for (auto RWAccIt0 = MinMaxReadWrite.begin(); RWAccIt0 != RWAccEnd;
353          ++RWAccIt0) {
354       for (auto RWAccIt1 = RWAccIt0 + 1; RWAccIt1 != RWAccEnd; ++RWAccIt1)
355         RunCondition = isl_ast_expr_and(
356             RunCondition, buildCondition(Build, RWAccIt0, RWAccIt1));
357       for (const Scop::MinMaxAccessTy &ROAccIt : MinMaxReadOnly)
358         RunCondition = isl_ast_expr_and(
359             RunCondition, buildCondition(Build, RWAccIt0, &ROAccIt));
360     }
361   }
362 }
363 
364 /// @brief Simple cost analysis for a given SCoP
365 ///
366 /// TODO: Improve this analysis and extract it to make it usable in other
367 ///       places too.
368 ///       In order to improve the cost model we could either keep track of
369 ///       performed optimizations (e.g., tiling) or compute properties on the
370 ///       original as well as optimized SCoP (e.g., #stride-one-accesses).
371 static bool benefitsFromPolly(Scop *Scop, bool PerformParallelTest) {
372 
373   // First check the user choice.
374   if (NoEarlyExit)
375     return true;
376 
377   // Check if nothing interesting happened.
378   if (!PerformParallelTest && !Scop->isOptimized() &&
379       Scop->getAliasGroups().empty())
380     return false;
381 
382   // The default assumption is that Polly improves the code.
383   return true;
384 }
385 
386 IslAst::IslAst(Scop *Scop) : S(Scop), Root(nullptr), RunCondition(nullptr) {}
387 
388 void IslAst::init(const Dependences &D) {
389   bool PerformParallelTest = PollyParallel || DetectParallel ||
390                              PollyVectorizerChoice != VECTORIZER_NONE;
391 
392   // Skip AST and code generation if there was no benefit achieved.
393   if (!benefitsFromPolly(S, PerformParallelTest))
394     return;
395 
396   isl_ctx *Ctx = S->getIslCtx();
397   isl_options_set_ast_build_atomic_upper_bound(Ctx, true);
398   isl_ast_build *Build;
399   AstBuildUserInfo BuildInfo;
400 
401   if (UseContext)
402     Build = isl_ast_build_from_context(S->getContext());
403   else
404     Build = isl_ast_build_from_context(isl_set_universe(S->getParamSpace()));
405 
406   Build = isl_ast_build_set_at_each_domain(Build, AtEachDomain, nullptr);
407 
408   if (PerformParallelTest) {
409     BuildInfo.Deps = &D;
410     BuildInfo.InParallelFor = 0;
411 
412     Build = isl_ast_build_set_before_each_for(Build, &astBuildBeforeFor,
413                                               &BuildInfo);
414     Build =
415         isl_ast_build_set_after_each_for(Build, &astBuildAfterFor, &BuildInfo);
416   }
417 
418   buildRunCondition(Build);
419 
420   Root = isl_ast_build_node_from_schedule(Build, S->getScheduleTree());
421 
422   isl_ast_build_free(Build);
423 }
424 
425 IslAst *IslAst::create(Scop *Scop, const Dependences &D) {
426   auto Ast = new IslAst(Scop);
427   Ast->init(D);
428   return Ast;
429 }
430 
431 IslAst::~IslAst() {
432   isl_ast_node_free(Root);
433   isl_ast_expr_free(RunCondition);
434 }
435 
436 __isl_give isl_ast_node *IslAst::getAst() { return isl_ast_node_copy(Root); }
437 __isl_give isl_ast_expr *IslAst::getRunCondition() {
438   return isl_ast_expr_copy(RunCondition);
439 }
440 
441 void IslAstInfo::releaseMemory() {
442   if (Ast) {
443     delete Ast;
444     Ast = nullptr;
445   }
446 }
447 
448 bool IslAstInfo::runOnScop(Scop &Scop) {
449   if (Ast)
450     delete Ast;
451 
452   S = &Scop;
453 
454   const Dependences &D = getAnalysis<DependenceInfo>().getDependences();
455 
456   Ast = IslAst::create(&Scop, D);
457 
458   DEBUG(printScop(dbgs(), Scop));
459   return false;
460 }
461 
462 __isl_give isl_ast_node *IslAstInfo::getAst() const { return Ast->getAst(); }
463 __isl_give isl_ast_expr *IslAstInfo::getRunCondition() const {
464   return Ast->getRunCondition();
465 }
466 
467 IslAstUserPayload *IslAstInfo::getNodePayload(__isl_keep isl_ast_node *Node) {
468   isl_id *Id = isl_ast_node_get_annotation(Node);
469   if (!Id)
470     return nullptr;
471   IslAstUserPayload *Payload = (IslAstUserPayload *)isl_id_get_user(Id);
472   isl_id_free(Id);
473   return Payload;
474 }
475 
476 bool IslAstInfo::isInnermost(__isl_keep isl_ast_node *Node) {
477   IslAstUserPayload *Payload = getNodePayload(Node);
478   return Payload && Payload->IsInnermost;
479 }
480 
481 bool IslAstInfo::isParallel(__isl_keep isl_ast_node *Node) {
482   return IslAstInfo::isInnermostParallel(Node) ||
483          IslAstInfo::isOutermostParallel(Node);
484 }
485 
486 bool IslAstInfo::isInnermostParallel(__isl_keep isl_ast_node *Node) {
487   IslAstUserPayload *Payload = getNodePayload(Node);
488   return Payload && Payload->IsInnermostParallel;
489 }
490 
491 bool IslAstInfo::isOutermostParallel(__isl_keep isl_ast_node *Node) {
492   IslAstUserPayload *Payload = getNodePayload(Node);
493   return Payload && Payload->IsOutermostParallel;
494 }
495 
496 bool IslAstInfo::isReductionParallel(__isl_keep isl_ast_node *Node) {
497   IslAstUserPayload *Payload = getNodePayload(Node);
498   return Payload && Payload->IsReductionParallel;
499 }
500 
501 bool IslAstInfo::isExecutedInParallel(__isl_keep isl_ast_node *Node) {
502 
503   if (!PollyParallel)
504     return false;
505 
506   // Do not parallelize innermost loops.
507   //
508   // Parallelizing innermost loops is often not profitable, especially if
509   // they have a low number of iterations.
510   //
511   // TODO: Decide this based on the number of loop iterations that will be
512   //       executed. This can possibly require run-time checks, which again
513   //       raises the question of both run-time check overhead and code size
514   //       costs.
515   if (!PollyParallelForce && isInnermost(Node))
516     return false;
517 
518   return isOutermostParallel(Node) && !isReductionParallel(Node);
519 }
520 
521 isl_union_map *IslAstInfo::getSchedule(__isl_keep isl_ast_node *Node) {
522   IslAstUserPayload *Payload = getNodePayload(Node);
523   return Payload ? isl_ast_build_get_schedule(Payload->Build) : nullptr;
524 }
525 
526 isl_pw_aff *
527 IslAstInfo::getMinimalDependenceDistance(__isl_keep isl_ast_node *Node) {
528   IslAstUserPayload *Payload = getNodePayload(Node);
529   return Payload ? isl_pw_aff_copy(Payload->MinimalDependenceDistance)
530                  : nullptr;
531 }
532 
533 IslAstInfo::MemoryAccessSet *
534 IslAstInfo::getBrokenReductions(__isl_keep isl_ast_node *Node) {
535   IslAstUserPayload *Payload = getNodePayload(Node);
536   return Payload ? &Payload->BrokenReductions : nullptr;
537 }
538 
539 isl_ast_build *IslAstInfo::getBuild(__isl_keep isl_ast_node *Node) {
540   IslAstUserPayload *Payload = getNodePayload(Node);
541   return Payload ? Payload->Build : nullptr;
542 }
543 
544 void IslAstInfo::printScop(raw_ostream &OS, Scop &S) const {
545   isl_ast_print_options *Options;
546   isl_ast_node *RootNode = getAst();
547   Function *F = S.getRegion().getEntry()->getParent();
548 
549   OS << ":: isl ast :: " << F->getName() << " :: " << S.getRegion().getNameStr()
550      << "\n";
551 
552   if (!RootNode) {
553     OS << ":: isl ast generation and code generation was skipped!\n\n";
554     return;
555   }
556 
557   isl_ast_expr *RunCondition = getRunCondition();
558   char *RtCStr, *AstStr;
559 
560   Options = isl_ast_print_options_alloc(S.getIslCtx());
561   Options = isl_ast_print_options_set_print_for(Options, cbPrintFor, nullptr);
562 
563   isl_printer *P = isl_printer_to_str(S.getIslCtx());
564   P = isl_printer_print_ast_expr(P, RunCondition);
565   RtCStr = isl_printer_get_str(P);
566   P = isl_printer_flush(P);
567   P = isl_printer_indent(P, 4);
568   P = isl_printer_set_output_format(P, ISL_FORMAT_C);
569   P = isl_ast_node_print(RootNode, P, Options);
570   AstStr = isl_printer_get_str(P);
571 
572   isl_union_map *Schedule =
573       isl_union_map_intersect_domain(S.getSchedule(), S.getDomains());
574 
575   DEBUG({
576     dbgs() << S.getContextStr() << "\n";
577     dbgs() << stringFromIslObj(Schedule);
578   });
579   OS << "\nif (" << RtCStr << ")\n\n";
580   OS << AstStr << "\n";
581   OS << "else\n";
582   OS << "    {  /* original code */ }\n\n";
583 
584   free(RtCStr);
585   free(AstStr);
586 
587   isl_ast_expr_free(RunCondition);
588   isl_union_map_free(Schedule);
589   isl_ast_node_free(RootNode);
590   isl_printer_free(P);
591 }
592 
593 void IslAstInfo::getAnalysisUsage(AnalysisUsage &AU) const {
594   // Get the Common analysis usage of ScopPasses.
595   ScopPass::getAnalysisUsage(AU);
596   AU.addRequired<ScopInfo>();
597   AU.addRequired<DependenceInfo>();
598 }
599 
600 char IslAstInfo::ID = 0;
601 
602 Pass *polly::createIslAstInfoPass() { return new IslAstInfo(); }
603 
604 INITIALIZE_PASS_BEGIN(IslAstInfo, "polly-ast",
605                       "Polly - Generate an AST of the SCoP (isl)", false,
606                       false);
607 INITIALIZE_PASS_DEPENDENCY(ScopInfo);
608 INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
609 INITIALIZE_PASS_END(IslAstInfo, "polly-ast",
610                     "Polly - Generate an AST from the SCoP (isl)", false, false)
611