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> EarlyExit("polly-no-early-exit",
75                                cl::desc("Dummy flag to keep LNT builders run"),
76                                cl::Hidden, cl::ZeroOrMore,
77                                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   if (PollyProcessUnprofitable)
374     return true;
375 
376   // Check if nothing interesting happened.
377   if (!PerformParallelTest && !Scop->isOptimized() &&
378       Scop->getAliasGroups().empty())
379     return false;
380 
381   // The default assumption is that Polly improves the code.
382   return true;
383 }
384 
385 IslAst::IslAst(Scop *Scop) : S(Scop), Root(nullptr), RunCondition(nullptr) {}
386 
387 void IslAst::init(const Dependences &D) {
388   bool PerformParallelTest = PollyParallel || DetectParallel ||
389                              PollyVectorizerChoice != VECTORIZER_NONE;
390 
391   // Skip AST and code generation if there was no benefit achieved.
392   if (!benefitsFromPolly(S, PerformParallelTest))
393     return;
394 
395   isl_ctx *Ctx = S->getIslCtx();
396   isl_options_set_ast_build_atomic_upper_bound(Ctx, true);
397   isl_ast_build *Build;
398   AstBuildUserInfo BuildInfo;
399 
400   if (UseContext)
401     Build = isl_ast_build_from_context(S->getContext());
402   else
403     Build = isl_ast_build_from_context(isl_set_universe(S->getParamSpace()));
404 
405   Build = isl_ast_build_set_at_each_domain(Build, AtEachDomain, nullptr);
406 
407   if (PerformParallelTest) {
408     BuildInfo.Deps = &D;
409     BuildInfo.InParallelFor = 0;
410 
411     Build = isl_ast_build_set_before_each_for(Build, &astBuildBeforeFor,
412                                               &BuildInfo);
413     Build =
414         isl_ast_build_set_after_each_for(Build, &astBuildAfterFor, &BuildInfo);
415   }
416 
417   buildRunCondition(Build);
418 
419   Root = isl_ast_build_node_from_schedule(Build, S->getScheduleTree());
420 
421   isl_ast_build_free(Build);
422 }
423 
424 IslAst *IslAst::create(Scop *Scop, const Dependences &D) {
425   auto Ast = new IslAst(Scop);
426   Ast->init(D);
427   return Ast;
428 }
429 
430 IslAst::~IslAst() {
431   isl_ast_node_free(Root);
432   isl_ast_expr_free(RunCondition);
433 }
434 
435 __isl_give isl_ast_node *IslAst::getAst() { return isl_ast_node_copy(Root); }
436 __isl_give isl_ast_expr *IslAst::getRunCondition() {
437   return isl_ast_expr_copy(RunCondition);
438 }
439 
440 void IslAstInfo::releaseMemory() {
441   if (Ast) {
442     delete Ast;
443     Ast = nullptr;
444   }
445 }
446 
447 bool IslAstInfo::runOnScop(Scop &Scop) {
448   if (Ast)
449     delete Ast;
450 
451   S = &Scop;
452 
453   const Dependences &D = getAnalysis<DependenceInfo>().getDependences();
454 
455   Ast = IslAst::create(&Scop, D);
456 
457   DEBUG(printScop(dbgs(), Scop));
458   return false;
459 }
460 
461 __isl_give isl_ast_node *IslAstInfo::getAst() const { return Ast->getAst(); }
462 __isl_give isl_ast_expr *IslAstInfo::getRunCondition() const {
463   return Ast->getRunCondition();
464 }
465 
466 IslAstUserPayload *IslAstInfo::getNodePayload(__isl_keep isl_ast_node *Node) {
467   isl_id *Id = isl_ast_node_get_annotation(Node);
468   if (!Id)
469     return nullptr;
470   IslAstUserPayload *Payload = (IslAstUserPayload *)isl_id_get_user(Id);
471   isl_id_free(Id);
472   return Payload;
473 }
474 
475 bool IslAstInfo::isInnermost(__isl_keep isl_ast_node *Node) {
476   IslAstUserPayload *Payload = getNodePayload(Node);
477   return Payload && Payload->IsInnermost;
478 }
479 
480 bool IslAstInfo::isParallel(__isl_keep isl_ast_node *Node) {
481   return IslAstInfo::isInnermostParallel(Node) ||
482          IslAstInfo::isOutermostParallel(Node);
483 }
484 
485 bool IslAstInfo::isInnermostParallel(__isl_keep isl_ast_node *Node) {
486   IslAstUserPayload *Payload = getNodePayload(Node);
487   return Payload && Payload->IsInnermostParallel;
488 }
489 
490 bool IslAstInfo::isOutermostParallel(__isl_keep isl_ast_node *Node) {
491   IslAstUserPayload *Payload = getNodePayload(Node);
492   return Payload && Payload->IsOutermostParallel;
493 }
494 
495 bool IslAstInfo::isReductionParallel(__isl_keep isl_ast_node *Node) {
496   IslAstUserPayload *Payload = getNodePayload(Node);
497   return Payload && Payload->IsReductionParallel;
498 }
499 
500 bool IslAstInfo::isExecutedInParallel(__isl_keep isl_ast_node *Node) {
501 
502   if (!PollyParallel)
503     return false;
504 
505   // Do not parallelize innermost loops.
506   //
507   // Parallelizing innermost loops is often not profitable, especially if
508   // they have a low number of iterations.
509   //
510   // TODO: Decide this based on the number of loop iterations that will be
511   //       executed. This can possibly require run-time checks, which again
512   //       raises the question of both run-time check overhead and code size
513   //       costs.
514   if (!PollyParallelForce && isInnermost(Node))
515     return false;
516 
517   return isOutermostParallel(Node) && !isReductionParallel(Node);
518 }
519 
520 isl_union_map *IslAstInfo::getSchedule(__isl_keep isl_ast_node *Node) {
521   IslAstUserPayload *Payload = getNodePayload(Node);
522   return Payload ? isl_ast_build_get_schedule(Payload->Build) : nullptr;
523 }
524 
525 isl_pw_aff *
526 IslAstInfo::getMinimalDependenceDistance(__isl_keep isl_ast_node *Node) {
527   IslAstUserPayload *Payload = getNodePayload(Node);
528   return Payload ? isl_pw_aff_copy(Payload->MinimalDependenceDistance)
529                  : nullptr;
530 }
531 
532 IslAstInfo::MemoryAccessSet *
533 IslAstInfo::getBrokenReductions(__isl_keep isl_ast_node *Node) {
534   IslAstUserPayload *Payload = getNodePayload(Node);
535   return Payload ? &Payload->BrokenReductions : nullptr;
536 }
537 
538 isl_ast_build *IslAstInfo::getBuild(__isl_keep isl_ast_node *Node) {
539   IslAstUserPayload *Payload = getNodePayload(Node);
540   return Payload ? Payload->Build : nullptr;
541 }
542 
543 void IslAstInfo::printScop(raw_ostream &OS, Scop &S) const {
544   isl_ast_print_options *Options;
545   isl_ast_node *RootNode = getAst();
546   Function *F = S.getRegion().getEntry()->getParent();
547 
548   OS << ":: isl ast :: " << F->getName() << " :: " << S.getRegion().getNameStr()
549      << "\n";
550 
551   if (!RootNode) {
552     OS << ":: isl ast generation and code generation was skipped!\n\n";
553     OS << ":: This is either because no useful optimizations could be applied "
554           "(use -polly-process-unprofitable to enforce code generation) or "
555           "because earlier passes such as dependence analysis timed out (use "
556           "-polly-dependences-computeout=0 to set dependence analysis timeout "
557           "to infinity)\n\n";
558     return;
559   }
560 
561   isl_ast_expr *RunCondition = getRunCondition();
562   char *RtCStr, *AstStr;
563 
564   Options = isl_ast_print_options_alloc(S.getIslCtx());
565   Options = isl_ast_print_options_set_print_for(Options, cbPrintFor, nullptr);
566 
567   isl_printer *P = isl_printer_to_str(S.getIslCtx());
568   P = isl_printer_print_ast_expr(P, RunCondition);
569   RtCStr = isl_printer_get_str(P);
570   P = isl_printer_flush(P);
571   P = isl_printer_indent(P, 4);
572   P = isl_printer_set_output_format(P, ISL_FORMAT_C);
573   P = isl_ast_node_print(RootNode, P, Options);
574   AstStr = isl_printer_get_str(P);
575 
576   isl_union_map *Schedule =
577       isl_union_map_intersect_domain(S.getSchedule(), S.getDomains());
578 
579   DEBUG({
580     dbgs() << S.getContextStr() << "\n";
581     dbgs() << stringFromIslObj(Schedule);
582   });
583   OS << "\nif (" << RtCStr << ")\n\n";
584   OS << AstStr << "\n";
585   OS << "else\n";
586   OS << "    {  /* original code */ }\n\n";
587 
588   free(RtCStr);
589   free(AstStr);
590 
591   isl_ast_expr_free(RunCondition);
592   isl_union_map_free(Schedule);
593   isl_ast_node_free(RootNode);
594   isl_printer_free(P);
595 }
596 
597 void IslAstInfo::getAnalysisUsage(AnalysisUsage &AU) const {
598   // Get the Common analysis usage of ScopPasses.
599   ScopPass::getAnalysisUsage(AU);
600   AU.addRequired<ScopInfo>();
601   AU.addRequired<DependenceInfo>();
602 }
603 
604 char IslAstInfo::ID = 0;
605 
606 Pass *polly::createIslAstInfoPass() { return new IslAstInfo(); }
607 
608 INITIALIZE_PASS_BEGIN(IslAstInfo, "polly-ast",
609                       "Polly - Generate an AST of the SCoP (isl)", false,
610                       false);
611 INITIALIZE_PASS_DEPENDENCY(ScopInfo);
612 INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
613 INITIALIZE_PASS_END(IslAstInfo, "polly-ast",
614                     "Polly - Generate an AST from the SCoP (isl)", false, false)
615