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