[llvm] 3b15a7c - [BFI] Use SmallPtrSets. NFCI.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 06:23:54 PST 2022
Author: Benjamin Kramer
Date: 2022-03-11T15:20:57+01:00
New Revision: 3b15a7c042098f2883b6b727ef412685e25f5849
URL: https://github.com/llvm/llvm-project/commit/3b15a7c042098f2883b6b727ef412685e25f5849
DIFF: https://github.com/llvm/llvm-project/commit/3b15a7c042098f2883b6b727ef412685e25f5849.diff
LOG: [BFI] Use SmallPtrSets. NFCI.
Added:
Modified:
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index dc884eddba732..256f1b7881d28 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -20,6 +20,7 @@
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SparseBitVector.h"
#include "llvm/ADT/Twine.h"
@@ -44,7 +45,6 @@
#include <list>
#include <queue>
#include <string>
-#include <unordered_set>
#include <utility>
#include <vector>
@@ -1515,7 +1515,7 @@ void BlockFrequencyInfoImpl<BT>::findReachableBlocks(
// Find all blocks to apply inference on, that is, reachable from the entry
// along edges with non-zero probablities
std::queue<const BlockT *> Queue;
- std::unordered_set<const BlockT *> Reachable;
+ SmallPtrSet<const BlockT *, 8> Reachable;
const BlockT *Entry = &F->front();
Queue.push(Entry);
Reachable.insert(Entry);
@@ -1526,16 +1526,14 @@ void BlockFrequencyInfoImpl<BT>::findReachableBlocks(
auto EP = BPI->getEdgeProbability(SrcBB, DstBB);
if (EP.isZero())
continue;
- if (Reachable.find(DstBB) == Reachable.end()) {
+ if (Reachable.insert(DstBB).second)
Queue.push(DstBB);
- Reachable.insert(DstBB);
- }
}
}
// Find all blocks to apply inference on, that is, backward reachable from
// the entry along (backward) edges with non-zero probablities
- std::unordered_set<const BlockT *> InverseReachable;
+ SmallPtrSet<const BlockT *, 8> InverseReachable;
for (const BlockT &BB : *F) {
// An exit block is a block without any successors
bool HasSucc = GraphTraits<const BlockT *>::child_begin(&BB) !=
@@ -1552,10 +1550,8 @@ void BlockFrequencyInfoImpl<BT>::findReachableBlocks(
auto EP = BPI->getEdgeProbability(DstBB, SrcBB);
if (EP.isZero())
continue;
- if (InverseReachable.find(DstBB) == InverseReachable.end()) {
+ if (InverseReachable.insert(DstBB).second)
Queue.push(DstBB);
- InverseReachable.insert(DstBB);
- }
}
}
@@ -1580,15 +1576,14 @@ void BlockFrequencyInfoImpl<BT>::initTransitionProbabilities(
// Find unique successors and corresponding probabilities for every block
for (size_t Src = 0; Src < NumBlocks; Src++) {
const BlockT *BB = Blocks[Src];
- std::unordered_set<const BlockT *> UniqueSuccs;
+ SmallPtrSet<const BlockT *, 2> UniqueSuccs;
for (const auto SI : children<const BlockT *>(BB)) {
// Ignore cold blocks
if (BlockIndex.find(SI) == BlockIndex.end())
continue;
// Ignore parallel edges between BB and SI blocks
- if (UniqueSuccs.find(SI) != UniqueSuccs.end())
+ if (!UniqueSuccs.insert(SI).second)
continue;
- UniqueSuccs.insert(SI);
// Ignore jumps with zero probability
auto EP = BPI->getEdgeProbability(BB, SI);
if (EP.isZero())
More information about the llvm-commits
mailing list