[llvm] 81ed4d0 - [UniformityAnalysis] Replace DenseMap with SmallVector indexed by block number. NFC (#210564)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 18 19:17:31 PDT 2026


Author: Fangrui Song
Date: 2026-07-19T02:17:26Z
New Revision: 81ed4d01aa5858ab3f3ffe4e5cc4f9111a8afc46

URL: https://github.com/llvm/llvm-project/commit/81ed4d01aa5858ab3f3ffe4e5cc4f9111a8afc46
DIFF: https://github.com/llvm/llvm-project/commit/81ed4d01aa5858ab3f3ffe4e5cc4f9111a8afc46.diff

LOG: [UniformityAnalysis] Replace DenseMap with SmallVector indexed by block number. NFC (#210564)

Added: 
    

Modified: 
    llvm/include/llvm/ADT/GenericUniformityImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/GenericUniformityImpl.h b/llvm/include/llvm/ADT/GenericUniformityImpl.h
index 737efde1d5e88..b7918122b891a 100644
--- a/llvm/include/llvm/ADT/GenericUniformityImpl.h
+++ b/llvm/include/llvm/ADT/GenericUniformityImpl.h
@@ -104,21 +104,26 @@ template <typename ContextT> class ModifiedPostOrder {
   void clear() { Order.clear(); }
   void compute(const CycleInfoT &CI);
 
-  unsigned count(BlockT *BB) const { return POIndex.count(BB); }
+  unsigned count(BlockT *BB) const {
+    unsigned Num = GraphTraits<BlockT *>::getNumber(BB);
+    return Num < POIndex.size() && POIndex[Num] != InvalidIndex;
+  }
   const BlockT *operator[](size_t Idx) const { return Order[Idx]; }
 
   void appendBlock(const BlockT &BB, bool IsReducibleCycleHeader = false) {
-    POIndex[&BB] = Order.size();
+    unsigned Num = GraphTraits<const BlockT *>::getNumber(&BB);
+    POIndex[Num] = Order.size();
     Order.push_back(&BB);
-    LLVM_DEBUG(dbgs() << "ModifiedPO(" << POIndex[&BB]
+    LLVM_DEBUG(dbgs() << "ModifiedPO(" << POIndex[Num]
                       << "): " << Context.print(&BB) << "\n");
     if (IsReducibleCycleHeader)
       ReducibleCycleHeaders.insert(&BB);
   }
 
   unsigned getIndex(const BlockT *BB) const {
-    assert(POIndex.count(BB));
-    return POIndex.lookup(BB);
+    unsigned Num = GraphTraits<const BlockT *>::getNumber(BB);
+    assert(Num < POIndex.size() && POIndex[Num] != InvalidIndex);
+    return POIndex[Num];
   }
 
   bool isReducibleCycleHeader(const BlockT *BB) const {
@@ -126,8 +131,10 @@ template <typename ContextT> class ModifiedPostOrder {
   }
 
 private:
+  static constexpr unsigned InvalidIndex = -1u;
+
   SmallVector<const BlockT *> Order;
-  DenseMap<const BlockT *, unsigned> POIndex;
+  SmallVector<unsigned> POIndex;
   SmallPtrSet<const BlockT *, 32> ReducibleCycleHeaders;
   const ContextT &Context;
 
@@ -1434,6 +1441,7 @@ void llvm::ModifiedPostOrder<ContextT>::compute(const CycleInfoT &CI) {
   SmallPtrSet<const BlockT *, 32> Finalized;
   SmallVector<const BlockT *> Stack;
   auto *F = CI.getFunction();
+  POIndex.assign(GraphTraits<const FunctionT *>::getMaxNumber(F), InvalidIndex);
   Stack.reserve(24); // FIXME made-up number
   Stack.push_back(&F->front());
   computeStackPO(Stack, CI, CycleRef(), Finalized);


        


More information about the llvm-commits mailing list