14
14
#include " bolt/Passes/CacheMetrics.h"
15
15
#include " bolt/Core/BinaryBasicBlock.h"
16
16
#include " bolt/Core/BinaryFunction.h"
17
- #include " llvm/Support/CommandLine.h"
18
17
#include < unordered_map>
19
18
20
19
using namespace llvm ;
21
20
using namespace bolt ;
22
21
23
- namespace opts {
24
-
25
- extern cl::OptionCategory BoltOptCategory;
26
-
27
- extern cl::opt<unsigned > ITLBPageSize;
28
- extern cl::opt<unsigned > ITLBEntries;
29
-
30
- } // namespace opts
31
-
32
22
namespace {
33
23
24
+ // / The following constants are used to estimate the number of i-TLB cache
25
+ // / misses for a given code layout. Empirically the values result in high
26
+ // / correlations between the estimations and the perf measurements.
27
+ // / The constants do not affect the code layout algorithms.
28
+ constexpr unsigned ITLBPageSize = 4096 ;
29
+ constexpr unsigned ITLBEntries = 16 ;
30
+
34
31
// / Initialize and return a position map for binary basic blocks
35
32
void extractBasicBlockInfo (
36
33
const std::vector<BinaryFunction *> &BinaryFunctions,
@@ -133,9 +130,6 @@ double expectedCacheHitRatio(
133
130
const std::vector<BinaryFunction *> &BinaryFunctions,
134
131
const std::unordered_map<BinaryBasicBlock *, uint64_t > &BBAddr,
135
132
const std::unordered_map<BinaryBasicBlock *, uint64_t > &BBSize) {
136
-
137
- const double PageSize = opts::ITLBPageSize;
138
- const uint64_t CacheEntries = opts::ITLBEntries;
139
133
std::unordered_map<const BinaryFunction *, Predecessors> Calls =
140
134
extractFunctionCalls (BinaryFunctions);
141
135
// Compute 'hotness' of the functions
@@ -155,7 +149,8 @@ double expectedCacheHitRatio(
155
149
for (BinaryFunction *BF : BinaryFunctions) {
156
150
if (BF->getLayout ().block_empty ())
157
151
continue ;
158
- double Page = BBAddr.at (BF->getLayout ().block_front ()) / PageSize;
152
+ const uint64_t Page =
153
+ BBAddr.at (BF->getLayout ().block_front ()) / ITLBPageSize;
159
154
PageSamples[Page] += FunctionSamples.at (BF);
160
155
}
161
156
@@ -166,15 +161,17 @@ double expectedCacheHitRatio(
166
161
if (BF->getLayout ().block_empty () || FunctionSamples.at (BF) == 0.0 )
167
162
continue ;
168
163
double Samples = FunctionSamples.at (BF);
169
- double Page = BBAddr.at (BF->getLayout ().block_front ()) / PageSize;
164
+ const uint64_t Page =
165
+ BBAddr.at (BF->getLayout ().block_front ()) / ITLBPageSize;
170
166
// The probability that the page is not present in the cache
171
- double MissProb = pow (1.0 - PageSamples[Page] / TotalSamples, CacheEntries);
167
+ const double MissProb =
168
+ pow (1.0 - PageSamples[Page] / TotalSamples, ITLBEntries);
172
169
173
170
// Processing all callers of the function
174
171
for (std::pair<BinaryFunction *, uint64_t > Pair : Calls[BF]) {
175
172
BinaryFunction *SrcFunction = Pair.first ;
176
- double SrcPage =
177
- BBAddr.at (SrcFunction->getLayout ().block_front ()) / PageSize ;
173
+ const uint64_t SrcPage =
174
+ BBAddr.at (SrcFunction->getLayout ().block_front ()) / ITLBPageSize ;
178
175
// Is this a 'long' or a 'short' call?
179
176
if (Page != SrcPage) {
180
177
// This is a miss
0 commit comments