diff options
| author | Congzhe Cao <congzhe.cao@huawei.com> | 2022-06-16 16:03:30 -0400 |
|---|---|---|
| committer | CongzheUalberta <congzhecao@gmail.com> | 2022-06-16 16:03:41 -0400 |
| commit | 4c77d0276b8351e533888c8e0c4e4df0277c583f (patch) | |
| tree | d84ae78a3b70e5732ddc2a0dd449942e130ceb00 /llvm/lib/Analysis/LoopCacheAnalysis.cpp | |
| parent | a9dccb0072af5bd1704a6e364864f8c0e0d02d62 (diff) | |
[Delinearization] Refactoring of fixed-size array delinearization
This is a follow-up patch to D122857 where we added delinearization of
fixed-size arrays to loop cache analysis, which resulted in some duplicate
code, i.e., "tryDelinearizeFixedSize()", in LoopCacheCost.cpp and
DependenceAnalysis.cpp. Refactoring is done in this patch.
This patch refactors out the main logic of "tryDelinearizeFixedSize()" as
"tryDelinearizeFixedSizeImpl()" and moves it to Delinearization.cpp, such that
clients can reuse "llvm::tryDelinearizeFixedSizeImpl()" wherever they would
like to delinearize fixed-size arrays. Currently it has two users, i.e.,
DependenceAnalysis.cpp and LoopCacheCost.cpp.
Reviewed By: Meinersbur, #loopoptwg
Differential Revision: https://reviews.llvm.org/D124745
Diffstat (limited to 'llvm/lib/Analysis/LoopCacheAnalysis.cpp')
| -rw-r--r-- | llvm/lib/Analysis/LoopCacheAnalysis.cpp | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp index eacd262184ad..002e99302803 100644 --- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp +++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp @@ -349,46 +349,21 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L, } bool IndexedReference::tryDelinearizeFixedSize( - ScalarEvolution *SE, Instruction *Src, const SCEV *SrcAccessFn, - SmallVectorImpl<const SCEV *> &SrcSubscripts) { - Value *SrcPtr = getLoadStorePointerOperand(Src); - const SCEVUnknown *SrcBase = - dyn_cast<SCEVUnknown>(SE->getPointerBase(SrcAccessFn)); - - // Check the simple case where the array dimensions are fixed size. - auto *SrcGEP = dyn_cast<GetElementPtrInst>(SrcPtr); - if (!SrcGEP) + const SCEV *AccessFn, SmallVectorImpl<const SCEV *> &Subscripts) { + SmallVector<int, 4> ArraySizes; + if (!tryDelinearizeFixedSizeImpl(&SE, &StoreOrLoadInst, AccessFn, Subscripts, + ArraySizes)) return false; - SmallVector<int, 4> SrcSizes; - getIndexExpressionsFromGEP(*SE, SrcGEP, SrcSubscripts, SrcSizes); - - // Check that the two size arrays are non-empty and equal in length and - // value. - if (SrcSizes.empty() || SrcSubscripts.size() <= 1) { - SrcSubscripts.clear(); - return false; - } - - Value *SrcBasePtr = SrcGEP->getOperand(0)->stripPointerCasts(); - - // Check that for identical base pointers we do not miss index offsets - // that have been added before this GEP is applied. - if (SrcBasePtr != SrcBase->getValue()) { - SrcSubscripts.clear(); - return false; - } - - assert(SrcSubscripts.size() == SrcSizes.size() + 1 && - "Expected equal number of entries in the list of size and " - "subscript."); - + // Populate Sizes with scev expressions to be used in calculations later. for (auto Idx : seq<unsigned>(1, Subscripts.size())) - Sizes.push_back(SE->getConstant(Subscripts[Idx]->getType(), SrcSizes[Idx - 1])); + Sizes.push_back( + SE.getConstant(Subscripts[Idx]->getType(), ArraySizes[Idx - 1])); LLVM_DEBUG({ dbgs() << "Delinearized subscripts of fixed-size array\n" - << "SrcGEP:" << *SrcGEP << "\n"; + << "GEP:" << *getLoadStorePointerOperand(&StoreOrLoadInst) + << "\n"; }); return true; } @@ -416,9 +391,9 @@ bool IndexedReference::delinearize(const LoopInfo &LI) { bool IsFixedSize = false; // Try to delinearize fixed-size arrays. - if (tryDelinearizeFixedSize(&SE, &StoreOrLoadInst, AccessFn, Subscripts)) { + if (tryDelinearizeFixedSize(AccessFn, Subscripts)) { IsFixedSize = true; - /// The last element of \p Sizes is the element size. + // The last element of Sizes is the element size. Sizes.push_back(ElemSize); LLVM_DEBUG(dbgs().indent(2) << "In Loop '" << L->getName() << "', AccessFn: " << *AccessFn << "\n"); |
