[PATCH] D83596: [BPI] Compile time improvement when erasing blocks (NFC)

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 10 16:25:59 PDT 2020


tejohnson created this revision.
tejohnson added reviewers: davidxl, xur.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

eraseBlock is trying to erase all probability info for the given BB.
This info is stored in a DenseMap organized like so:

  using Edge = std::pair<const BasicBlock *, unsigned>;
  DenseMap<Edge, BranchProbability> Probs;

where the unsigned in the Edge key is the successor id.

It was walking through every single map entry, checking if the BB in the
key's pair matched the given BB. Much more efficient is to do what
another method (getEdgeProbability) was already doing, which is to walk
the successors of the BB, and simply do a map lookup on the key formed
from each <BB, successor id> pair.

Doing this dropped the overall compile time for a file containing a
very large function by around 32%.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83596

Files:
  llvm/lib/Analysis/BranchProbabilityInfo.cpp


Index: llvm/lib/Analysis/BranchProbabilityInfo.cpp
===================================================================
--- llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -1056,10 +1056,10 @@
 }
 
 void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) {
-  for (auto I = Probs.begin(), E = Probs.end(); I != E; ++I) {
-    auto Key = I->first;
-    if (Key.first == BB)
-      Probs.erase(Key);
+  for (const_succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
+    auto MapI = Probs.find(std::make_pair(BB, I.getSuccessorIndex()));
+    if (MapI != Probs.end())
+      Probs.erase(MapI);
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83596.277164.patch
Type: text/x-patch
Size: 668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200710/2eec1a63/attachment.bin>


More information about the llvm-commits mailing list