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