Polly 24.0.0git
ScopInfo.h
Go to the documentation of this file.
1//===- polly/ScopInfo.h -----------------------------------------*- 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// Store the polyhedral model representation of a static control flow region,
10// also called SCoP (Static Control Part).
11//
12// This representation is shared among several tools in the polyhedral
13// community, which are e.g. CLooG, Pluto, Loopo, Graphite.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef POLLY_SCOPINFO_H
18#define POLLY_SCOPINFO_H
19
20#include "polly/ScopDetection.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/MapVector.h"
25#include "llvm/ADT/SetVector.h"
26#include "llvm/IR/DebugLoc.h"
27#include "llvm/IR/Instruction.h"
28#include "llvm/IR/Instructions.h"
29#include "llvm/IR/ValueHandle.h"
31#include <cassert>
32#include <cstddef>
33#include <forward_list>
34#include <list>
35#include <optional>
36
37namespace polly {
38using llvm::AnalysisInfoMixin;
39using llvm::ArrayRef;
40using llvm::AssertingVH;
41using llvm::AssumptionCache;
42using llvm::cast;
43using llvm::DataLayout;
44using llvm::DenseMap;
45using llvm::DenseSet;
46using llvm::function_ref;
47using llvm::isa;
48using llvm::iterator_range;
49using llvm::LoadInst;
50using llvm::make_range;
51using llvm::MapVector;
52using llvm::MemIntrinsic;
53using llvm::OptionalPassInfoMixin;
54using llvm::PHINode;
55using llvm::RegionNode;
56using llvm::RequiredPassInfoMixin;
57using llvm::SetVector;
58using llvm::SmallPtrSetImpl;
59using llvm::SmallVector;
60using llvm::SmallVectorImpl;
61using llvm::StringMap;
62using llvm::Type;
63using llvm::Use;
64using llvm::Value;
65using llvm::ValueToValueMap;
66
67class MemoryAccess;
68
69//===---------------------------------------------------------------------===//
70
71extern bool UseInstructionNames;
72
73// The maximal number of basic sets we allow during domain construction to
74// be created. More complex scops will result in very high compile time and
75// are also unlikely to result in good code.
76extern unsigned const MaxDisjunctsInDomain;
77
78/// The different memory kinds used in Polly.
79///
80/// We distinguish between arrays and various scalar memory objects. We use
81/// the term ``array'' to describe memory objects that consist of a set of
82/// individual data elements arranged in a multi-dimensional grid. A scalar
83/// memory object describes an individual data element and is used to model
84/// the definition and uses of llvm::Values.
85///
86/// The polyhedral model does traditionally not reason about SSA values. To
87/// reason about llvm::Values we model them "as if" they were zero-dimensional
88/// memory objects, even though they were not actually allocated in (main)
89/// memory. Memory for such objects is only alloca[ed] at CodeGeneration
90/// time. To relate the memory slots used during code generation with the
91/// llvm::Values they belong to the new names for these corresponding stack
92/// slots are derived by appending suffixes (currently ".s2a" and ".phiops")
93/// to the name of the original llvm::Value. To describe how def/uses are
94/// modeled exactly we use these suffixes here as well.
95///
96/// There are currently four different kinds of memory objects:
97enum class MemoryKind {
98 /// MemoryKind::Array: Models a one or multi-dimensional array
99 ///
100 /// A memory object that can be described by a multi-dimensional array.
101 /// Memory objects of this type are used to model actual multi-dimensional
102 /// arrays as they exist in LLVM-IR, but they are also used to describe
103 /// other objects:
104 /// - A single data element allocated on the stack using 'alloca' is
105 /// modeled as a one-dimensional, single-element array.
106 /// - A single data element allocated as a global variable is modeled as
107 /// one-dimensional, single-element array.
108 /// - Certain multi-dimensional arrays with variable size, which in
109 /// LLVM-IR are commonly expressed as a single-dimensional access with a
110 /// complicated access function, are modeled as multi-dimensional
111 /// memory objects (grep for "delinearization").
113
114 /// MemoryKind::Value: Models an llvm::Value
115 ///
116 /// Memory objects of type MemoryKind::Value are used to model the data flow
117 /// induced by llvm::Values. For each llvm::Value that is used across
118 /// BasicBlocks, one ScopArrayInfo object is created. A single memory WRITE
119 /// stores the llvm::Value at its definition into the memory object and at
120 /// each use of the llvm::Value (ignoring trivial intra-block uses) a
121 /// corresponding READ is added. For instance, the use/def chain of a
122 /// llvm::Value %V depicted below
123 /// ______________________
124 /// |DefBB: |
125 /// | %V = float op ... |
126 /// ----------------------
127 /// | |
128 /// _________________ _________________
129 /// |UseBB1: | |UseBB2: |
130 /// | use float %V | | use float %V |
131 /// ----------------- -----------------
132 ///
133 /// is modeled as if the following memory accesses occurred:
134 ///
135 /// __________________________
136 /// |entry: |
137 /// | %V.s2a = alloca float |
138 /// --------------------------
139 /// |
140 /// ___________________________________
141 /// |DefBB: |
142 /// | store %float %V, float* %V.s2a |
143 /// -----------------------------------
144 /// | |
145 /// ____________________________________ ___________________________________
146 /// |UseBB1: | |UseBB2: |
147 /// | %V.reload1 = load float* %V.s2a | | %V.reload2 = load float* %V.s2a|
148 /// | use float %V.reload1 | | use float %V.reload2 |
149 /// ------------------------------------ -----------------------------------
150 ///
152
153 /// MemoryKind::PHI: Models PHI nodes within the SCoP
154 ///
155 /// Besides the MemoryKind::Value memory object used to model the normal
156 /// llvm::Value dependences described above, PHI nodes require an additional
157 /// memory object of type MemoryKind::PHI to describe the forwarding of values
158 /// to
159 /// the PHI node.
160 ///
161 /// As an example, a PHIInst instructions
162 ///
163 /// %PHI = phi float [ %Val1, %IncomingBlock1 ], [ %Val2, %IncomingBlock2 ]
164 ///
165 /// is modeled as if the accesses occurred this way:
166 ///
167 /// _______________________________
168 /// |entry: |
169 /// | %PHI.phiops = alloca float |
170 /// -------------------------------
171 /// | |
172 /// __________________________________ __________________________________
173 /// |IncomingBlock1: | |IncomingBlock2: |
174 /// | ... | | ... |
175 /// | store float %Val1 %PHI.phiops | | store float %Val2 %PHI.phiops |
176 /// | br label % JoinBlock | | br label %JoinBlock |
177 /// ---------------------------------- ----------------------------------
178 /// \ /
179 /// \ /
180 /// _________________________________________
181 /// |JoinBlock: |
182 /// | %PHI = load float, float* PHI.phiops |
183 /// -----------------------------------------
184 ///
185 /// Note that there can also be a scalar write access for %PHI if used in a
186 /// different BasicBlock, i.e. there can be a memory object %PHI.phiops as
187 /// well as a memory object %PHI.s2a.
189
190 /// MemoryKind::ExitPHI: Models PHI nodes in the SCoP's exit block
191 ///
192 /// For PHI nodes in the Scop's exit block a special memory object kind is
193 /// used. The modeling used is identical to MemoryKind::PHI, with the
194 /// exception
195 /// that there are no READs from these memory objects. The PHINode's
196 /// llvm::Value is treated as a value escaping the SCoP. WRITE accesses
197 /// write directly to the escaping value's ".s2a" alloca.
199};
200
201/// Maps from a loop to the affine function expressing its backedge taken count.
202/// The backedge taken count already enough to express iteration domain as we
203/// only allow loops with canonical induction variable.
204/// A canonical induction variable is:
205/// an integer recurrence that starts at 0 and increments by one each time
206/// through the loop.
207using LoopBoundMapType = std::map<const Loop *, const SCEV *>;
208
209using AccFuncVector = std::vector<std::unique_ptr<MemoryAccess>>;
210
211/// A class to store information about arrays in the SCoP.
212///
213/// Objects are accessible via the ScoP, MemoryAccess or the id associated with
214/// the MemoryAccess access function.
215///
216class ScopArrayInfo final {
217public:
218 /// Construct a ScopArrayInfo object.
219 ///
220 /// @param BasePtr The array base pointer.
221 /// @param ElementType The type of the elements stored in the array.
222 /// @param IslCtx The isl context used to create the base pointer id.
223 /// @param DimensionSizes A vector containing the size of each dimension.
224 /// @param Kind The kind of the array object.
225 /// @param DL The data layout of the module.
226 /// @param S The scop this array object belongs to.
227 /// @param BaseName The optional name of this memory reference.
229 ArrayRef<const SCEV *> DimensionSizes, MemoryKind Kind,
230 const DataLayout &DL, Scop *S, const char *BaseName = nullptr);
231
232 /// Destructor to free the isl id of the base pointer.
234
235 /// Update the element type of the ScopArrayInfo object.
236 ///
237 /// Memory accesses referencing this ScopArrayInfo object may use
238 /// different element sizes. This function ensures the canonical element type
239 /// stored is small enough to model accesses to the current element type as
240 /// well as to @p NewElementType.
241 ///
242 /// @param NewElementType An element type that is used to access this array.
243 void updateElementType(Type *NewElementType);
244
245 /// Update the sizes of the ScopArrayInfo object.
246 ///
247 /// A ScopArrayInfo object may be created without all outer dimensions being
248 /// available. This function is called when new memory accesses are added for
249 /// this ScopArrayInfo object. It verifies that sizes are compatible and adds
250 /// additional outer array dimensions, if needed.
251 ///
252 /// @param Sizes A vector of array sizes where the rightmost array
253 /// sizes need to match the innermost array sizes already
254 /// defined in SAI.
255 /// @param CheckConsistency Update sizes, even if new sizes are inconsistent
256 /// with old sizes
257 bool updateSizes(ArrayRef<const SCEV *> Sizes, bool CheckConsistency = true);
258
259 /// Set the base pointer to @p BP.
260 void setBasePtr(Value *BP) { BasePtr = BP; }
261
262 /// Return the base pointer.
263 Value *getBasePtr() const { return BasePtr; }
264
265 // Set IsOnHeap to the value in parameter.
266 void setIsOnHeap(bool value) { IsOnHeap = value; }
267
268 /// For indirect accesses return the origin SAI of the BP, else null.
270
271 /// The set of derived indirect SAIs for this origin SAI.
272 const SmallSetVector<ScopArrayInfo *, 2> &getDerivedSAIs() const {
273 return DerivedSAIs;
274 }
275
276 /// Return the number of dimensions.
277 unsigned getNumberOfDimensions() const {
280 return 0;
281 return DimensionSizes.size();
282 }
283
284 /// Return the size of dimension @p dim as SCEV*.
285 //
286 // Scalars do not have array dimensions and the first dimension of
287 // a (possibly multi-dimensional) array also does not carry any size
288 // information, in case the array is not newly created.
289 const SCEV *getDimensionSize(unsigned Dim) const {
290 assert(Dim < getNumberOfDimensions() && "Invalid dimension");
291 return DimensionSizes[Dim];
292 }
293
294 /// Return the size of dimension @p dim as isl::pw_aff.
295 //
296 // Scalars do not have array dimensions and the first dimension of
297 // a (possibly multi-dimensional) array also does not carry any size
298 // information, in case the array is not newly created.
299 isl::pw_aff getDimensionSizePw(unsigned Dim) const {
300 assert(Dim < getNumberOfDimensions() && "Invalid dimension");
301 return DimensionSizesPw[Dim];
302 }
303
304 /// Get the canonical element type of this array.
305 ///
306 /// @returns The canonical element type of this array.
307 Type *getElementType() const { return ElementType; }
308
309 /// Get element size in bytes.
310 int getElemSizeInBytes() const;
311
312 /// Get the name of this memory reference.
313 std::string getName() const;
314
315 /// Return the isl id for the base pointer.
316 isl::id getBasePtrId() const;
317
318 /// Return what kind of memory this represents.
319 MemoryKind getKind() const { return Kind; }
320
321 /// Is this array info modeling an llvm::Value?
322 bool isValueKind() const { return Kind == MemoryKind::Value; }
323
324 /// Is this array info modeling special PHI node memory?
325 ///
326 /// During code generation of PHI nodes, there is a need for two kinds of
327 /// virtual storage. The normal one as it is used for all scalar dependences,
328 /// where the result of the PHI node is stored and later loaded from as well
329 /// as a second one where the incoming values of the PHI nodes are stored
330 /// into and reloaded when the PHI is executed. As both memories use the
331 /// original PHI node as virtual base pointer, we have this additional
332 /// attribute to distinguish the PHI node specific array modeling from the
333 /// normal scalar array modeling.
334 bool isPHIKind() const { return Kind == MemoryKind::PHI; }
335
336 /// Is this array info modeling an MemoryKind::ExitPHI?
337 bool isExitPHIKind() const { return Kind == MemoryKind::ExitPHI; }
338
339 /// Is this array info modeling an array?
340 bool isArrayKind() const { return Kind == MemoryKind::Array; }
341
342 /// Is this array allocated on heap
343 ///
344 /// This property is only relevant if the array is allocated by Polly instead
345 /// of pre-existing. If false, it is allocated using alloca instead malloca.
346 bool isOnHeap() const { return IsOnHeap; }
347
348#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
349 /// Dump a readable representation to stderr.
350 void dump() const;
351#endif
352
353 /// Print a readable representation to @p OS.
354 ///
355 /// @param SizeAsPwAff Print the size as isl::pw_aff
356 void print(raw_ostream &OS, bool SizeAsPwAff = false) const;
357
358 /// Access the ScopArrayInfo associated with an access function.
360
361 /// Access the ScopArrayInfo associated with an isl Id.
362 static const ScopArrayInfo *getFromId(isl::id Id);
363
364 /// Get the space of this array access.
365 isl::space getSpace() const;
366
367 /// If the array is read only
368 bool isReadOnly();
369
370 /// Verify that @p Array is compatible to this ScopArrayInfo.
371 ///
372 /// Two arrays are compatible if their dimensionality, the sizes of their
373 /// dimensions, and their element sizes match.
374 ///
375 /// @param Array The array to compare against.
376 ///
377 /// @returns True, if the arrays are compatible, False otherwise.
378 bool isCompatibleWith(const ScopArrayInfo *Array) const;
379
380private:
381 void addDerivedSAI(ScopArrayInfo *DerivedSAI) {
382 DerivedSAIs.insert(DerivedSAI);
383 }
384
385 /// For indirect accesses this is the SAI of the BP origin.
387
388 /// For origin SAIs the set of derived indirect SAIs.
389 SmallSetVector<ScopArrayInfo *, 2> DerivedSAIs;
390
391 /// The base pointer.
392 AssertingVH<Value> BasePtr;
393
394 /// The canonical element type of this array.
395 ///
396 /// The canonical element type describes the minimal accessible element in
397 /// this array. Not all elements accessed, need to be of the very same type,
398 /// but the allocation size of the type of the elements loaded/stored from/to
399 /// this array needs to be a multiple of the allocation size of the canonical
400 /// type.
402
403 /// The isl id for the base pointer.
405
406 /// True if the newly allocated array is on heap.
407 bool IsOnHeap = false;
408
409 /// The sizes of each dimension as SCEV*.
410 SmallVector<const SCEV *, 4> DimensionSizes;
411
412 /// The sizes of each dimension as isl::pw_aff.
413 SmallVector<isl::pw_aff, 4> DimensionSizesPw;
414
415 /// The type of this scop array info object.
416 ///
417 /// We distinguish between SCALAR, PHI and ARRAY objects.
419
420 /// The data layout of the module.
421 const DataLayout &DL;
422
423 /// The scop this SAI object belongs to.
425};
426
427/// Represent memory accesses in statements.
428class MemoryAccess final {
429 friend class Scop;
430 friend class ScopStmt;
431 friend class ScopBuilder;
432
433public:
434 /// The access type of a memory access
435 ///
436 /// There are three kind of access types:
437 ///
438 /// * A read access
439 ///
440 /// A certain set of memory locations are read and may be used for internal
441 /// calculations.
442 ///
443 /// * A must-write access
444 ///
445 /// A certain set of memory locations is definitely written. The old value is
446 /// replaced by a newly calculated value. The old value is not read or used at
447 /// all.
448 ///
449 /// * A may-write access
450 ///
451 /// A certain set of memory locations may be written. The memory location may
452 /// contain a new value if there is actually a write or the old value may
453 /// remain, if no write happens.
455 READ = 0x1,
458 };
459
460 /// Reduction access type
461 ///
462 /// Commutative and associative binary operations suitable for reductions
464 RT_NONE, ///< Indicate no reduction at all
465 RT_ADD, ///< Addition
466 RT_MUL, ///< Multiplication
467 RT_BOR, ///< Bitwise Or
468 RT_BXOR, ///< Bitwise XOr
469 RT_BAND, ///< Bitwise And
470
471 RT_BOTTOM, ///< Pseudo type for the data flow analysis
472 };
473
474 using SubscriptsTy = SmallVector<const SCEV *, 4>;
475
476private:
477 /// A unique identifier for this memory access.
478 ///
479 /// The identifier is unique between all memory accesses belonging to the same
480 /// scop statement.
482
483 /// What is modeled by this MemoryAccess.
484 /// @see MemoryKind
486
487 /// Whether it a reading or writing access, and if writing, whether it
488 /// is conditional (MAY_WRITE).
490
491 /// Reduction type for reduction like accesses, RT_NONE otherwise
492 ///
493 /// An access is reduction like if it is part of a load-store chain in which
494 /// both access the same memory location (use the same LLVM-IR value
495 /// as pointer reference). Furthermore, between the load and the store there
496 /// is exactly one binary operator which is known to be associative and
497 /// commutative.
498 ///
499 /// TODO:
500 ///
501 /// We can later lift the constraint that the same LLVM-IR value defines the
502 /// memory location to handle scops such as the following:
503 ///
504 /// for i
505 /// for j
506 /// sum[i+j] = sum[i] + 3;
507 ///
508 /// Here not all iterations access the same memory location, but iterations
509 /// for which j = 0 holds do. After lifting the equality check in ScopBuilder,
510 /// subsequent transformations do not only need check if a statement is
511 /// reduction like, but they also need to verify that the reduction
512 /// property is only exploited for statement instances that load from and
513 /// store to the same data location. Doing so at dependence analysis time
514 /// could allow us to handle the above example.
516
517 /// Parent ScopStmt of this access.
519
520 /// The domain under which this access is not modeled precisely.
521 ///
522 /// The invalid domain for an access describes all parameter combinations
523 /// under which the statement looks to be executed but is in fact not because
524 /// some assumption/restriction makes the access invalid.
526
527 // Properties describing the accessed array.
528 // TODO: It might be possible to move them to ScopArrayInfo.
529 // @{
530
531 /// The base address (e.g., A for A[i+j]).
532 ///
533 /// The #BaseAddr of a memory access of kind MemoryKind::Array is the base
534 /// pointer of the memory access.
535 /// The #BaseAddr of a memory access of kind MemoryKind::PHI or
536 /// MemoryKind::ExitPHI is the PHI node itself.
537 /// The #BaseAddr of a memory access of kind MemoryKind::Value is the
538 /// instruction defining the value.
539 AssertingVH<Value> BaseAddr;
540
541 /// Type a single array element wrt. this access.
543
544 /// Size of each dimension of the accessed array.
545 SmallVector<const SCEV *, 4> Sizes;
546 // @}
547
548 // Properties describing the accessed element.
549 // @{
550
551 /// The access instruction of this memory access.
552 ///
553 /// For memory accesses of kind MemoryKind::Array the access instruction is
554 /// the Load or Store instruction performing the access.
555 ///
556 /// For memory accesses of kind MemoryKind::PHI or MemoryKind::ExitPHI the
557 /// access instruction of a load access is the PHI instruction. The access
558 /// instruction of a PHI-store is the incoming's block's terminator
559 /// instruction.
560 ///
561 /// For memory accesses of kind MemoryKind::Value the access instruction of a
562 /// load access is nullptr because generally there can be multiple
563 /// instructions in the statement using the same llvm::Value. The access
564 /// instruction of a write access is the instruction that defines the
565 /// llvm::Value.
566 Instruction *AccessInstruction = nullptr;
567
568 /// Incoming block and value of a PHINode.
569 SmallVector<std::pair<BasicBlock *, Value *>, 4> Incoming;
570
571 /// The value associated with this memory access.
572 ///
573 /// - For array memory accesses (MemoryKind::Array) it is the loaded result
574 /// or the stored value. If the access instruction is a memory intrinsic it
575 /// the access value is also the memory intrinsic.
576 /// - For accesses of kind MemoryKind::Value it is the access instruction
577 /// itself.
578 /// - For accesses of kind MemoryKind::PHI or MemoryKind::ExitPHI it is the
579 /// PHI node itself (for both, READ and WRITE accesses).
580 ///
581 AssertingVH<Value> AccessValue;
582
583 /// Are all the subscripts affine expression?
584 bool IsAffine = true;
585
586 /// Subscript expression for each dimension.
588
589 /// Relation from statement instances to the accessed array elements.
590 ///
591 /// In the common case this relation is a function that maps a set of loop
592 /// indices to the memory address from which a value is loaded/stored:
593 ///
594 /// for i
595 /// for j
596 /// S: A[i + 3 j] = ...
597 ///
598 /// => { S[i,j] -> A[i + 3j] }
599 ///
600 /// In case the exact access function is not known, the access relation may
601 /// also be a one to all mapping { S[i,j] -> A[o] } describing that any
602 /// element accessible through A might be accessed.
603 ///
604 /// In case of an access to a larger element belonging to an array that also
605 /// contains smaller elements, the access relation models the larger access
606 /// with multiple smaller accesses of the size of the minimal array element
607 /// type:
608 ///
609 /// short *A;
610 ///
611 /// for i
612 /// S: A[i] = *((double*)&A[4 * i]);
613 ///
614 /// => { S[i] -> A[i]; S[i] -> A[o] : 4i <= o <= 4i + 3 }
616
617 /// Updated access relation read from JSCOP file.
619 // @}
620
622
624
625 /// Compute bounds on an over approximated access relation.
626 ///
627 /// @param ElementSize The size of one element accessed.
628 void computeBoundsOnAccessRelation(unsigned ElementSize);
629
630 /// Get the original access function as read from IR.
632
633 /// Return the space in which the access relation lives in.
635
636 /// Get the new access function imported or set by a pass
638
639 /// Fold the memory access to consider parametric offsets
640 ///
641 /// To recover memory accesses with array size parameters in the subscript
642 /// expression we post-process the delinearization results.
643 ///
644 /// We would normally recover from an access A[exp0(i) * N + exp1(i)] into an
645 /// array A[][N] the 2D access A[exp0(i)][exp1(i)]. However, another valid
646 /// delinearization is A[exp0(i) - 1][exp1(i) + N] which - depending on the
647 /// range of exp1(i) - may be preferable. Specifically, for cases where we
648 /// know exp1(i) is negative, we want to choose the latter expression.
649 ///
650 /// As we commonly do not have any information about the range of exp1(i),
651 /// we do not choose one of the two options, but instead create a piecewise
652 /// access function that adds the (-1, N) offsets as soon as exp1(i) becomes
653 /// negative. For a 2D array such an access function is created by applying
654 /// the piecewise map:
655 ///
656 /// [i,j] -> [i, j] : j >= 0
657 /// [i,j] -> [i-1, j+N] : j < 0
658 ///
659 /// We can generalize this mapping to arbitrary dimensions by applying this
660 /// piecewise mapping pairwise from the rightmost to the leftmost access
661 /// dimension. It would also be possible to cover a wider range by introducing
662 /// more cases and adding multiple of Ns to these cases. However, this has
663 /// not yet been necessary.
664 /// The introduction of different cases necessarily complicates the memory
665 /// access function, but cases that can be statically proven to not happen
666 /// will be eliminated later on.
667 void foldAccessRelation();
668
669 /// Create the access relation for the underlying memory intrinsic.
671
672 /// Assemble the access relation from all available information.
673 ///
674 /// In particular, used the information passes in the constructor and the
675 /// parent ScopStmt set by setStatment().
676 ///
677 /// @param SAI Info object for the accessed array.
678 void buildAccessRelation(const ScopArrayInfo *SAI);
679
680 /// Carry index overflows of dimensions with constant size to the next higher
681 /// dimension.
682 ///
683 /// For dimensions that have constant size, modulo the index by the size and
684 /// add up the carry (floored division) to the next higher dimension. This is
685 /// how overflow is defined in row-major order.
686 /// It happens e.g. when ScalarEvolution computes the offset to the base
687 /// pointer and would algebraically sum up all lower dimensions' indices of
688 /// constant size.
689 ///
690 /// Example:
691 /// float (*A)[4];
692 /// A[1][6] -> A[2][2]
694
695public:
696 /// Create a new MemoryAccess.
697 ///
698 /// @param Stmt The parent statement.
699 /// @param AccessInst The instruction doing the access.
700 /// @param BaseAddr The accessed array's address.
701 /// @param ElemType The type of the accessed array elements.
702 /// @param AccType Whether read or write access.
703 /// @param IsAffine Whether the subscripts are affine expressions.
704 /// @param Kind The kind of memory accessed.
705 /// @param Subscripts Subscript expressions
706 /// @param Sizes Dimension lengths of the accessed array.
707 MemoryAccess(ScopStmt *Stmt, Instruction *AccessInst, AccessType AccType,
708 Value *BaseAddress, Type *ElemType, bool Affine,
709 ArrayRef<const SCEV *> Subscripts, ArrayRef<const SCEV *> Sizes,
711
712 /// Create a new MemoryAccess that corresponds to @p AccRel.
713 ///
714 /// Along with @p Stmt and @p AccType it uses information about dimension
715 /// lengths of the accessed array, the type of the accessed array elements,
716 /// the name of the accessed array that is derived from the object accessible
717 /// via @p AccRel.
718 ///
719 /// @param Stmt The parent statement.
720 /// @param AccType Whether read or write access.
721 /// @param AccRel The access relation that describes the memory access.
723
724 MemoryAccess(const MemoryAccess &) = delete;
727
728 /// Add a new incoming block/value pairs for this PHI/ExitPHI access.
729 ///
730 /// @param IncomingBlock The PHI's incoming block.
731 /// @param IncomingValue The value when reaching the PHI from the @p
732 /// IncomingBlock.
733 void addIncoming(BasicBlock *IncomingBlock, Value *IncomingValue) {
734 assert(!isRead());
736 Incoming.emplace_back(std::make_pair(IncomingBlock, IncomingValue));
737 }
738
739 /// Return the list of possible PHI/ExitPHI values.
740 ///
741 /// After code generation moves some PHIs around during region simplification,
742 /// we cannot reliably locate the original PHI node and its incoming values
743 /// anymore. For this reason we remember these explicitly for all PHI-kind
744 /// accesses.
745 ArrayRef<std::pair<BasicBlock *, Value *>> getIncoming() const {
747 return Incoming;
748 }
749
750 /// Get the type of a memory access.
751 enum AccessType getType() { return AccType; }
752
753 /// Is this a reduction like access?
754 bool isReductionLike() const { return RedType != RT_NONE; }
755
756 /// Is this a read memory access?
757 bool isRead() const { return AccType == MemoryAccess::READ; }
758
759 /// Is this a must-write memory access?
760 bool isMustWrite() const { return AccType == MemoryAccess::MUST_WRITE; }
761
762 /// Is this a may-write memory access?
763 bool isMayWrite() const { return AccType == MemoryAccess::MAY_WRITE; }
764
765 /// Is this a write memory access?
766 bool isWrite() const { return isMustWrite() || isMayWrite(); }
767
768 /// Is this a memory intrinsic access (memcpy, memset, memmove)?
769 bool isMemoryIntrinsic() const {
770 return isa<MemIntrinsic>(getAccessInstruction());
771 }
772
773 /// Check if a new access relation was imported or set by a pass.
774 bool hasNewAccessRelation() const { return !NewAccessRelation.is_null(); }
775
776 /// Return the newest access relation of this access.
777 ///
778 /// There are two possibilities:
779 /// 1) The original access relation read from the LLVM-IR.
780 /// 2) A new access relation imported from a json file or set by another
781 /// pass (e.g., for privatization).
782 ///
783 /// As 2) is by construction "newer" than 1) we return the new access
784 /// relation if present.
785 ///
790
791 /// Old name of getLatestAccessRelation().
793
794 /// Get an isl map describing the memory address accessed.
795 ///
796 /// In most cases the memory address accessed is well described by the access
797 /// relation obtained with getAccessRelation. However, in case of arrays
798 /// accessed with types of different size the access relation maps one access
799 /// to multiple smaller address locations. This method returns an isl map that
800 /// relates each dynamic statement instance to the unique memory location
801 /// that is loaded from / stored to.
802 ///
803 /// For an access relation { S[i] -> A[o] : 4i <= o <= 4i + 3 } this method
804 /// will return the address function { S[i] -> A[4i] }.
805 ///
806 /// @returns The address function for this memory access.
808
809 /// Return the access relation after the schedule was applied.
812
813 /// Get an isl string representing the access function read from IR.
814 std::string getOriginalAccessRelationStr() const;
815
816 /// Get an isl string representing a new access function, if available.
817 std::string getNewAccessRelationStr() const;
818
819 /// Get an isl string representing the latest access relation.
820 std::string getAccessRelationStr() const;
821
822 /// Get the original base address of this access (e.g. A for A[i+j]) when
823 /// detected.
824 ///
825 /// This address may differ from the base address referenced by the original
826 /// ScopArrayInfo to which this array belongs, as this memory access may
827 /// have been canonicalized to a ScopArrayInfo which has a different but
828 /// identically-valued base pointer in case invariant load hoisting is
829 /// enabled.
830 Value *getOriginalBaseAddr() const { return BaseAddr; }
831
832 /// Get the detection-time base array isl::id for this access.
834
835 /// Get the base array isl::id for this access, modifiable through
836 /// setNewAccessRelation().
838
839 /// Old name of getOriginalArrayId().
841
842 /// Get the detection-time ScopArrayInfo object for the base address.
844
845 /// Get the ScopArrayInfo object for the base address, or the one set
846 /// by setNewAccessRelation().
848
849 /// Legacy name of getOriginalScopArrayInfo().
852 }
853
854 /// Return a string representation of the access's reduction type.
855 std::string getReductionOperatorStr() const;
856
857 /// Return a string representation of the reduction type @p RT.
858 static std::string getReductionOperatorStr(ReductionType RT);
859
860 /// Return the element type of the accessed array wrt. this access.
861 Type *getElementType() const { return ElementType; }
862
863 /// Return the access value of this memory access.
864 Value *getAccessValue() const { return AccessValue; }
865
866 /// Return llvm::Value that is stored by this access, if available.
867 ///
868 /// PHI nodes may not have a unique value available that is stored, as in
869 /// case of region statements one out of possibly several llvm::Values
870 /// might be stored. In this case nullptr is returned.
872 assert(isWrite() && "Only write statement store values");
873 if (isAnyPHIKind()) {
874 if (Incoming.size() == 1)
875 return Incoming[0].second;
876 return nullptr;
877 }
878 return AccessValue;
879 }
880
881 /// Return the access instruction of this memory access.
882 Instruction *getAccessInstruction() const { return AccessInstruction; }
883
884 /// Return an iterator range containing the subscripts.
885 iterator_range<SubscriptsTy::const_iterator> subscripts() const {
886 return make_range(Subscripts.begin(), Subscripts.end());
887 }
888
889 /// Return the number of access function subscript.
890 unsigned getNumSubscripts() const { return Subscripts.size(); }
891
892 /// Return the access function subscript in the dimension @p Dim.
893 const SCEV *getSubscript(unsigned Dim) const { return Subscripts[Dim]; }
894
895 /// Compute the isl representation for the SCEV @p E wrt. this access.
896 ///
897 /// Note that this function will also adjust the invalid context accordingly.
898 isl::pw_aff getPwAff(const SCEV *E);
899
900 /// Get the invalid domain for this access.
902
903 /// Get the invalid context for this access.
905
906 /// Get the stride of this memory access in the specified Schedule. Schedule
907 /// is a map from the statement to a schedule where the innermost dimension is
908 /// the dimension of the innermost loop containing the statement.
909 isl::set getStride(isl::map Schedule) const;
910
911 /// Is the stride of the access equal to a certain width? Schedule is a map
912 /// from the statement to a schedule where the innermost dimension is the
913 /// dimension of the innermost loop containing the statement.
914 bool isStrideX(isl::map Schedule, int StrideWidth) const;
915
916 /// Is consecutive memory accessed for a given statement instance set?
917 /// Schedule is a map from the statement to a schedule where the innermost
918 /// dimension is the dimension of the innermost loop containing the
919 /// statement.
920 bool isStrideOne(isl::map Schedule) const;
921
922 /// Is always the same memory accessed for a given statement instance set?
923 /// Schedule is a map from the statement to a schedule where the innermost
924 /// dimension is the dimension of the innermost loop containing the
925 /// statement.
926 bool isStrideZero(isl::map Schedule) const;
927
928 /// Return the kind when this access was first detected.
930 assert(!getOriginalScopArrayInfo() /* not yet initialized */ ||
931 getOriginalScopArrayInfo()->getKind() == Kind);
932 return Kind;
933 }
934
935 /// Return the kind considering a potential setNewAccessRelation.
938 }
939
940 /// Whether this is an access of an explicit load or store in the IR.
941 bool isOriginalArrayKind() const {
943 }
944
945 /// Whether storage memory is either an custom .s2a/.phiops alloca
946 /// (false) or an existing pointer into an array (true).
947 bool isLatestArrayKind() const {
949 }
950
951 /// Old name of isOriginalArrayKind.
952 bool isArrayKind() const { return isOriginalArrayKind(); }
953
954 /// Whether this access is an array to a scalar memory object, without
955 /// considering changes by setNewAccessRelation.
956 ///
957 /// Scalar accesses are accesses to MemoryKind::Value, MemoryKind::PHI or
958 /// MemoryKind::ExitPHI.
959 bool isOriginalScalarKind() const {
961 }
962
963 /// Whether this access is an array to a scalar memory object, also
964 /// considering changes by setNewAccessRelation.
965 bool isLatestScalarKind() const {
967 }
968
969 /// Old name of isOriginalScalarKind.
970 bool isScalarKind() const { return isOriginalScalarKind(); }
971
972 /// Was this MemoryAccess detected as a scalar dependences?
973 bool isOriginalValueKind() const {
975 }
976
977 /// Is this MemoryAccess currently modeling scalar dependences?
978 bool isLatestValueKind() const {
980 }
981
982 /// Old name of isOriginalValueKind().
983 bool isValueKind() const { return isOriginalValueKind(); }
984
985 /// Was this MemoryAccess detected as a special PHI node access?
986 bool isOriginalPHIKind() const {
988 }
989
990 /// Is this MemoryAccess modeling special PHI node accesses, also
991 /// considering a potential change by setNewAccessRelation?
992 bool isLatestPHIKind() const { return getLatestKind() == MemoryKind::PHI; }
993
994 /// Old name of isOriginalPHIKind.
995 bool isPHIKind() const { return isOriginalPHIKind(); }
996
997 /// Was this MemoryAccess detected as the accesses of a PHI node in the
998 /// SCoP's exit block?
1001 }
1002
1003 /// Is this MemoryAccess modeling the accesses of a PHI node in the
1004 /// SCoP's exit block? Can be changed to an array access using
1005 /// setNewAccessRelation().
1006 bool isLatestExitPHIKind() const {
1008 }
1009
1010 /// Old name of isOriginalExitPHIKind().
1011 bool isExitPHIKind() const { return isOriginalExitPHIKind(); }
1012
1013 /// Was this access detected as one of the two PHI types?
1016 }
1017
1018 /// Does this access originate from one of the two PHI types? Can be
1019 /// changed to an array access using setNewAccessRelation().
1020 bool isLatestAnyPHIKind() const {
1022 }
1023
1024 /// Old name of isOriginalAnyPHIKind().
1025 bool isAnyPHIKind() const { return isOriginalAnyPHIKind(); }
1026
1027 /// Get the statement that contains this memory access.
1028 ScopStmt *getStatement() const { return Statement; }
1029
1030 /// Get the reduction type of this access
1032
1033 /// Update the original access relation.
1034 ///
1035 /// We need to update the original access relation during scop construction,
1036 /// when unifying the memory accesses that access the same scop array info
1037 /// object. After the scop has been constructed, the original access relation
1038 /// should not be changed any more. Instead setNewAccessRelation should
1039 /// be called.
1041
1042 /// Set the updated access relation read from JSCOP file.
1044
1045 /// Return whether the MemoryyAccess is a partial access. That is, the access
1046 /// is not executed in some instances of the parent statement's domain.
1047 bool isLatestPartialAccess() const;
1048
1049 /// Mark this a reduction like access
1051
1052 /// Align the parameters in the access relation to the scop context
1053 void realignParams();
1054
1055 /// Update the dimensionality of the memory access.
1056 ///
1057 /// During scop construction some memory accesses may not be constructed with
1058 /// their full dimensionality, but outer dimensions may have been omitted if
1059 /// they took the value 'zero'. By updating the dimensionality of the
1060 /// statement we add additional zero-valued dimensions to match the
1061 /// dimensionality of the ScopArrayInfo object that belongs to this memory
1062 /// access.
1063 void updateDimensionality();
1064
1065 /// Get identifier for the memory access.
1066 ///
1067 /// This identifier is unique for all accesses that belong to the same scop
1068 /// statement.
1069 isl::id getId() const;
1070
1071 /// Print the MemoryAccess.
1072 ///
1073 /// @param OS The output stream the MemoryAccess is printed to.
1074 void print(raw_ostream &OS) const;
1075
1076#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1077 /// Print the MemoryAccess to stderr.
1078 void dump() const;
1079#endif
1080
1081 /// Is the memory access affine?
1082 bool isAffine() const { return IsAffine; }
1083};
1084
1085raw_ostream &operator<<(raw_ostream &OS, MemoryAccess::ReductionType RT);
1086
1087/// Ordered list type to hold accesses.
1088using MemoryAccessList = std::forward_list<MemoryAccess *>;
1089
1090/// Helper structure for invariant memory accesses.
1092 /// The memory access that is (partially) invariant.
1094
1095 /// The context under which the access is not invariant.
1097};
1098
1099/// Ordered container type to hold invariant accesses.
1100using InvariantAccessesTy = SmallVector<InvariantAccess, 8>;
1101
1102/// Type for equivalent invariant accesses and their domain context.
1104 /// The pointer that identifies this equivalence class
1106
1107 /// Memory accesses now treated invariant
1108 ///
1109 /// These memory accesses access the pointer location that identifies
1110 /// this equivalence class. They are treated as invariant and hoisted during
1111 /// code generation.
1113
1114 /// The execution context under which the memory location is accessed
1115 ///
1116 /// It is the union of the execution domains of the memory accesses in the
1117 /// InvariantAccesses list.
1119
1120 /// The type of the invariant access
1121 ///
1122 /// It is used to differentiate between differently typed invariant loads from
1123 /// the same location.
1125};
1126
1127/// Type for invariant accesses equivalence classes.
1128using InvariantEquivClassesTy = SmallVector<InvariantEquivClassTy, 8>;
1129
1130/// Statement of the Scop
1131///
1132/// A Scop statement represents an instruction in the Scop.
1133///
1134/// It is further described by its iteration domain, its schedule and its data
1135/// accesses.
1136/// At the moment every statement represents a single basic block of LLVM-IR.
1137class ScopStmt final {
1138 friend class ScopBuilder;
1139
1140public:
1141 using MemoryAccessVec = llvm::SmallVector<MemoryAccess *, 8>;
1142 /// Create the ScopStmt from a BasicBlock.
1143 ScopStmt(Scop &parent, BasicBlock &bb, StringRef Name, Loop *SurroundingLoop,
1144 std::vector<Instruction *> Instructions);
1145
1146 /// Create an overapproximating ScopStmt for the region @p R.
1147 ///
1148 /// @param EntryBlockInstructions The list of instructions that belong to the
1149 /// entry block of the region statement.
1150 /// Instructions are only tracked for entry
1151 /// blocks for now. We currently do not allow
1152 /// to modify the instructions of blocks later
1153 /// in the region statement.
1154 ScopStmt(Scop &parent, Region &R, StringRef Name, Loop *SurroundingLoop,
1155 std::vector<Instruction *> EntryBlockInstructions);
1156
1157 /// Create a copy statement.
1158 ///
1159 /// @param Stmt The parent statement.
1160 /// @param SourceRel The source location.
1161 /// @param TargetRel The target location.
1162 /// @param Domain The original domain under which the copy statement would
1163 /// be executed.
1164 ScopStmt(Scop &parent, isl::map SourceRel, isl::map TargetRel,
1166
1167 ScopStmt(const ScopStmt &) = delete;
1168 const ScopStmt &operator=(const ScopStmt &) = delete;
1170
1171private:
1172 /// Polyhedral description
1173 //@{
1174
1175 /// The Scop containing this ScopStmt.
1177
1178 /// The domain under which this statement is not modeled precisely.
1179 ///
1180 /// The invalid domain for a statement describes all parameter combinations
1181 /// under which the statement looks to be executed but is in fact not because
1182 /// some assumption/restriction makes the statement/scop invalid.
1184
1185 /// The iteration domain describes the set of iterations for which this
1186 /// statement is executed.
1187 ///
1188 /// Example:
1189 /// for (i = 0; i < 100 + b; ++i)
1190 /// for (j = 0; j < i; ++j)
1191 /// S(i,j);
1192 ///
1193 /// 'S' is executed for different values of i and j. A vector of all
1194 /// induction variables around S (i, j) is called iteration vector.
1195 /// The domain describes the set of possible iteration vectors.
1196 ///
1197 /// In this case it is:
1198 ///
1199 /// Domain: 0 <= i <= 100 + b
1200 /// 0 <= j <= i
1201 ///
1202 /// A pair of statement and iteration vector (S, (5,3)) is called statement
1203 /// instance.
1205
1206 /// The memory accesses of this statement.
1207 ///
1208 /// The only side effects of a statement are its memory accesses.
1210
1211 /// Mapping from instructions to (scalar) memory accesses.
1212 DenseMap<const Instruction *, MemoryAccessList> InstructionToAccess;
1213
1214 /// The set of values defined elsewhere required in this ScopStmt and
1215 /// their MemoryKind::Value READ MemoryAccesses.
1216 DenseMap<Value *, MemoryAccess *> ValueReads;
1217
1218 /// The set of values defined in this ScopStmt that are required
1219 /// elsewhere, mapped to their MemoryKind::Value WRITE MemoryAccesses.
1220 DenseMap<Instruction *, MemoryAccess *> ValueWrites;
1221
1222 /// Map from PHI nodes to its incoming value when coming from this
1223 /// statement.
1224 ///
1225 /// Non-affine subregions can have multiple exiting blocks that are incoming
1226 /// blocks of the PHI nodes. This map ensures that there is only one write
1227 /// operation for the complete subregion. A PHI selecting the relevant value
1228 /// will be inserted.
1229 DenseMap<PHINode *, MemoryAccess *> PHIWrites;
1230
1231 /// Map from PHI nodes to its read access in this statement.
1232 DenseMap<PHINode *, MemoryAccess *> PHIReads;
1233
1234 //@}
1235
1236 /// A SCoP statement represents either a basic block (affine/precise case) or
1237 /// a whole region (non-affine case).
1238 ///
1239 /// Only one of the following two members will therefore be set and indicate
1240 /// which kind of statement this is.
1241 ///
1242 ///{
1243
1244 /// The BasicBlock represented by this statement (in the affine case).
1245 BasicBlock *BB = nullptr;
1246
1247 /// The region represented by this statement (in the non-affine case).
1248 Region *R = nullptr;
1249
1250 ///}
1251
1252 /// The isl AST build for the new generated AST.
1254
1255 SmallVector<Loop *, 4> NestLoops;
1256
1257 std::string BaseName;
1258
1259 /// The closest loop that contains this statement.
1261
1262 /// Vector for Instructions in this statement.
1263 std::vector<Instruction *> Instructions;
1264
1265 /// Remove @p MA from dictionaries pointing to them.
1267
1268public:
1269 /// Get an isl_ctx pointer.
1270 isl::ctx getIslCtx() const;
1271
1272 /// Get the iteration domain of this ScopStmt.
1273 ///
1274 /// @return The iteration domain of this ScopStmt.
1275 isl::set getDomain() const;
1276
1277 /// Get the space of the iteration domain
1278 ///
1279 /// @return The space of the iteration domain
1280 isl::space getDomainSpace() const;
1281
1282 /// Get the id of the iteration domain space
1283 ///
1284 /// @return The id of the iteration domain space
1285 isl::id getDomainId() const;
1286
1287 /// Get an isl string representing this domain.
1288 std::string getDomainStr() const;
1289
1290 /// Get the schedule function of this ScopStmt.
1291 ///
1292 /// @return The schedule function of this ScopStmt, if it does not contain
1293 /// extension nodes, and nullptr, otherwise.
1294 isl::map getSchedule() const;
1295
1296 /// Get an isl string representing this schedule.
1297 ///
1298 /// @return An isl string representing this schedule, if it does not contain
1299 /// extension nodes, and an empty string, otherwise.
1300 std::string getScheduleStr() const;
1301
1302 /// Get the invalid domain for this statement.
1304
1305 /// Get the invalid context for this statement.
1307
1308 /// Set the invalid context for this statement to @p ID.
1309 void setInvalidDomain(isl::set ID);
1310
1311 /// Get the BasicBlock represented by this ScopStmt (if any).
1312 ///
1313 /// @return The BasicBlock represented by this ScopStmt, or null if the
1314 /// statement represents a region.
1315 BasicBlock *getBasicBlock() const { return BB; }
1316
1317 /// Return true if this statement represents a single basic block.
1318 bool isBlockStmt() const { return BB != nullptr; }
1319
1320 /// Return true if this is a copy statement.
1321 bool isCopyStmt() const { return BB == nullptr && R == nullptr; }
1322
1323 /// Get the region represented by this ScopStmt (if any).
1324 ///
1325 /// @return The region represented by this ScopStmt, or null if the statement
1326 /// represents a basic block.
1327 Region *getRegion() const { return R; }
1328
1329 /// Return true if this statement represents a whole region.
1330 bool isRegionStmt() const { return R != nullptr; }
1331
1332 /// Return a BasicBlock from this statement.
1333 ///
1334 /// For block statements, it returns the BasicBlock itself. For subregion
1335 /// statements, return its entry block.
1336 BasicBlock *getEntryBlock() const;
1337
1338 /// Return whether @p L is boxed within this statement.
1339 bool contains(const Loop *L) const {
1340 // Block statements never contain loops.
1341 if (isBlockStmt())
1342 return false;
1343
1344 return getRegion()->contains(L);
1345 }
1346
1347 /// Return whether this statement represents @p BB.
1348 bool represents(BasicBlock *BB) const {
1349 if (isCopyStmt())
1350 return false;
1351 if (isBlockStmt())
1352 return BB == getBasicBlock();
1353 return getRegion()->contains(BB);
1354 }
1355
1356 /// Return whether this statement contains @p Inst.
1357 bool contains(Instruction *Inst) const {
1358 if (!Inst)
1359 return false;
1360 if (isBlockStmt())
1361 return llvm::is_contained(Instructions, Inst);
1362 return represents(Inst->getParent());
1363 }
1364
1365 /// Return the closest innermost loop that contains this statement, but is not
1366 /// contained in it.
1367 ///
1368 /// For block statement, this is just the loop that contains the block. Region
1369 /// statements can contain boxed loops, so getting the loop of one of the
1370 /// region's BBs might return such an inner loop. For instance, the region's
1371 /// entry could be a header of a loop, but the region might extend to BBs
1372 /// after the loop exit. Similarly, the region might only contain parts of the
1373 /// loop body and still include the loop header.
1374 ///
1375 /// Most of the time the surrounding loop is the top element of #NestLoops,
1376 /// except when it is empty. In that case it return the loop that the whole
1377 /// SCoP is contained in. That can be nullptr if there is no such loop.
1378 Loop *getSurroundingLoop() const {
1379 assert(!isCopyStmt() &&
1380 "No surrounding loop for artificially created statements");
1381 return SurroundingLoop;
1382 }
1383
1384 /// Return true if this statement does not contain any accesses.
1385 bool isEmpty() const { return MemAccs.empty(); }
1386
1387 /// Find all array accesses for @p Inst.
1388 ///
1389 /// @param Inst The instruction accessing an array.
1390 ///
1391 /// @return A list of array accesses (MemoryKind::Array) accessed by @p Inst.
1392 /// If there is no such access, it returns nullptr.
1393 const MemoryAccessList *
1394 lookupArrayAccessesFor(const Instruction *Inst) const {
1395 auto It = InstructionToAccess.find(Inst);
1396 if (It == InstructionToAccess.end())
1397 return nullptr;
1398 if (It->second.empty())
1399 return nullptr;
1400 return &It->second;
1401 }
1402
1403 /// Return the only array access for @p Inst, if existing.
1404 ///
1405 /// @param Inst The instruction for which to look up the access.
1406 /// @returns The unique array memory access related to Inst or nullptr if
1407 /// no array access exists
1408 MemoryAccess *getArrayAccessOrNULLFor(const Instruction *Inst) const {
1409 auto It = InstructionToAccess.find(Inst);
1410 if (It == InstructionToAccess.end())
1411 return nullptr;
1412
1413 MemoryAccess *ArrayAccess = nullptr;
1414
1415 for (auto Access : It->getSecond()) {
1416 if (!Access->isArrayKind())
1417 continue;
1418
1419 assert(!ArrayAccess && "More then one array access for instruction");
1420
1421 ArrayAccess = Access;
1422 }
1423
1424 return ArrayAccess;
1425 }
1426
1427 /// Return the only array access for @p Inst.
1428 ///
1429 /// @param Inst The instruction for which to look up the access.
1430 /// @returns The unique array memory access related to Inst.
1431 MemoryAccess &getArrayAccessFor(const Instruction *Inst) const {
1432 MemoryAccess *ArrayAccess = getArrayAccessOrNULLFor(Inst);
1433
1434 assert(ArrayAccess && "No array access found for instruction!");
1435 return *ArrayAccess;
1436 }
1437
1438 /// Return the MemoryAccess that writes the value of an instruction
1439 /// defined in this statement, or nullptr if not existing, respectively
1440 /// not yet added.
1441 MemoryAccess *lookupValueWriteOf(Instruction *Inst) const {
1442 assert((isRegionStmt() && R->contains(Inst)) ||
1443 (!isRegionStmt() && Inst->getParent() == BB));
1444 return ValueWrites.lookup(Inst);
1445 }
1446
1447 /// Return the MemoryAccess that reloads a value, or nullptr if not
1448 /// existing, respectively not yet added.
1450 return ValueReads.lookup(Inst);
1451 }
1452
1453 /// Return the MemoryAccess that loads a PHINode value, or nullptr if not
1454 /// existing, respectively not yet added.
1456 return PHIReads.lookup(PHI);
1457 }
1458
1459 /// Return the PHI write MemoryAccess for the incoming values from any
1460 /// basic block in this ScopStmt, or nullptr if not existing,
1461 /// respectively not yet added.
1463 assert(isBlockStmt() || R->getExit() == PHI->getParent());
1464 return PHIWrites.lookup(PHI);
1465 }
1466
1467 /// Return the input access of the value, or null if no such MemoryAccess
1468 /// exists.
1469 ///
1470 /// The input access is the MemoryAccess that makes an inter-statement value
1471 /// available in this statement by reading it at the start of this statement.
1472 /// This can be a MemoryKind::Value if defined in another statement or a
1473 /// MemoryKind::PHI if the value is a PHINode in this statement.
1475 if (isa<PHINode>(Val))
1476 if (auto InputMA = lookupPHIReadOf(cast<PHINode>(Val))) {
1477 assert(!lookupValueReadOf(Val) && "input accesses must be unique; a "
1478 "statement cannot read a .s2a and "
1479 ".phiops simultaneously");
1480 return InputMA;
1481 }
1482
1483 if (auto *InputMA = lookupValueReadOf(Val))
1484 return InputMA;
1485
1486 return nullptr;
1487 }
1488
1489 /// Add @p Access to this statement's list of accesses.
1490 ///
1491 /// @param Access The access to add.
1492 /// @param Prepend If true, will add @p Access before all other instructions
1493 /// (instead of appending it).
1494 void addAccess(MemoryAccess *Access, bool Prepend = false);
1495
1496 /// Remove a MemoryAccess from this statement.
1497 ///
1498 /// Note that scalar accesses that are caused by MA will
1499 /// be eliminated too.
1501
1502 /// Remove @p MA from this statement.
1503 ///
1504 /// In contrast to removeMemoryAccess(), no other access will be eliminated.
1505 ///
1506 /// @param MA The MemoryAccess to be removed.
1507 /// @param AfterHoisting If true, also remove from data access lists.
1508 /// These lists are filled during
1509 /// ScopBuilder::buildAccessRelations. Therefore, if this
1510 /// method is called before buildAccessRelations, false
1511 /// must be passed.
1512 void removeSingleMemoryAccess(MemoryAccess *MA, bool AfterHoisting = true);
1513
1514 using iterator = MemoryAccessVec::iterator;
1515 using const_iterator = MemoryAccessVec::const_iterator;
1516
1517 iterator begin() { return MemAccs.begin(); }
1518 iterator end() { return MemAccs.end(); }
1519 const_iterator begin() const { return MemAccs.begin(); }
1520 const_iterator end() const { return MemAccs.end(); }
1521 size_t size() const { return MemAccs.size(); }
1522
1523 unsigned getNumIterators() const;
1524
1525 Scop *getParent() { return &Parent; }
1526 const Scop *getParent() const { return &Parent; }
1527
1528 const std::vector<Instruction *> &getInstructions() const {
1529 return Instructions;
1530 }
1531
1532 /// Set the list of instructions for this statement. It replaces the current
1533 /// list.
1534 void setInstructions(ArrayRef<Instruction *> Range) {
1535 Instructions.assign(Range.begin(), Range.end());
1536 }
1537
1538 std::vector<Instruction *>::const_iterator insts_begin() const {
1539 return Instructions.begin();
1540 }
1541
1542 std::vector<Instruction *>::const_iterator insts_end() const {
1543 return Instructions.end();
1544 }
1545
1546 /// The range of instructions in this statement.
1547 iterator_range<std::vector<Instruction *>::const_iterator> insts() const {
1548 return {insts_begin(), insts_end()};
1549 }
1550
1551 /// Insert an instruction before all other instructions in this statement.
1552 void prependInstruction(Instruction *Inst) {
1553 Instructions.insert(Instructions.begin(), Inst);
1554 }
1555
1556 const char *getBaseName() const;
1557
1558 /// Set the isl AST build.
1560
1561 /// Get the isl AST build.
1563
1564 /// Restrict the domain of the statement.
1565 ///
1566 /// @param NewDomain The new statement domain.
1567 void restrictDomain(isl::set NewDomain);
1568
1569 /// Get the loop for a dimension.
1570 ///
1571 /// @param Dimension The dimension of the induction variable
1572 /// @return The loop at a certain dimension.
1573 Loop *getLoopForDimension(unsigned Dimension) const;
1574
1575 /// Align the parameters in the statement to the scop context
1576 void realignParams();
1577
1578 /// Print the ScopStmt.
1579 ///
1580 /// @param OS The output stream the ScopStmt is printed to.
1581 /// @param PrintInstructions Whether to print the statement's instructions as
1582 /// well.
1583 void print(raw_ostream &OS, bool PrintInstructions) const;
1584
1585 /// Print the instructions in ScopStmt.
1586 ///
1587 void printInstructions(raw_ostream &OS) const;
1588
1589 /// Check whether there is a value read access for @p V in this statement, and
1590 /// if not, create one.
1591 ///
1592 /// This allows to add MemoryAccesses after the initial creation of the Scop
1593 /// by ScopBuilder.
1594 ///
1595 /// @return The already existing or newly created MemoryKind::Value READ
1596 /// MemoryAccess.
1597 ///
1598 /// @see ScopBuilder::ensureValueRead(Value*,ScopStmt*)
1600
1601#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1602 /// Print the ScopStmt to stderr.
1603 void dump() const;
1604#endif
1605};
1606
1607/// Print ScopStmt S to raw_ostream OS.
1608raw_ostream &operator<<(raw_ostream &OS, const ScopStmt &S);
1609
1610/// Static Control Part
1611///
1612/// A Scop is the polyhedral representation of a control flow region detected
1613/// by the Scop detection. It is generated by translating the LLVM-IR and
1614/// abstracting its effects.
1615///
1616/// A Scop consists of a set of:
1617///
1618/// * A set of statements executed in the Scop.
1619///
1620/// * A set of global parameters
1621/// Those parameters are scalar integer values, which are constant during
1622/// execution.
1623///
1624/// * A context
1625/// This context contains information about the values the parameters
1626/// can take and relations between different parameters.
1627class Scop final {
1628public:
1629 /// Type to represent a pair of minimal/maximal access to an array.
1630 using MinMaxAccessTy = std::pair<isl::pw_multi_aff, isl::pw_multi_aff>;
1631
1632 /// Vector of minimal/maximal accesses to different arrays.
1633 using MinMaxVectorTy = SmallVector<MinMaxAccessTy, 4>;
1634
1635 /// Pair of minimal/maximal access vectors representing
1636 /// read write and read only accesses
1637 using MinMaxVectorPairTy = std::pair<MinMaxVectorTy, MinMaxVectorTy>;
1638
1639 /// Vector of pair of minimal/maximal access vectors representing
1640 /// non read only and read only accesses for each alias group.
1641 using MinMaxVectorPairVectorTy = SmallVector<MinMaxVectorPairTy, 4>;
1642
1643private:
1644 friend class ScopBuilder;
1645
1646 /// Isl context.
1647 ///
1648 /// We need a shared_ptr with reference counter to delete the context when all
1649 /// isl objects are deleted. We will distribute the shared_ptr to all objects
1650 /// that use the context to create isl objects, and increase the reference
1651 /// counter. By doing this, we guarantee that the context is deleted when we
1652 /// delete the last object that creates isl objects with the context. This
1653 /// declaration needs to be the first in class to gracefully destroy all isl
1654 /// objects before the context.
1655 std::shared_ptr<isl_ctx> IslCtx;
1656
1657 ScalarEvolution *SE;
1658 DominatorTree *DT;
1659
1660 /// The underlying Region.
1661 Region &R;
1662
1663 /// The name of the SCoP (identical to the regions name)
1664 std::optional<std::string> name;
1665
1666 // Access functions of the SCoP.
1667 //
1668 // This owns all the MemoryAccess objects of the Scop created in this pass.
1670
1671 /// Flag to indicate that the scheduler actually optimized the SCoP.
1672 bool IsOptimized = false;
1673
1674 /// True if the underlying region has a single exiting block.
1676
1677 /// Flag to remember if the SCoP contained an error block or not.
1678 bool HasErrorBlock = false;
1679
1680 /// Max loop depth.
1681 unsigned MaxLoopDepth = 0;
1682
1683 /// Number of copy statements.
1684 unsigned CopyStmtsNum = 0;
1685
1686 using StmtSet = std::list<ScopStmt>;
1687
1688 /// The statements in this Scop.
1690
1691 /// Parameters of this Scop
1693
1694 /// Mapping from parameters to their ids.
1695 DenseMap<const SCEV *, isl::id> ParameterIds;
1696
1697 /// The context of the SCoP created during SCoP detection.
1699
1700 /// OptimizationRemarkEmitter object for displaying diagnostic remarks
1701 OptimizationRemarkEmitter &ORE;
1702
1703 /// A map from basic blocks to vector of SCoP statements. Currently this
1704 /// vector comprises only of a single statement.
1705 DenseMap<BasicBlock *, std::vector<ScopStmt *>> StmtMap;
1706
1707 /// A map from instructions to SCoP statements.
1708 DenseMap<Instruction *, ScopStmt *> InstStmtMap;
1709
1710 /// A map from basic blocks to their domains.
1711 DenseMap<BasicBlock *, isl::set> DomainMap;
1712
1713 /// Constraints on parameters.
1715
1716 /// The affinator used to translate SCEVs to isl expressions.
1718
1720 std::map<std::pair<AssertingVH<const Value>, MemoryKind>,
1721 std::unique_ptr<ScopArrayInfo>>;
1722
1723 using ArrayNameMapTy = StringMap<std::unique_ptr<ScopArrayInfo>>;
1724
1725 using ArrayInfoSetTy = SetVector<ScopArrayInfo *>;
1726
1727 /// A map to remember ScopArrayInfo objects for all base pointers.
1728 ///
1729 /// As PHI nodes may have two array info objects associated, we add a flag
1730 /// that distinguishes between the PHI node specific ArrayInfo object
1731 /// and the normal one.
1733
1734 /// A map to remember ScopArrayInfo objects for all names of memory
1735 /// references.
1737
1738 /// A set to remember ScopArrayInfo objects.
1739 /// @see Scop::ScopArrayInfoMap
1741
1742 /// The assumptions under which this scop was built.
1743 ///
1744 /// When constructing a scop sometimes the exact representation of a statement
1745 /// or condition would be very complex, but there is a common case which is a
1746 /// lot simpler, but which is only valid under certain assumptions. The
1747 /// assumed context records the assumptions taken during the construction of
1748 /// this scop and that need to be code generated as a run-time test.
1750
1751 /// The restrictions under which this SCoP was built.
1752 ///
1753 /// The invalid context is similar to the assumed context as it contains
1754 /// constraints over the parameters. However, while we need the constraints
1755 /// in the assumed context to be "true" the constraints in the invalid context
1756 /// need to be "false". Otherwise they behave the same.
1758
1759 /// The context under which the SCoP must have defined behavior. Optimizer and
1760 /// code generator can assume that the SCoP will only be executed with
1761 /// parameter values within this context. This might be either because we can
1762 /// prove that other values are impossible or explicitly have undefined
1763 /// behavior, such as due to no-wrap flags. If this becomes too complex, can
1764 /// also be nullptr.
1765 ///
1766 /// In contrast to Scop::AssumedContext and Scop::InvalidContext, these do not
1767 /// need to be checked at runtime.
1768 ///
1769 /// Scop::Context on the other side is an overapproximation and does not
1770 /// include all requirements, but is always defined. However, there is still
1771 /// no guarantee that there is no undefined behavior in
1772 /// DefinedBehaviorContext. Moreover, AssumedContext and InvalidContext are
1773 /// gist'd using Scop::Context, but here we can add assumptions that only hold
1774 /// under RTC-checked conditions.
1776
1777 /// The schedule of the SCoP
1778 ///
1779 /// The schedule of the SCoP describes the execution order of the statements
1780 /// in the scop by assigning each statement instance a possibly
1781 /// multi-dimensional execution time. The schedule is stored as a tree of
1782 /// schedule nodes.
1783 ///
1784 /// The most common nodes in a schedule tree are so-called band nodes. Band
1785 /// nodes map statement instances into a multi dimensional schedule space.
1786 /// This space can be seen as a multi-dimensional clock.
1787 ///
1788 /// Example:
1789 ///
1790 /// <S,(5,4)> may be mapped to (5,4) by this schedule:
1791 ///
1792 /// s0 = i (Year of execution)
1793 /// s1 = j (Day of execution)
1794 ///
1795 /// or to (9, 20) by this schedule:
1796 ///
1797 /// s0 = i + j (Year of execution)
1798 /// s1 = 20 (Day of execution)
1799 ///
1800 /// The order statement instances are executed is defined by the
1801 /// schedule vectors they are mapped to. A statement instance
1802 /// <A, (i, j, ..)> is executed before a statement instance <B, (i', ..)>, if
1803 /// the schedule vector of A is lexicographic smaller than the schedule
1804 /// vector of B.
1805 ///
1806 /// Besides band nodes, schedule trees contain additional nodes that specify
1807 /// a textual ordering between two subtrees or filter nodes that filter the
1808 /// set of statement instances that will be scheduled in a subtree. There
1809 /// are also several other nodes. A full description of the different nodes
1810 /// in a schedule tree is given in the isl manual.
1812
1813 /// Is this Scop marked as not to be transformed by an optimization heuristic?
1815
1816 /// Whether the schedule has been modified after derived from the CFG by
1817 /// ScopBuilder.
1818 bool ScheduleModified = false;
1819
1820 /// The set of minimal/maximal accesses for each alias group.
1821 ///
1822 /// When building runtime alias checks we look at all memory instructions and
1823 /// build so called alias groups. Each group contains a set of accesses to
1824 /// different base arrays which might alias with each other. However, between
1825 /// alias groups there is no aliasing possible.
1826 ///
1827 /// In a program with int and float pointers annotated with tbaa information
1828 /// we would probably generate two alias groups, one for the int pointers and
1829 /// one for the float pointers.
1830 ///
1831 /// During code generation we will create a runtime alias check for each alias
1832 /// group to ensure the SCoP is executed in an alias free environment.
1834
1835 /// Mapping from invariant loads to the representing invariant load of
1836 /// their equivalence class.
1837 ValueToValueMap InvEquivClassVMap;
1838
1839 /// List of invariant accesses.
1841
1842 /// The smallest array index not yet assigned.
1843 long ArrayIdx = 0;
1844
1845 /// The smallest statement index not yet assigned.
1846 long StmtIdx = 0;
1847
1848 /// A number that uniquely represents a Scop within its function
1849 const int ID;
1850
1851 /// Map of values to the MemoryAccess that writes its definition.
1852 ///
1853 /// There must be at most one definition per llvm::Instruction in a SCoP.
1854 DenseMap<Value *, MemoryAccess *> ValueDefAccs;
1855
1856 /// Map of values to the MemoryAccess that reads a PHI.
1857 DenseMap<PHINode *, MemoryAccess *> PHIReadAccs;
1858
1859 /// List of all uses (i.e. read MemoryAccesses) for a MemoryKind::Value
1860 /// scalar.
1861 DenseMap<const ScopArrayInfo *, SmallVector<MemoryAccess *, 4>> ValueUseAccs;
1862
1863 /// List of all incoming values (write MemoryAccess) of a MemoryKind::PHI or
1864 /// MemoryKind::ExitPHI scalar.
1865 DenseMap<const ScopArrayInfo *, SmallVector<MemoryAccess *, 4>>
1867
1868 /// Scop constructor; invoked from ScopBuilder::buildScop.
1869 Scop(Region &R, ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT,
1870 ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE,
1871 int ID);
1872
1873 /// Return the access for the base ptr of @p MA if any.
1875
1876 /// Create an id for @p Param and store it in the ParameterIds map.
1877 void createParameterId(const SCEV *Param);
1878
1879 /// Add the bounds of the parameters to the context.
1880 void addParameterBounds();
1881
1882 /// Simplify the assumed and invalid context.
1883 void simplifyContexts();
1884
1885 /// Create a new SCoP statement for @p BB.
1886 ///
1887 /// A new statement for @p BB will be created and added to the statement
1888 /// vector
1889 /// and map.
1890 ///
1891 /// @param BB The basic block we build the statement for.
1892 /// @param Name The name of the new statement.
1893 /// @param SurroundingLoop The loop the created statement is contained in.
1894 /// @param Instructions The instructions in the statement.
1895 void addScopStmt(BasicBlock *BB, StringRef Name, Loop *SurroundingLoop,
1896 std::vector<Instruction *> Instructions);
1897
1898 /// Create a new SCoP statement for @p R.
1899 ///
1900 /// A new statement for @p R will be created and added to the statement vector
1901 /// and map.
1902 ///
1903 /// @param R The region we build the statement for.
1904 /// @param Name The name of the new statement.
1905 /// @param SurroundingLoop The loop the created statement is contained
1906 /// in.
1907 /// @param EntryBlockInstructions The (interesting) instructions in the
1908 /// entry block of the region statement.
1909 void addScopStmt(Region *R, StringRef Name, Loop *SurroundingLoop,
1910 std::vector<Instruction *> EntryBlockInstructions);
1911
1912 /// Removes @p Stmt from the StmtMap.
1913 void removeFromStmtMap(ScopStmt &Stmt);
1914
1915 /// Removes all statements where the entry block of the statement does not
1916 /// have a corresponding domain in the domain map (or it is empty).
1918
1919 /// Collect all memory access relations of a given type.
1920 ///
1921 /// @param Predicate A predicate function that returns true if an access is
1922 /// of a given type.
1923 ///
1924 /// @returns The set of memory accesses in the scop that match the predicate.
1926 getAccessesOfType(std::function<bool(MemoryAccess &)> Predicate);
1927
1928 /// @name Helper functions for printing the Scop.
1929 ///
1930 //@{
1931 void printContext(raw_ostream &OS) const;
1932 void printArrayInfo(raw_ostream &OS) const;
1933 void printStatements(raw_ostream &OS, bool PrintInstructions) const;
1934 void printAliasAssumptions(raw_ostream &OS) const;
1935 //@}
1936
1937public:
1938 Scop(const Scop &) = delete;
1939 Scop &operator=(const Scop &) = delete;
1941
1942 /// Factory pattern for creating a new (empty) SCoP.
1943 static std::unique_ptr<Scop> makeScop(Region &R, ScalarEvolution &SE,
1944 LoopInfo &LI, DominatorTree &DT,
1946 OptimizationRemarkEmitter &ORE, int ID);
1947
1948 /// Increment actual number of aliasing assumptions taken
1949 ///
1950 /// @param Step Number of new aliasing assumptions which should be added to
1951 /// the number of already taken assumptions.
1952 static void incrementNumberOfAliasingAssumptions(unsigned Step);
1953
1954 /// Get the count of copy statements added to this Scop.
1955 ///
1956 /// @return The count of copy statements added to this Scop.
1957 unsigned getCopyStmtsNum() { return CopyStmtsNum; }
1958
1959 /// Create a new copy statement.
1960 ///
1961 /// A new statement will be created and added to the statement vector.
1962 ///
1963 /// @param SourceRel The source location.
1964 /// @param TargetRel The target location.
1965 /// @param Domain The original domain under which the copy statement would
1966 /// be executed.
1967 ScopStmt *addScopStmt(isl::map SourceRel, isl::map TargetRel,
1969
1970 /// Add the access function to all MemoryAccess objects of the Scop
1971 /// created in this pass.
1973 AccessFunctions.emplace_back(Access);
1974
1975 // Register value definitions.
1976 if (Access->isWrite() && Access->isOriginalValueKind()) {
1977 assert(!ValueDefAccs.count(Access->getAccessValue()) &&
1978 "there can be just one definition per value");
1979 ValueDefAccs[Access->getAccessValue()] = Access;
1980 } else if (Access->isRead() && Access->isOriginalPHIKind()) {
1981 PHINode *PHI = cast<PHINode>(Access->getAccessInstruction());
1982 assert(!PHIReadAccs.count(PHI) &&
1983 "there can be just one PHI read per PHINode");
1984 PHIReadAccs[PHI] = Access;
1985 }
1986 }
1987
1988 /// Add metadata for @p Access.
1989 void addAccessData(MemoryAccess *Access);
1990
1991 /// Add new invariant access equivalence class
1992 void
1993 addInvariantEquivClass(const InvariantEquivClassTy &InvariantEquivClass) {
1994 InvariantEquivClasses.emplace_back(InvariantEquivClass);
1995 }
1996
1997 /// Add mapping from invariant loads to the representing invariant load of
1998 /// their equivalence class.
1999 void addInvariantLoadMapping(const Value *LoadInst, Value *ClassRep) {
2000 InvEquivClassVMap[LoadInst] = ClassRep;
2001 }
2002
2003 /// Remove the metadata stored for @p Access.
2004 void removeAccessData(MemoryAccess *Access);
2005
2006 /// Return the scalar evolution.
2007 ScalarEvolution *getSE() const;
2008
2009 /// Return the dominator tree.
2010 DominatorTree *getDT() const { return DT; }
2011
2012 /// Return the LoopInfo used for this Scop.
2013 LoopInfo *getLI() const { return Affinator.getLI(); }
2014
2015 /// Get the count of parameters used in this Scop.
2016 ///
2017 /// @return The count of parameters used in this Scop.
2018 size_t getNumParams() const { return Parameters.size(); }
2019
2020 /// Return whether given SCEV is used as the parameter in this Scop.
2021 bool isParam(const SCEV *Param) const { return Parameters.count(Param); }
2022
2023 /// Take a list of parameters and add the new ones to the scop.
2024 void addParams(const ParameterSetTy &NewParameters);
2025
2026 /// Return an iterator range containing the scop parameters.
2027 iterator_range<ParameterSetTy::iterator> parameters() const {
2028 return make_range(Parameters.begin(), Parameters.end());
2029 }
2030
2031 /// Return an iterator range containing invariant accesses.
2032 iterator_range<InvariantEquivClassesTy::iterator> invariantEquivClasses() {
2033 return make_range(InvariantEquivClasses.begin(),
2034 InvariantEquivClasses.end());
2035 }
2036
2037 /// Return an iterator range containing all the MemoryAccess objects of the
2038 /// Scop.
2039 iterator_range<AccFuncVector::iterator> access_functions() {
2040 return make_range(AccessFunctions.begin(), AccessFunctions.end());
2041 }
2042
2043 /// Return whether this scop is empty, i.e. contains no statements that
2044 /// could be executed.
2045 bool isEmpty() const { return Stmts.empty(); }
2046
2047 StringRef getName() {
2048 if (!name)
2049 name = R.getNameStr();
2050 return *name;
2051 }
2052
2053 using array_iterator = ArrayInfoSetTy::iterator;
2054 using const_array_iterator = ArrayInfoSetTy::const_iterator;
2055 using array_range = iterator_range<ArrayInfoSetTy::iterator>;
2056 using const_array_range = iterator_range<ArrayInfoSetTy::const_iterator>;
2057
2058 inline array_iterator array_begin() { return ScopArrayInfoSet.begin(); }
2059
2060 inline array_iterator array_end() { return ScopArrayInfoSet.end(); }
2061
2063 return ScopArrayInfoSet.begin();
2064 }
2065
2067 return ScopArrayInfoSet.end();
2068 }
2069
2071 return array_range(array_begin(), array_end());
2072 }
2073
2074 inline const_array_range arrays() const {
2076 }
2077
2078 /// Return the isl_id that represents a certain parameter.
2079 ///
2080 /// @param Parameter A SCEV that was recognized as a Parameter.
2081 ///
2082 /// @return The corresponding isl_id or NULL otherwise.
2083 isl::id getIdForParam(const SCEV *Parameter) const;
2084
2085 /// Get the maximum region of this static control part.
2086 ///
2087 /// @return The maximum region of this static control part.
2088 inline const Region &getRegion() const { return R; }
2089 inline Region &getRegion() { return R; }
2090
2091 /// Return the function this SCoP is in.
2092 Function &getFunction() const { return *R.getEntry()->getParent(); }
2093
2094 /// Check if @p L is contained in the SCoP.
2095 bool contains(const Loop *L) const { return R.contains(L); }
2096
2097 /// Check if @p BB is contained in the SCoP.
2098 bool contains(const BasicBlock *BB) const { return R.contains(BB); }
2099
2100 /// Check if @p I is contained in the SCoP.
2101 bool contains(const Instruction *I) const { return R.contains(I); }
2102
2103 /// Return the unique exit block of the SCoP.
2104 BasicBlock *getExit() const { return R.getExit(); }
2105
2106 /// Return the unique exiting block of the SCoP if any.
2107 BasicBlock *getExitingBlock() const { return R.getExitingBlock(); }
2108
2109 /// Return the unique entry block of the SCoP.
2110 BasicBlock *getEntry() const { return R.getEntry(); }
2111
2112 /// Return the unique entering block of the SCoP if any.
2113 BasicBlock *getEnteringBlock() const { return R.getEnteringBlock(); }
2114
2115 /// Return true if @p BB is the exit block of the SCoP.
2116 bool isExit(BasicBlock *BB) const { return getExit() == BB; }
2117
2118 /// Return a range of all basic blocks in the SCoP.
2119 Region::block_range blocks() const { return R.blocks(); }
2120
2121 /// Return true if and only if @p BB dominates the SCoP.
2122 bool isDominatedBy(const DominatorTree &DT, BasicBlock *BB) const;
2123
2124 /// Get the maximum depth of the loop.
2125 ///
2126 /// @return The maximum depth of the loop.
2127 inline unsigned getMaxLoopDepth() const { return MaxLoopDepth; }
2128
2129 /// Return the invariant equivalence class for @p Val if any.
2131
2132 /// Return the set of invariant accesses.
2136
2137 /// Check if the scop has any invariant access.
2139
2140 /// Mark the SCoP as optimized by the scheduler.
2141 void markAsOptimized() { IsOptimized = true; }
2142
2143 /// Check if the SCoP has been optimized by the scheduler.
2144 bool isOptimized() const { return IsOptimized; }
2145
2146 /// Return the ID of the Scop
2147 int getID() const { return ID; }
2148
2149 /// Get the name of the entry and exit blocks of this Scop.
2150 ///
2151 /// These along with the function name can uniquely identify a Scop.
2152 ///
2153 /// @return std::pair whose first element is the entry name & second element
2154 /// is the exit name.
2155 std::pair<std::string, std::string> getEntryExitStr() const;
2156
2157 /// Get the name of this Scop.
2158 std::string getNameStr() const;
2159
2160 /// Get the constraint on parameter of this Scop.
2161 ///
2162 /// @return The constraint on parameter of this Scop.
2163 isl::set getContext() const;
2164
2165 /// Return the context where execution behavior is defined. Might return
2166 /// nullptr.
2168
2169 /// Return the define behavior context, or if not available, its approximation
2170 /// from all other contexts.
2172 if (!DefinedBehaviorContext.is_null())
2174
2175 return Context.intersect_params(AssumedContext).subtract(InvalidContext);
2176 }
2177
2178 /// Return space of isl context parameters.
2179 ///
2180 /// Returns the set of context parameters that are currently constrained. In
2181 /// case the full set of parameters is needed, see @getFullParamSpace.
2182 isl::space getParamSpace() const;
2183
2184 /// Return the full space of parameters.
2185 ///
2186 /// getParamSpace will only return the parameters of the context that are
2187 /// actually constrained, whereas getFullParamSpace will return all
2188 // parameters. This is useful in cases, where we need to ensure all
2189 // parameters are available, as certain isl functions will abort if this is
2190 // not the case.
2192
2193 /// Get the assumed context for this Scop.
2194 ///
2195 /// @return The assumed context of this Scop.
2197
2198 /// Return true if the optimized SCoP can be executed.
2199 ///
2200 /// In addition to the runtime check context this will also utilize the domain
2201 /// constraints to decide it the optimized version can actually be executed.
2202 ///
2203 /// @returns True if the optimized SCoP can be executed.
2204 bool hasFeasibleRuntimeContext() const;
2205
2206 /// Check if the assumption in @p Set is trivial or not.
2207 ///
2208 /// @param Set The relations between parameters that are assumed to hold.
2209 /// @param Sign Enum to indicate if the assumptions in @p Set are positive
2210 /// (needed/assumptions) or negative (invalid/restrictions).
2211 ///
2212 /// @returns True if the assumption @p Set is not trivial.
2214
2215 /// Track and report an assumption.
2216 ///
2217 /// Use 'clang -Rpass-analysis=polly-scops' or 'opt
2218 /// -pass-remarks-analysis=polly-scops' to output the assumptions.
2219 ///
2220 /// @param Kind The assumption kind describing the underlying cause.
2221 /// @param Set The relations between parameters that are assumed to hold.
2222 /// @param Loc The location in the source that caused this assumption.
2223 /// @param Sign Enum to indicate if the assumptions in @p Set are positive
2224 /// (needed/assumptions) or negative (invalid/restrictions).
2225 /// @param BB The block in which this assumption was taken. Used to
2226 /// calculate hotness when emitting remark.
2227 ///
2228 /// @returns True if the assumption is not trivial.
2229 bool trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
2230 AssumptionSign Sign, BasicBlock *BB);
2231
2232 /// Add the conditions from @p Set (or subtract them if @p Sign is
2233 /// AS_RESTRICTION) to the defined behaviour context.
2235
2236 /// Add assumptions to assumed context.
2237 ///
2238 /// The assumptions added will be assumed to hold during the execution of the
2239 /// scop. However, as they are generally not statically provable, at code
2240 /// generation time run-time checks will be generated that ensure the
2241 /// assumptions hold.
2242 ///
2243 /// WARNING: We currently exploit in simplifyAssumedContext the knowledge
2244 /// that assumptions do not change the set of statement instances
2245 /// executed.
2246 ///
2247 /// @param Kind The assumption kind describing the underlying cause.
2248 /// @param Set The relations between parameters that are assumed to hold.
2249 /// @param Loc The location in the source that caused this assumption.
2250 /// @param Sign Enum to indicate if the assumptions in @p Set are positive
2251 /// (needed/assumptions) or negative (invalid/restrictions).
2252 /// @param BB The block in which this assumption was taken. Used to
2253 /// calculate hotness when emitting remark.
2254 /// @param RTC Does the assumption require a runtime check?
2255 void addAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
2256 AssumptionSign Sign, BasicBlock *BB, bool RTC = true);
2257
2258 /// Mark the scop as invalid.
2259 ///
2260 /// This method adds an assumption to the scop that is always invalid. As a
2261 /// result, the scop will not be optimized later on. This function is commonly
2262 /// called when a condition makes it impossible (or too compile time
2263 /// expensive) to process this scop any further.
2264 ///
2265 /// @param Kind The assumption kind describing the underlying cause.
2266 /// @param Loc The location in the source that triggered .
2267 /// @param BB The BasicBlock where it was triggered.
2268 void invalidate(AssumptionKind Kind, DebugLoc Loc, BasicBlock *BB = nullptr);
2269
2270 /// Get the invalid context for this Scop.
2271 ///
2272 /// @return The invalid context of this Scop.
2274
2275 /// Return true if and only if the InvalidContext is trivial (=empty).
2276 bool hasTrivialInvalidContext() const { return InvalidContext.is_empty(); }
2277
2278 /// Return all alias groups for this SCoP.
2280 return MinMaxAliasGroups;
2281 }
2282
2283 void addAliasGroup(MinMaxVectorTy &MinMaxAccessesReadWrite,
2284 MinMaxVectorTy &MinMaxAccessesReadOnly) {
2285 MinMaxAliasGroups.emplace_back();
2286 MinMaxAliasGroups.back().first = MinMaxAccessesReadWrite;
2287 MinMaxAliasGroups.back().second = MinMaxAccessesReadOnly;
2288 }
2289
2290 /// Remove statements from the list of scop statements.
2291 ///
2292 /// @param ShouldDelete A function that returns true if the statement passed
2293 /// to it should be deleted.
2294 /// @param AfterHoisting If true, also remove from data access lists.
2295 /// These lists are filled during
2296 /// ScopBuilder::buildAccessRelations. Therefore, if this
2297 /// method is called before buildAccessRelations, false
2298 /// must be passed.
2299 void removeStmts(function_ref<bool(ScopStmt &)> ShouldDelete,
2300 bool AfterHoisting = true);
2301
2302 /// Get an isl string representing the context.
2303 std::string getContextStr() const;
2304
2305 /// Get an isl string representing the assumed context.
2306 std::string getAssumedContextStr() const;
2307
2308 /// Get an isl string representing the invalid context.
2309 std::string getInvalidContextStr() const;
2310
2311 /// Return the list of ScopStmts that represent the given @p BB.
2312 ArrayRef<ScopStmt *> getStmtListFor(BasicBlock *BB) const;
2313
2314 /// Get the statement to put a PHI WRITE into.
2315 ///
2316 /// @param U The operand of a PHINode.
2317 ScopStmt *getIncomingStmtFor(const Use &U) const;
2318
2319 /// Return the last statement representing @p BB.
2320 ///
2321 /// Of the sequence of statements that represent a @p BB, this is the last one
2322 /// to be executed. It is typically used to determine which instruction to add
2323 /// a MemoryKind::PHI WRITE to. For this purpose, it is not strictly required
2324 /// to be executed last, only that the incoming value is available in it.
2325 ScopStmt *getLastStmtFor(BasicBlock *BB) const;
2326
2327 /// Return the ScopStmts that represents the Region @p R, or nullptr if
2328 /// it is not represented by any statement in this Scop.
2329 ArrayRef<ScopStmt *> getStmtListFor(Region *R) const;
2330
2331 /// Return the ScopStmts that represents @p RN; can return nullptr if
2332 /// the RegionNode is not within the SCoP or has been removed due to
2333 /// simplifications.
2334 ArrayRef<ScopStmt *> getStmtListFor(RegionNode *RN) const;
2335
2336 /// Return the ScopStmt an instruction belongs to, or nullptr if it
2337 /// does not belong to any statement in this Scop.
2338 ScopStmt *getStmtFor(Instruction *Inst) const {
2339 return InstStmtMap.lookup(Inst);
2340 }
2341
2342 /// Return the number of statements in the SCoP.
2343 size_t getSize() const { return Stmts.size(); }
2344
2345 /// @name Statements Iterators
2346 ///
2347 /// These iterators iterate over all statements of this Scop.
2348 //@{
2349 using iterator = StmtSet::iterator;
2350 using const_iterator = StmtSet::const_iterator;
2351
2352 iterator begin() { return Stmts.begin(); }
2353 iterator end() { return Stmts.end(); }
2354 const_iterator begin() const { return Stmts.begin(); }
2355 const_iterator end() const { return Stmts.end(); }
2356
2357 using reverse_iterator = StmtSet::reverse_iterator;
2358 using const_reverse_iterator = StmtSet::const_reverse_iterator;
2359
2360 reverse_iterator rbegin() { return Stmts.rbegin(); }
2361 reverse_iterator rend() { return Stmts.rend(); }
2362 const_reverse_iterator rbegin() const { return Stmts.rbegin(); }
2363 const_reverse_iterator rend() const { return Stmts.rend(); }
2364 //@}
2365
2366 /// Return the set of required invariant loads.
2368 return DC.RequiredILS;
2369 }
2370
2371 /// Add @p LI to the set of required invariant loads.
2372 void addRequiredInvariantLoad(LoadInst *LI) { DC.RequiredILS.insert(LI); }
2373
2374 /// Return the set of boxed (thus overapproximated) loops.
2375 const BoxedLoopsSetTy &getBoxedLoops() const { return DC.BoxedLoopsSet; }
2376
2377 /// Return true if and only if @p R is a non-affine subregion.
2378 bool isNonAffineSubRegion(const Region *R) {
2379 return DC.NonAffineSubRegionSet.count(R);
2380 }
2381
2382 const MapInsnToMemAcc &getInsnToMemAccMap() const { return DC.InsnToMemAcc; }
2383
2384 /// Return the (possibly new) ScopArrayInfo object for @p Access.
2385 ///
2386 /// @param ElementType The type of the elements stored in this array.
2387 /// @param Kind The kind of the array info object.
2388 /// @param BaseName The optional name of this memory reference.
2389 ScopArrayInfo *getOrCreateScopArrayInfo(Value *BasePtr, Type *ElementType,
2390 ArrayRef<const SCEV *> Sizes,
2392 const char *BaseName = nullptr);
2393
2394 /// Create an array and return the corresponding ScopArrayInfo object.
2395 ///
2396 /// @param ElementType The type of the elements stored in this array.
2397 /// @param BaseName The name of this memory reference.
2398 /// @param Sizes The sizes of dimensions.
2399 ScopArrayInfo *createScopArrayInfo(Type *ElementType,
2400 const std::string &BaseName,
2401 const std::vector<unsigned> &Sizes);
2402
2403 /// Return the cached ScopArrayInfo object for @p BasePtr.
2404 ///
2405 /// @param BasePtr The base pointer the object has been stored for.
2406 /// @param Kind The kind of array info object.
2407 ///
2408 /// @returns The ScopArrayInfo pointer or NULL if no such pointer is
2409 /// available.
2411
2412 /// Return the cached ScopArrayInfo object for @p BasePtr.
2413 ///
2414 /// @param BasePtr The base pointer the object has been stored for.
2415 /// @param Kind The kind of array info object.
2416 ///
2417 /// @returns The ScopArrayInfo pointer (may assert if no such pointer is
2418 /// available).
2420
2421 /// Invalidate ScopArrayInfo object for base address.
2422 ///
2423 /// @param BasePtr The base pointer of the ScopArrayInfo object to invalidate.
2424 /// @param Kind The Kind of the ScopArrayInfo object.
2426 auto It = ScopArrayInfoMap.find(std::make_pair(BasePtr, Kind));
2427 if (It == ScopArrayInfoMap.end())
2428 return;
2429 ScopArrayInfoSet.remove(It->second.get());
2430 ScopArrayInfoMap.erase(It);
2431 }
2432
2433 /// Set new isl context.
2434 void setContext(isl::set NewContext);
2435
2436 /// Update maximal loop depth. If @p Depth is smaller than current value,
2437 /// then maximal loop depth is not updated.
2438 void updateMaxLoopDepth(unsigned Depth) {
2439 MaxLoopDepth = std::max(MaxLoopDepth, Depth);
2440 }
2441
2442 /// Align the parameters in the statement to the scop context
2443 void realignParams();
2444
2445 /// Return true if this SCoP can be profitably optimized.
2446 ///
2447 /// @param ScalarsAreUnprofitable Never consider statements with scalar writes
2448 /// as profitably optimizable.
2449 ///
2450 /// @return Whether this SCoP can be profitably optimized.
2451 bool isProfitable(bool ScalarsAreUnprofitable) const;
2452
2453 /// Return true if the SCoP contained at least one error block.
2454 bool hasErrorBlock() const { return HasErrorBlock; }
2455
2456 /// Notify SCoP that it contains an error block
2458
2459 /// Return true if the underlying region has a single exiting block.
2460 bool hasSingleExitEdge() const { return HasSingleExitEdge; }
2461
2462 /// Print the static control part.
2463 ///
2464 /// @param OS The output stream the static control part is printed to.
2465 /// @param PrintInstructions Whether to print the statement's instructions as
2466 /// well.
2467 void print(raw_ostream &OS, bool PrintInstructions) const;
2468
2469#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2470 /// Print the ScopStmt to stderr.
2471 void dump() const;
2472#endif
2473
2474 /// Get the isl context of this static control part.
2475 ///
2476 /// @return The isl context of this static control part.
2477 isl::ctx getIslCtx() const;
2478
2479 /// Directly return the shared_ptr of the context.
2480 const std::shared_ptr<isl_ctx> &getSharedIslCtx() const { return IslCtx; }
2481
2482 /// Compute the isl representation for the SCEV @p E
2483 ///
2484 /// @param E The SCEV that should be translated.
2485 /// @param BB An (optional) basic block in which the isl_pw_aff is computed.
2486 /// SCEVs known to not reference any loops in the SCoP can be
2487 /// passed without a @p BB.
2488 /// @param NonNegative Flag to indicate the @p E has to be non-negative.
2489 /// @param IsInsideDomain If true, assumptions only need to apply during the
2490 /// execution of @p BB. That is, when we know that we
2491 /// are in its domain. Must be false if the SCEV is
2492 /// evaluated outside a ScopStmt, or for code that
2493 /// computes the domain (since while doing that, we
2494 /// don't know whether we are in the domain yet).
2495 ///
2496 /// Note that this function will always return a valid isl_pw_aff. However, if
2497 /// the translation of @p E was deemed to complex the SCoP is invalidated and
2498 /// a dummy value of appropriate dimension is returned. This allows to bail
2499 /// for complex cases without "error handling code" needed on the users side.
2500 PWACtx getPwAff(const SCEV *E, BasicBlock *BB = nullptr,
2501 bool NonNegative = false,
2502 RecordedAssumptionsTy *RecordedAssumptions = nullptr,
2503 bool IsInsideDomain = true);
2504
2505 /// Compute the isl representation for the SCEV @p E
2506 ///
2507 /// This function is like @see Scop::getPwAff() but strips away the invalid
2508 /// domain part associated with the piecewise affine function.
2510 getPwAffOnly(const SCEV *E, BasicBlock *BB = nullptr,
2511 RecordedAssumptionsTy *RecordedAssumptions = nullptr);
2512
2513 /// Check if an <nsw> AddRec for the loop L is cached.
2514 bool hasNSWAddRecForLoop(Loop *L) { return Affinator.hasNSWAddRecForLoop(L); }
2515
2516 /// Return the domain of @p Stmt.
2517 ///
2518 /// @param Stmt The statement for which the conditions should be returned.
2519 isl::set getDomainConditions(const ScopStmt *Stmt) const;
2520
2521 /// Return the domain of @p BB.
2522 ///
2523 /// @param BB The block for which the conditions should be returned.
2524 isl::set getDomainConditions(BasicBlock *BB) const;
2525
2526 /// Return the domain of @p BB. If it does not exist, create an empty one.
2527 isl::set &getOrInitEmptyDomain(BasicBlock *BB) { return DomainMap[BB]; }
2528
2529 /// Check if domain is determined for @p BB.
2530 bool isDomainDefined(BasicBlock *BB) const { return DomainMap.count(BB) > 0; }
2531
2532 /// Set domain for @p BB.
2533 void setDomain(BasicBlock *BB, isl::set &Domain) { DomainMap[BB] = Domain; }
2534
2535 /// Get a union set containing the iteration domains of all statements.
2536 isl::union_set getDomains() const;
2537
2538 /// Get a union map of all may-writes performed in the SCoP.
2540
2541 /// Get a union map of all must-writes performed in the SCoP.
2543
2544 /// Get a union map of all writes performed in the SCoP.
2546
2547 /// Get a union map of all reads performed in the SCoP.
2549
2550 /// Get a union map of all memory accesses performed in the SCoP.
2552
2553 /// Get a union map of all memory accesses performed in the SCoP.
2554 ///
2555 /// @param Array The array to which the accesses should belong.
2557
2558 /// Get the schedule of all the statements in the SCoP.
2559 ///
2560 /// @return The schedule of all the statements in the SCoP, if the schedule of
2561 /// the Scop does not contain extension nodes, and nullptr, otherwise.
2563
2564 /// Get a schedule tree describing the schedule of all statements.
2566
2567 /// Update the current schedule
2568 ///
2569 /// NewSchedule The new schedule (given as a flat union-map).
2570 void setSchedule(isl::union_map NewSchedule);
2571
2572 /// Update the current schedule
2573 ///
2574 /// NewSchedule The new schedule (given as schedule tree).
2575 void setScheduleTree(isl::schedule NewSchedule);
2576
2577 /// Whether the schedule is the original schedule as derived from the CFG by
2578 /// ScopBuilder.
2579 bool isOriginalSchedule() const { return !ScheduleModified; }
2580
2581 /// Intersects the domains of all statements in the SCoP.
2582 ///
2583 /// @return true if a change was made
2585
2586 /// Get the depth of a loop relative to the outermost loop in the Scop.
2587 ///
2588 /// This will return
2589 /// 0 if @p L is an outermost loop in the SCoP
2590 /// >0 for other loops in the SCoP
2591 /// -1 if @p L is nullptr or there is no outermost loop in the SCoP
2592 int getRelativeLoopDepth(const Loop *L) const;
2593
2594 /// Find the ScopArrayInfo associated with an isl Id
2595 /// that has name @p Name.
2596 ScopArrayInfo *getArrayInfoByName(const std::string BaseName);
2597
2598 /// Simplify the SCoP representation.
2599 ///
2600 /// @param AfterHoisting Whether it is called after invariant load hoisting.
2601 /// When true, also removes statements without
2602 /// side-effects.
2603 void simplifySCoP(bool AfterHoisting);
2604
2605 /// Get the next free array index.
2606 ///
2607 /// This function returns a unique index which can be used to identify an
2608 /// array.
2609 long getNextArrayIdx() { return ArrayIdx++; }
2610
2611 /// Get the next free statement index.
2612 ///
2613 /// This function returns a unique index which can be used to identify a
2614 /// statement.
2615 long getNextStmtIdx() { return StmtIdx++; }
2616
2617 /// Get the representing SCEV for @p S if applicable, otherwise @p S.
2618 ///
2619 /// Invariant loads of the same location are put in an equivalence class and
2620 /// only one of them is chosen as a representing element that will be
2621 /// modeled as a parameter. The others have to be normalized, i.e.,
2622 /// replaced by the representing element of their equivalence class, in order
2623 /// to get the correct parameter value, e.g., in the SCEVAffinator.
2624 ///
2625 /// @param S The SCEV to normalize.
2626 ///
2627 /// @return The representing SCEV for invariant loads or @p S if none.
2628 const SCEV *getRepresentingInvariantLoadSCEV(const SCEV *S) const;
2629
2630 /// Return the MemoryAccess that writes an llvm::Value, represented by a
2631 /// ScopArrayInfo.
2632 ///
2633 /// There can be at most one such MemoryAccess per llvm::Value in the SCoP.
2634 /// Zero is possible for read-only values.
2635 MemoryAccess *getValueDef(const ScopArrayInfo *SAI) const;
2636
2637 /// Return all MemoryAccesses that us an llvm::Value, represented by a
2638 /// ScopArrayInfo.
2639 ArrayRef<MemoryAccess *> getValueUses(const ScopArrayInfo *SAI) const;
2640
2641 /// Return the MemoryAccess that represents an llvm::PHINode.
2642 ///
2643 /// ExitPHIs's PHINode is not within the SCoPs. This function returns nullptr
2644 /// for them.
2645 MemoryAccess *getPHIRead(const ScopArrayInfo *SAI) const;
2646
2647 /// Return all MemoryAccesses for all incoming statements of a PHINode,
2648 /// represented by a ScopArrayInfo.
2649 ArrayRef<MemoryAccess *> getPHIIncomings(const ScopArrayInfo *SAI) const;
2650
2651 /// Return whether @p Inst has a use outside of this SCoP.
2652 bool isEscaping(Instruction *Inst);
2653
2665
2666 /// Collect statistic about this SCoP.
2667 ///
2668 /// These are most commonly used for LLVM's static counters (Statistic.h) in
2669 /// various places. If statistics are disabled, only zeros are returned to
2670 /// avoid the overhead.
2672
2673 /// Is this Scop marked as not to be transformed by an optimization heuristic?
2674 /// In this case, only user-directed transformations are allowed.
2676
2677 /// Mark this Scop to not apply an optimization heuristic.
2679};
2680
2681/// Print Scop scop to raw_ostream OS.
2682raw_ostream &operator<<(raw_ostream &OS, const Scop &scop);
2683
2685private:
2686 /// A map of Region to its Scop object containing
2687 /// Polly IR of static control part.
2688 llvm::SmallDenseMap<const Region *, std::unique_ptr<Scop>> RegionToScopMap;
2689 const DataLayout &DL;
2691 ScalarEvolution &SE;
2692 LoopInfo &LI;
2693 AAResults &AA;
2694 DominatorTree &DT;
2695 AssumptionCache &AC;
2696 OptimizationRemarkEmitter &ORE;
2697
2698public:
2699 ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE,
2700 LoopInfo &LI, AAResults &AA, DominatorTree &DT, AssumptionCache &AC,
2701 OptimizationRemarkEmitter &ORE);
2702
2703 /// Get the Scop object for the given Region.
2704 ///
2705 /// @return If the given region is the maximal region within a scop, return
2706 /// the scop object. If the given region is a subregion, return a
2707 /// nullptr. Top level region containing the entry block of a function
2708 /// is not considered in the scop creation.
2709 Scop *getScop(const Region *R);
2710
2711 /// Recompute the Scop-Information for a function.
2712 ///
2713 /// This invalidates any iterators.
2714 void invalidate();
2715};
2716} // end namespace polly
2717
2718#endif // POLLY_SCOPINFO_H
isl::checked::set params() const
Represent memory accesses in statements.
Definition ScopInfo.h:428
const ScopArrayInfo * getLatestScopArrayInfo() const
Get the ScopArrayInfo object for the base address, or the one set by setNewAccessRelation().
Definition ScopInfo.cpp:610
std::string getAccessRelationStr() const
Get an isl string representing the latest access relation.
Definition ScopInfo.cpp:663
void addIncoming(BasicBlock *IncomingBlock, Value *IncomingValue)
Add a new incoming block/value pairs for this PHI/ExitPHI access.
Definition ScopInfo.h:733
isl::map getNewAccessRelation() const
Get the new access function imported or set by a pass.
Definition ScopInfo.cpp:655
void dump() const
Print the MemoryAccess to stderr.
isl::set assumeNoOutOfBound()
Definition ScopInfo.cpp:697
isl::id getArrayId() const
Old name of getOriginalArrayId().
Definition ScopInfo.h:840
SmallVector< const SCEV *, 4 > Sizes
Size of each dimension of the accessed array.
Definition ScopInfo.h:545
bool isOriginalArrayKind() const
Whether this is an access of an explicit load or store in the IR.
Definition ScopInfo.h:941
void foldAccessRelation()
Fold the memory access to consider parametric offsets.
Definition ScopInfo.cpp:800
AssertingVH< Value > AccessValue
The value associated with this memory access.
Definition ScopInfo.h:581
bool isOriginalValueKind() const
Was this MemoryAccess detected as a scalar dependences?
Definition ScopInfo.h:973
MemoryAccess & operator=(const MemoryAccess &)=delete
bool isLatestPHIKind() const
Is this MemoryAccess modeling special PHI node accesses, also considering a potential change by setNe...
Definition ScopInfo.h:992
isl::space getOriginalAccessRelationSpace() const
Return the space in which the access relation lives in.
Definition ScopInfo.cpp:651
bool isAnyPHIKind() const
Old name of isOriginalAnyPHIKind().
Definition ScopInfo.h:1025
friend class Scop
Definition ScopInfo.h:429
AccessType
The access type of a memory access.
Definition ScopInfo.h:454
void markAsReductionLike(ReductionType RT)
Mark this a reduction like access.
Definition ScopInfo.h:1050
ReductionType
Reduction access type.
Definition ScopInfo.h:463
@ RT_BOTTOM
Pseudo type for the data flow analysis.
Definition ScopInfo.h:471
@ RT_BOR
Bitwise Or.
Definition ScopInfo.h:467
@ RT_BAND
Bitwise And.
Definition ScopInfo.h:469
@ RT_ADD
Addition.
Definition ScopInfo.h:465
@ RT_BXOR
Bitwise XOr.
Definition ScopInfo.h:468
@ RT_NONE
Indicate no reduction at all.
Definition ScopInfo.h:464
@ RT_MUL
Multiplication.
Definition ScopInfo.h:466
isl::basic_map createBasicAccessMap(ScopStmt *Statement)
Definition ScopInfo.cpp:667
SubscriptsTy Subscripts
Subscript expression for each dimension.
Definition ScopInfo.h:587
isl::map getLatestAccessRelation() const
Return the newest access relation of this access.
Definition ScopInfo.h:786
isl::id getOriginalArrayId() const
Get the detection-time base array isl::id for this access.
Definition ScopInfo.cpp:617
MemoryAccess(const MemoryAccess &)=delete
isl::pw_aff getPwAff(const SCEV *E)
Compute the isl representation for the SCEV E wrt.
Instruction * AccessInstruction
The access instruction of this memory access.
Definition ScopInfo.h:566
void computeBoundsOnAccessRelation(unsigned ElementSize)
Compute bounds on an over approximated access relation.
Definition ScopInfo.cpp:755
ReductionType RedType
Reduction type for reduction like accesses, RT_NONE otherwise.
Definition ScopInfo.h:515
bool isValueKind() const
Old name of isOriginalValueKind().
Definition ScopInfo.h:983
bool hasNewAccessRelation() const
Check if a new access relation was imported or set by a pass.
Definition ScopInfo.h:774
isl::id Id
A unique identifier for this memory access.
Definition ScopInfo.h:481
bool isOriginalExitPHIKind() const
Was this MemoryAccess detected as the accesses of a PHI node in the SCoP's exit block?
Definition ScopInfo.h:999
bool isLatestArrayKind() const
Whether storage memory is either an custom .s2a/.phiops alloca (false) or an existing pointer into an...
Definition ScopInfo.h:947
bool isPHIKind() const
Old name of isOriginalPHIKind.
Definition ScopInfo.h:995
bool isWrite() const
Is this a write memory access?
Definition ScopInfo.h:766
bool IsAffine
Are all the subscripts affine expression?
Definition ScopInfo.h:584
ReductionType getReductionType() const
Get the reduction type of this access.
Definition ScopInfo.h:1031
MemoryKind getLatestKind() const
Return the kind considering a potential setNewAccessRelation.
Definition ScopInfo.h:936
const ScopArrayInfo * getOriginalScopArrayInfo() const
Get the detection-time ScopArrayInfo object for the base address.
Definition ScopInfo.cpp:603
AssertingVH< Value > BaseAddr
The base address (e.g., A for A[i+j]).
Definition ScopInfo.h:539
bool isOriginalAnyPHIKind() const
Was this access detected as one of the two PHI types?
Definition ScopInfo.h:1014
void updateDimensionality()
Update the dimensionality of the memory access.
Definition ScopInfo.cpp:482
Instruction * getAccessInstruction() const
Return the access instruction of this memory access.
Definition ScopInfo.h:882
iterator_range< SubscriptsTy::const_iterator > subscripts() const
Return an iterator range containing the subscripts.
Definition ScopInfo.h:885
bool isStrideZero(isl::map Schedule) const
Is always the same memory accessed for a given statement instance set?
bool isLatestPartialAccess() const
Return whether the MemoryyAccess is a partial access.
std::string getOriginalAccessRelationStr() const
Get an isl string representing the access function read from IR.
Definition ScopInfo.cpp:647
bool isExitPHIKind() const
Old name of isOriginalExitPHIKind().
Definition ScopInfo.h:1011
Value * tryGetValueStored()
Return llvm::Value that is stored by this access, if available.
Definition ScopInfo.h:871
friend class ScopStmt
Definition ScopInfo.h:430
isl::set InvalidDomain
The domain under which this access is not modeled precisely.
Definition ScopInfo.h:525
enum AccessType getType()
Get the type of a memory access.
Definition ScopInfo.h:751
bool isLatestScalarKind() const
Whether this access is an array to a scalar memory object, also considering changes by setNewAccessRe...
Definition ScopInfo.h:965
bool isRead() const
Is this a read memory access?
Definition ScopInfo.h:757
void buildAccessRelation(const ScopArrayInfo *SAI)
Assemble the access relation from all available information.
Definition ScopInfo.cpp:867
isl::id getId() const
Get identifier for the memory access.
Definition ScopInfo.cpp:967
isl::map NewAccessRelation
Updated access relation read from JSCOP file.
Definition ScopInfo.h:618
SmallVector< const SCEV *, 4 > SubscriptsTy
Definition ScopInfo.h:474
unsigned getNumSubscripts() const
Return the number of access function subscript.
Definition ScopInfo.h:890
isl::map getAddressFunction() const
Get an isl map describing the memory address accessed.
Definition ScopInfo.cpp:627
void setAccessRelation(isl::map AccessRelation)
Update the original access relation.
bool isMustWrite() const
Is this a must-write memory access?
Definition ScopInfo.h:760
bool isScalarKind() const
Old name of isOriginalScalarKind.
Definition ScopInfo.h:970
isl::map AccessRelation
Relation from statement instances to the accessed array elements.
Definition ScopInfo.h:615
friend class ScopBuilder
Definition ScopInfo.h:431
void realignParams()
Align the parameters in the access relation to the scop context.
Definition ScopInfo.cpp:951
Type * getElementType() const
Return the element type of the accessed array wrt. this access.
Definition ScopInfo.h:861
const SCEV * getSubscript(unsigned Dim) const
Return the access function subscript in the dimension Dim.
Definition ScopInfo.h:893
bool isReductionLike() const
Is this a reduction like access?
Definition ScopInfo.h:754
bool isOriginalPHIKind() const
Was this MemoryAccess detected as a special PHI node access?
Definition ScopInfo.h:986
isl::set getInvalidContext() const
Get the invalid context for this access.
Definition ScopInfo.h:904
void print(raw_ostream &OS) const
Print the MemoryAccess.
Definition ScopInfo.cpp:983
const ScopArrayInfo * getScopArrayInfo() const
Legacy name of getOriginalScopArrayInfo().
Definition ScopInfo.h:850
void wrapConstantDimensions()
Carry index overflows of dimensions with constant size to the next higher dimension.
Definition ScopInfo.cpp:430
bool isOriginalScalarKind() const
Whether this access is an array to a scalar memory object, without considering changes by setNewAcces...
Definition ScopInfo.h:959
ScopStmt * Statement
Parent ScopStmt of this access.
Definition ScopInfo.h:518
bool isStrideX(isl::map Schedule, int StrideWidth) const
Is the stride of the access equal to a certain width?
bool isStrideOne(isl::map Schedule) const
Is consecutive memory accessed for a given statement instance set?
Type * ElementType
Type a single array element wrt. this access.
Definition ScopInfo.h:542
enum AccessType AccType
Whether it a reading or writing access, and if writing, whether it is conditional (MAY_WRITE).
Definition ScopInfo.h:489
std::string getNewAccessRelationStr() const
Get an isl string representing a new access function, if available.
Definition ScopInfo.cpp:659
void buildMemIntrinsicAccessRelation()
Create the access relation for the underlying memory intrinsic.
Definition ScopInfo.cpp:731
isl::set getInvalidDomain() const
Get the invalid domain for this access.
Definition ScopInfo.h:901
ArrayRef< std::pair< BasicBlock *, Value * > > getIncoming() const
Return the list of possible PHI/ExitPHI values.
Definition ScopInfo.h:745
Value * getOriginalBaseAddr() const
Get the original base address of this access (e.g.
Definition ScopInfo.h:830
ScopStmt * getStatement() const
Get the statement that contains this memory access.
Definition ScopInfo.h:1028
bool isLatestExitPHIKind() const
Is this MemoryAccess modeling the accesses of a PHI node in the SCoP's exit block?
Definition ScopInfo.h:1006
bool isAffine() const
Is the memory access affine?
Definition ScopInfo.h:1082
isl::set getStride(isl::map Schedule) const
Get the stride of this memory access in the specified Schedule.
bool isMayWrite() const
Is this a may-write memory access?
Definition ScopInfo.h:763
isl::id getLatestArrayId() const
Get the base array isl::id for this access, modifiable through setNewAccessRelation().
Definition ScopInfo.cpp:621
MemoryKind Kind
What is modeled by this MemoryAccess.
Definition ScopInfo.h:485
bool isLatestAnyPHIKind() const
Does this access originate from one of the two PHI types?
Definition ScopInfo.h:1020
bool isLatestValueKind() const
Is this MemoryAccess currently modeling scalar dependences?
Definition ScopInfo.h:978
isl::pw_multi_aff applyScheduleToAccessRelation(isl::union_map Schedule) const
Return the access relation after the schedule was applied.
Definition ScopInfo.cpp:632
MemoryAccess(ScopStmt *Stmt, Instruction *AccessInst, AccessType AccType, Value *BaseAddress, Type *ElemType, bool Affine, ArrayRef< const SCEV * > Subscripts, ArrayRef< const SCEV * > Sizes, Value *AccessValue, MemoryKind Kind)
Create a new MemoryAccess.
Definition ScopInfo.cpp:913
std::string getReductionOperatorStr() const
Return a string representation of the access's reduction type.
Definition ScopInfo.cpp:963
SmallVector< std::pair< BasicBlock *, Value * >, 4 > Incoming
Incoming block and value of a PHINode.
Definition ScopInfo.h:569
isl::map getAccessRelation() const
Old name of getLatestAccessRelation().
Definition ScopInfo.h:792
Value * getAccessValue() const
Return the access value of this memory access.
Definition ScopInfo.h:864
isl::map getOriginalAccessRelation() const
Get the original access function as read from IR.
Definition ScopInfo.cpp:643
void setNewAccessRelation(isl::map NewAccessRelation)
Set the updated access relation read from JSCOP file.
bool isArrayKind() const
Old name of isOriginalArrayKind.
Definition ScopInfo.h:952
bool isMemoryIntrinsic() const
Is this a memory intrinsic access (memcpy, memset, memmove)?
Definition ScopInfo.h:769
MemoryKind getOriginalKind() const
Return the kind when this access was first detected.
Definition ScopInfo.h:929
Translate a SCEV to an isl::pw_aff and the domain on which it is invalid.
A class to store information about arrays in the SCoP.
Definition ScopInfo.h:216
const SCEV * getDimensionSize(unsigned Dim) const
Return the size of dimension dim as SCEV*.
Definition ScopInfo.h:289
Type * ElementType
The canonical element type of this array.
Definition ScopInfo.h:401
isl::space getSpace() const
Get the space of this array access.
Definition ScopInfo.cpp:255
const SmallSetVector< ScopArrayInfo *, 2 > & getDerivedSAIs() const
The set of derived indirect SAIs for this origin SAI.
Definition ScopInfo.h:272
SmallSetVector< ScopArrayInfo *, 2 > DerivedSAIs
For origin SAIs the set of derived indirect SAIs.
Definition ScopInfo.h:389
isl::id Id
The isl id for the base pointer.
Definition ScopInfo.h:404
SmallVector< isl::pw_aff, 4 > DimensionSizesPw
The sizes of each dimension as isl::pw_aff.
Definition ScopInfo.h:413
bool isExitPHIKind() const
Is this array info modeling an MemoryKind::ExitPHI?
Definition ScopInfo.h:337
bool isReadOnly()
If the array is read only.
Definition ScopInfo.cpp:261
bool updateSizes(ArrayRef< const SCEV * > Sizes, bool CheckConsistency=true)
Update the sizes of the ScopArrayInfo object.
Definition ScopInfo.cpp:343
~ScopArrayInfo()
Destructor to free the isl id of the base pointer.
bool isArrayKind() const
Is this array info modeling an array?
Definition ScopInfo.h:340
MemoryKind getKind() const
Return what kind of memory this represents.
Definition ScopInfo.h:319
bool isValueKind() const
Is this array info modeling an llvm::Value?
Definition ScopInfo.h:322
bool IsOnHeap
True if the newly allocated array is on heap.
Definition ScopInfo.h:407
ScopArrayInfo(Value *BasePtr, Type *ElementType, isl::ctx IslCtx, ArrayRef< const SCEV * > DimensionSizes, MemoryKind Kind, const DataLayout &DL, Scop *S, const char *BaseName=nullptr)
Construct a ScopArrayInfo object.
Definition ScopInfo.cpp:229
static const ScopArrayInfo * getFromId(isl::id Id)
Access the ScopArrayInfo associated with an isl Id.
Definition ScopInfo.cpp:424
void setIsOnHeap(bool value)
Definition ScopInfo.h:266
std::string getName() const
Get the name of this memory reference.
Definition ScopInfo.cpp:376
bool isPHIKind() const
Is this array info modeling special PHI node memory?
Definition ScopInfo.h:334
Value * getBasePtr() const
Return the base pointer.
Definition ScopInfo.h:263
int getElemSizeInBytes() const
Get element size in bytes.
Definition ScopInfo.cpp:378
isl::pw_aff getDimensionSizePw(unsigned Dim) const
Return the size of dimension dim as isl::pw_aff.
Definition ScopInfo.h:299
AssertingVH< Value > BasePtr
The base pointer.
Definition ScopInfo.h:392
bool isCompatibleWith(const ScopArrayInfo *Array) const
Verify that Array is compatible to this ScopArrayInfo.
Definition ScopInfo.cpp:269
void addDerivedSAI(ScopArrayInfo *DerivedSAI)
Definition ScopInfo.h:381
bool isOnHeap() const
Is this array allocated on heap.
Definition ScopInfo.h:346
void updateElementType(Type *NewElementType)
Update the element type of the ScopArrayInfo object.
Definition ScopInfo.cpp:299
const ScopArrayInfo * BasePtrOriginSAI
For indirect accesses this is the SAI of the BP origin.
Definition ScopInfo.h:386
const DataLayout & DL
The data layout of the module.
Definition ScopInfo.h:421
void setBasePtr(Value *BP)
Set the base pointer to BP.
Definition ScopInfo.h:260
isl::id getBasePtrId() const
Return the isl id for the base pointer.
Definition ScopInfo.cpp:382
Scop & S
The scop this SAI object belongs to.
Definition ScopInfo.h:424
static const ScopArrayInfo * getFromAccessFunction(isl::pw_multi_aff PMA)
Access the ScopArrayInfo associated with an access function.
Definition ScopInfo.cpp:418
unsigned getNumberOfDimensions() const
Return the number of dimensions.
Definition ScopInfo.h:277
void print(raw_ostream &OS, bool SizeAsPwAff=false) const
Print a readable representation to OS.
Definition ScopInfo.cpp:388
Type * getElementType() const
Get the canonical element type of this array.
Definition ScopInfo.h:307
SmallVector< const SCEV *, 4 > DimensionSizes
The sizes of each dimension as SCEV*.
Definition ScopInfo.h:410
MemoryKind Kind
The type of this scop array info object.
Definition ScopInfo.h:418
void dump() const
Dump a readable representation to stderr.
Definition ScopInfo.cpp:385
const ScopArrayInfo * getBasePtrOriginSAI() const
For indirect accesses return the origin SAI of the BP, else null.
Definition ScopInfo.h:269
Pass to detect the maximal static control parts (Scops) of a function.
AAResults & AA
Definition ScopInfo.h:2693
void invalidate()
Recompute the Scop-Information for a function.
AssumptionCache & AC
Definition ScopInfo.h:2695
DominatorTree & DT
Definition ScopInfo.h:2694
LoopInfo & LI
Definition ScopInfo.h:2692
ScopDetection & SD
Definition ScopInfo.h:2690
const DataLayout & DL
Definition ScopInfo.h:2689
Scop * getScop(const Region *R)
Get the Scop object for the given Region.
ScalarEvolution & SE
Definition ScopInfo.h:2691
OptimizationRemarkEmitter & ORE
Definition ScopInfo.h:2696
ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE, LoopInfo &LI, AAResults &AA, DominatorTree &DT, AssumptionCache &AC, OptimizationRemarkEmitter &ORE)
llvm::SmallDenseMap< const Region *, std::unique_ptr< Scop > > RegionToScopMap
A map of Region to its Scop object containing Polly IR of static control part.
Definition ScopInfo.h:2688
Statement of the Scop.
Definition ScopInfo.h:1137
iterator end()
Definition ScopInfo.h:1518
llvm::SmallVector< MemoryAccess *, 8 > MemoryAccessVec
Definition ScopInfo.h:1141
MemoryAccess & getArrayAccessFor(const Instruction *Inst) const
Return the only array access for Inst.
Definition ScopInfo.h:1431
Scop * getParent()
Definition ScopInfo.h:1525
BasicBlock * getEntryBlock() const
Return a BasicBlock from this statement.
void dump() const
Print the ScopStmt to stderr.
bool isEmpty() const
Return true if this statement does not contain any accesses.
Definition ScopInfo.h:1385
std::vector< Instruction * > Instructions
Vector for Instructions in this statement.
Definition ScopInfo.h:1263
void print(raw_ostream &OS, bool PrintInstructions) const
Print the ScopStmt.
Region * R
The region represented by this statement (in the non-affine case).
Definition ScopInfo.h:1248
DenseMap< PHINode *, MemoryAccess * > PHIWrites
Map from PHI nodes to its incoming value when coming from this statement.
Definition ScopInfo.h:1229
const Scop * getParent() const
Definition ScopInfo.h:1526
std::vector< Instruction * >::const_iterator insts_end() const
Definition ScopInfo.h:1542
isl::set Domain
The iteration domain describes the set of iterations for which this statement is executed.
Definition ScopInfo.h:1204
const std::vector< Instruction * > & getInstructions() const
Definition ScopInfo.h:1528
bool isBlockStmt() const
Return true if this statement represents a single basic block.
Definition ScopInfo.h:1318
void removeSingleMemoryAccess(MemoryAccess *MA, bool AfterHoisting=true)
Remove MA from this statement.
MemoryAccess * ensureValueRead(Value *V)
Check whether there is a value read access for V in this statement, and if not, create one.
void setInstructions(ArrayRef< Instruction * > Range)
Set the list of instructions for this statement.
Definition ScopInfo.h:1534
Loop * SurroundingLoop
The closest loop that contains this statement.
Definition ScopInfo.h:1260
ScopStmt(Scop &parent, BasicBlock &bb, StringRef Name, Loop *SurroundingLoop, std::vector< Instruction * > Instructions)
Create the ScopStmt from a BasicBlock.
MemoryAccess * lookupInputAccessOf(Value *Val) const
Return the input access of the value, or null if no such MemoryAccess exists.
Definition ScopInfo.h:1474
MemoryAccessVec::const_iterator const_iterator
Definition ScopInfo.h:1515
std::string getScheduleStr() const
Get an isl string representing this schedule.
const_iterator end() const
Definition ScopInfo.h:1520
void prependInstruction(Instruction *Inst)
Insert an instruction before all other instructions in this statement.
Definition ScopInfo.h:1552
const ScopStmt & operator=(const ScopStmt &)=delete
std::string getDomainStr() const
Get an isl string representing this domain.
const MemoryAccessList * lookupArrayAccessesFor(const Instruction *Inst) const
Find all array accesses for Inst.
Definition ScopInfo.h:1394
std::vector< Instruction * >::const_iterator insts_begin() const
Definition ScopInfo.h:1538
size_t size() const
Definition ScopInfo.h:1521
isl::set getInvalidContext() const
Get the invalid context for this statement.
Definition ScopInfo.h:1306
void realignParams()
Align the parameters in the statement to the scop context.
void removeAccessData(MemoryAccess *MA)
Remove MA from dictionaries pointing to them.
ScopStmt(const ScopStmt &)=delete
isl::map getSchedule() const
Get the schedule function of this ScopStmt.
isl::set getInvalidDomain() const
Get the invalid domain for this statement.
Definition ScopInfo.h:1303
SmallVector< Loop *, 4 > NestLoops
Definition ScopInfo.h:1255
MemoryAccessVec::iterator iterator
Definition ScopInfo.h:1514
DenseMap< const Instruction *, MemoryAccessList > InstructionToAccess
Mapping from instructions to (scalar) memory accesses.
Definition ScopInfo.h:1212
Scop & Parent
Polyhedral description.
Definition ScopInfo.h:1176
void restrictDomain(isl::set NewDomain)
Restrict the domain of the statement.
std::string BaseName
Definition ScopInfo.h:1257
isl::ctx getIslCtx() const
Get an isl_ctx pointer.
Region * getRegion() const
Get the region represented by this ScopStmt (if any).
Definition ScopInfo.h:1327
bool represents(BasicBlock *BB) const
Return whether this statement represents BB.
Definition ScopInfo.h:1348
friend class ScopBuilder
Definition ScopInfo.h:1138
DenseMap< Instruction *, MemoryAccess * > ValueWrites
The set of values defined in this ScopStmt that are required elsewhere, mapped to their MemoryKind::V...
Definition ScopInfo.h:1220
iterator_range< std::vector< Instruction * >::const_iterator > insts() const
The range of instructions in this statement.
Definition ScopInfo.h:1547
MemoryAccess * lookupPHIReadOf(PHINode *PHI) const
Return the MemoryAccess that loads a PHINode value, or nullptr if not existing, respectively not yet ...
Definition ScopInfo.h:1455
BasicBlock * getBasicBlock() const
Get the BasicBlock represented by this ScopStmt (if any).
Definition ScopInfo.h:1315
void removeMemoryAccess(MemoryAccess *MA)
Remove a MemoryAccess from this statement.
MemoryAccessVec MemAccs
The memory accesses of this statement.
Definition ScopInfo.h:1209
const char * getBaseName() const
bool contains(const Loop *L) const
Return whether L is boxed within this statement.
Definition ScopInfo.h:1339
isl::ast_build Build
}
Definition ScopInfo.h:1253
bool isCopyStmt() const
Return true if this is a copy statement.
Definition ScopInfo.h:1321
DenseMap< Value *, MemoryAccess * > ValueReads
The set of values defined elsewhere required in this ScopStmt and their MemoryKind::Value READ Memory...
Definition ScopInfo.h:1216
isl::ast_build getAstBuild() const
Get the isl AST build.
Definition ScopInfo.h:1562
isl::set InvalidDomain
The domain under which this statement is not modeled precisely.
Definition ScopInfo.h:1183
DenseMap< PHINode *, MemoryAccess * > PHIReads
Map from PHI nodes to its read access in this statement.
Definition ScopInfo.h:1232
MemoryAccess * getArrayAccessOrNULLFor(const Instruction *Inst) const
Return the only array access for Inst, if existing.
Definition ScopInfo.h:1408
isl::id getDomainId() const
Get the id of the iteration domain space.
void addAccess(MemoryAccess *Access, bool Prepend=false)
Add Access to this statement's list of accesses.
bool isRegionStmt() const
Return true if this statement represents a whole region.
Definition ScopInfo.h:1330
void setInvalidDomain(isl::set ID)
Set the invalid context for this statement to ID.
unsigned getNumIterators() const
Loop * getLoopForDimension(unsigned Dimension) const
Get the loop for a dimension.
isl::set getDomain() const
Get the iteration domain of this ScopStmt.
const_iterator begin() const
Definition ScopInfo.h:1519
void setAstBuild(isl::ast_build B)
Set the isl AST build.
Definition ScopInfo.h:1559
MemoryAccess * lookupValueWriteOf(Instruction *Inst) const
Return the MemoryAccess that writes the value of an instruction defined in this statement,...
Definition ScopInfo.h:1441
Loop * getSurroundingLoop() const
Return the closest innermost loop that contains this statement, but is not contained in it.
Definition ScopInfo.h:1378
BasicBlock * BB
A SCoP statement represents either a basic block (affine/precise case) or a whole region (non-affine ...
Definition ScopInfo.h:1245
isl::space getDomainSpace() const
Get the space of the iteration domain.
MemoryAccess * lookupPHIWriteOf(PHINode *PHI) const
Return the PHI write MemoryAccess for the incoming values from any basic block in this ScopStmt,...
Definition ScopInfo.h:1462
void printInstructions(raw_ostream &OS) const
Print the instructions in ScopStmt.
MemoryAccess * lookupValueReadOf(Value *Inst) const
Return the MemoryAccess that reloads a value, or nullptr if not existing, respectively not yet added.
Definition ScopInfo.h:1449
bool contains(Instruction *Inst) const
Return whether this statement contains Inst.
Definition ScopInfo.h:1357
iterator begin()
Definition ScopInfo.h:1517
Static Control Part.
Definition ScopInfo.h:1627
InvariantEquivClassTy * lookupInvariantEquivClass(Value *Val)
Return the invariant equivalence class for Val if any.
isl::schedule getScheduleTree() const
Get a schedule tree describing the schedule of all statements.
isl::set InvalidContext
The restrictions under which this SCoP was built.
Definition ScopInfo.h:1757
bool IsOptimized
Flag to indicate that the scheduler actually optimized the SCoP.
Definition ScopInfo.h:1672
bool HasErrorBlock
Flag to remember if the SCoP contained an error block or not.
Definition ScopInfo.h:1678
void intersectDefinedBehavior(isl::set Set, AssumptionSign Sign)
Add the conditions from Set (or subtract them if Sign is AS_RESTRICTION) to the defined behaviour con...
isl::space getFullParamSpace() const
Return the full space of parameters.
ArrayRef< MemoryAccess * > getValueUses(const ScopArrayInfo *SAI) const
Return all MemoryAccesses that us an llvm::Value, represented by a ScopArrayInfo.
bool isParam(const SCEV *Param) const
Return whether given SCEV is used as the parameter in this Scop.
Definition ScopInfo.h:2021
DenseMap< const ScopArrayInfo *, SmallVector< MemoryAccess *, 4 > > ValueUseAccs
List of all uses (i.e.
Definition ScopInfo.h:1861
isl::union_map getMayWrites()
Get a union map of all may-writes performed in the SCoP.
void printContext(raw_ostream &OS) const
const MinMaxVectorPairVectorTy & getAliasGroups() const
Return all alias groups for this SCoP.
Definition ScopInfo.h:2279
isl::set getInvalidContext() const
Get the invalid context for this Scop.
void invalidateScopArrayInfo(Value *BasePtr, MemoryKind Kind)
Invalidate ScopArrayInfo object for base address.
Definition ScopInfo.h:2425
void dump() const
Print the ScopStmt to stderr.
isl::union_map getSchedule() const
Get the schedule of all the statements in the SCoP.
void invalidate(AssumptionKind Kind, DebugLoc Loc, BasicBlock *BB=nullptr)
Mark the scop as invalid.
MemoryAccess * getValueDef(const ScopArrayInfo *SAI) const
Return the MemoryAccess that writes an llvm::Value, represented by a ScopArrayInfo.
ScalarEvolution * getSE() const
Return the scalar evolution.
ScalarEvolution * SE
Definition ScopInfo.h:1657
DominatorTree * getDT() const
Return the dominator tree.
Definition ScopInfo.h:2010
unsigned getMaxLoopDepth() const
Get the maximum depth of the loop.
Definition ScopInfo.h:2127
void printAliasAssumptions(raw_ostream &OS) const
ArrayRef< MemoryAccess * > getPHIIncomings(const ScopArrayInfo *SAI) const
Return all MemoryAccesses for all incoming statements of a PHINode, represented by a ScopArrayInfo.
bool hasInvariantAccesses()
Check if the scop has any invariant access.
Definition ScopInfo.h:2138
ScopStmt * getStmtFor(Instruction *Inst) const
Return the ScopStmt an instruction belongs to, or nullptr if it does not belong to any statement in t...
Definition ScopInfo.h:2338
void setDomain(BasicBlock *BB, isl::set &Domain)
Set domain for BB.
Definition ScopInfo.h:2533
ScopArrayInfo * getScopArrayInfo(Value *BasePtr, MemoryKind Kind)
Return the cached ScopArrayInfo object for BasePtr.
ParameterSetTy Parameters
Parameters of this Scop.
Definition ScopInfo.h:1692
bool hasDisableHeuristicsHint() const
Is this Scop marked as not to be transformed by an optimization heuristic?
Definition ScopInfo.h:2675
bool hasTrivialInvalidContext() const
Return true if and only if the InvalidContext is trivial (=empty).
Definition ScopInfo.h:2276
ArrayInfoSetTy ScopArrayInfoSet
A set to remember ScopArrayInfo objects.
Definition ScopInfo.h:1740
ValueToValueMap InvEquivClassVMap
Mapping from invariant loads to the representing invariant load of their equivalence class.
Definition ScopInfo.h:1837
iterator_range< AccFuncVector::iterator > access_functions()
Return an iterator range containing all the MemoryAccess objects of the Scop.
Definition ScopInfo.h:2039
isl::union_map getReads()
Get a union map of all reads performed in the SCoP.
unsigned getCopyStmtsNum()
Get the count of copy statements added to this Scop.
Definition ScopInfo.h:1957
bool isDomainDefined(BasicBlock *BB) const
Check if domain is determined for BB.
Definition ScopInfo.h:2530
unsigned CopyStmtsNum
Number of copy statements.
Definition ScopInfo.h:1684
bool HasDisableHeuristicsHint
Is this Scop marked as not to be transformed by an optimization heuristic?
Definition ScopInfo.h:1814
DenseMap< BasicBlock *, std::vector< ScopStmt * > > StmtMap
A map from basic blocks to vector of SCoP statements.
Definition ScopInfo.h:1705
const MapInsnToMemAcc & getInsnToMemAccMap() const
Definition ScopInfo.h:2382
void addParams(const ParameterSetTy &NewParameters)
Take a list of parameters and add the new ones to the scop.
iterator end()
Definition ScopInfo.h:2353
isl::set getAssumedContext() const
Get the assumed context for this Scop.
Scop & operator=(const Scop &)=delete
void addScopStmt(BasicBlock *BB, StringRef Name, Loop *SurroundingLoop, std::vector< Instruction * > Instructions)
Create a new SCoP statement for BB.
SCEVAffinator Affinator
The affinator used to translate SCEVs to isl expressions.
Definition ScopInfo.h:1717
ScopArrayInfo * getOrCreateScopArrayInfo(Value *BasePtr, Type *ElementType, ArrayRef< const SCEV * > Sizes, MemoryKind Kind, const char *BaseName=nullptr)
Return the (possibly new) ScopArrayInfo object for Access.
DominatorTree * DT
Definition ScopInfo.h:1658
const InvariantLoadsSetTy & getRequiredInvariantLoads() const
Return the set of required invariant loads.
Definition ScopInfo.h:2367
void addAccessFunction(MemoryAccess *Access)
Add the access function to all MemoryAccess objects of the Scop created in this pass.
Definition ScopInfo.h:1972
isl::schedule Schedule
The schedule of the SCoP.
Definition ScopInfo.h:1811
iterator begin()
Definition ScopInfo.h:2352
isl::set getBestKnownDefinedBehaviorContext() const
Return the define behavior context, or if not available, its approximation from all other contexts.
Definition ScopInfo.h:2171
bool contains(const Instruction *I) const
Check if I is contained in the SCoP.
Definition ScopInfo.h:2101
SmallVector< MinMaxVectorPairTy, 4 > MinMaxVectorPairVectorTy
Vector of pair of minimal/maximal access vectors representing non read only and read only accesses fo...
Definition ScopInfo.h:1641
isl::set Context
Constraints on parameters.
Definition ScopInfo.h:1714
unsigned MaxLoopDepth
Max loop depth.
Definition ScopInfo.h:1681
isl::union_set getDomains() const
Get a union set containing the iteration domains of all statements.
const BoxedLoopsSetTy & getBoxedLoops() const
Return the set of boxed (thus overapproximated) loops.
Definition ScopInfo.h:2375
std::shared_ptr< isl_ctx > IslCtx
Isl context.
Definition ScopInfo.h:1655
void addAliasGroup(MinMaxVectorTy &MinMaxAccessesReadWrite, MinMaxVectorTy &MinMaxAccessesReadOnly)
Definition ScopInfo.h:2283
int getID() const
Return the ID of the Scop.
Definition ScopInfo.h:2147
void markAsOptimized()
Mark the SCoP as optimized by the scheduler.
Definition ScopInfo.h:2141
bool isOriginalSchedule() const
Whether the schedule is the original schedule as derived from the CFG by ScopBuilder.
Definition ScopInfo.h:2579
ArrayInfoSetTy::iterator array_iterator
Definition ScopInfo.h:2053
std::string getAssumedContextStr() const
Get an isl string representing the assumed context.
bool isProfitable(bool ScalarsAreUnprofitable) const
Return true if this SCoP can be profitably optimized.
array_iterator array_begin()
Definition ScopInfo.h:2058
bool isDominatedBy(const DominatorTree &DT, BasicBlock *BB) const
Return true if and only if BB dominates the SCoP.
ScopArrayInfo * getArrayInfoByName(const std::string BaseName)
Find the ScopArrayInfo associated with an isl Id that has name Name.
array_range arrays()
Definition ScopInfo.h:2070
void addAccessData(MemoryAccess *Access)
Add metadata for Access.
isl::set getDomainConditions(const ScopStmt *Stmt) const
Return the domain of Stmt.
void addInvariantEquivClass(const InvariantEquivClassTy &InvariantEquivClass)
Add new invariant access equivalence class.
Definition ScopInfo.h:1993
AccFuncVector AccessFunctions
Definition ScopInfo.h:1669
DenseMap< Value *, MemoryAccess * > ValueDefAccs
Map of values to the MemoryAccess that writes its definition.
Definition ScopInfo.h:1854
isl::union_map getMustWrites()
Get a union map of all must-writes performed in the SCoP.
reverse_iterator rbegin()
Definition ScopInfo.h:2360
std::pair< std::string, std::string > getEntryExitStr() const
Get the name of the entry and exit blocks of this Scop.
isl::pw_aff getPwAffOnly(const SCEV *E, BasicBlock *BB=nullptr, RecordedAssumptionsTy *RecordedAssumptions=nullptr)
Compute the isl representation for the SCEV E.
ScopStatistics getStatistics() const
Collect statistic about this SCoP.
std::string getContextStr() const
Get an isl string representing the context.
std::pair< MinMaxVectorTy, MinMaxVectorTy > MinMaxVectorPairTy
Pair of minimal/maximal access vectors representing read write and read only accesses.
Definition ScopInfo.h:1637
DenseMap< BasicBlock *, isl::set > DomainMap
A map from basic blocks to their domains.
Definition ScopInfo.h:1711
isl::union_map getAccessesOfType(std::function< bool(MemoryAccess &)> Predicate)
Collect all memory access relations of a given type.
void removeStmts(function_ref< bool(ScopStmt &)> ShouldDelete, bool AfterHoisting=true)
Remove statements from the list of scop statements.
void addInvariantLoadMapping(const Value *LoadInst, Value *ClassRep)
Add mapping from invariant loads to the representing invariant load of their equivalence class.
Definition ScopInfo.h:1999
int getRelativeLoopDepth(const Loop *L) const
Get the depth of a loop relative to the outermost loop in the Scop.
isl::ctx getIslCtx() const
Get the isl context of this static control part.
LoopInfo * getLI() const
Return the LoopInfo used for this Scop.
Definition ScopInfo.h:2013
std::string getInvalidContextStr() const
Get an isl string representing the invalid context.
StringRef getName()
Definition ScopInfo.h:2047
iterator_range< ArrayInfoSetTy::iterator > array_range
Definition ScopInfo.h:2055
PWACtx getPwAff(const SCEV *E, BasicBlock *BB=nullptr, bool NonNegative=false, RecordedAssumptionsTy *RecordedAssumptions=nullptr, bool IsInsideDomain=true)
Compute the isl representation for the SCEV E.
bool HasSingleExitEdge
True if the underlying region has a single exiting block.
Definition ScopInfo.h:1675
DenseMap< Instruction *, ScopStmt * > InstStmtMap
A map from instructions to SCoP statements.
Definition ScopInfo.h:1708
bool isEscaping(Instruction *Inst)
Return whether Inst has a use outside of this SCoP.
void removeStmtNotInDomainMap()
Removes all statements where the entry block of the statement does not have a corresponding domain in...
bool hasNSWAddRecForLoop(Loop *L)
Check if an <nsw> AddRec for the loop L is cached.
Definition ScopInfo.h:2514
void updateMaxLoopDepth(unsigned Depth)
Update maximal loop depth.
Definition ScopInfo.h:2438
ScopDetection::DetectionContext & DC
The context of the SCoP created during SCoP detection.
Definition ScopInfo.h:1698
void print(raw_ostream &OS, bool PrintInstructions) const
Print the static control part.
const_iterator end() const
Definition ScopInfo.h:2355
void printStatements(raw_ostream &OS, bool PrintInstructions) const
isl::union_map getWrites()
Get a union map of all writes performed in the SCoP.
reverse_iterator rend()
Definition ScopInfo.h:2361
void setSchedule(isl::union_map NewSchedule)
Update the current schedule.
bool hasErrorBlock() const
Return true if the SCoP contained at least one error block.
Definition ScopInfo.h:2454
void setContext(isl::set NewContext)
Set new isl context.
bool hasFeasibleRuntimeContext() const
Return true if the optimized SCoP can be executed.
DenseMap< const SCEV *, isl::id > ParameterIds
Mapping from parameters to their ids.
Definition ScopInfo.h:1695
isl::space getParamSpace() const
Return space of isl context parameters.
bool isExit(BasicBlock *BB) const
Return true if BB is the exit block of the SCoP.
Definition ScopInfo.h:2116
void addRequiredInvariantLoad(LoadInst *LI)
Add LI to the set of required invariant loads.
Definition ScopInfo.h:2372
const std::shared_ptr< isl_ctx > & getSharedIslCtx() const
Directly return the shared_ptr of the context.
Definition ScopInfo.h:2480
SmallVector< MinMaxAccessTy, 4 > MinMaxVectorTy
Vector of minimal/maximal accesses to different arrays.
Definition ScopInfo.h:1633
isl::set getDefinedBehaviorContext() const
Return the context where execution behavior is defined.
Definition ScopInfo.h:2167
friend class ScopBuilder
Definition ScopInfo.h:1644
Region::block_range blocks() const
Return a range of all basic blocks in the SCoP.
Definition ScopInfo.h:2119
const_iterator begin() const
Definition ScopInfo.h:2354
isl::set & getOrInitEmptyDomain(BasicBlock *BB)
Return the domain of BB. If it does not exist, create an empty one.
Definition ScopInfo.h:2527
StmtSet::const_reverse_iterator const_reverse_iterator
Definition ScopInfo.h:2358
std::string getNameStr() const
Get the name of this Scop.
DenseMap< PHINode *, MemoryAccess * > PHIReadAccs
Map of values to the MemoryAccess that reads a PHI.
Definition ScopInfo.h:1857
static void incrementNumberOfAliasingAssumptions(unsigned Step)
Increment actual number of aliasing assumptions taken.
long StmtIdx
The smallest statement index not yet assigned.
Definition ScopInfo.h:1846
std::pair< isl::pw_multi_aff, isl::pw_multi_aff > MinMaxAccessTy
Type to represent a pair of minimal/maximal access to an array.
Definition ScopInfo.h:1630
iterator_range< ArrayInfoSetTy::const_iterator > const_array_range
Definition ScopInfo.h:2056
std::optional< std::string > name
The name of the SCoP (identical to the regions name)
Definition ScopInfo.h:1664
size_t getSize() const
Return the number of statements in the SCoP.
Definition ScopInfo.h:2343
void createParameterId(const SCEV *Param)
Create an id for Param and store it in the ParameterIds map.
const_reverse_iterator rbegin() const
Definition ScopInfo.h:2362
BasicBlock * getEnteringBlock() const
Return the unique entering block of the SCoP if any.
Definition ScopInfo.h:2113
ArrayNameMapTy ScopArrayNameMap
A map to remember ScopArrayInfo objects for all names of memory references.
Definition ScopInfo.h:1736
isl::set DefinedBehaviorContext
The context under which the SCoP must have defined behavior.
Definition ScopInfo.h:1775
iterator_range< ParameterSetTy::iterator > parameters() const
Return an iterator range containing the scop parameters.
Definition ScopInfo.h:2027
bool isEmpty() const
Return whether this scop is empty, i.e.
Definition ScopInfo.h:2045
DenseMap< const ScopArrayInfo *, SmallVector< MemoryAccess *, 4 > > PHIIncomingAccs
List of all incoming values (write MemoryAccess) of a MemoryKind::PHI or MemoryKind::ExitPHI scalar.
Definition ScopInfo.h:1866
void markDisableHeuristics()
Mark this Scop to not apply an optimization heuristic.
Definition ScopInfo.h:2678
isl::id getIdForParam(const SCEV *Parameter) const
Return the isl_id that represents a certain parameter.
iterator_range< InvariantEquivClassesTy::iterator > invariantEquivClasses()
Return an iterator range containing invariant accesses.
Definition ScopInfo.h:2032
bool isOptimized() const
Check if the SCoP has been optimized by the scheduler.
Definition ScopInfo.h:2144
InvariantEquivClassesTy InvariantEquivClasses
List of invariant accesses.
Definition ScopInfo.h:1840
StmtSet::iterator iterator
Definition ScopInfo.h:2349
BasicBlock * getExitingBlock() const
Return the unique exiting block of the SCoP if any.
Definition ScopInfo.h:2107
Region & R
The underlying Region.
Definition ScopInfo.h:1661
OptimizationRemarkEmitter & ORE
OptimizationRemarkEmitter object for displaying diagnostic remarks.
Definition ScopInfo.h:1701
ArrayInfoSetTy::const_iterator const_array_iterator
Definition ScopInfo.h:2054
bool ScheduleModified
Whether the schedule has been modified after derived from the CFG by ScopBuilder.
Definition ScopInfo.h:1818
size_t getNumParams() const
Get the count of parameters used in this Scop.
Definition ScopInfo.h:2018
void addParameterBounds()
Add the bounds of the parameters to the context.
bool restrictDomains(isl::union_set Domain)
Intersects the domains of all statements in the SCoP.
const_array_iterator array_begin() const
Definition ScopInfo.h:2062
isl::union_map getAccesses()
Get a union map of all memory accesses performed in the SCoP.
ScopArrayInfo * createScopArrayInfo(Type *ElementType, const std::string &BaseName, const std::vector< unsigned > &Sizes)
Create an array and return the corresponding ScopArrayInfo object.
BasicBlock * getExit() const
Return the unique exit block of the SCoP.
Definition ScopInfo.h:2104
long getNextStmtIdx()
Get the next free statement index.
Definition ScopInfo.h:2615
void notifyErrorBlock()
Notify SCoP that it contains an error block.
Definition ScopInfo.h:2457
StmtSet Stmts
The statements in this Scop.
Definition ScopInfo.h:1689
SetVector< ScopArrayInfo * > ArrayInfoSetTy
Definition ScopInfo.h:1725
StmtSet::reverse_iterator reverse_iterator
Definition ScopInfo.h:2357
void removeAccessData(MemoryAccess *Access)
Remove the metadata stored for Access.
ArrayRef< ScopStmt * > getStmtListFor(BasicBlock *BB) const
Return the list of ScopStmts that represent the given BB.
MemoryAccess * getPHIRead(const ScopArrayInfo *SAI) const
Return the MemoryAccess that represents an llvm::PHINode.
std::map< std::pair< AssertingVH< const Value >, MemoryKind >, std::unique_ptr< ScopArrayInfo > > ArrayInfoMapTy
Definition ScopInfo.h:1719
bool contains(const Loop *L) const
Check if L is contained in the SCoP.
Definition ScopInfo.h:2095
static std::unique_ptr< Scop > makeScop(Region &R, ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE, int ID)
Factory pattern for creating a new (empty) SCoP.
void realignParams()
Align the parameters in the statement to the scop context.
array_iterator array_end()
Definition ScopInfo.h:2060
Function & getFunction() const
Return the function this SCoP is in.
Definition ScopInfo.h:2092
ArrayInfoMapTy ScopArrayInfoMap
A map to remember ScopArrayInfo objects for all base pointers.
Definition ScopInfo.h:1732
StmtSet::const_iterator const_iterator
Definition ScopInfo.h:2350
void printArrayInfo(raw_ostream &OS) const
bool isNonAffineSubRegion(const Region *R)
Return true if and only if R is a non-affine subregion.
Definition ScopInfo.h:2378
Scop(Region &R, ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE, int ID)
Scop constructor; invoked from ScopBuilder::buildScop.
const SCEV * getRepresentingInvariantLoadSCEV(const SCEV *S) const
Get the representing SCEV for S if applicable, otherwise S.
long getNextArrayIdx()
Get the next free array index.
Definition ScopInfo.h:2609
void simplifyContexts()
Simplify the assumed and invalid context.
bool hasSingleExitEdge() const
Return true if the underlying region has a single exiting block.
Definition ScopInfo.h:2460
const_array_iterator array_end() const
Definition ScopInfo.h:2066
ScopArrayInfo * getScopArrayInfoOrNull(Value *BasePtr, MemoryKind Kind)
Return the cached ScopArrayInfo object for BasePtr.
const_reverse_iterator rend() const
Definition ScopInfo.h:2363
MemoryAccess * lookupBasePtrAccess(MemoryAccess *MA)
Return the access for the base ptr of MA if any.
InvariantEquivClassesTy & getInvariantAccesses()
Return the set of invariant accesses.
Definition ScopInfo.h:2133
isl::set AssumedContext
The assumptions under which this scop was built.
Definition ScopInfo.h:1749
Scop(const Scop &)=delete
void addAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB, bool RTC=true)
Add assumptions to assumed context.
MinMaxVectorPairVectorTy MinMaxAliasGroups
The set of minimal/maximal accesses for each alias group.
Definition ScopInfo.h:1833
std::list< ScopStmt > StmtSet
Definition ScopInfo.h:1686
const Region & getRegion() const
Get the maximum region of this static control part.
Definition ScopInfo.h:2088
Region & getRegion()
Definition ScopInfo.h:2089
bool isEffectiveAssumption(isl::set Set, AssumptionSign Sign)
Check if the assumption in Set is trivial or not.
void simplifySCoP(bool AfterHoisting)
Simplify the SCoP representation.
ScopStmt * getIncomingStmtFor(const Use &U) const
Get the statement to put a PHI WRITE into.
bool trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB)
Track and report an assumption.
isl::set getContext() const
Get the constraint on parameter of this Scop.
long ArrayIdx
The smallest array index not yet assigned.
Definition ScopInfo.h:1843
void setScheduleTree(isl::schedule NewSchedule)
Update the current schedule.
BasicBlock * getEntry() const
Return the unique entry block of the SCoP.
Definition ScopInfo.h:2110
const_array_range arrays() const
Definition ScopInfo.h:2074
const int ID
A number that uniquely represents a Scop within its function.
Definition ScopInfo.h:1849
ScopStmt * getLastStmtFor(BasicBlock *BB) const
Return the last statement representing BB.
void removeFromStmtMap(ScopStmt &Stmt)
Removes Stmt from the StmtMap.
bool contains(const BasicBlock *BB) const
Check if BB is contained in the SCoP.
Definition ScopInfo.h:2098
StringMap< std::unique_ptr< ScopArrayInfo > > ArrayNameMapTy
Definition ScopInfo.h:1723
B()
#define S(TYPE, NAME)
#define assert(exp)
std::forward_list< MemoryAccess * > MemoryAccessList
Ordered list type to hold accesses.
Definition ScopInfo.h:1088
std::pair< isl::pw_aff, isl::set > PWACtx
The result type of the SCEVAffinator.
unsigned const MaxDisjunctsInDomain
Definition ScopInfo.cpp:115
SmallVector< InvariantAccess, 8 > InvariantAccessesTy
Ordered container type to hold invariant accesses.
Definition ScopInfo.h:1100
llvm::SetVector< llvm::AssertingVH< llvm::LoadInst > > InvariantLoadsSetTy
Type for a set of invariant loads.
Definition ScopHelper.h:110
llvm::SetVector< const llvm::SCEV * > ParameterSetTy
Set type for parameters.
Definition ScopHelper.h:113
AssumptionSign
Enum to distinguish between assumptions and restrictions.
Definition ScopHelper.h:58
MemoryKind
The different memory kinds used in Polly.
Definition ScopInfo.h:97
@ Array
MemoryKind::Array: Models a one or multi-dimensional array.
Definition ScopInfo.h:112
@ Value
MemoryKind::Value: Models an llvm::Value.
Definition ScopInfo.h:151
@ PHI
MemoryKind::PHI: Models PHI nodes within the SCoP.
Definition ScopInfo.h:188
@ ExitPHI
MemoryKind::ExitPHI: Models PHI nodes in the SCoP's exit block.
Definition ScopInfo.h:198
std::map< const Instruction *, MemAcc > MapInsnToMemAcc
raw_ostream & operator<<(raw_ostream &OS, MemoryAccess::ReductionType RT)
Definition ScopInfo.cpp:969
std::vector< std::unique_ptr< MemoryAccess > > AccFuncVector
Definition ScopInfo.h:209
std::map< const Loop *, const SCEV * > LoopBoundMapType
Maps from a loop to the affine function expressing its backedge taken count.
Definition ScopInfo.h:207
bool UseInstructionNames
Definition ScopInfo.cpp:153
llvm::SetVector< const llvm::Loop * > BoxedLoopsSetTy
Set of loops (used to remember loops in non-affine subregions).
Definition ScopHelper.h:116
llvm::SmallVector< Assumption, 8 > RecordedAssumptionsTy
Definition ScopHelper.h:81
AssumptionKind
Enumeration of assumptions Polly can take.
Definition ScopHelper.h:44
SmallVector< InvariantEquivClassTy, 8 > InvariantEquivClassesTy
Type for invariant accesses equivalence classes.
Definition ScopInfo.h:1128
Helper structure for invariant memory accesses.
Definition ScopInfo.h:1091
MemoryAccess * MA
The memory access that is (partially) invariant.
Definition ScopInfo.h:1093
isl::set NonHoistableCtx
The context under which the access is not invariant.
Definition ScopInfo.h:1096
Type for equivalent invariant accesses and their domain context.
Definition ScopInfo.h:1103
MemoryAccessList InvariantAccesses
Memory accesses now treated invariant.
Definition ScopInfo.h:1112
Type * AccessType
The type of the invariant access.
Definition ScopInfo.h:1124
isl::set ExecutionContext
The execution context under which the memory location is accessed.
Definition ScopInfo.h:1118
const SCEV * IdentifyingPointer
The pointer that identifies this equivalence class.
Definition ScopInfo.h:1105
Context variables for SCoP detection.
static TupleKindPtr Domain("Domain")
static TupleKindPtr Range("Range")