diff options
Diffstat (limited to 'llvm/include/llvm/Analysis/LoopAccessAnalysis.h')
-rw-r--r-- | llvm/include/llvm/Analysis/LoopAccessAnalysis.h | 136 |
1 files changed, 56 insertions, 80 deletions
diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h index 7f8639ac90d1..a5237e9ba59e 100644 --- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h +++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h @@ -15,27 +15,22 @@ #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H #include "llvm/ADT/EquivalenceClasses.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/SetVector.h" -#include "llvm/Analysis/AliasAnalysis.h" -#include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/LoopAnalysisManager.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/IR/DiagnosticInfo.h" -#include "llvm/IR/ValueHandle.h" #include "llvm/Pass.h" -#include "llvm/Support/raw_ostream.h" namespace llvm { -class Value; +class AAResults; class DataLayout; -class ScalarEvolution; class Loop; -class SCEV; -class SCEVUnionPredicate; class LoopAccessInfo; class OptimizationRemarkEmitter; +class raw_ostream; +class SCEV; +class SCEVUnionPredicate; +class Value; /// Collection of parameters shared beetween the Loop Vectorizer and the /// Loop Access Analysis. @@ -329,9 +324,45 @@ private: void mergeInStatus(VectorizationSafetyStatus S); }; +class RuntimePointerChecking; +/// A grouping of pointers. A single memcheck is required between +/// two groups. +struct RuntimeCheckingPtrGroup { + /// Create a new pointer checking group containing a single + /// pointer, with index \p Index in RtCheck. + RuntimeCheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck); + + /// Tries to add the pointer recorded in RtCheck at index + /// \p Index to this pointer checking group. We can only add a pointer + /// to a checking group if we will still be able to get + /// the upper and lower bounds of the check. Returns true in case + /// of success, false otherwise. + bool addPointer(unsigned Index); + + /// Constitutes the context of this pointer checking group. For each + /// pointer that is a member of this group we will retain the index + /// at which it appears in RtCheck. + RuntimePointerChecking &RtCheck; + /// The SCEV expression which represents the upper bound of all the + /// pointers in this group. + const SCEV *High; + /// The SCEV expression which represents the lower bound of all the + /// pointers in this group. + const SCEV *Low; + /// Indices of all the pointers that constitute this grouping. + SmallVector<unsigned, 2> Members; +}; + +/// A memcheck which made up of a pair of grouped pointers. +typedef std::pair<const RuntimeCheckingPtrGroup *, + const RuntimeCheckingPtrGroup *> + RuntimePointerCheck; + /// Holds information about the memory runtime legality checks to verify /// that a group of pointers do not overlap. class RuntimePointerChecking { + friend struct RuntimeCheckingPtrGroup; + public: struct PointerInfo { /// Holds the pointer value that we need to check. @@ -381,59 +412,20 @@ public: /// No run-time memory checking is necessary. bool empty() const { return Pointers.empty(); } - /// A grouping of pointers. A single memcheck is required between - /// two groups. - struct CheckingPtrGroup { - /// Create a new pointer checking group containing a single - /// pointer, with index \p Index in RtCheck. - CheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck) - : RtCheck(RtCheck), High(RtCheck.Pointers[Index].End), - Low(RtCheck.Pointers[Index].Start) { - Members.push_back(Index); - } - - /// Tries to add the pointer recorded in RtCheck at index - /// \p Index to this pointer checking group. We can only add a pointer - /// to a checking group if we will still be able to get - /// the upper and lower bounds of the check. Returns true in case - /// of success, false otherwise. - bool addPointer(unsigned Index); - - /// Constitutes the context of this pointer checking group. For each - /// pointer that is a member of this group we will retain the index - /// at which it appears in RtCheck. - RuntimePointerChecking &RtCheck; - /// The SCEV expression which represents the upper bound of all the - /// pointers in this group. - const SCEV *High; - /// The SCEV expression which represents the lower bound of all the - /// pointers in this group. - const SCEV *Low; - /// Indices of all the pointers that constitute this grouping. - SmallVector<unsigned, 2> Members; - }; - - /// A memcheck which made up of a pair of grouped pointers. - /// - /// These *have* to be const for now, since checks are generated from - /// CheckingPtrGroups in LAI::addRuntimeChecks which is a const member - /// function. FIXME: once check-generation is moved inside this class (after - /// the PtrPartition hack is removed), we could drop const. - typedef std::pair<const CheckingPtrGroup *, const CheckingPtrGroup *> - PointerCheck; - /// Generate the checks and store it. This also performs the grouping /// of pointers to reduce the number of memchecks necessary. void generateChecks(MemoryDepChecker::DepCandidates &DepCands, bool UseDependencies); /// Returns the checks that generateChecks created. - const SmallVector<PointerCheck, 4> &getChecks() const { return Checks; } + const SmallVector<RuntimePointerCheck, 4> &getChecks() const { + return Checks; + } /// Decide if we need to add a check between two groups of pointers, /// according to needsChecking. - bool needsChecking(const CheckingPtrGroup &M, - const CheckingPtrGroup &N) const; + bool needsChecking(const RuntimeCheckingPtrGroup &M, + const RuntimeCheckingPtrGroup &N) const; /// Returns the number of run-time checks required according to /// needsChecking. @@ -443,7 +435,8 @@ public: void print(raw_ostream &OS, unsigned Depth = 0) const; /// Print \p Checks. - void printChecks(raw_ostream &OS, const SmallVectorImpl<PointerCheck> &Checks, + void printChecks(raw_ostream &OS, + const SmallVectorImpl<RuntimePointerCheck> &Checks, unsigned Depth = 0) const; /// This flag indicates if we need to add the runtime check. @@ -453,7 +446,7 @@ public: SmallVector<PointerInfo, 2> Pointers; /// Holds a partitioning of pointers into "check groups". - SmallVector<CheckingPtrGroup, 2> CheckingGroups; + SmallVector<RuntimeCheckingPtrGroup, 2> CheckingGroups; /// Check if pointers are in the same partition /// @@ -472,6 +465,8 @@ public: return Pointers[PtrIdx]; } + ScalarEvolution *getSE() const { return SE; } + private: /// Groups pointers such that a single memcheck is required /// between two different groups. This will clear the CheckingGroups vector @@ -481,15 +476,14 @@ private: bool UseDependencies); /// Generate the checks and return them. - SmallVector<PointerCheck, 4> - generateChecks() const; + SmallVector<RuntimePointerCheck, 4> generateChecks() const; /// Holds a pointer to the ScalarEvolution analysis. ScalarEvolution *SE; /// Set of run-time checks required to establish independence of /// otherwise may-aliasing pointers in the loop. - SmallVector<PointerCheck, 4> Checks; + SmallVector<RuntimePointerCheck, 4> Checks; }; /// Drive the analysis of memory accesses in the loop @@ -516,7 +510,7 @@ private: class LoopAccessInfo { public: LoopAccessInfo(Loop *L, ScalarEvolution *SE, const TargetLibraryInfo *TLI, - AliasAnalysis *AA, DominatorTree *DT, LoopInfo *LI); + AAResults *AA, DominatorTree *DT, LoopInfo *LI); /// Return true we can analyze the memory accesses in the loop and there are /// no memory dependence cycles. @@ -549,24 +543,6 @@ public: unsigned getNumStores() const { return NumStores; } unsigned getNumLoads() const { return NumLoads;} - /// Add code that checks at runtime if the accessed arrays overlap. - /// - /// Returns a pair of instructions where the first element is the first - /// instruction generated in possibly a sequence of instructions and the - /// second value is the final comparator value or NULL if no check is needed. - std::pair<Instruction *, Instruction *> - addRuntimeChecks(Instruction *Loc) const; - - /// Generete the instructions for the checks in \p PointerChecks. - /// - /// Returns a pair of instructions where the first element is the first - /// instruction generated in possibly a sequence of instructions and the - /// second value is the final comparator value or NULL if no check is needed. - std::pair<Instruction *, Instruction *> - addRuntimeChecks(Instruction *Loc, - const SmallVectorImpl<RuntimePointerChecking::PointerCheck> - &PointerChecks) const; - /// The diagnostics report generated for the analysis. E.g. why we /// couldn't analyze the loop. const OptimizationRemarkAnalysis *getReport() const { return Report.get(); } @@ -607,7 +583,7 @@ public: private: /// Analyze the loop. - void analyzeLoop(AliasAnalysis *AA, LoopInfo *LI, + void analyzeLoop(AAResults *AA, LoopInfo *LI, const TargetLibraryInfo *TLI, DominatorTree *DT); /// Check if the structure of the loop allows it to be analyzed by this @@ -750,7 +726,7 @@ private: // The used analysis passes. ScalarEvolution *SE = nullptr; const TargetLibraryInfo *TLI = nullptr; - AliasAnalysis *AA = nullptr; + AAResults *AA = nullptr; DominatorTree *DT = nullptr; LoopInfo *LI = nullptr; }; |