1717
1818#include < cmath>
1919
20- namespace llvm {
20+ using namespace llvm ;
2121
22- static const unsigned heatSize = 100 ;
23- static const char heatPalette[heatSize ][8 ] = {
22+ static constexpr unsigned HeatSize = 100 ;
23+ static constexpr char HeatPalette[HeatSize ][8 ] = {
2424 " #3d50c3" , " #4055c8" , " #4358cb" , " #465ecf" , " #4961d2" , " #4c66d6" , " #4f69d9" ,
2525 " #536edd" , " #5572df" , " #5977e3" , " #5b7ae5" , " #5f7fe8" , " #6282ea" , " #6687ed" ,
2626 " #6a8bef" , " #6c8ff1" , " #7093f3" , " #7396f5" , " #779af7" , " #7a9df8" , " #7ea1fa" ,
@@ -37,43 +37,37 @@ static const char heatPalette[heatSize][8] = {
3737 " #d24b40" , " #d0473d" , " #cc403a" , " #ca3b37" , " #c53334" , " #c32e31" , " #be242e" ,
3838 " #bb1b2c" , " #b70d28" };
3939
40- uint64_t
41- getNumOfCalls (Function &callerFunction, Function &calledFunction) {
42- uint64_t counter = 0 ;
43- for (User *U : calledFunction.users ()) {
44- if (auto CI = dyn_cast<CallInst>(U)) {
45- if (CI->getCaller () == (&callerFunction)) {
46- counter += 1 ;
47- }
48- }
49- }
50- return counter;
40+ uint64_t llvm::getNumOfCalls (const Function &CallerFunction,
41+ const Function &CalledFunction) {
42+ uint64_t Counter = 0 ;
43+ for (const User *U : CalledFunction.users ())
44+ if (auto CI = dyn_cast<CallInst>(U))
45+ Counter += CI->getCaller () == &CallerFunction;
46+ return Counter;
5147}
5248
53- uint64_t getMaxFreq (const Function &F, const BlockFrequencyInfo *BFI) {
54- uint64_t maxFreq = 0 ;
49+ uint64_t llvm:: getMaxFreq (const Function &F, const BlockFrequencyInfo *BFI) {
50+ uint64_t MaxFreq = 0 ;
5551 for (const BasicBlock &BB : F) {
56- uint64_t freqVal = BFI->getBlockFreq (&BB).getFrequency ();
57- if (freqVal >= maxFreq )
58- maxFreq = freqVal ;
52+ uint64_t FreqVal = BFI->getBlockFreq (&BB).getFrequency ();
53+ if (FreqVal >= MaxFreq )
54+ MaxFreq = FreqVal ;
5955 }
60- return maxFreq ;
56+ return MaxFreq ;
6157}
6258
63- std::string getHeatColor (uint64_t freq , uint64_t maxFreq ) {
64- if (freq > maxFreq )
65- freq = maxFreq ;
66- double percent = (freq > 0 ) ? log2 (double (freq )) / log2 (maxFreq ) : 0 ;
67- return getHeatColor (percent );
59+ std::string llvm:: getHeatColor (uint64_t Freq , uint64_t MaxFreq ) {
60+ if (Freq > MaxFreq )
61+ Freq = MaxFreq ;
62+ double Percent = (Freq > 0 ) ? log2 (double (Freq )) / log2 (MaxFreq ) : 0 ;
63+ return getHeatColor (Percent );
6864}
6965
70- std::string getHeatColor (double percent ) {
71- if (percent > 1.0 )
72- percent = 1.0 ;
73- if (percent < 0.0 )
74- percent = 0.0 ;
75- unsigned colorId = unsigned (round (percent * (heatSize - 1.0 )));
76- return heatPalette[colorId ];
66+ std::string llvm:: getHeatColor (double Percent ) {
67+ if (Percent > 1.0 )
68+ Percent = 1.0 ;
69+ if (Percent < 0.0 )
70+ Percent = 0.0 ;
71+ unsigned ColorID = unsigned (round (Percent * (HeatSize - 1.0 )));
72+ return HeatPalette[ColorID ];
7773}
78-
79- } // namespace llvm
0 commit comments