mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ColdBlockInfo: overhaul analysis pass
The old analysis pass doesn't take into account profile data, nor does it consider post-dominance. It primarily dealt with _fastPath/_slowPath. A block that is dominated by a cold block is itself cold. That's true whether it's forwards or backwards dominance. We can also consider a call to any `Never` returning function as a cold-exit, though the block(s) leading up to that call may be executed frequently because of concurrency. For now, I'm ignoring the concurrency case and assuming it's cold. To make use of this "no return" prediction, use the `-enable-noreturn-prediction` flag, which is currently off by default.
This commit is contained in:
@@ -27,8 +27,8 @@ private:
|
||||
uint64_t count;
|
||||
|
||||
public:
|
||||
explicit ProfileCounter() : count(UINT64_MAX) {}
|
||||
ProfileCounter(uint64_t Count) : count(Count) {
|
||||
explicit constexpr ProfileCounter() : count(UINT64_MAX) {}
|
||||
constexpr ProfileCounter(uint64_t Count) : count(Count) {
|
||||
if (Count == UINT64_MAX) {
|
||||
count = UINT64_MAX - 1;
|
||||
}
|
||||
@@ -40,6 +40,22 @@ public:
|
||||
return count;
|
||||
}
|
||||
explicit operator bool() const { return hasValue(); }
|
||||
|
||||
/// Saturating addition of another counter to this one, meaning that overflow
|
||||
/// is avoided. If overflow would have happened, this function returns true
|
||||
/// and the maximum representable value will be set in this counter.
|
||||
bool add_saturating(ProfileCounter other) {
|
||||
assert(hasValue() && other.hasValue());
|
||||
|
||||
// Will we go over the max representable value by adding other?
|
||||
if (count > ((UINT64_MAX-1) - other.count)) {
|
||||
count = UINT64_MAX - 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
count += other.count;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} // end namespace swift
|
||||
|
||||
|
||||
Reference in New Issue
Block a user