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