Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 1 | /*! \file */ |
| 2 | /* |
| 3 | * tsan_annotations.h -- ThreadSanitizer annotations to support data |
| 4 | * race detection in OpenMP programs. |
| 5 | */ |
| 6 | |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // The LLVM Compiler Infrastructure |
| 10 | // |
| 11 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 12 | // Source Licenses. See LICENSE.txt for details. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef TSAN_ANNOTATIONS_H |
| 17 | #define TSAN_ANNOTATIONS_H |
| 18 | |
| 19 | #include "kmp_config.h" |
| 20 | |
| 21 | /* types as used in tsan/rtl/tsan_interface_ann.cc */ |
| 22 | typedef unsigned long uptr; |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 23 | typedef signed long sptr; |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | /* Declaration of all annotation functions in tsan/rtl/tsan_interface_ann.cc */ |
| 30 | void AnnotateHappensBefore(const char *f, int l, uptr addr); |
| 31 | void AnnotateHappensAfter(const char *f, int l, uptr addr); |
| 32 | void AnnotateCondVarSignal(const char *f, int l, uptr cv); |
| 33 | void AnnotateCondVarSignalAll(const char *f, int l, uptr cv); |
| 34 | void AnnotateMutexIsNotPHB(const char *f, int l, uptr mu); |
| 35 | void AnnotateCondVarWait(const char *f, int l, uptr cv, uptr lock); |
| 36 | void AnnotateRWLockCreate(const char *f, int l, uptr m); |
| 37 | void AnnotateRWLockCreateStatic(const char *f, int l, uptr m); |
| 38 | void AnnotateRWLockDestroy(const char *f, int l, uptr m); |
| 39 | void AnnotateRWLockAcquired(const char *f, int l, uptr m, uptr is_w); |
| 40 | void AnnotateRWLockReleased(const char *f, int l, uptr m, uptr is_w); |
| 41 | void AnnotateTraceMemory(const char *f, int l, uptr mem); |
| 42 | void AnnotateFlushState(const char *f, int l); |
| 43 | void AnnotateNewMemory(const char *f, int l, uptr mem, uptr size); |
| 44 | void AnnotateNoOp(const char *f, int l, uptr mem); |
| 45 | void AnnotateFlushExpectedRaces(const char *f, int l); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 46 | void AnnotateEnableRaceDetection(const char *f, int l, int enable); |
| 47 | void AnnotateMutexIsUsedAsCondVar(const char *f, int l, uptr mu); |
| 48 | void AnnotatePCQGet(const char *f, int l, uptr pcq); |
| 49 | void AnnotatePCQPut(const char *f, int l, uptr pcq); |
| 50 | void AnnotatePCQDestroy(const char *f, int l, uptr pcq); |
| 51 | void AnnotatePCQCreate(const char *f, int l, uptr pcq); |
| 52 | void AnnotateExpectRace(const char *f, int l, uptr mem, char *desc); |
| 53 | void AnnotateBenignRaceSized(const char *f, int l, uptr mem, uptr size, |
| 54 | char *desc); |
| 55 | void AnnotateBenignRace(const char *f, int l, uptr mem, char *desc); |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 56 | void AnnotateIgnoreReadsBegin(const char *f, int l); |
| 57 | void AnnotateIgnoreReadsEnd(const char *f, int l); |
| 58 | void AnnotateIgnoreWritesBegin(const char *f, int l); |
| 59 | void AnnotateIgnoreWritesEnd(const char *f, int l); |
| 60 | void AnnotateIgnoreSyncBegin(const char *f, int l); |
| 61 | void AnnotateIgnoreSyncEnd(const char *f, int l); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 62 | void AnnotatePublishMemoryRange(const char *f, int l, uptr addr, uptr size); |
| 63 | void AnnotateUnpublishMemoryRange(const char *f, int l, uptr addr, uptr size); |
| 64 | void AnnotateThreadName(const char *f, int l, char *name); |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 65 | void WTFAnnotateHappensBefore(const char *f, int l, uptr addr); |
| 66 | void WTFAnnotateHappensAfter(const char *f, int l, uptr addr); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 67 | void WTFAnnotateBenignRaceSized(const char *f, int l, uptr mem, uptr sz, |
| 68 | char *desc); |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 69 | int RunningOnValgrind(); |
| 70 | double ValgrindSlowdown(void); |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 71 | const char *ThreadSanitizerQuery(const char *query); |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 72 | void AnnotateMemoryIsInitialized(const char *f, int l, uptr mem, uptr sz); |
| 73 | |
| 74 | #ifdef __cplusplus |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | #ifdef TSAN_SUPPORT |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 79 | #define ANNOTATE_HAPPENS_AFTER(addr) \ |
| 80 | AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr) |
| 81 | #define ANNOTATE_HAPPENS_BEFORE(addr) \ |
| 82 | AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr) |
| 83 | #define ANNOTATE_IGNORE_WRITES_BEGIN() \ |
| 84 | AnnotateIgnoreWritesBegin(__FILE__, __LINE__) |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 85 | #define ANNOTATE_IGNORE_WRITES_END() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 86 | #define ANNOTATE_RWLOCK_CREATE(lck) \ |
| 87 | AnnotateRWLockCreate(__FILE__, __LINE__, (uptr)lck) |
| 88 | #define ANNOTATE_RWLOCK_RELEASED(lck) \ |
| 89 | AnnotateRWLockAcquired(__FILE__, __LINE__, (uptr)lck, 1) |
| 90 | #define ANNOTATE_RWLOCK_ACQUIRED(lck) \ |
| 91 | AnnotateRWLockReleased(__FILE__, __LINE__, (uptr)lck, 1) |
| 92 | #define ANNOTATE_BARRIER_BEGIN(addr) \ |
| 93 | AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr) |
| 94 | #define ANNOTATE_BARRIER_END(addr) \ |
| 95 | AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr) |
| 96 | #define ANNOTATE_REDUCE_AFTER(addr) \ |
| 97 | AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr) |
| 98 | #define ANNOTATE_REDUCE_BEFORE(addr) \ |
| 99 | AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr) |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 100 | #else |
| 101 | #define ANNOTATE_HAPPENS_AFTER(addr) |
| 102 | #define ANNOTATE_HAPPENS_BEFORE(addr) |
| 103 | #define ANNOTATE_IGNORE_WRITES_BEGIN() |
| 104 | #define ANNOTATE_IGNORE_WRITES_END() |
| 105 | #define ANNOTATE_RWLOCK_CREATE(lck) |
| 106 | #define ANNOTATE_RWLOCK_RELEASED(lck) |
| 107 | #define ANNOTATE_RWLOCK_ACQUIRED(lck) |
Jonas Hahnfeld | 35801a2 | 2017-02-15 08:14:22 +0000 | [diff] [blame] | 108 | #define ANNOTATE_BARRIER_BEGIN(addr) |
| 109 | #define ANNOTATE_BARRIER_END(addr) |
Jonas Hahnfeld | 50fed04 | 2016-11-07 15:58:36 +0000 | [diff] [blame] | 110 | #define ANNOTATE_REDUCE_AFTER(addr) |
| 111 | #define ANNOTATE_REDUCE_BEFORE(addr) |
| 112 | #endif |
| 113 | |
| 114 | #define ANNOTATE_QUEUING |
| 115 | #define ANNOTATE_TICKET |
| 116 | #define ANNOTATE_FUTEX |
| 117 | #define ANNOTATE_TAS |
| 118 | #define ANNOTATE_DRDPA |
| 119 | |
| 120 | #ifdef ANNOTATE_QUEUING |
| 121 | #define ANNOTATE_QUEUING_CREATE(lck) |
| 122 | #define ANNOTATE_QUEUING_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) |
| 123 | #define ANNOTATE_QUEUING_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) |
| 124 | #else |
| 125 | #define ANNOTATE_QUEUING_CREATE(lck) |
| 126 | #define ANNOTATE_QUEUING_RELEASED(lck) |
| 127 | #define ANNOTATE_QUEUING_ACQUIRED(lck) |
| 128 | #endif |
| 129 | |
| 130 | #ifdef ANNOTATE_TICKET |
| 131 | #define ANNOTATE_TICKET_CREATE(lck) |
| 132 | #define ANNOTATE_TICKET_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) |
| 133 | #define ANNOTATE_TICKET_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) |
| 134 | #else |
| 135 | #define ANNOTATE_TICKET_CREATE(lck) |
| 136 | #define ANNOTATE_TICKET_RELEASED(lck) |
| 137 | #define ANNOTATE_TICKET_ACQUIRED(lck) |
| 138 | #endif |
| 139 | |
| 140 | #ifdef ANNOTATE_FUTEX |
| 141 | #define ANNOTATE_FUTEX_CREATE(lck) |
| 142 | #define ANNOTATE_FUTEX_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) |
| 143 | #define ANNOTATE_FUTEX_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) |
| 144 | #else |
| 145 | #define ANNOTATE_FUTEX_CREATE(lck) |
| 146 | #define ANNOTATE_FUTEX_RELEASED(lck) |
| 147 | #define ANNOTATE_FUTEX_ACQUIRED(lck) |
| 148 | #endif |
| 149 | |
| 150 | #ifdef ANNOTATE_TAS |
| 151 | #define ANNOTATE_TAS_CREATE(lck) |
| 152 | #define ANNOTATE_TAS_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) |
| 153 | #define ANNOTATE_TAS_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) |
| 154 | #else |
| 155 | #define ANNOTATE_TAS_CREATE(lck) |
| 156 | #define ANNOTATE_TAS_RELEASED(lck) |
| 157 | #define ANNOTATE_TAS_ACQUIRED(lck) |
| 158 | #endif |
| 159 | |
| 160 | #ifdef ANNOTATE_DRDPA |
| 161 | #define ANNOTATE_DRDPA_CREATE(lck) |
| 162 | #define ANNOTATE_DRDPA_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) |
| 163 | #define ANNOTATE_DRDPA_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) |
| 164 | #else |
| 165 | #define ANNOTATE_DRDPA_CREATE(lck) |
| 166 | #define ANNOTATE_DRDPA_RELEASED(lck) |
| 167 | #define ANNOTATE_DRDPA_ACQUIRED(lck) |
| 168 | #endif |
| 169 | |
| 170 | #endif |