-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[DA] Cache delinearization results. NFCI. #164379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -420,6 +420,12 @@ class DependenceInfo { | |||||
| Function *F; | ||||||
| SmallVector<const SCEVPredicate *, 4> Assumptions; | ||||||
|
|
||||||
| /// Cache for delinearized subscripts to avoid recomputation. | ||||||
| /// Maps (Instruction, Loop, AccessFn) -> Subscripts | ||||||
| DenseMap<std::tuple<Instruction *, Loop *, const SCEV *>, | ||||||
| SmallVector<const SCEV *, 4>> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Consider a smaller SmallVector, maybe even |
||||||
| DelinearizationCache; | ||||||
|
|
||||||
| /// Subscript - This private struct represents a pair of subscripts from | ||||||
| /// a pair of potentially multi-dimensional array references. We use a | ||||||
| /// vector of them to guide subscript partitioning. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3463,11 +3463,37 @@ bool DependenceInfo::tryDelinearize(Instruction *Src, Instruction *Dst, | |
|
|
||
| SmallVector<const SCEV *, 4> SrcSubscripts, DstSubscripts; | ||
|
|
||
| if (!tryDelinearizeFixedSize(Src, Dst, SrcAccessFn, DstAccessFn, | ||
| SrcSubscripts, DstSubscripts) && | ||
| !tryDelinearizeParametricSize(Src, Dst, SrcAccessFn, DstAccessFn, | ||
| SrcSubscripts, DstSubscripts)) | ||
| return false; | ||
| // Check cache for both Src and Dst subscripts | ||
| auto SrcCacheKey = std::make_tuple(Src, SrcLoop, SrcAccessFn); | ||
| auto DstCacheKey = std::make_tuple(Dst, DstLoop, DstAccessFn); | ||
| auto SrcCacheIt = DelinearizationCache.find(SrcCacheKey); | ||
| auto DstCacheIt = DelinearizationCache.find(DstCacheKey); | ||
|
Comment on lines
+3469
to
+3470
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using |
||
| bool SrcCached = (SrcCacheIt != DelinearizationCache.end()); | ||
| bool DstCached = (DstCacheIt != DelinearizationCache.end()); | ||
|
|
||
| if (SrcCached && DstCached) { | ||
| // Both are cached - use cached values and skip delinearization | ||
| SrcSubscripts = SrcCacheIt->second; | ||
| DstSubscripts = DstCacheIt->second; | ||
| LLVM_DEBUG(dbgs() << " Delinearization cache hit for both Src and Dst\n"); | ||
| } else { | ||
| // At least one is not cached - need to compute both | ||
| if (!tryDelinearizeFixedSize(Src, Dst, SrcAccessFn, DstAccessFn, | ||
| SrcSubscripts, DstSubscripts) && | ||
| !tryDelinearizeParametricSize(Src, Dst, SrcAccessFn, DstAccessFn, | ||
| SrcSubscripts, DstSubscripts)) | ||
| return false; | ||
|
|
||
| // Cache the results | ||
| if (!SrcCached) { | ||
| DelinearizationCache[SrcCacheKey] = SrcSubscripts; | ||
| LLVM_DEBUG(dbgs() << " Cached Src subscripts\n"); | ||
| } | ||
| if (!DstCached) { | ||
| DelinearizationCache[DstCacheKey] = DstSubscripts; | ||
| LLVM_DEBUG(dbgs() << " Cached Dst subscripts\n"); | ||
| } | ||
| } | ||
|
Comment on lines
+3466
to
+3496
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refactoring into a function for lookup. Src and Dst computation need to be disentangled or looked up together. |
||
|
|
||
| assert(isLoopInvariant(SrcBase, SrcLoop) && | ||
| isLoopInvariant(DstBase, DstLoop) && | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the key need to be a tuple? Wouldn't
Instruction *orconst SCEV *be sufficient?