1 //===- ScopDetection.h - Detect Scops ---------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Detect the maximal Scops of a function. 10 // 11 // A static control part (Scop) is a subgraph of the control flow graph (CFG) 12 // that only has statically known control flow and can therefore be described 13 // within the polyhedral model. 14 // 15 // Every Scop fulfills these restrictions: 16 // 17 // * It is a single entry single exit region 18 // 19 // * Only affine linear bounds in the loops 20 // 21 // Every natural loop in a Scop must have a number of loop iterations that can 22 // be described as an affine linear function in surrounding loop iterators or 23 // parameters. (A parameter is a scalar that does not change its value during 24 // execution of the Scop). 25 // 26 // * Only comparisons of affine linear expressions in conditions 27 // 28 // * All loops and conditions perfectly nested 29 // 30 // The control flow needs to be structured such that it could be written using 31 // just 'for' and 'if' statements, without the need for any 'goto', 'break' or 32 // 'continue'. 33 // 34 // * Side effect free functions call 35 // 36 // Only function calls and intrinsics that do not have side effects are allowed 37 // (readnone). 38 // 39 // The Scop detection finds the largest Scops by checking if the largest 40 // region is a Scop. If this is not the case, its canonical subregions are 41 // checked until a region is a Scop. It is now tried to extend this Scop by 42 // creating a larger non canonical region. 43 // 44 //===----------------------------------------------------------------------===// 45 46 #ifndef POLLY_SCOPDETECTION_H 47 #define POLLY_SCOPDETECTION_H 48 49 #include "polly/ScopDetectionDiagnostic.h" 50 #include "polly/Support/ScopHelper.h" 51 #include "llvm/Analysis/AliasSetTracker.h" 52 #include "llvm/Analysis/RegionInfo.h" 53 #include "llvm/Analysis/ScalarEvolutionExpressions.h" 54 #include "llvm/Pass.h" 55 #include <set> 56 57 namespace llvm { 58 class AAResults; 59 } // namespace llvm 60 61 namespace polly { 62 using llvm::AAResults; 63 using llvm::AliasSetTracker; 64 using llvm::AnalysisInfoMixin; 65 using llvm::AnalysisKey; 66 using llvm::AnalysisUsage; 67 using llvm::BranchInst; 68 using llvm::CallInst; 69 using llvm::DenseMap; 70 using llvm::DominatorTree; 71 using llvm::Function; 72 using llvm::FunctionAnalysisManager; 73 using llvm::FunctionPass; 74 using llvm::IntrinsicInst; 75 using llvm::LoopInfo; 76 using llvm::Module; 77 using llvm::OptimizationRemarkEmitter; 78 using llvm::PassInfoMixin; 79 using llvm::PreservedAnalyses; 80 using llvm::RegionInfo; 81 using llvm::ScalarEvolution; 82 using llvm::SCEVUnknown; 83 using llvm::SetVector; 84 using llvm::SmallSetVector; 85 using llvm::SmallVectorImpl; 86 using llvm::StringRef; 87 using llvm::SwitchInst; 88 89 using ParamSetType = std::set<const SCEV *>; 90 91 // Description of the shape of an array. 92 struct ArrayShape { 93 // Base pointer identifying all accesses to this array. 94 const SCEVUnknown *BasePointer; 95 96 // Sizes of each delinearized dimension. 97 SmallVector<const SCEV *, 4> DelinearizedSizes; 98 ArrayShapeArrayShape99 ArrayShape(const SCEVUnknown *B) : BasePointer(B) {} 100 }; 101 102 struct MemAcc { 103 const Instruction *Insn; 104 105 // A pointer to the shape description of the array. 106 std::shared_ptr<ArrayShape> Shape; 107 108 // Subscripts computed by delinearization. 109 SmallVector<const SCEV *, 4> DelinearizedSubscripts; 110 MemAccMemAcc111 MemAcc(const Instruction *I, std::shared_ptr<ArrayShape> S) 112 : Insn(I), Shape(S) {} 113 }; 114 115 using MapInsnToMemAcc = std::map<const Instruction *, MemAcc>; 116 using PairInstSCEV = std::pair<const Instruction *, const SCEV *>; 117 using AFs = std::vector<PairInstSCEV>; 118 using BaseToAFs = std::map<const SCEVUnknown *, AFs>; 119 using BaseToElSize = std::map<const SCEVUnknown *, const SCEV *>; 120 121 extern bool PollyTrackFailures; 122 extern bool PollyDelinearize; 123 extern bool PollyUseRuntimeAliasChecks; 124 extern bool PollyProcessUnprofitable; 125 extern bool PollyInvariantLoadHoisting; 126 extern bool PollyAllowUnsignedOperations; 127 extern bool PollyAllowFullFunction; 128 129 /// A function attribute which will cause Polly to skip the function 130 extern StringRef PollySkipFnAttr; 131 132 //===----------------------------------------------------------------------===// 133 /// Pass to detect the maximal static control parts (Scops) of a 134 /// function. 135 class ScopDetection { 136 public: 137 using RegionSet = SetVector<const Region *>; 138 139 // Remember the valid regions 140 RegionSet ValidRegions; 141 142 /// Context variables for SCoP detection. 143 struct DetectionContext { 144 Region &CurRegion; // The region to check. 145 AliasSetTracker AST; // The AliasSetTracker to hold the alias information. 146 bool Verifying; // If we are in the verification phase? 147 148 /// Container to remember rejection reasons for this region. 149 RejectLog Log; 150 151 /// Map a base pointer to all access functions accessing it. 152 /// 153 /// This map is indexed by the base pointer. Each element of the map 154 /// is a list of memory accesses that reference this base pointer. 155 BaseToAFs Accesses; 156 157 /// The set of base pointers with non-affine accesses. 158 /// 159 /// This set contains all base pointers and the locations where they are 160 /// used for memory accesses that can not be detected as affine accesses. 161 llvm::SetVector<std::pair<const SCEVUnknown *, Loop *>> NonAffineAccesses; 162 BaseToElSize ElementSize; 163 164 /// The region has at least one load instruction. 165 bool hasLoads = false; 166 167 /// The region has at least one store instruction. 168 bool hasStores = false; 169 170 /// Flag to indicate the region has at least one unknown access. 171 bool HasUnknownAccess = false; 172 173 /// The set of non-affine subregions in the region we analyze. 174 RegionSet NonAffineSubRegionSet; 175 176 /// The set of loops contained in non-affine regions. 177 BoxedLoopsSetTy BoxedLoopsSet; 178 179 /// Loads that need to be invariant during execution. 180 InvariantLoadsSetTy RequiredILS; 181 182 /// Map to memory access description for the corresponding LLVM 183 /// instructions. 184 MapInsnToMemAcc InsnToMemAcc; 185 186 /// Initialize a DetectionContext from scratch. DetectionContextDetectionContext187 DetectionContext(Region &R, AAResults &AA, bool Verify) 188 : CurRegion(R), AST(AA), Verifying(Verify), Log(&R) {} 189 }; 190 191 /// Helper data structure to collect statistics about loop counts. 192 struct LoopStats { 193 int NumLoops; 194 int MaxDepth; 195 }; 196 197 int NextScopID = 0; getNextID()198 int getNextID() { return NextScopID++; } 199 200 private: 201 //===--------------------------------------------------------------------===// 202 203 /// Analyses used 204 //@{ 205 const DominatorTree &DT; 206 ScalarEvolution &SE; 207 LoopInfo &LI; 208 RegionInfo &RI; 209 AAResults &AA; 210 //@} 211 212 /// Map to remember detection contexts for all regions. 213 using DetectionContextMapTy = 214 DenseMap<BBPair, std::unique_ptr<DetectionContext>>; 215 DetectionContextMapTy DetectionContextMap; 216 217 /// Cache for the isErrorBlock function. 218 DenseMap<std::tuple<const BasicBlock *, const Region *>, bool> 219 ErrorBlockCache; 220 221 /// Remove cached results for @p R. 222 void removeCachedResults(const Region &R); 223 224 /// Remove cached results for the children of @p R recursively. 225 void removeCachedResultsRecursively(const Region &R); 226 227 /// Check if @p S0 and @p S1 do contain multiple possibly aliasing pointers. 228 /// 229 /// @param S0 A expression to check. 230 /// @param S1 Another expression to check or nullptr. 231 /// @param Scope The loop/scope the expressions are checked in. 232 /// 233 /// @returns True, if multiple possibly aliasing pointers are used in @p S0 234 /// (and @p S1 if given). 235 bool involvesMultiplePtrs(const SCEV *S0, const SCEV *S1, Loop *Scope) const; 236 237 /// Add the region @p AR as over approximated sub-region in @p Context. 238 /// 239 /// @param AR The non-affine subregion. 240 /// @param Context The current detection context. 241 /// 242 /// @returns True if the subregion can be over approximated, false otherwise. 243 bool addOverApproximatedRegion(Region *AR, DetectionContext &Context) const; 244 245 /// Find for a given base pointer terms that hint towards dimension 246 /// sizes of a multi-dimensional array. 247 /// 248 /// @param Context The current detection context. 249 /// @param BasePointer A base pointer indicating the virtual array we are 250 /// interested in. 251 SmallVector<const SCEV *, 4> 252 getDelinearizationTerms(DetectionContext &Context, 253 const SCEVUnknown *BasePointer) const; 254 255 /// Check if the dimension size of a delinearized array is valid. 256 /// 257 /// @param Context The current detection context. 258 /// @param Sizes The sizes of the different array dimensions. 259 /// @param BasePointer The base pointer we are interested in. 260 /// @param Scope The location where @p BasePointer is being used. 261 /// @returns True if one or more array sizes could be derived - meaning: we 262 /// see this array as multi-dimensional. 263 bool hasValidArraySizes(DetectionContext &Context, 264 SmallVectorImpl<const SCEV *> &Sizes, 265 const SCEVUnknown *BasePointer, Loop *Scope) const; 266 267 /// Derive access functions for a given base pointer. 268 /// 269 /// @param Context The current detection context. 270 /// @param Sizes The sizes of the different array dimensions. 271 /// @param BasePointer The base pointer of all the array for which to compute 272 /// access functions. 273 /// @param Shape The shape that describes the derived array sizes and 274 /// which should be filled with newly computed access 275 /// functions. 276 /// @returns True if a set of affine access functions could be derived. 277 bool computeAccessFunctions(DetectionContext &Context, 278 const SCEVUnknown *BasePointer, 279 std::shared_ptr<ArrayShape> Shape) const; 280 281 /// Check if all accesses to a given BasePointer are affine. 282 /// 283 /// @param Context The current detection context. 284 /// @param BasePointer the base pointer we are interested in. 285 /// @param Scope The location where @p BasePointer is being used. 286 /// @param True if consistent (multi-dimensional) array accesses could be 287 /// derived for this array. 288 bool hasBaseAffineAccesses(DetectionContext &Context, 289 const SCEVUnknown *BasePointer, Loop *Scope) const; 290 291 // Delinearize all non affine memory accesses and return false when there 292 // exists a non affine memory access that cannot be delinearized. Return true 293 // when all array accesses are affine after delinearization. 294 bool hasAffineMemoryAccesses(DetectionContext &Context) const; 295 296 // Try to expand the region R. If R can be expanded return the expanded 297 // region, NULL otherwise. 298 Region *expandRegion(Region &R); 299 300 /// Find the Scops in this region tree. 301 /// 302 /// @param The region tree to scan for scops. 303 void findScops(Region &R); 304 305 /// Check if all basic block in the region are valid. 306 /// 307 /// @param Context The context of scop detection. 308 /// 309 /// @return True if all blocks in R are valid, false otherwise. 310 bool allBlocksValid(DetectionContext &Context); 311 312 /// Check if a region has sufficient compute instructions. 313 /// 314 /// This function checks if a region has a non-trivial number of instructions 315 /// in each loop. This can be used as an indicator whether a loop is worth 316 /// optimizing. 317 /// 318 /// @param Context The context of scop detection. 319 /// @param NumLoops The number of loops in the region. 320 /// 321 /// @return True if region is has sufficient compute instructions, 322 /// false otherwise. 323 bool hasSufficientCompute(DetectionContext &Context, 324 int NumAffineLoops) const; 325 326 /// Check if the unique affine loop might be amendable to distribution. 327 /// 328 /// This function checks if the number of non-trivial blocks in the unique 329 /// affine loop in Context.CurRegion is at least two, thus if the loop might 330 /// be amendable to distribution. 331 /// 332 /// @param Context The context of scop detection. 333 /// 334 /// @return True only if the affine loop might be amendable to distributable. 335 bool hasPossiblyDistributableLoop(DetectionContext &Context) const; 336 337 /// Check if a region is profitable to optimize. 338 /// 339 /// Regions that are unlikely to expose interesting optimization opportunities 340 /// are called 'unprofitable' and may be skipped during scop detection. 341 /// 342 /// @param Context The context of scop detection. 343 /// 344 /// @return True if region is profitable to optimize, false otherwise. 345 bool isProfitableRegion(DetectionContext &Context) const; 346 347 /// Check if a region is a Scop. 348 /// 349 /// @param Context The context of scop detection. 350 /// 351 /// @return True if R is a Scop, false otherwise. 352 bool isValidRegion(DetectionContext &Context); 353 354 /// Check if an intrinsic call can be part of a Scop. 355 /// 356 /// @param II The intrinsic call instruction to check. 357 /// @param Context The current detection context. 358 /// 359 /// @return True if the call instruction is valid, false otherwise. 360 bool isValidIntrinsicInst(IntrinsicInst &II, DetectionContext &Context) const; 361 362 /// Check if a call instruction can be part of a Scop. 363 /// 364 /// @param CI The call instruction to check. 365 /// @param Context The current detection context. 366 /// 367 /// @return True if the call instruction is valid, false otherwise. 368 bool isValidCallInst(CallInst &CI, DetectionContext &Context) const; 369 370 /// Check if the given loads could be invariant and can be hoisted. 371 /// 372 /// If true is returned the loads are added to the required invariant loads 373 /// contained in the @p Context. 374 /// 375 /// @param RequiredILS The loads to check. 376 /// @param Context The current detection context. 377 /// 378 /// @return True if all loads can be assumed invariant. 379 bool onlyValidRequiredInvariantLoads(InvariantLoadsSetTy &RequiredILS, 380 DetectionContext &Context) const; 381 382 /// Check if a value is invariant in the region Reg. 383 /// 384 /// @param Val Value to check for invariance. 385 /// @param Reg The region to consider for the invariance of Val. 386 /// @param Ctx The current detection context. 387 /// 388 /// @return True if the value represented by Val is invariant in the region 389 /// identified by Reg. 390 bool isInvariant(Value &Val, const Region &Reg, DetectionContext &Ctx) const; 391 392 /// Check if the memory access caused by @p Inst is valid. 393 /// 394 /// @param Inst The access instruction. 395 /// @param AF The access function. 396 /// @param BP The access base pointer. 397 /// @param Context The current detection context. 398 bool isValidAccess(Instruction *Inst, const SCEV *AF, const SCEVUnknown *BP, 399 DetectionContext &Context) const; 400 401 /// Check if a memory access can be part of a Scop. 402 /// 403 /// @param Inst The instruction accessing the memory. 404 /// @param Context The context of scop detection. 405 /// 406 /// @return True if the memory access is valid, false otherwise. 407 bool isValidMemoryAccess(MemAccInst Inst, DetectionContext &Context) const; 408 409 /// Check if an instruction can be part of a Scop. 410 /// 411 /// @param Inst The instruction to check. 412 /// @param Context The context of scop detection. 413 /// 414 /// @return True if the instruction is valid, false otherwise. 415 bool isValidInstruction(Instruction &Inst, DetectionContext &Context); 416 417 /// Check if the switch @p SI with condition @p Condition is valid. 418 /// 419 /// @param BB The block to check. 420 /// @param SI The switch to check. 421 /// @param Condition The switch condition. 422 /// @param IsLoopBranch Flag to indicate the branch is a loop exit/latch. 423 /// @param Context The context of scop detection. 424 /// 425 /// @return True if the branch @p BI is valid. 426 bool isValidSwitch(BasicBlock &BB, SwitchInst *SI, Value *Condition, 427 bool IsLoopBranch, DetectionContext &Context) const; 428 429 /// Check if the branch @p BI with condition @p Condition is valid. 430 /// 431 /// @param BB The block to check. 432 /// @param BI The branch to check. 433 /// @param Condition The branch condition. 434 /// @param IsLoopBranch Flag to indicate the branch is a loop exit/latch. 435 /// @param Context The context of scop detection. 436 /// 437 /// @return True if the branch @p BI is valid. 438 bool isValidBranch(BasicBlock &BB, BranchInst *BI, Value *Condition, 439 bool IsLoopBranch, DetectionContext &Context); 440 441 /// Check if the SCEV @p S is affine in the current @p Context. 442 /// 443 /// This will also use a heuristic to decide if we want to require loads to be 444 /// invariant to make the expression affine or if we want to treat is as 445 /// non-affine. 446 /// 447 /// @param S The expression to be checked. 448 /// @param Scope The loop nest in which @p S is used. 449 /// @param Context The context of scop detection. 450 bool isAffine(const SCEV *S, Loop *Scope, DetectionContext &Context) const; 451 452 /// Check if the control flow in a basic block is valid. 453 /// 454 /// This function checks if a certain basic block is terminated by a 455 /// Terminator instruction we can handle or, if this is not the case, 456 /// registers this basic block as the start of a non-affine region. 457 /// 458 /// This function optionally allows unreachable statements. 459 /// 460 /// @param BB The BB to check the control flow. 461 /// @param IsLoopBranch Flag to indicate the branch is a loop exit/latch. 462 // @param AllowUnreachable Allow unreachable statements. 463 /// @param Context The context of scop detection. 464 /// 465 /// @return True if the BB contains only valid control flow. 466 bool isValidCFG(BasicBlock &BB, bool IsLoopBranch, bool AllowUnreachable, 467 DetectionContext &Context); 468 469 /// Is a loop valid with respect to a given region. 470 /// 471 /// @param L The loop to check. 472 /// @param Context The context of scop detection. 473 /// 474 /// @return True if the loop is valid in the region. 475 bool isValidLoop(Loop *L, DetectionContext &Context); 476 477 /// Count the number of loops and the maximal loop depth in @p L. 478 /// 479 /// @param L The loop to check. 480 /// @param SE The scalar evolution analysis. 481 /// @param MinProfitableTrips The minimum number of trip counts from which 482 /// a loop is assumed to be profitable and 483 /// consequently is counted. 484 /// returns A tuple of number of loops and their maximal depth. 485 static ScopDetection::LoopStats 486 countBeneficialSubLoops(Loop *L, ScalarEvolution &SE, 487 unsigned MinProfitableTrips); 488 489 /// Check if the function @p F is marked as invalid. 490 /// 491 /// @note An OpenMP subfunction will be marked as invalid. 492 static bool isValidFunction(Function &F); 493 494 /// Can ISL compute the trip count of a loop. 495 /// 496 /// @param L The loop to check. 497 /// @param Context The context of scop detection. 498 /// 499 /// @return True if ISL can compute the trip count of the loop. 500 bool canUseISLTripCount(Loop *L, DetectionContext &Context); 501 502 /// Print the locations of all detected scops. 503 void printLocations(Function &F); 504 505 /// Check if a region is reducible or not. 506 /// 507 /// @param Region The region to check. 508 /// @param DbgLoc Parameter to save the location of instruction that 509 /// causes irregular control flow if the region is irreducible. 510 /// 511 /// @return True if R is reducible, false otherwise. 512 bool isReducibleRegion(Region &R, DebugLoc &DbgLoc) const; 513 514 /// Track diagnostics for invalid scops. 515 /// 516 /// @param Context The context of scop detection. 517 /// @param Assert Throw an assert in verify mode or not. 518 /// @param Args Argument list that gets passed to the constructor of RR. 519 template <class RR, typename... Args> 520 inline bool invalid(DetectionContext &Context, bool Assert, 521 Args &&...Arguments) const; 522 523 public: 524 ScopDetection(const DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, 525 RegionInfo &RI, AAResults &AA, OptimizationRemarkEmitter &ORE); 526 527 void detect(Function &F); 528 529 /// Get the RegionInfo stored in this pass. 530 /// 531 /// This was added to give the DOT printer easy access to this information. getRI()532 RegionInfo *getRI() const { return &RI; } 533 534 /// Get the LoopInfo stored in this pass. getLI()535 LoopInfo *getLI() const { return &LI; } 536 537 /// Is the region is the maximum region of a Scop? 538 /// 539 /// @param R The Region to test if it is maximum. 540 /// @param Verify Rerun the scop detection to verify SCoP was not invalidated 541 /// meanwhile. Do not use if the region's DetectionContect is 542 /// referenced by a Scop that is still to be processed. 543 /// 544 /// @return Return true if R is the maximum Region in a Scop, false otherwise. 545 bool isMaxRegionInScop(const Region &R, bool Verify = true); 546 547 /// Return the detection context for @p R, nullptr if @p R was invalid. 548 DetectionContext *getDetectionContext(const Region *R) const; 549 550 /// Return the set of rejection causes for @p R. 551 const RejectLog *lookupRejectionLog(const Region *R) const; 552 553 /// Get a message why a region is invalid 554 /// 555 /// @param R The region for which we get the error message 556 /// 557 /// @return The error or "" if no error appeared. 558 std::string regionIsInvalidBecause(const Region *R) const; 559 560 /// @name Maximum Region In Scops Iterators 561 /// 562 /// These iterators iterator over all maximum region in Scops of this 563 /// function. 564 //@{ 565 using iterator = RegionSet::iterator; 566 using const_iterator = RegionSet::const_iterator; 567 begin()568 iterator begin() { return ValidRegions.begin(); } end()569 iterator end() { return ValidRegions.end(); } 570 begin()571 const_iterator begin() const { return ValidRegions.begin(); } end()572 const_iterator end() const { return ValidRegions.end(); } 573 //@} 574 575 /// Emit rejection remarks for all rejected regions. 576 /// 577 /// @param F The function to emit remarks for. 578 void emitMissedRemarks(const Function &F); 579 580 /// Mark the function as invalid so we will not extract any scop from 581 /// the function. 582 /// 583 /// @param F The function to mark as invalid. 584 static void markFunctionAsInvalid(Function *F); 585 586 /// Verify if all valid Regions in this Function are still valid 587 /// after some transformations. 588 void verifyAnalysis(); 589 590 /// Verify if R is still a valid part of Scop after some transformations. 591 /// 592 /// @param R The Region to verify. 593 void verifyRegion(const Region &R); 594 595 /// Count the number of loops and the maximal loop depth in @p R. 596 /// 597 /// @param R The region to check 598 /// @param SE The scalar evolution analysis. 599 /// @param MinProfitableTrips The minimum number of trip counts from which 600 /// a loop is assumed to be profitable and 601 /// consequently is counted. 602 /// returns A tuple of number of loops and their maximal depth. 603 static ScopDetection::LoopStats 604 countBeneficialLoops(Region *R, ScalarEvolution &SE, LoopInfo &LI, 605 unsigned MinProfitableTrips); 606 607 /// Check if the block is a error block. 608 /// 609 /// A error block is currently any block that fulfills at least one of 610 /// the following conditions: 611 /// 612 /// - It is terminated by an unreachable instruction 613 /// - It contains a call to a non-pure function that is not immediately 614 /// dominated by a loop header and that does not dominate the region exit. 615 /// This is a heuristic to pick only error blocks that are conditionally 616 /// executed and can be assumed to be not executed at all without the 617 /// domains being available. 618 /// 619 /// @param BB The block to check. 620 /// @param R The analyzed region. 621 /// 622 /// @return True if the block is a error block, false otherwise. 623 bool isErrorBlock(llvm::BasicBlock &BB, const llvm::Region &R); 624 625 private: 626 /// OptimizationRemarkEmitter object used to emit diagnostic remarks 627 OptimizationRemarkEmitter &ORE; 628 }; 629 630 struct ScopAnalysis : AnalysisInfoMixin<ScopAnalysis> { 631 static AnalysisKey Key; 632 633 using Result = ScopDetection; 634 635 ScopAnalysis(); 636 637 Result run(Function &F, FunctionAnalysisManager &FAM); 638 }; 639 640 struct ScopAnalysisPrinterPass final : PassInfoMixin<ScopAnalysisPrinterPass> { ScopAnalysisPrinterPassfinal641 ScopAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {} 642 643 PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); 644 645 raw_ostream &OS; 646 }; 647 648 class ScopDetectionWrapperPass final : public FunctionPass { 649 std::unique_ptr<ScopDetection> Result; 650 651 public: 652 ScopDetectionWrapperPass(); 653 654 /// @name FunctionPass interface 655 ///@{ 656 static char ID; 657 void getAnalysisUsage(AnalysisUsage &AU) const override; 658 void releaseMemory() override; 659 bool runOnFunction(Function &F) override; 660 void print(raw_ostream &OS, const Module *M = nullptr) const override; 661 ///@} 662 getSD()663 ScopDetection &getSD() const { return *Result; } 664 }; 665 666 llvm::Pass *createScopDetectionPrinterLegacyPass(llvm::raw_ostream &OS); 667 } // namespace polly 668 669 namespace llvm { 670 void initializeScopDetectionWrapperPassPass(llvm::PassRegistry &); 671 void initializeScopDetectionPrinterLegacyPassPass(llvm::PassRegistry &); 672 } // namespace llvm 673 674 #endif // POLLY_SCOPDETECTION_H 675