1 //===-- tsan_update_shadow_word_inl.h ---------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
12 // Body of the hottest inner loop.
13 // If we wrap this body into a function, compilers (both gcc and clang)
14 // produce sligtly less efficient code.
15 //===----------------------------------------------------------------------===//
17 StatInc(thr, StatShadowProcessed);
18 const unsigned kAccessSize = 1 << kAccessSizeLog;
19 u64 *sp = &shadow_mem[idx];
22 StatInc(thr, StatShadowZero);
24 StoreIfNotYetStored(sp, &store_word);
25 // The above StoreIfNotYetStored could be done unconditionally
26 // and it even shows 4% gain on synthetic benchmarks (r4307).
29 // is the memory access equal to the previous?
30 if (Shadow::Addr0AndSizeAreEqual(cur, old)) {
31 StatInc(thr, StatShadowSameSize);
33 if (Shadow::TidsAreEqual(old, cur)) {
34 StatInc(thr, StatShadowSameThread);
35 if (old.IsRWWeakerOrEqual(kAccessIsWrite, kIsAtomic))
36 StoreIfNotYetStored(sp, &store_word);
39 StatInc(thr, StatShadowAnotherThread);
40 if (HappensBefore(old, thr)) {
41 if (old.IsRWWeakerOrEqual(kAccessIsWrite, kIsAtomic))
42 StoreIfNotYetStored(sp, &store_word);
45 if (old.IsBothReadsOrAtomic(kAccessIsWrite, kIsAtomic))
49 // Do the memory access intersect?
50 if (Shadow::TwoRangesIntersect(old, cur, kAccessSize)) {
51 StatInc(thr, StatShadowIntersect);
52 if (Shadow::TidsAreEqual(old, cur)) {
53 StatInc(thr, StatShadowSameThread);
56 StatInc(thr, StatShadowAnotherThread);
57 if (old.IsBothReadsOrAtomic(kAccessIsWrite, kIsAtomic))
59 if (HappensBefore(old, thr))
63 // The accesses do not intersect.
64 StatInc(thr, StatShadowNotIntersect);