diff --git a/bolt/lib/Core/BinaryFunctionProfile.cpp b/bolt/lib/Core/BinaryFunctionProfile.cpp --- a/bolt/lib/Core/BinaryFunctionProfile.cpp +++ b/bolt/lib/Core/BinaryFunctionProfile.cpp @@ -27,17 +27,16 @@ extern cl::OptionCategory BoltOptCategory; -cl::opt -IndirectCallPromotion("indirect-call-promotion", - cl::init(ICP_NONE), - cl::desc("indirect call promotion"), - cl::values( - clEnumValN(ICP_NONE, "none", "do not perform indirect call promotion"), - clEnumValN(ICP_CALLS, "calls", "perform ICP on indirect calls"), - clEnumValN(ICP_JUMP_TABLES, "jump-tables", "perform ICP on jump tables"), - clEnumValN(ICP_ALL, "all", "perform ICP on calls and jump tables")), - cl::ZeroOrMore, - cl::cat(BoltOptCategory)); +cl::opt ICP( + "indirect-call-promotion", cl::init(ICP_NONE), + cl::desc("indirect call promotion"), + cl::values( + clEnumValN(ICP_NONE, "none", "do not perform indirect call promotion"), + clEnumValN(ICP_CALLS, "calls", "perform ICP on indirect calls"), + clEnumValN(ICP_JUMP_TABLES, "jump-tables", + "perform ICP on jump tables"), + clEnumValN(ICP_ALL, "all", "perform ICP on calls and jump tables")), + cl::ZeroOrMore, cl::cat(BoltOptCategory)); extern cl::opt JumpTables; @@ -173,8 +172,7 @@ } JT->Count += TotalBranchCount; - if (opts::IndirectCallPromotion < ICP_JUMP_TABLES && - opts::JumpTables < JTS_AGGRESSIVE) + if (opts::ICP < ICP_JUMP_TABLES && opts::JumpTables < JTS_AGGRESSIVE) continue; if (JT->Counts.empty()) diff --git a/bolt/lib/Passes/IndirectCallPromotion.cpp b/bolt/lib/Passes/IndirectCallPromotion.cpp --- a/bolt/lib/Passes/IndirectCallPromotion.cpp +++ b/bolt/lib/Passes/IndirectCallPromotion.cpp @@ -28,7 +28,7 @@ extern cl::OptionCategory BoltOptCategory; -extern cl::opt IndirectCallPromotion; +extern cl::opt ICP; extern cl::opt Verbosity; extern cl::opt ExecutionCountThreshold; @@ -58,13 +58,13 @@ "calls"), cl::init(30), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory)); -static cl::opt IndirectCallPromotionMispredictThreshold( +static cl::opt ICPMispredictThreshold( "indirect-call-promotion-mispredict-threshold", cl::desc("misprediction threshold for skipping ICP on an " "indirect call"), cl::init(0), cl::ZeroOrMore, cl::cat(BoltOptCategory)); -static cl::opt IndirectCallPromotionUseMispredicts( +static cl::opt ICPUseMispredicts( "indirect-call-promotion-use-mispredicts", cl::desc("use misprediction frequency for determining whether or not ICP " "should be applied at a callsite. The " @@ -72,19 +72,19 @@ "by this heuristic"), cl::ZeroOrMore, cl::cat(BoltOptCategory)); -static cl::opt IndirectCallPromotionTopN( - "indirect-call-promotion-topn", - cl::desc("limit number of targets to consider when doing indirect " - "call promotion. 0 = no limit"), - cl::init(3), cl::ZeroOrMore, cl::cat(BoltOptCategory)); +static cl::opt + ICPTopN("indirect-call-promotion-topn", + cl::desc("limit number of targets to consider when doing indirect " + "call promotion. 0 = no limit"), + cl::init(3), cl::ZeroOrMore, cl::cat(BoltOptCategory)); -static cl::opt IndirectCallPromotionCallsTopN( +static cl::opt ICPCallsTopN( "indirect-call-promotion-calls-topn", cl::desc("limit number of targets to consider when doing indirect " "call promotion on calls. 0 = no limit"), cl::init(0), cl::ZeroOrMore, cl::cat(BoltOptCategory)); -static cl::opt IndirectCallPromotionJumpTablesTopN( +static cl::opt ICPJumpTablesTopN( "indirect-call-promotion-jump-tables-topn", cl::desc("limit number of targets to consider when doing indirect " "call promotion on jump tables. 0 = no limit"), @@ -545,9 +545,8 @@ TotalMemAccesses += HotTargets[I].first; } uint64_t RemainingMemAccesses = TotalMemAccesses; - const size_t TopN = opts::IndirectCallPromotionJumpTablesTopN != 0 - ? opts::IndirectCallPromotionTopN - : opts::IndirectCallPromotionTopN; + const size_t TopN = + opts::ICPJumpTablesTopN != 0 ? opts::ICPTopN : opts::ICPTopN; size_t I = 0; for (; I < HotTargets.size(); ++I) { const uint64_t MemAccesses = HotTargets[I].first; @@ -942,12 +941,12 @@ return 0; } - size_t TopN = opts::IndirectCallPromotionTopN; + size_t TopN = opts::ICPTopN; if (IsJumpTable) { - if (opts::IndirectCallPromotionJumpTablesTopN != 0) - TopN = opts::IndirectCallPromotionJumpTablesTopN; - } else if (opts::IndirectCallPromotionCallsTopN != 0) { - TopN = opts::IndirectCallPromotionCallsTopN; + if (opts::ICPJumpTablesTopN != 0) + TopN = opts::ICPJumpTablesTopN; + } else if (opts::ICPCallsTopN != 0) { + TopN = opts::ICPCallsTopN; } const size_t TrialN = TopN ? std::min(TopN, Targets.size()) : Targets.size(); @@ -961,12 +960,12 @@ uint64_t TotalMispredictsTopN = 0; size_t N = 0; - if (opts::IndirectCallPromotionUseMispredicts && + if (opts::ICPUseMispredicts && (!IsJumpTable || opts::ICPJumpTablesByTarget)) { // Count total number of mispredictions for (at most) the top N targets. // We may choose a smaller N (TrialN vs. N) if the frequency threshold // is exceeded by fewer targets. - double Threshold = double(opts::IndirectCallPromotionMispredictThreshold); + double Threshold = double(opts::ICPMispredictThreshold); for (size_t I = 0; I < TrialN && Threshold > 0; ++I, ++N) { Threshold -= (100.0 * Targets[I].Mispreds) / NumCalls; TotalMispredictsTopN += Targets[I].Mispreds; @@ -977,15 +976,13 @@ // frequency is greater than the threshold, we should try ICP on this // callsite. const double TopNFrequency = (100.0 * TotalMispredictsTopN) / NumCalls; - if (TopNFrequency == 0 || - TopNFrequency < opts::IndirectCallPromotionMispredictThreshold) { + if (TopNFrequency == 0 || TopNFrequency < opts::ICPMispredictThreshold) { if (opts::Verbosity >= 1) { const ptrdiff_t InstIdx = &Inst - &(*BB.begin()); outs() << "BOLT-INFO: ICP failed in " << *BB.getFunction() << " @ " << InstIdx << " in " << BB.getName() << ", calls = " << NumCalls << ", top N mis. frequency " << format("%.1f", TopNFrequency) - << "% < " << opts::IndirectCallPromotionMispredictThreshold - << "%\n"; + << "% < " << opts::ICPMispredictThreshold << "%\n"; } return 0; } @@ -1025,15 +1022,14 @@ const double TopNMispredictFrequency = (100.0 * TotalMispredictsTopN) / NumCalls; - if (TopNMispredictFrequency < - opts::IndirectCallPromotionMispredictThreshold) { + if (TopNMispredictFrequency < opts::ICPMispredictThreshold) { if (opts::Verbosity >= 1) { const ptrdiff_t InstIdx = &Inst - &(*BB.begin()); outs() << "BOLT-INFO: ICP failed in " << *BB.getFunction() << " @ " << InstIdx << " in " << BB.getName() << ", calls = " << NumCalls << ", top N mispredict frequency " << format("%.1f", TopNMispredictFrequency) << "% < " - << opts::IndirectCallPromotionMispredictThreshold << "%\n"; + << opts::ICPMispredictThreshold << "%\n"; } return 0; } @@ -1092,16 +1088,14 @@ } void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) { - if (opts::IndirectCallPromotion == ICP_NONE) + if (opts::ICP == ICP_NONE) return; auto &BFs = BC.getBinaryFunctions(); - const bool OptimizeCalls = (opts::IndirectCallPromotion == ICP_CALLS || - opts::IndirectCallPromotion == ICP_ALL); + const bool OptimizeCalls = (opts::ICP == ICP_CALLS || opts::ICP == ICP_ALL); const bool OptimizeJumpTables = - (opts::IndirectCallPromotion == ICP_JUMP_TABLES || - opts::IndirectCallPromotion == ICP_ALL); + (opts::ICP == ICP_JUMP_TABLES || opts::ICP == ICP_ALL); std::unique_ptr RA; std::unique_ptr CG;