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