|
36 | 36 | #include "llvm/IR/Metadata.h"
|
37 | 37 | #include "llvm/IR/Module.h"
|
38 | 38 | #include "llvm/IR/Type.h"
|
| 39 | +#include "llvm/ProfileData/InstrProf.h" |
39 | 40 | #include "llvm/Support/CommandLine.h"
|
40 | 41 | #include "llvm/Support/Debug.h"
|
41 | 42 | #include "llvm/Support/MathExtras.h"
|
@@ -243,6 +244,24 @@ static bool isVtableAccess(Instruction *I) {
|
243 | 244 | return false;
|
244 | 245 | }
|
245 | 246 |
|
| 247 | +// Do not instrument known races/"benign races" that come from compiler |
| 248 | +// instrumentatin. The user has no way of suppressing them. |
| 249 | +bool shouldInstrumentReadWriteFromAddress(Value *Addr) { |
| 250 | + // Peel off GEPs and BitCasts. |
| 251 | + Addr = Addr->stripInBoundsOffsets(); |
| 252 | + |
| 253 | + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Addr)) { |
| 254 | + if (GV->hasSection()) { |
| 255 | + StringRef SectionName = GV->getSection(); |
| 256 | + // Check if the global is in the PGO counters section. |
| 257 | + if (SectionName.endswith(getInstrProfCountersSectionName( |
| 258 | + /*AddSegment=*/false))) |
| 259 | + return false; |
| 260 | + } |
| 261 | + } |
| 262 | + return true; |
| 263 | +} |
| 264 | + |
246 | 265 | bool ThreadSanitizer::addrPointsToConstantData(Value *Addr) {
|
247 | 266 | // If this is a GEP, just analyze its pointer operand.
|
248 | 267 | if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Addr))
|
@@ -285,10 +304,15 @@ void ThreadSanitizer::chooseInstructionsToInstrument(
|
285 | 304 | E = Local.rend(); It != E; ++It) {
|
286 | 305 | Instruction *I = *It;
|
287 | 306 | if (StoreInst *Store = dyn_cast<StoreInst>(I)) {
|
288 |
| - WriteTargets.insert(Store->getPointerOperand()); |
| 307 | + Value *Addr = Store->getPointerOperand(); |
| 308 | + if (!shouldInstrumentReadWriteFromAddress(Addr)) |
| 309 | + continue; |
| 310 | + WriteTargets.insert(Addr); |
289 | 311 | } else {
|
290 | 312 | LoadInst *Load = cast<LoadInst>(I);
|
291 | 313 | Value *Addr = Load->getPointerOperand();
|
| 314 | + if (!shouldInstrumentReadWriteFromAddress(Addr)) |
| 315 | + continue; |
292 | 316 | if (WriteTargets.count(Addr)) {
|
293 | 317 | // We will write to this temp, so no reason to analyze the read.
|
294 | 318 | NumOmittedReadsBeforeWrite++;
|
|
0 commit comments