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