Coverage Report

Created: 2017-06-23 12:40

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