Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/ADT/GenericCycleImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ bool GenericCycle<ContextT>::contains(const GenericCycle *C) const {
template <typename ContextT>
void GenericCycle<ContextT>::getExitBlocks(
SmallVectorImpl<BlockT *> &TmpStorage) const {
if (!ExitBlocksCache->empty()) {
TmpStorage = *ExitBlocksCache;
return;
}

TmpStorage.clear();

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

TmpStorage.resize(NumExitBlocks);
}
ExitBlocksCache->append(TmpStorage.begin(), TmpStorage.end());
}

template <typename ContextT>
Expand Down
7 changes: 6 additions & 1 deletion llvm/include/llvm/ADT/GenericCycleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ template <typename ContextT> class GenericCycle {
/// always have the same depth.
unsigned Depth = 0;

/// Cache for the results of GetExitBlocks
std::unique_ptr<SmallVector<BlockT *, 4>> ExitBlocksCache;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unique_ptr is not required. The cache is just a vector and it does not even own the pointers in it. The vector can be declared without being a unique_ptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I declare the cache as a pointer is that the getExitBlocks is a const function, so I cannot modify it (update the cache) in that function. This is a WAR of it. I can also try to make this as a mutable vector.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, mutable is for this kind of case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be unique_ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


void clear() {
Entries.clear();
Children.clear();
Blocks.clear();
Depth = 0;
ParentCycle = nullptr;
ExitBlocksCache->clear();
}

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

public:
GenericCycle() = default;
GenericCycle()
: ExitBlocksCache(std::make_unique<SmallVector<BlockT *, 4>>()) {};

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