[compiler-rt] 14c7507 - tsan: add LIKELY/UNLIKELY to MetaMap::GetSync

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 04:30:00 PDT 2021


Author: Dmitry Vyukov
Date: 2021-08-02T13:29:55+02:00
New Revision: 14c7507b9d5936074076eb19deecd163c1315f94

URL: https://github.com/llvm/llvm-project/commit/14c7507b9d5936074076eb19deecd163c1315f94
DIFF: https://github.com/llvm/llvm-project/commit/14c7507b9d5936074076eb19deecd163c1315f94.diff

LOG: tsan: add LIKELY/UNLIKELY to MetaMap::GetSync

MetaMap::GetSync shows up in profiles,
so add LIKELY/UNLIKELY annotations.

Depends on D107256.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107257

Added: 
    

Modified: 
    compiler-rt/lib/tsan/rtl/tsan_sync.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_sync.cpp b/compiler-rt/lib/tsan/rtl/tsan_sync.cpp
index dc1081a9b8b1..a1bcdcf9cfdb 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_sync.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_sync.cpp
@@ -194,18 +194,13 @@ SyncVar *MetaMap::GetSync(ThreadState *thr, uptr pc, uptr addr, bool create) {
   u32 *meta = MemToMeta(addr);
   u32 idx0 = *meta;
   u32 myidx = 0;
-  SyncVar *mys = 0;
+  SyncVar *mys = nullptr;
   for (;;) {
-    u32 idx = idx0;
-    for (;;) {
-      if (idx == 0)
-        break;
-      if (idx & kFlagBlock)
-        break;
+    for (u32 idx = idx0; idx && !(idx & kFlagBlock);) {
       DCHECK(idx & kFlagSync);
       SyncVar * s = sync_alloc_.Map(idx & ~kFlagMask);
-      if (s->addr == addr) {
-        if (myidx != 0) {
+      if (LIKELY(s->addr == addr)) {
+        if (UNLIKELY(myidx != 0)) {
           mys->Reset(thr->proc());
           sync_alloc_.Free(&thr->proc()->sync_cache, myidx);
         }


        


More information about the llvm-commits mailing list