[BOLT][NFC] Eliminate uses of throwing std::map::at (#92950)
Remove calls to std::unordered_map::at, std::map::at, and std::vector::at.
This commit is contained in:
parent
7c5c8b2f47
commit
c8fc234ee2
@ -283,7 +283,9 @@ public:
|
||||
|
||||
/// Returns the number of basic blocks in a function.
|
||||
size_t getNumBasicBlocks(uint64_t OutputAddress) const {
|
||||
return NumBasicBlocksMap.at(OutputAddress);
|
||||
auto It = NumBasicBlocksMap.find(OutputAddress);
|
||||
assert(It != NumBasicBlocksMap.end());
|
||||
return It->second;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -934,10 +934,13 @@ std::string BinaryContext::generateJumpTableName(const BinaryFunction &BF,
|
||||
uint64_t Offset = 0;
|
||||
if (const JumpTable *JT = BF.getJumpTableContainingAddress(Address)) {
|
||||
Offset = Address - JT->getAddress();
|
||||
auto Itr = JT->Labels.find(Offset);
|
||||
if (Itr != JT->Labels.end())
|
||||
return std::string(Itr->second->getName());
|
||||
Id = JumpTableIds.at(JT->getAddress());
|
||||
auto JTLabelsIt = JT->Labels.find(Offset);
|
||||
if (JTLabelsIt != JT->Labels.end())
|
||||
return std::string(JTLabelsIt->second->getName());
|
||||
|
||||
auto JTIdsIt = JumpTableIds.find(JT->getAddress());
|
||||
assert(JTIdsIt != JumpTableIds.end());
|
||||
Id = JTIdsIt->second;
|
||||
} else {
|
||||
Id = JumpTableIds[Address] = BF.JumpTables.size();
|
||||
}
|
||||
|
@ -813,7 +813,9 @@ void BinaryEmitter::emitJumpTable(const JumpTable &JT, MCSection *HotSection,
|
||||
// determining its destination.
|
||||
std::map<MCSymbol *, uint64_t> LabelCounts;
|
||||
if (opts::JumpTables > JTS_SPLIT && !JT.Counts.empty()) {
|
||||
MCSymbol *CurrentLabel = JT.Labels.at(0);
|
||||
auto It = JT.Labels.find(0);
|
||||
assert(It != JT.Labels.end());
|
||||
MCSymbol *CurrentLabel = It->second;
|
||||
uint64_t CurrentLabelCount = 0;
|
||||
for (unsigned Index = 0; Index < JT.Entries.size(); ++Index) {
|
||||
auto LI = JT.Labels.find(Index * JT.EntrySize);
|
||||
|
@ -114,8 +114,9 @@ void DynoStats::print(raw_ostream &OS, const DynoStats *Other,
|
||||
for (auto &Stat : llvm::reverse(SortedHistogram)) {
|
||||
OS << format("%20s,%'18lld", Printer->getOpcodeName(Stat.second).data(),
|
||||
Stat.first * opts::DynoStatsScale);
|
||||
|
||||
MaxOpcodeHistogramTy MaxMultiMap = OpcodeHistogram.at(Stat.second).second;
|
||||
auto It = OpcodeHistogram.find(Stat.second);
|
||||
assert(It != OpcodeHistogram.end());
|
||||
MaxOpcodeHistogramTy MaxMultiMap = It->second.second;
|
||||
// Start with function name:BB offset with highest execution count.
|
||||
for (auto &Max : llvm::reverse(MaxMultiMap)) {
|
||||
OS << format(", %'18lld, ", Max.first * opts::DynoStatsScale)
|
||||
|
@ -56,7 +56,9 @@ std::deque<BinaryFunction *> BinaryFunctionCallGraph::buildTraversalOrder() {
|
||||
std::stack<NodeId> Worklist;
|
||||
|
||||
for (BinaryFunction *Func : Funcs) {
|
||||
const NodeId Id = FuncToNodeId.at(Func);
|
||||
auto It = FuncToNodeId.find(Func);
|
||||
assert(It != FuncToNodeId.end());
|
||||
const NodeId Id = It->second;
|
||||
Worklist.push(Id);
|
||||
NodeStatus[Id] = NEW;
|
||||
}
|
||||
|
@ -1563,23 +1563,28 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
|
||||
const bool Ascending =
|
||||
opts::DynoStatsSortOrderOpt == opts::DynoStatsSortOrder::Ascending;
|
||||
|
||||
if (SortAll) {
|
||||
std::function<bool(const DynoStats &, const DynoStats &)>
|
||||
DynoStatsComparator =
|
||||
SortAll ? [](const DynoStats &StatsA,
|
||||
const DynoStats &StatsB) { return StatsA < StatsB; }
|
||||
: [](const DynoStats &StatsA, const DynoStats &StatsB) {
|
||||
return StatsA.lessThan(StatsB, opts::PrintSortedBy);
|
||||
};
|
||||
|
||||
llvm::stable_sort(Functions,
|
||||
[Ascending, &Stats](const BinaryFunction *A,
|
||||
const BinaryFunction *B) {
|
||||
return Ascending ? Stats.at(A) < Stats.at(B)
|
||||
: Stats.at(B) < Stats.at(A);
|
||||
[Ascending, &Stats, DynoStatsComparator](
|
||||
const BinaryFunction *A, const BinaryFunction *B) {
|
||||
auto StatsItr = Stats.find(A);
|
||||
assert(StatsItr != Stats.end());
|
||||
const DynoStats &StatsA = StatsItr->second;
|
||||
|
||||
StatsItr = Stats.find(B);
|
||||
assert(StatsItr != Stats.end());
|
||||
const DynoStats &StatsB = StatsItr->second;
|
||||
|
||||
return Ascending ? DynoStatsComparator(StatsA, StatsB)
|
||||
: DynoStatsComparator(StatsB, StatsA);
|
||||
});
|
||||
} else {
|
||||
llvm::stable_sort(
|
||||
Functions, [Ascending, &Stats](const BinaryFunction *A,
|
||||
const BinaryFunction *B) {
|
||||
const DynoStats &StatsA = Stats.at(A);
|
||||
const DynoStats &StatsB = Stats.at(B);
|
||||
return Ascending ? StatsA.lessThan(StatsB, opts::PrintSortedBy)
|
||||
: StatsB.lessThan(StatsA, opts::PrintSortedBy);
|
||||
});
|
||||
}
|
||||
|
||||
BC.outs() << "BOLT-INFO: top functions sorted by ";
|
||||
if (SortAll) {
|
||||
|
@ -67,7 +67,20 @@ calcTSPScore(const std::vector<BinaryFunction *> &BinaryFunctions,
|
||||
for (BinaryBasicBlock *DstBB : SrcBB->successors()) {
|
||||
if (SrcBB != DstBB && BI->Count != BinaryBasicBlock::COUNT_NO_PROFILE) {
|
||||
JumpCount += BI->Count;
|
||||
if (BBAddr.at(SrcBB) + BBSize.at(SrcBB) == BBAddr.at(DstBB))
|
||||
|
||||
auto BBAddrIt = BBAddr.find(SrcBB);
|
||||
assert(BBAddrIt != BBAddr.end());
|
||||
uint64_t SrcBBAddr = BBAddrIt->second;
|
||||
|
||||
auto BBSizeIt = BBSize.find(SrcBB);
|
||||
assert(BBSizeIt != BBSize.end());
|
||||
uint64_t SrcBBSize = BBSizeIt->second;
|
||||
|
||||
BBAddrIt = BBAddr.find(DstBB);
|
||||
assert(BBAddrIt != BBAddr.end());
|
||||
uint64_t DstBBAddr = BBAddrIt->second;
|
||||
|
||||
if (SrcBBAddr + SrcBBSize == DstBBAddr)
|
||||
Score += BI->Count;
|
||||
}
|
||||
++BI;
|
||||
@ -149,20 +162,28 @@ double expectedCacheHitRatio(
|
||||
for (BinaryFunction *BF : BinaryFunctions) {
|
||||
if (BF->getLayout().block_empty())
|
||||
continue;
|
||||
const uint64_t Page =
|
||||
BBAddr.at(BF->getLayout().block_front()) / ITLBPageSize;
|
||||
PageSamples[Page] += FunctionSamples.at(BF);
|
||||
auto BBAddrIt = BBAddr.find(BF->getLayout().block_front());
|
||||
assert(BBAddrIt != BBAddr.end());
|
||||
const uint64_t Page = BBAddrIt->second / ITLBPageSize;
|
||||
|
||||
auto FunctionSamplesIt = FunctionSamples.find(BF);
|
||||
assert(FunctionSamplesIt != FunctionSamples.end());
|
||||
PageSamples[Page] += FunctionSamplesIt->second;
|
||||
}
|
||||
|
||||
// Computing the expected number of misses for every function
|
||||
double Misses = 0;
|
||||
for (BinaryFunction *BF : BinaryFunctions) {
|
||||
// Skip the function if it has no samples
|
||||
if (BF->getLayout().block_empty() || FunctionSamples.at(BF) == 0.0)
|
||||
auto FunctionSamplesIt = FunctionSamples.find(BF);
|
||||
assert(FunctionSamplesIt != FunctionSamples.end());
|
||||
double Samples = FunctionSamplesIt->second;
|
||||
if (BF->getLayout().block_empty() || Samples == 0.0)
|
||||
continue;
|
||||
double Samples = FunctionSamples.at(BF);
|
||||
const uint64_t Page =
|
||||
BBAddr.at(BF->getLayout().block_front()) / ITLBPageSize;
|
||||
|
||||
auto BBAddrIt = BBAddr.find(BF->getLayout().block_front());
|
||||
assert(BBAddrIt != BBAddr.end());
|
||||
const uint64_t Page = BBAddrIt->second / ITLBPageSize;
|
||||
// The probability that the page is not present in the cache
|
||||
const double MissProb =
|
||||
pow(1.0 - PageSamples[Page] / TotalSamples, ITLBEntries);
|
||||
@ -170,8 +191,10 @@ double expectedCacheHitRatio(
|
||||
// Processing all callers of the function
|
||||
for (std::pair<BinaryFunction *, uint64_t> Pair : Calls[BF]) {
|
||||
BinaryFunction *SrcFunction = Pair.first;
|
||||
const uint64_t SrcPage =
|
||||
BBAddr.at(SrcFunction->getLayout().block_front()) / ITLBPageSize;
|
||||
|
||||
BBAddrIt = BBAddr.find(SrcFunction->getLayout().block_front());
|
||||
assert(BBAddrIt != BBAddr.end());
|
||||
const uint64_t SrcPage = BBAddrIt->second / ITLBPageSize;
|
||||
// Is this a 'long' or a 'short' call?
|
||||
if (Page != SrcPage) {
|
||||
// This is a miss
|
||||
|
@ -355,7 +355,9 @@ Inliner::inlineCall(BinaryBasicBlock &CallerBB,
|
||||
std::vector<BinaryBasicBlock *> Successors(BB.succ_size());
|
||||
llvm::transform(BB.successors(), Successors.begin(),
|
||||
[&InlinedBBMap](const BinaryBasicBlock *BB) {
|
||||
return InlinedBBMap.at(BB);
|
||||
auto It = InlinedBBMap.find(BB);
|
||||
assert(It != InlinedBBMap.end());
|
||||
return It->second;
|
||||
});
|
||||
|
||||
if (CallerFunction.hasValidProfile() && Callee.hasValidProfile())
|
||||
|
@ -372,8 +372,10 @@ createFlowFunction(const BinaryFunction::BasicBlockOrderType &BlockOrder) {
|
||||
|
||||
// Create necessary metadata for the flow function
|
||||
for (FlowJump &Jump : Func.Jumps) {
|
||||
Func.Blocks.at(Jump.Source).SuccJumps.push_back(&Jump);
|
||||
Func.Blocks.at(Jump.Target).PredJumps.push_back(&Jump);
|
||||
assert(Jump.Source < Func.Blocks.size());
|
||||
Func.Blocks[Jump.Source].SuccJumps.push_back(&Jump);
|
||||
assert(Jump.Target < Func.Blocks.size());
|
||||
Func.Blocks[Jump.Target].PredJumps.push_back(&Jump);
|
||||
}
|
||||
return Func;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user