Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 944e082

Browse files
committed
[LAA] Lift RuntimePointerCheck out of LoopAccessInfo, NFC
I am planning to add more nested classes inside RuntimePointerCheck so all these triple-nesting would be hard to follow. Also rename it to RuntimePointerChecking (i.e. append 'ing'). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242218 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a8eaf29 commit 944e082

File tree

5 files changed

+173
-176
lines changed

5 files changed

+173
-176
lines changed

include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 120 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,122 @@ class MemoryDepChecker {
292292
bool couldPreventStoreLoadForward(unsigned Distance, unsigned TypeByteSize);
293293
};
294294

295+
/// This struct holds information about the memory runtime legality check that
296+
/// a group of pointers do not overlap.
297+
struct RuntimePointerChecking {
298+
RuntimePointerChecking(ScalarEvolution *SE) : Need(false), SE(SE) {}
299+
300+
/// Reset the state of the pointer runtime information.
301+
void reset() {
302+
Need = false;
303+
Pointers.clear();
304+
Starts.clear();
305+
Ends.clear();
306+
IsWritePtr.clear();
307+
DependencySetId.clear();
308+
AliasSetId.clear();
309+
Exprs.clear();
310+
}
311+
312+
/// Insert a pointer and calculate the start and end SCEVs.
313+
void insert(Loop *Lp, Value *Ptr, bool WritePtr, unsigned DepSetId,
314+
unsigned ASId, const ValueToValueMap &Strides);
315+
316+
/// \brief No run-time memory checking is necessary.
317+
bool empty() const { return Pointers.empty(); }
318+
319+
/// A grouping of pointers. A single memcheck is required between
320+
/// two groups.
321+
struct CheckingPtrGroup {
322+
/// \brief Create a new pointer checking group containing a single
323+
/// pointer, with index \p Index in RtCheck.
324+
CheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck)
325+
: RtCheck(RtCheck), High(RtCheck.Ends[Index]),
326+
Low(RtCheck.Starts[Index]) {
327+
Members.push_back(Index);
328+
}
329+
330+
/// \brief Tries to add the pointer recorded in RtCheck at index
331+
/// \p Index to this pointer checking group. We can only add a pointer
332+
/// to a checking group if we will still be able to get
333+
/// the upper and lower bounds of the check. Returns true in case
334+
/// of success, false otherwise.
335+
bool addPointer(unsigned Index);
336+
337+
/// Constitutes the context of this pointer checking group. For each
338+
/// pointer that is a member of this group we will retain the index
339+
/// at which it appears in RtCheck.
340+
RuntimePointerChecking &RtCheck;
341+
/// The SCEV expression which represents the upper bound of all the
342+
/// pointers in this group.
343+
const SCEV *High;
344+
/// The SCEV expression which represents the lower bound of all the
345+
/// pointers in this group.
346+
const SCEV *Low;
347+
/// Indices of all the pointers that constitute this grouping.
348+
SmallVector<unsigned, 2> Members;
349+
};
350+
351+
/// \brief Groups pointers such that a single memcheck is required
352+
/// between two different groups. This will clear the CheckingGroups vector
353+
/// and re-compute it. We will only group dependecies if \p UseDependencies
354+
/// is true, otherwise we will create a separate group for each pointer.
355+
void groupChecks(MemoryDepChecker::DepCandidates &DepCands,
356+
bool UseDependencies);
357+
358+
/// \brief Decide whether we need to issue a run-time check for pointer at
359+
/// index \p I and \p J to prove their independence.
360+
///
361+
/// If \p PtrPartition is set, it contains the partition number for
362+
/// pointers (-1 if the pointer belongs to multiple partitions). In this
363+
/// case omit checks between pointers belonging to the same partition.
364+
bool needsChecking(unsigned I, unsigned J,
365+
const SmallVectorImpl<int> *PtrPartition) const;
366+
367+
/// \brief Decide if we need to add a check between two groups of pointers,
368+
/// according to needsChecking.
369+
bool needsChecking(const CheckingPtrGroup &M, const CheckingPtrGroup &N,
370+
const SmallVectorImpl<int> *PtrPartition) const;
371+
372+
/// \brief Return true if any pointer requires run-time checking according
373+
/// to needsChecking.
374+
bool needsAnyChecking(const SmallVectorImpl<int> *PtrPartition) const;
375+
376+
/// \brief Returns the number of run-time checks required according to
377+
/// needsChecking.
378+
unsigned getNumberOfChecks(const SmallVectorImpl<int> *PtrPartition) const;
379+
380+
/// \brief Print the list run-time memory checks necessary.
381+
///
382+
/// If \p PtrPartition is set, it contains the partition number for
383+
/// pointers (-1 if the pointer belongs to multiple partitions). In this
384+
/// case omit checks between pointers belonging to the same partition.
385+
void print(raw_ostream &OS, unsigned Depth = 0,
386+
const SmallVectorImpl<int> *PtrPartition = nullptr) const;
387+
388+
/// This flag indicates if we need to add the runtime check.
389+
bool Need;
390+
/// Holds the pointers that we need to check.
391+
SmallVector<TrackingVH<Value>, 2> Pointers;
392+
/// Holds the pointer value at the beginning of the loop.
393+
SmallVector<const SCEV *, 2> Starts;
394+
/// Holds the pointer value at the end of the loop.
395+
SmallVector<const SCEV *, 2> Ends;
396+
/// Holds the information if this pointer is used for writing to memory.
397+
SmallVector<bool, 2> IsWritePtr;
398+
/// Holds the id of the set of pointers that could be dependent because of a
399+
/// shared underlying object.
400+
SmallVector<unsigned, 2> DependencySetId;
401+
/// Holds the id of the disjoint alias set to which this pointer belongs.
402+
SmallVector<unsigned, 2> AliasSetId;
403+
/// Holds at position i the SCEV for the access i
404+
SmallVector<const SCEV *, 2> Exprs;
405+
/// Holds a partitioning of pointers into "check groups".
406+
SmallVector<CheckingPtrGroup, 2> CheckingGroups;
407+
/// Holds a pointer to the ScalarEvolution analysis.
408+
ScalarEvolution *SE;
409+
};
410+
295411
/// \brief Drive the analysis of memory accesses in the loop
296412
///
297413
/// This class is responsible for analyzing the memory accesses of a loop. It
@@ -308,123 +424,6 @@ class MemoryDepChecker {
308424
/// RuntimePointerCheck class.
309425
class LoopAccessInfo {
310426
public:
311-
/// This struct holds information about the memory runtime legality check that
312-
/// a group of pointers do not overlap.
313-
struct RuntimePointerCheck {
314-
RuntimePointerCheck(ScalarEvolution *SE) : Need(false), SE(SE) {}
315-
316-
/// Reset the state of the pointer runtime information.
317-
void reset() {
318-
Need = false;
319-
Pointers.clear();
320-
Starts.clear();
321-
Ends.clear();
322-
IsWritePtr.clear();
323-
DependencySetId.clear();
324-
AliasSetId.clear();
325-
Exprs.clear();
326-
}
327-
328-
/// Insert a pointer and calculate the start and end SCEVs.
329-
void insert(Loop *Lp, Value *Ptr, bool WritePtr, unsigned DepSetId,
330-
unsigned ASId, const ValueToValueMap &Strides);
331-
332-
/// \brief No run-time memory checking is necessary.
333-
bool empty() const { return Pointers.empty(); }
334-
335-
/// A grouping of pointers. A single memcheck is required between
336-
/// two groups.
337-
struct CheckingPtrGroup {
338-
/// \brief Create a new pointer checking group containing a single
339-
/// pointer, with index \p Index in RtCheck.
340-
CheckingPtrGroup(unsigned Index, RuntimePointerCheck &RtCheck)
341-
: RtCheck(RtCheck), High(RtCheck.Ends[Index]),
342-
Low(RtCheck.Starts[Index]) {
343-
Members.push_back(Index);
344-
}
345-
346-
/// \brief Tries to add the pointer recorded in RtCheck at index
347-
/// \p Index to this pointer checking group. We can only add a pointer
348-
/// to a checking group if we will still be able to get
349-
/// the upper and lower bounds of the check. Returns true in case
350-
/// of success, false otherwise.
351-
bool addPointer(unsigned Index);
352-
353-
/// Constitutes the context of this pointer checking group. For each
354-
/// pointer that is a member of this group we will retain the index
355-
/// at which it appears in RtCheck.
356-
RuntimePointerCheck &RtCheck;
357-
/// The SCEV expression which represents the upper bound of all the
358-
/// pointers in this group.
359-
const SCEV *High;
360-
/// The SCEV expression which represents the lower bound of all the
361-
/// pointers in this group.
362-
const SCEV *Low;
363-
/// Indices of all the pointers that constitute this grouping.
364-
SmallVector<unsigned, 2> Members;
365-
};
366-
367-
/// \brief Groups pointers such that a single memcheck is required
368-
/// between two different groups. This will clear the CheckingGroups vector
369-
/// and re-compute it. We will only group dependecies if \p UseDependencies
370-
/// is true, otherwise we will create a separate group for each pointer.
371-
void groupChecks(MemoryDepChecker::DepCandidates &DepCands,
372-
bool UseDependencies);
373-
374-
/// \brief Decide whether we need to issue a run-time check for pointer at
375-
/// index \p I and \p J to prove their independence.
376-
///
377-
/// If \p PtrPartition is set, it contains the partition number for
378-
/// pointers (-1 if the pointer belongs to multiple partitions). In this
379-
/// case omit checks between pointers belonging to the same partition.
380-
bool needsChecking(unsigned I, unsigned J,
381-
const SmallVectorImpl<int> *PtrPartition) const;
382-
383-
/// \brief Decide if we need to add a check between two groups of pointers,
384-
/// according to needsChecking.
385-
bool needsChecking(const CheckingPtrGroup &M,
386-
const CheckingPtrGroup &N,
387-
const SmallVectorImpl<int> *PtrPartition) const;
388-
389-
/// \brief Return true if any pointer requires run-time checking according
390-
/// to needsChecking.
391-
bool needsAnyChecking(const SmallVectorImpl<int> *PtrPartition) const;
392-
393-
/// \brief Returns the number of run-time checks required according to
394-
/// needsChecking.
395-
unsigned getNumberOfChecks(const SmallVectorImpl<int> *PtrPartition) const;
396-
397-
/// \brief Print the list run-time memory checks necessary.
398-
///
399-
/// If \p PtrPartition is set, it contains the partition number for
400-
/// pointers (-1 if the pointer belongs to multiple partitions). In this
401-
/// case omit checks between pointers belonging to the same partition.
402-
void print(raw_ostream &OS, unsigned Depth = 0,
403-
const SmallVectorImpl<int> *PtrPartition = nullptr) const;
404-
405-
/// This flag indicates if we need to add the runtime check.
406-
bool Need;
407-
/// Holds the pointers that we need to check.
408-
SmallVector<TrackingVH<Value>, 2> Pointers;
409-
/// Holds the pointer value at the beginning of the loop.
410-
SmallVector<const SCEV*, 2> Starts;
411-
/// Holds the pointer value at the end of the loop.
412-
SmallVector<const SCEV*, 2> Ends;
413-
/// Holds the information if this pointer is used for writing to memory.
414-
SmallVector<bool, 2> IsWritePtr;
415-
/// Holds the id of the set of pointers that could be dependent because of a
416-
/// shared underlying object.
417-
SmallVector<unsigned, 2> DependencySetId;
418-
/// Holds the id of the disjoint alias set to which this pointer belongs.
419-
SmallVector<unsigned, 2> AliasSetId;
420-
/// Holds at position i the SCEV for the access i
421-
SmallVector<const SCEV *, 2> Exprs;
422-
/// Holds a partitioning of pointers into "check groups".
423-
SmallVector<CheckingPtrGroup, 2> CheckingGroups;
424-
/// Holds a pointer to the ScalarEvolution analysis.
425-
ScalarEvolution *SE;
426-
};
427-
428427
LoopAccessInfo(Loop *L, ScalarEvolution *SE, const DataLayout &DL,
429428
const TargetLibraryInfo *TLI, AliasAnalysis *AA,
430429
DominatorTree *DT, LoopInfo *LI,
@@ -434,15 +433,15 @@ class LoopAccessInfo {
434433
/// no memory dependence cycles.
435434
bool canVectorizeMemory() const { return CanVecMem; }
436435

437-
const RuntimePointerCheck *getRuntimePointerCheck() const {
438-
return &PtrRtCheck;
436+
const RuntimePointerChecking *getRuntimePointerChecking() const {
437+
return &PtrRtChecking;
439438
}
440439

441440
/// \brief Number of memchecks required to prove independence of otherwise
442441
/// may-alias pointers.
443442
unsigned getNumRuntimePointerChecks(
444443
const SmallVectorImpl<int> *PtrPartition = nullptr) const {
445-
return PtrRtCheck.getNumberOfChecks(PtrPartition);
444+
return PtrRtChecking.getNumberOfChecks(PtrPartition);
446445
}
447446

448447
/// Return true if the block BB needs to be predicated in order for the loop
@@ -512,7 +511,7 @@ class LoopAccessInfo {
512511

513512
/// We need to check that all of the pointers in this list are disjoint
514513
/// at runtime.
515-
RuntimePointerCheck PtrRtCheck;
514+
RuntimePointerChecking PtrRtChecking;
516515

517516
/// \brief the Memory Dependence Checker which can determine the
518517
/// loop-independent and loop-carried dependences between memory accesses.

0 commit comments

Comments
 (0)