17
17
18
18
#include < cmath>
19
19
20
- namespace llvm {
20
+ using namespace llvm ;
21
21
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 ] = {
24
24
" #3d50c3" , " #4055c8" , " #4358cb" , " #465ecf" , " #4961d2" , " #4c66d6" , " #4f69d9" ,
25
25
" #536edd" , " #5572df" , " #5977e3" , " #5b7ae5" , " #5f7fe8" , " #6282ea" , " #6687ed" ,
26
26
" #6a8bef" , " #6c8ff1" , " #7093f3" , " #7396f5" , " #779af7" , " #7a9df8" , " #7ea1fa" ,
@@ -37,43 +37,37 @@ static const char heatPalette[heatSize][8] = {
37
37
" #d24b40" , " #d0473d" , " #cc403a" , " #ca3b37" , " #c53334" , " #c32e31" , " #be242e" ,
38
38
" #bb1b2c" , " #b70d28" };
39
39
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;
51
47
}
52
48
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 ;
55
51
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 ;
59
55
}
60
- return maxFreq ;
56
+ return MaxFreq ;
61
57
}
62
58
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 );
68
64
}
69
65
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 ];
77
73
}
78
-
79
- } // namespace llvm
0 commit comments