Coverage Report

Created: 2019-04-21 11:35

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