Skip to content

Commit 08ce9cd

Browse files
committed
Add cache in GenericCycleInfo
1 parent b8ee0aa commit 08ce9cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/include/llvm/ADT/GenericCycleImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ bool GenericCycle<ContextT>::contains(const GenericCycle *C) const {
4747
template <typename ContextT>
4848
void GenericCycle<ContextT>::getExitBlocks(
4949
SmallVectorImpl<BlockT *> &TmpStorage) const {
50+
if (!ExitBlocksCache->empty()) {
51+
TmpStorage = *ExitBlocksCache;
52+
return;
53+
}
54+
5055
TmpStorage.clear();
5156

5257
size_t NumExitBlocks = 0;
@@ -65,6 +70,7 @@ void GenericCycle<ContextT>::getExitBlocks(
6570

6671
TmpStorage.resize(NumExitBlocks);
6772
}
73+
ExitBlocksCache->append(TmpStorage.begin(), TmpStorage.end());
6874
}
6975

7076
template <typename ContextT>

llvm/include/llvm/ADT/GenericCycleInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ template <typename ContextT> class GenericCycle {
7474
/// always have the same depth.
7575
unsigned Depth = 0;
7676

77+
/// Cache for the results of GetExitBlocks
78+
std::unique_ptr<SmallVector<BlockT *, 4>> ExitBlocksCache;
79+
7780
void clear() {
7881
Entries.clear();
7982
Children.clear();
8083
Blocks.clear();
8184
Depth = 0;
8285
ParentCycle = nullptr;
86+
ExitBlocksCache->clear();
8387
}
8488

8589
void appendEntry(BlockT *Block) { Entries.push_back(Block); }
@@ -91,7 +95,8 @@ template <typename ContextT> class GenericCycle {
9195
GenericCycle &operator=(GenericCycle &&Rhs) = delete;
9296

9397
public:
94-
GenericCycle() = default;
98+
GenericCycle()
99+
: ExitBlocksCache(std::make_unique<SmallVector<BlockT *, 4>>()){};
95100

96101
/// \brief Whether the cycle is a natural loop.
97102
bool isReducible() const { return Entries.size() == 1; }

0 commit comments

Comments
 (0)