From 97b808bf70010c8784aa303870e8a0281cf624e6 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 29 Jun 2013 17:52:08 +0000 Subject: [PATCH] LoopVectorizer: Pack MemAccessInfo pairs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185263 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/LoopVectorize.cpp | 47 ++++++++++------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 6c698dfabe6..f41bd28776b 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2864,7 +2864,8 @@ namespace { class AccessAnalysis { public: /// \brief Read or write access location. - typedef std::pair MemAccessInfo; + typedef PointerIntPair MemAccessInfo; + typedef SmallPtrSet MemAccessInfoSet; /// \brief Set of potential dependent memory accesses. typedef EquivalenceClasses DepCandidates; @@ -2875,14 +2876,14 @@ public: /// \brief Register a load and whether it is only read from. void addLoad(Value *Ptr, bool IsReadOnly) { - Accesses.insert(std::make_pair(Ptr, false)); + Accesses.insert(MemAccessInfo(Ptr, false)); if (IsReadOnly) ReadOnlyPtr.insert(Ptr); } /// \brief Register a store. void addStore(Value *Ptr) { - Accesses.insert(std::make_pair(Ptr, true)); + Accesses.insert(MemAccessInfo(Ptr, true)); } /// \brief Check whether we can check the pointers at runtime for @@ -2904,7 +2905,7 @@ public: bool isDependencyCheckNeeded() { return !CheckDeps.empty(); } - DenseSet &getDependenciesToCheck() { return CheckDeps; } + MemAccessInfoSet &getDependenciesToCheck() { return CheckDeps; } private: typedef SetVector PtrAccessSet; @@ -2925,7 +2926,7 @@ private: UnderlyingObjToAccessMap ObjToLastAccess; /// Set of accesses that need a further dependence check. - DenseSet CheckDeps; + MemAccessInfoSet CheckDeps; /// Set of pointers that are read only. SmallPtrSet ReadOnlyPtr; @@ -2976,11 +2977,11 @@ bool AccessAnalysis::canCheckPtrAtRT( for (PtrAccessSet::iterator AI = Accesses.begin(), AE = Accesses.end(); AI != AE; ++AI) { const MemAccessInfo &Access = *AI; - Value *Ptr = Access.first; - bool IsWrite = Access.second; + Value *Ptr = Access.getPointer(); + bool IsWrite = Access.getInt(); // Just add write checks if we have both. - if (!IsWrite && Accesses.count(std::make_pair(Ptr, true))) + if (!IsWrite && Accesses.count(MemAccessInfo(Ptr, true))) continue; if (IsWrite) @@ -2993,7 +2994,7 @@ bool AccessAnalysis::canCheckPtrAtRT( unsigned DepId; if (IsDepCheckNeeded) { - Value *Leader = DepCands.getLeaderValue(Access).first; + Value *Leader = DepCands.getLeaderValue(Access).getPointer(); unsigned &LeaderId = DepSetId[Leader]; if (!LeaderId) LeaderId = RunningDepId++; @@ -3030,8 +3031,8 @@ void AccessAnalysis::processMemAccesses(bool UseDeferred) { PtrAccessSet &S = UseDeferred ? DeferredAccesses : Accesses; for (PtrAccessSet::iterator AI = S.begin(), AE = S.end(); AI != AE; ++AI) { const MemAccessInfo &Access = *AI; - Value *Ptr = Access.first; - bool IsWrite = Access.second; + Value *Ptr = Access.getPointer(); + bool IsWrite = Access.getInt(); DepCands.insert(Access); @@ -3140,7 +3141,8 @@ namespace { /// class MemoryDepChecker { public: - typedef std::pair MemAccessInfo; + typedef PointerIntPair MemAccessInfo; + typedef SmallPtrSet MemAccessInfoSet; MemoryDepChecker(ScalarEvolution *Se, DataLayout *Dl, const Loop *L) : SE(Se), DL(Dl), InnermostLoop(L), AccessIdx(0) {} @@ -3149,7 +3151,7 @@ public: /// of a write access. void addAccess(StoreInst *SI) { Value *Ptr = SI->getPointerOperand(); - Accesses[std::make_pair(Ptr, true)].push_back(AccessIdx); + Accesses[MemAccessInfo(Ptr, true)].push_back(AccessIdx); InstMap.push_back(SI); ++AccessIdx; } @@ -3158,7 +3160,7 @@ public: /// of a write access. void addAccess(LoadInst *LI) { Value *Ptr = LI->getPointerOperand(); - Accesses[std::make_pair(Ptr, false)].push_back(AccessIdx); + Accesses[MemAccessInfo(Ptr, false)].push_back(AccessIdx); InstMap.push_back(LI); ++AccessIdx; } @@ -3167,7 +3169,7 @@ public: /// /// Only checks sets with elements in \p CheckDeps. bool areDepsSafe(AccessAnalysis::DepCandidates &AccessSets, - DenseSet &CheckDeps); + MemAccessInfoSet &CheckDeps); /// \brief The maximum number of bytes of a vector register we can vectorize /// the accesses safely with. @@ -3331,10 +3333,10 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, const MemAccessInfo &B, unsigned BIdx) { assert (AIdx < BIdx && "Must pass arguments in program order"); - Value *APtr = A.first; - Value *BPtr = B.first; - bool AIsWrite = A.second; - bool BIsWrite = B.second; + Value *APtr = A.getPointer(); + Value *BPtr = B.getPointer(); + bool AIsWrite = A.getInt(); + bool BIsWrite = B.getInt(); // Two reads are independent. if (!AIsWrite && !BIsWrite) @@ -3450,7 +3452,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, bool MemoryDepChecker::areDepsSafe(AccessAnalysis::DepCandidates &AccessSets, - DenseSet &CheckDeps) { + MemAccessInfoSet &CheckDeps) { MaxSafeDepDistBytes = -1U; while (!CheckDeps.empty()) { @@ -3492,11 +3494,6 @@ bool LoopVectorizationLegality::canVectorizeMemory() { typedef SmallVector ValueVector; typedef SmallPtrSet ValueSet; - // Stores a pair of memory access location and whether the access is a store - // (true) or a load (false). - typedef std::pair MemAccessInfo; - typedef DenseSet PtrAccessSet; - // Holds the Load and Store *instructions*. ValueVector Loads; ValueVector Stores; -- 2.34.1