diff options
author | Craig Topper <craig.topper@gmail.com> | 2017-05-18 00:51:39 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2017-05-18 00:51:39 +0000 |
commit | 8a950275f77981c10e10e6497114f07fef62beb7 (patch) | |
tree | cce4e5e5a8986be6fe78ba5c8dcc3e107369d9ed /llvm/lib/Analysis/CallGraphSCCPass.cpp | |
parent | 9add1594d2cd5250bf6ea57bcfdb3dce676ba736 (diff) | |
download | bcm5719-llvm-8a950275f77981c10e10e6497114f07fef62beb7.tar.gz bcm5719-llvm-8a950275f77981c10e10e6497114f07fef62beb7.zip |
[Statistics] Add a method to atomically update a statistic that contains a maximum
Summary:
There are several places in the codebase that try to calculate a maximum value in a Statistic object. We currently do this in one of two ways:
MaxNumFoo = std::max(MaxNumFoo, NumFoo);
or
MaxNumFoo = (MaxNumFoo > NumFoo) ? MaxNumFoo : NumFoo;
The first version reads from MaxNumFoo one time and uncontionally rwrites to it. The second version possibly reads it twice depending on the result of the first compare. But we have no way of knowing if the value was changed by another thread between the reads and the writes.
This patch adds a method to the Statistic object that can ensure that we only store if our value is the max and the previous max didn't change after we read it. If it changed we'll recheck if our value should still be the max or not and try again.
This spawned from an audit I'm trying to do of all places we uses the implicit conversion to unsigned on the Statistics objects. See my previous thread on llvm-dev https://groups.google.com/forum/#!topic/llvm-dev/yfvxiorKrDQ
Reviewers: dberlin, chandlerc, hfinkel, dblaikie
Reviewed By: chandlerc
Subscribers: llvm-commits, sanjoy
Differential Revision: https://reviews.llvm.org/D33301
llvm-svn: 303318
Diffstat (limited to 'llvm/lib/Analysis/CallGraphSCCPass.cpp')
-rw-r--r-- | llvm/lib/Analysis/CallGraphSCCPass.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp index 8058e5b1935..5896e6e0902 100644 --- a/llvm/lib/Analysis/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp @@ -477,10 +477,8 @@ bool CGPassManager::runOnModule(Module &M) { if (DevirtualizedCall) DEBUG(dbgs() << " CGSCCPASSMGR: Stopped iteration after " << Iteration << " times, due to -max-cg-scc-iterations\n"); - - if (Iteration > MaxSCCIterations) - MaxSCCIterations = Iteration; - + + MaxSCCIterations.updateMax(Iteration); } Changed |= doFinalization(CG); return Changed; |