12
12
13
13
#include " bolt/Passes/MCF.h"
14
14
#include " bolt/Core/BinaryFunction.h"
15
+ #include " bolt/Core/ParallelUtilities.h"
15
16
#include " bolt/Passes/DataflowInfoManager.h"
16
17
#include " bolt/Utils/CommandLineOpts.h"
17
18
#include " llvm/ADT/DenseMap.h"
19
+ #include " llvm/ADT/STLExtras.h"
18
20
#include " llvm/Support/CommandLine.h"
19
21
#include < algorithm>
20
22
#include < vector>
@@ -432,7 +434,7 @@ void equalizeBBCounts(DataflowInfoManager &Info, BinaryFunction &BF) {
432
434
}
433
435
}
434
436
435
- void estimateEdgeCounts (BinaryFunction &BF) {
437
+ void EstimateEdgeCounts::runOnFunction (BinaryFunction &BF) {
436
438
EdgeWeightMap PredEdgeWeights;
437
439
EdgeWeightMap SuccEdgeWeights;
438
440
if (!opts::IterativeGuess) {
@@ -453,5 +455,25 @@ void estimateEdgeCounts(BinaryFunction &BF) {
453
455
recalculateBBCounts (BF, /* AllEdges=*/ false );
454
456
}
455
457
458
+ Error EstimateEdgeCounts::runOnFunctions (BinaryContext &BC) {
459
+ if (llvm::none_of (llvm::make_second_range (BC.getBinaryFunctions ()),
460
+ [](const BinaryFunction &BF) {
461
+ return BF.getProfileFlags () == BinaryFunction::PF_SAMPLE;
462
+ }))
463
+ return Error::success ();
464
+
465
+ ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
466
+ runOnFunction (BF);
467
+ };
468
+ ParallelUtilities::PredicateTy SkipFunc = [&](const BinaryFunction &BF) {
469
+ return BF.getProfileFlags () != BinaryFunction::PF_SAMPLE;
470
+ };
471
+
472
+ ParallelUtilities::runOnEachFunction (
473
+ BC, ParallelUtilities::SchedulingPolicy::SP_BB_QUADRATIC, WorkFun,
474
+ SkipFunc, " EstimateEdgeCounts" );
475
+ return Error::success ();
476
+ }
477
+
456
478
} // namespace bolt
457
479
} // namespace llvm
0 commit comments