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