Coverage Report

Created: 2017-10-03 07:32

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