[compiler-rt] b3420ad - [scudo][standalone] Code tidying (NFC)

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 16:00:49 PST 2020


Author: Kostya Kortchinsky
Date: 2020-11-02T16:00:31-08:00
New Revision: b3420adf5a8491b4c63b54c7750fbbb6368a0a23

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

LOG: [scudo][standalone] Code tidying (NFC)

- we have clutter-reducing helpers for relaxed atomics that were barely
  used, use them everywhere we can
- clang-format everything with a recent version

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

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/memtag.h
    compiler-rt/lib/scudo/standalone/options.h
    compiler-rt/lib/scudo/standalone/primary32.h
    compiler-rt/lib/scudo/standalone/primary64.h
    compiler-rt/lib/scudo/standalone/secondary.h
    compiler-rt/lib/scudo/standalone/stack_depot.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/memtag.h b/compiler-rt/lib/scudo/standalone/memtag.h
index 519c827e6828..b9f8ccd41627 100644
--- a/compiler-rt/lib/scudo/standalone/memtag.h
+++ b/compiler-rt/lib/scudo/standalone/memtag.h
@@ -28,9 +28,7 @@ inline constexpr uptr archMemoryTagGranuleSize() { return 16; }
 
 inline uptr untagPointer(uptr Ptr) { return Ptr & ((1ULL << 56) - 1); }
 
-inline uint8_t extractTag(uptr Ptr) {
-  return (Ptr >> 56) & 0xf;
-}
+inline uint8_t extractTag(uptr Ptr) { return (Ptr >> 56) & 0xf; }
 
 #else
 
