1212
1313#include " bolt/Passes/MCF.h"
1414#include " bolt/Core/BinaryFunction.h"
15+ #include " bolt/Core/ParallelUtilities.h"
1516#include " bolt/Passes/DataflowInfoManager.h"
1617#include " bolt/Utils/CommandLineOpts.h"
1718#include " llvm/ADT/DenseMap.h"
19+ #include " llvm/ADT/STLExtras.h"
1820#include " llvm/Support/CommandLine.h"
1921#include < algorithm>
2022#include < vector>
@@ -432,7 +434,7 @@ void equalizeBBCounts(DataflowInfoManager &Info, BinaryFunction &BF) {
432434 }
433435}
434436
435- void estimateEdgeCounts (BinaryFunction &BF) {
437+ void EstimateEdgeCounts::runOnFunction (BinaryFunction &BF) {
436438 EdgeWeightMap PredEdgeWeights;
437439 EdgeWeightMap SuccEdgeWeights;
438440 if (!opts::IterativeGuess) {
@@ -453,5 +455,25 @@ void estimateEdgeCounts(BinaryFunction &BF) {
453455 recalculateBBCounts (BF, /* AllEdges=*/ false );
454456}
455457
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+
456478} // namespace bolt
457479} // namespace llvm
0 commit comments