[llvm] 14bf60d - [CycleInfo] Deduplicate getExitBlocks with a set. NFC (#210557)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 18 16:55:07 PDT 2026
Author: Fangrui Song
Date: 2026-07-18T23:55:03Z
New Revision: 14bf60dacab081559bedca01ab426f52793b38cb
URL: https://github.com/llvm/llvm-project/commit/14bf60dacab081559bedca01ab426f52793b38cb
DIFF: https://github.com/llvm/llvm-project/commit/14bf60dacab081559bedca01ab426f52793b38cb.diff
LOG: [CycleInfo] Deduplicate getExitBlocks with a set. NFC (#210557)
Fix the O(exit_blocks^2) hazard.
Added:
Modified:
llvm/include/llvm/ADT/GenericCycleImpl.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/GenericCycleImpl.h b/llvm/include/llvm/ADT/GenericCycleImpl.h
index e2da17af20826..9ebdb5972780d 100644
--- a/llvm/include/llvm/ADT/GenericCycleImpl.h
+++ b/llvm/include/llvm/ADT/GenericCycleImpl.h
@@ -40,27 +40,13 @@ void GenericCycleInfo<ContextT>::getExitBlocks(
if (ExitBlocksCaches.empty())
ExitBlocksCaches.resize(NumCycles);
auto &Cache = ExitBlocksCaches[C.Index];
- if (!Cache.empty()) {
- TmpStorage.append(Cache.begin(), Cache.end());
- return;
- }
-
- size_t NumExitBlocks = 0;
- for (BlockT *Block : getBlocks(C)) {
- llvm::append_range(Cache, successors(Block));
-
- for (size_t Idx = NumExitBlocks, End = Cache.size(); Idx < End; ++Idx) {
- BlockT *Succ = Cache[Idx];
- if (!contains(C, Succ)) {
- auto ExitEndIt = Cache.begin() + NumExitBlocks;
- if (std::find(Cache.begin(), ExitEndIt, Succ) == ExitEndIt)
- Cache[NumExitBlocks++] = Succ;
- }
- }
-
- Cache.resize(NumExitBlocks);
+ if (Cache.empty()) {
+ SmallPtrSet<BlockT *, 4> Seen;
+ for (BlockT *Block : getBlocks(C))
+ for (BlockT *Succ : successors(Block))
+ if (!contains(C, Succ) && Seen.insert(Succ).second)
+ Cache.push_back(Succ);
}
-
TmpStorage.append(Cache.begin(), Cache.end());
}
More information about the llvm-commits
mailing list