[PATCH] D119674: [BOLT] Make BinaryFunction::eraseInvalidBBs() thread-safe

Maksim Panchenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 13 11:15:39 PST 2022


maksfb created this revision.
maksfb added reviewers: yota9, rafauler, Amir, ayermolo.
maksfb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Calculation of the size of a basic block is not thread-safe, hence add a
lock.

Additionally, free CFG-related members after the deletion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119674

Files:
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/lib/Core/BinaryFunction.cpp


Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -348,7 +348,10 @@
     } else {
       assert(!isEntryPoint(*BB) && "all entry blocks must be valid");
       ++Count;
-      Bytes += BC.computeCodeSize(BB->begin(), BB->end());
+      if (BB->size()) {
+        std::unique_lock<std::shared_timed_mutex> Lock(BC.CtxMutex);
+        Bytes += BB->estimateSize();
+      }
     }
   }
   BasicBlocksLayout = std::move(NewLayout);
@@ -372,6 +375,9 @@
   if (Count > 0)
     recomputeLandingPads();
 
+  for (BinaryBasicBlock *BB : DeletedBasicBlocks)
+    BB->releaseCFG();
+
   return std::make_pair(Count, Bytes);
 }
 
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -710,8 +710,6 @@
   void releaseCFG() {
     for (BinaryBasicBlock *BB : BasicBlocks)
       BB->releaseCFG();
-    for (BinaryBasicBlock *BB : DeletedBasicBlocks)
-      BB->releaseCFG();
 
     clearList(CallSites);
     clearList(ColdCallSites);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119674.408283.patch
Type: text/x-patch
Size: 1208 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220213/24d03061/attachment.bin>


More information about the llvm-commits mailing list