mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-15 04:00:56 +00:00
[BOLT][NFC] Minor cleanup in ICP getCallTargets and canPromoteCallsite
Minor refactoring. NFC. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D124898
This commit is contained in:
parent
9a8d33dbd8
commit
2ad1c7540e
@ -206,7 +206,7 @@ std::vector<IndirectCallPromotion::Callsite>
|
||||
IndirectCallPromotion::getCallTargets(BinaryBasicBlock &BB,
|
||||
const MCInst &Inst) const {
|
||||
BinaryFunction &BF = *BB.getFunction();
|
||||
BinaryContext &BC = BF.getBinaryContext();
|
||||
const BinaryContext &BC = BF.getBinaryContext();
|
||||
std::vector<Callsite> Targets;
|
||||
|
||||
if (const JumpTable *JT = BF.getJumpTable(Inst)) {
|
||||
@ -512,6 +512,7 @@ IndirectCallPromotion::findCallTargetSymbols(std::vector<Callsite> &Targets,
|
||||
return SymTargets;
|
||||
}
|
||||
|
||||
// Use memory profile to select hot targets.
|
||||
JumpTableInfoType HotTargets =
|
||||
maybeGetHotJumpTableTargets(BB, CallInst, TargetFetchInst, JT);
|
||||
|
||||
@ -917,25 +918,28 @@ IndirectCallPromotion::fixCFG(BinaryBasicBlock &IndCallBlock,
|
||||
size_t IndirectCallPromotion::canPromoteCallsite(
|
||||
const BinaryBasicBlock &BB, const MCInst &Inst,
|
||||
const std::vector<Callsite> &Targets, uint64_t NumCalls) {
|
||||
BinaryFunction *BF = BB.getFunction();
|
||||
const BinaryContext &BC = BF->getBinaryContext();
|
||||
|
||||
if (BB.getKnownExecutionCount() < opts::ExecutionCountThreshold)
|
||||
return 0;
|
||||
|
||||
const bool IsJumpTable = BB.getFunction()->getJumpTable(Inst);
|
||||
const bool IsJumpTable = BF->getJumpTable(Inst);
|
||||
|
||||
auto computeStats = [&](size_t N) {
|
||||
for (size_t I = 0; I < N; ++I)
|
||||
if (!IsJumpTable)
|
||||
TotalNumFrequentCalls += Targets[I].Branches;
|
||||
else
|
||||
if (IsJumpTable)
|
||||
TotalNumFrequentJmps += Targets[I].Branches;
|
||||
else
|
||||
TotalNumFrequentCalls += Targets[I].Branches;
|
||||
};
|
||||
|
||||
// If we have no targets (or no calls), skip this callsite.
|
||||
if (Targets.empty() || !NumCalls) {
|
||||
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
|
||||
outs() << "BOLT-INFO: ICP failed in " << *BF << " @ " << InstIdx << " in "
|
||||
<< BB.getName() << ", calls = " << NumCalls
|
||||
<< ", targets empty or NumCalls == 0.\n";
|
||||
}
|
||||
return 0;
|
||||
@ -950,7 +954,6 @@ size_t IndirectCallPromotion::canPromoteCallsite(
|
||||
const size_t TrialN = TopN ? std::min(TopN, Targets.size()) : Targets.size();
|
||||
|
||||
if (opts::ICPTopCallsites > 0) {
|
||||
BinaryContext &BC = BB.getFunction()->getBinaryContext();
|
||||
if (!BC.MIB->hasAnnotation(Inst, "DoICP"))
|
||||
return 0;
|
||||
}
|
||||
@ -978,8 +981,8 @@ size_t IndirectCallPromotion::canPromoteCallsite(
|
||||
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
|
||||
outs() << "BOLT-INFO: ICP failed in " << *BF << " @ " << InstIdx
|
||||
<< " in " << BB.getName() << ", calls = " << NumCalls
|
||||
<< ", top N mis. frequency " << format("%.1f", TopNFrequency)
|
||||
<< "% < " << opts::ICPMispredictThreshold << "%\n";
|
||||
}
|
||||
@ -1024,9 +1027,9 @@ size_t IndirectCallPromotion::canPromoteCallsite(
|
||||
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 "
|
||||
outs() << "BOLT-INFO: ICP failed in " << *BF << " @ " << InstIdx
|
||||
<< " in " << BB.getName() << ", calls = " << NumCalls
|
||||
<< ", top N mispredict frequency "
|
||||
<< format("%.1f", TopNMispredictFrequency) << "% < "
|
||||
<< opts::ICPMispredictThreshold << "%\n";
|
||||
}
|
||||
@ -1038,7 +1041,7 @@ size_t IndirectCallPromotion::canPromoteCallsite(
|
||||
// Filter functions that can have ICP applied (for debugging)
|
||||
if (!opts::ICPFuncsList.empty()) {
|
||||
for (std::string &Name : opts::ICPFuncsList)
|
||||
if (BB.getFunction()->hasName(Name))
|
||||
if (BF->hasName(Name))
|
||||
return N;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user