BlockFrequencyInfoImpl.cpp (276479) | BlockFrequencyInfoImpl.cpp (277320) |
---|---|
1//===- BlockFrequencyImplInfo.cpp - Block Frequency Info Implementation ---===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Loops should be simplified before this analysis. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/Analysis/BlockFrequencyInfoImpl.h" 15#include "llvm/ADT/SCCIterator.h" 16#include "llvm/Support/raw_ostream.h" | 1//===- BlockFrequencyImplInfo.cpp - Block Frequency Info Implementation ---===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Loops should be simplified before this analysis. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/Analysis/BlockFrequencyInfoImpl.h" 15#include "llvm/ADT/SCCIterator.h" 16#include "llvm/Support/raw_ostream.h" |
17#include <deque> | 17#include <numeric> |
18 19using namespace llvm; 20using namespace llvm::bfi_detail; 21 22#define DEBUG_TYPE "block-freq" 23 24ScaledNumber<uint64_t> BlockMass::toScaled() const { 25 if (isFull()) --- 92 unchanged lines hidden (view full) --- 118static void combineWeight(Weight &W, const Weight &OtherW) { 119 assert(OtherW.TargetNode.isValid()); 120 if (!W.Amount) { 121 W = OtherW; 122 return; 123 } 124 assert(W.Type == OtherW.Type); 125 assert(W.TargetNode == OtherW.TargetNode); | 18 19using namespace llvm; 20using namespace llvm::bfi_detail; 21 22#define DEBUG_TYPE "block-freq" 23 24ScaledNumber<uint64_t> BlockMass::toScaled() const { 25 if (isFull()) --- 92 unchanged lines hidden (view full) --- 118static void combineWeight(Weight &W, const Weight &OtherW) { 119 assert(OtherW.TargetNode.isValid()); 120 if (!W.Amount) { 121 W = OtherW; 122 return; 123 } 124 assert(W.Type == OtherW.Type); 125 assert(W.TargetNode == OtherW.TargetNode); |
126 assert(W.Amount < W.Amount + OtherW.Amount && "Unexpected overflow"); 127 W.Amount += OtherW.Amount; | 126 assert(OtherW.Amount && "Expected non-zero weight"); 127 if (W.Amount > W.Amount + OtherW.Amount) 128 // Saturate on overflow. 129 W.Amount = UINT64_MAX; 130 else 131 W.Amount += OtherW.Amount; |
128} 129static void combineWeightsBySorting(WeightList &Weights) { 130 // Sort so edges to the same node are adjacent. 131 std::sort(Weights.begin(), Weights.end(), 132 [](const Weight &L, 133 const Weight &R) { return L.TargetNode < R.TargetNode; }); 134 135 // Combine adjacent edges. --- 66 unchanged lines hidden (view full) --- 202 // for each weight can cause a 32-bit overflow. 203 int Shift = 0; 204 if (DidOverflow) 205 Shift = 33; 206 else if (Total > UINT32_MAX) 207 Shift = 33 - countLeadingZeros(Total); 208 209 // Early exit if nothing needs to be scaled. | 132} 133static void combineWeightsBySorting(WeightList &Weights) { 134 // Sort so edges to the same node are adjacent. 135 std::sort(Weights.begin(), Weights.end(), 136 [](const Weight &L, 137 const Weight &R) { return L.TargetNode < R.TargetNode; }); 138 139 // Combine adjacent edges. --- 66 unchanged lines hidden (view full) --- 206 // for each weight can cause a 32-bit overflow. 207 int Shift = 0; 208 if (DidOverflow) 209 Shift = 33; 210 else if (Total > UINT32_MAX) 211 Shift = 33 - countLeadingZeros(Total); 212 213 // Early exit if nothing needs to be scaled. |
210 if (!Shift) | 214 if (!Shift) { 215 // If we didn't overflow then combineWeights() shouldn't have changed the 216 // sum of the weights, but let's double-check. 217 assert(Total == std::accumulate(Weights.begin(), Weights.end(), UINT64_C(0), 218 [](uint64_t Sum, const Weight &W) { 219 return Sum + W.Amount; 220 }) && 221 "Expected total to be correct"); |
211 return; | 222 return; |
223 } |
|
212 213 // Recompute the total through accumulation (rather than shifting it) so that | 224 225 // Recompute the total through accumulation (rather than shifting it) so that |
214 // it's accurate after shifting. | 226 // it's accurate after shifting and any changes combineWeights() made above. |
215 Total = 0; 216 217 // Sum the weights to each node and shift right if necessary. 218 for (Weight &W : Weights) { 219 // Scale down below UINT32_MAX. Since Shift is larger than necessary, we 220 // can round here without concern about overflow. 221 assert(W.TargetNode.isValid()); 222 W.Amount = std::max(UINT64_C(1), shiftRightAndRound(W.Amount, Shift)); --- 475 unchanged lines hidden --- | 227 Total = 0; 228 229 // Sum the weights to each node and shift right if necessary. 230 for (Weight &W : Weights) { 231 // Scale down below UINT32_MAX. Since Shift is larger than necessary, we 232 // can round here without concern about overflow. 233 assert(W.TargetNode.isValid()); 234 W.Amount = std::max(UINT64_C(1), shiftRightAndRound(W.Amount, Shift)); --- 475 unchanged lines hidden --- |