@@ -82,7 +80,7 @@ inline void enableMemoryTagChecksTestOnly() {
 class ScopedDisableMemoryTagChecks {
   size_t PrevTCO;
 
- public:
+public:
   ScopedDisableMemoryTagChecks() {
     __asm__ __volatile__(".arch_extension mte; mrs %0, tco; msr tco, #1"
                          : "=r"(PrevTCO));
@@ -190,8 +188,8 @@ inline void resizeTaggedChunk(uptr OldPtr, uptr NewPtr, uptr BlockEnd) {
 
   2:
   )"
-                       : [ Cur ] "+&r"(RoundOldPtr), [ End ] "+&r"(NewPtr)
-                       : [ BlockEnd ] "r"(BlockEnd)
+                       : [Cur] "+&r"(RoundOldPtr), [End] "+&r"(NewPtr)
+                       : [BlockEnd] "r"(BlockEnd)
                        : "memory");
 }
 

diff  --git a/compiler-rt/lib/scudo/standalone/options.h b/compiler-rt/lib/scudo/standalone/options.h
index 3051e8af4f7a..2cffc4d75c38 100644
--- a/compiler-rt/lib/scudo/standalone/options.h
+++ b/compiler-rt/lib/scudo/standalone/options.h
@@ -40,9 +40,7 @@ struct AtomicOptions {
   atomic_u32 Val;
 
 public:
-  Options load() const {
-    return Options{atomic_load(&Val, memory_order_relaxed)};
-  }
+  Options load() const { return Options{atomic_load_relaxed(&Val)}; }
 
   void clear(OptionBit Opt) {
     atomic_fetch_and(&Val, ~(1U << static_cast<u32>(Opt)),
@@ -54,7 +52,7 @@ struct AtomicOptions {
   }
 
   void setFillContentsMode(FillContentsMode FillContents) {
-    u32 Opts = atomic_load(&Val, memory_order_relaxed), NewOpts;
+    u32 Opts = atomic_load_relaxed(&Val), NewOpts;
     do {
       NewOpts = Opts;
       NewOpts &= ~(3U << static_cast<u32>(OptionBit::FillContents0of2));

diff  --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h
index a159a584c7cb..d6c294b72095 100644
--- a/compiler-rt/lib/scudo/standalone/primary32.h
+++ b/compiler-rt/lib/scudo/standalone/primary32.h
@@ -190,7 +190,7 @@ class SizeClassAllocator32 {
       const s32 Interval =
           Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
               MinReleaseToOsIntervalMs);
-      atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
+      atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
       return true;
     }
     // Not supported by the Primary, but not an error either.
@@ -462,8 +462,7 @@ class SizeClassAllocator32 {
     }
 
     if (!Force) {
-      const s32 IntervalMs =
-          atomic_load(&ReleaseToOsIntervalMs, memory_order_relaxed);
+      const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
       if (IntervalMs < 0)
         return 0;
       if (Sci->ReleaseInfo.LastReleaseAtNs +

diff  --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 1f7ac38cefed..b6c6f32cda3d 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -191,7 +191,7 @@ class SizeClassAllocator64 {
       const s32 Interval =
           Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
               MinReleaseToOsIntervalMs);
-      atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
+      atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
       return true;
     }
     // Not supported by the Primary, but not an error either.
@@ -470,8 +470,7 @@ class SizeClassAllocator64 {
     }
 
     if (!Force) {
-      const s32 IntervalMs =
-          atomic_load(&ReleaseToOsIntervalMs, memory_order_relaxed);
+      const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
       if (IntervalMs < 0)
         return 0;
       if (Region->ReleaseInfo.LastReleaseAtNs +

diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index da435fd86adc..ca86d2dd212d 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -94,7 +94,7 @@ class MapAllocatorCache {
     bool EntryCached = false;
     bool EmptyCache = false;
     const u64 Time = getMonotonicTime();
-    const u32 MaxCount = atomic_load(&MaxEntriesCount, memory_order_relaxed);
+    const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
     {
       ScopedLock L(Mutex);
       if (EntriesCount >= MaxCount) {
@@ -121,15 +121,14 @@ class MapAllocatorCache {
     s32 Interval;
     if (EmptyCache)
       empty();
-    else if ((Interval = atomic_load(&ReleaseToOsIntervalMs,
-                                     memory_order_relaxed)) >= 0)
+    else if ((Interval = atomic_load_relaxed(&ReleaseToOsIntervalMs)) >= 0)
       releaseOlderThan(Time - static_cast<u64>(Interval) * 1000000);
     return EntryCached;
   }
 
   bool retrieve(uptr Size, LargeBlock::Header **H) {
     const uptr PageSize = getPageSizeCached();
-    const u32 MaxCount = atomic_load(&MaxEntriesCount, memory_order_relaxed);
+    const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
     ScopedLock L(Mutex);
     if (EntriesCount == 0)
       return false;
@@ -154,8 +153,8 @@ class MapAllocatorCache {
   }
 
   bool canCache(uptr Size) {
-    return atomic_load(&MaxEntriesCount, memory_order_relaxed) != 0U &&
-           Size <= atomic_load(&MaxEntrySize, memory_order_relaxed);
+    return atomic_load_relaxed(&MaxEntriesCount) != 0U &&
+           Size <= atomic_load_relaxed(&MaxEntrySize);
   }
 
   bool setOption(Option O, sptr Value) {
@@ -163,17 +162,16 @@ class MapAllocatorCache {
       const s32 Interval =
           Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
               MinReleaseToOsIntervalMs);
-      atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
+      atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
       return true;
     } else if (O == Option::MaxCacheEntriesCount) {
       const u32 MaxCount = static_cast<u32>(Value);
       if (MaxCount > EntriesArraySize)
         return false;
-      atomic_store(&MaxEntriesCount, MaxCount, memory_order_relaxed);
+      atomic_store_relaxed(&MaxEntriesCount, MaxCount);
       return true;
     } else if (O == Option::MaxCacheEntrySize) {
-      atomic_store(&MaxEntrySize, static_cast<uptr>(Value),
-                   memory_order_relaxed);
+      atomic_store_relaxed(&MaxEntrySize, static_cast<uptr>(Value));
       return true;
     }
     // Not supported by the Secondary Cache, but not an error either.

diff  --git a/compiler-rt/lib/scudo/standalone/stack_depot.h b/compiler-rt/lib/scudo/standalone/stack_depot.h
index f2f4d9597795..7968f7efff7c 100644
--- a/compiler-rt/lib/scudo/standalone/stack_depot.h
+++ b/compiler-rt/lib/scudo/standalone/stack_depot.h
@@ -20,7 +20,7 @@ class MurMur2HashBuilder {
   static const u32 R = 24;
   u32 H;
 
- public:
+public:
   explicit MurMur2HashBuilder(u32 Init = 0) { H = Seed ^ Init; }
   void add(u32 K) {
     K *= M;


        


More information about the llvm-commits mailing list