[PATCH] D33301: [Statistics] Add a method to atomically update a statistic that contains a maximum
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 17 18:05:12 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303318: [Statistics] Add a method to atomically update a statistic that contains a… (authored by ctopper).
Changed prior to commit:
https://reviews.llvm.org/D33301?vs=99357&id=99381#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33301
Files:
llvm/trunk/include/llvm/ADT/Statistic.h
llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
llvm/trunk/lib/Transforms/Scalar/SROA.cpp
Index: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp
@@ -3898,8 +3898,7 @@
}
NumAllocaPartitionUses += NumUses;
- MaxUsesPerAllocaPartition =
- std::max<unsigned>(NumUses, MaxUsesPerAllocaPartition);
+ MaxUsesPerAllocaPartition.updateMax(NumUses);
// Now that we've processed all the slices in the new partition, check if any
// PHIs or Selects would block promotion.
@@ -4016,8 +4015,7 @@
}
NumAllocaPartitions += NumPartitions;
- MaxPartitionsPerAlloca =
- std::max<unsigned>(NumPartitions, MaxPartitionsPerAlloca);
+ MaxPartitionsPerAlloca.updateMax(NumPartitions);
// Migrate debug information from the old alloca to the new alloca(s)
// and the individual partitions.
Index: llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
===================================================================
--- llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
+++ llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
@@ -477,10 +477,8 @@
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;
Index: llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
+++ llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
@@ -110,8 +110,8 @@
Builder.FuncInfo.StatepointStackSlots.size() &&
"Broken invariant");
- StatepointMaxSlotsRequired = std::max<unsigned long>(
- StatepointMaxSlotsRequired, Builder.FuncInfo.StatepointStackSlots.size());
+ StatepointMaxSlotsRequired.updateMax(
+ Builder.FuncInfo.StatepointStackSlots.size());
return SpillSlot;
}
Index: llvm/trunk/include/llvm/ADT/Statistic.h
===================================================================
--- llvm/trunk/include/llvm/ADT/Statistic.h
+++ llvm/trunk/include/llvm/ADT/Statistic.h
@@ -101,6 +101,16 @@
return init();
}
+ void updateMax(unsigned V) {
+ unsigned PrevMax = Value.load(std::memory_order_relaxed);
+ // Keep trying to update max until we succeed or another thread produces
+ // a bigger max than us.
+ while (V > PrevMax && !Value.compare_exchange_weak(
+ PrevMax, V, std::memory_order_relaxed)) {
+ }
+ init();
+ }
+
#else // Statistics are disabled in release builds.
const Statistic &operator=(unsigned Val) {
@@ -131,6 +141,8 @@
return *this;
}
+ void updateMax(unsigned V) {}
+
#endif // !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)
protected:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33301.99381.patch
Type: text/x-patch
Size: 2978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170518/de17d55e/attachment.bin>
More information about the llvm-commits
mailing list