[compiler-rt] r177381 - tsan: do not allocate sync vars on relaxed atomic operations
Dmitry Vyukov
dvyukov at google.com
Tue Mar 19 02:15:32 PDT 2013
Author: dvyukov
Date: Tue Mar 19 04:15:31 2013
New Revision: 177381
URL: http://llvm.org/viewvc/llvm-project?rev=177381&view=rev
Log:
tsan: do not allocate sync vars on relaxed atomic operations
helps to reduce memory consumption if an atomic is used only with relaxed ops (stats)
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc?rev=177381&r1=177380&r2=177381&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc Tue Mar 19 04:15:31 2013
@@ -290,16 +290,20 @@ static void AtomicStore(ThreadState *thr
template<typename T, T (*F)(volatile T *v, T op)>
static T AtomicRMW(ThreadState *thr, uptr pc, volatile T *a, T v, morder mo) {
MemoryWriteAtomic(thr, pc, (uptr)a, SizeLog<T>());
- SyncVar *s = CTX()->synctab.GetOrCreateAndLock(thr, pc, (uptr)a, true);
- thr->clock.set(thr->tid, thr->fast_state.epoch());
- if (IsAcqRelOrder(mo))
- thr->clock.acq_rel(&s->clock);
- else if (IsReleaseOrder(mo))
- thr->clock.release(&s->clock);
- else if (IsAcquireOrder(mo))
- thr->clock.acquire(&s->clock);
+ SyncVar *s = 0;
+ if (mo != mo_relaxed) {
+ s = CTX()->synctab.GetOrCreateAndLock(thr, pc, (uptr)a, true);
+ thr->clock.set(thr->tid, thr->fast_state.epoch());
+ if (IsAcqRelOrder(mo))
+ thr->clock.acq_rel(&s->clock);
+ else if (IsReleaseOrder(mo))
+ thr->clock.release(&s->clock);
+ else if (IsAcquireOrder(mo))
+ thr->clock.acquire(&s->clock);
+ }
v = F(a, v);
- s->mtx.Unlock();
+ if (s)
+ s->mtx.Unlock();
return v;
}
@@ -350,17 +354,21 @@ static bool AtomicCAS(ThreadState *thr,
volatile T *a, T *c, T v, morder mo, morder fmo) {
(void)fmo; // Unused because llvm does not pass it yet.
MemoryWriteAtomic(thr, pc, (uptr)a, SizeLog<T>());
- SyncVar *s = CTX()->synctab.GetOrCreateAndLock(thr, pc, (uptr)a, true);
- thr->clock.set(thr->tid, thr->fast_state.epoch());
- if (IsAcqRelOrder(mo))
- thr->clock.acq_rel(&s->clock);
- else if (IsReleaseOrder(mo))
- thr->clock.release(&s->clock);
- else if (IsAcquireOrder(mo))
- thr->clock.acquire(&s->clock);
+ SyncVar *s = 0;
+ if (mo != mo_relaxed) {
+ s = CTX()->synctab.GetOrCreateAndLock(thr, pc, (uptr)a, true);
+ thr->clock.set(thr->tid, thr->fast_state.epoch());
+ if (IsAcqRelOrder(mo))
+ thr->clock.acq_rel(&s->clock);
+ else if (IsReleaseOrder(mo))
+ thr->clock.release(&s->clock);
+ else if (IsAcquireOrder(mo))
+ thr->clock.acquire(&s->clock);
+ }
T cc = *c;
T pr = func_cas(a, cc, v);
- s->mtx.Unlock();
+ if (s)
+ s->mtx.Unlock();
if (pr == cc)
return true;
*c = pr;
More information about the llvm-commits
mailing list