[BOLT][NFC] Avoid unnecessary copies with push_back

Summary: Small refactoring inspired by clang-tidy modernize-use-emplace

(cherry picked from FBD28307493)
This commit is contained in:
Amir Ayupov 2021-05-07 18:43:25 -07:00 committed by Maksim Panchenko
parent 94653797f3
commit 9a884543f1
18 changed files with 40 additions and 45 deletions

View File

@ -1326,15 +1326,14 @@ void BinaryContext::fixBinaryDataHoles() {
while (Itr != End) {
if (Itr->second->getAddress() > EndAddress) {
uint64_t Gap = Itr->second->getAddress() - EndAddress;
Holes.push_back(std::make_pair(EndAddress, Gap));
Holes.emplace_back(EndAddress, Gap);
}
EndAddress = Itr->second->getEndAddress();
++Itr;
}
if (EndAddress < Section.getEndAddress()) {
Holes.push_back(std::make_pair(EndAddress,
Section.getEndAddress() - EndAddress));
Holes.emplace_back(EndAddress, Section.getEndAddress() - EndAddress);
}
// If there is already a symbol at the start of the hole, grow that symbol

View File

@ -461,7 +461,7 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, bool EmitColdPart,
const auto Offset = BC.MIB->getAnnotationAs<uint32_t>(Instr, "Offset");
MCSymbol *LocSym = BC.Ctx->createTempSymbol();
Streamer.emitLabel(LocSym);
BB->getLocSyms().emplace_back(std::make_pair(Offset, LocSym));
BB->getLocSyms().emplace_back(Offset, LocSym);
}
Streamer.emitInstruction(Instr, *BC.STI);

View File

@ -1610,7 +1610,7 @@ public:
BB->setIndex(BasicBlocks.size() - 1);
if (CurrentState == State::Disassembled) {
BasicBlockOffsets.emplace_back(std::make_pair(Offset, BB));
BasicBlockOffsets.emplace_back(Offset, BB);
} else if (CurrentState == State::CFG) {
BB->setLayoutIndex(layout_size());
BasicBlocksLayout.emplace_back(BB);

View File

@ -266,7 +266,7 @@ BoltAddressTranslation::getFallthroughsInTrace(
}
if (Iter->second & BRANCHENTRY)
break;
Res.emplace_back(std::make_pair(Src, Iter->first));
Res.emplace_back(Src, Iter->first);
}
return Res;

View File

@ -138,7 +138,7 @@ extractFunctionCalls(const std::vector<BinaryFunction *> &BinaryFunctions) {
continue;
// Record the call
Calls[DstFunction].push_back(std::make_pair(SrcFunction, Count));
Calls[DstFunction].emplace_back(SrcFunction, Count);
}
}
}

View File

@ -969,7 +969,7 @@ bool DataAggregator::recordTrace(
} else {
Offset = BB->getOffset();
}
Branches->emplace_back(std::make_pair(Offset, NextBB->getOffset()));
Branches->emplace_back(Offset, NextBB->getOffset());
}
BB = NextBB;

View File

@ -175,11 +175,11 @@ DebugLocWriter::addList(const DebugLocationsVector &LocList) {
void SimpleBinaryPatcher::addBinaryPatch(uint32_t Offset,
const std::string &NewValue) {
Patches.emplace_back(std::make_pair(Offset, NewValue));
Patches.emplace_back(Offset, NewValue);
}
void SimpleBinaryPatcher::addBytePatch(uint32_t Offset, uint8_t Value) {
Patches.emplace_back(std::make_pair(Offset, std::string(1, Value)));
Patches.emplace_back(Offset, std::string(1, Value));
}
void SimpleBinaryPatcher::addLEPatch(uint32_t Offset, uint64_t NewValue,
@ -189,7 +189,7 @@ void SimpleBinaryPatcher::addLEPatch(uint32_t Offset, uint64_t NewValue,
LE64[I] = NewValue & 0xff;
NewValue >>= 8;
}
Patches.emplace_back(std::make_pair(Offset, LE64));
Patches.emplace_back(Offset, LE64);
}
void SimpleBinaryPatcher::addUDataPatch(uint32_t Offset, uint64_t Value, uint64_t Size) {

View File

@ -184,11 +184,11 @@ BinaryFunctionCallGraph buildCallGraph(BinaryContext &BC,
BC.MIB->getAnnotationAs<IndirectCallSiteProfile>(Inst, "CallProfile");
for (const IndirectCallProfile &CSI : ICSP) {
if (CSI.Symbol)
Counts.push_back(std::make_pair(CSI.Symbol, CSI.Count));
Counts.emplace_back(CSI.Symbol, CSI.Count);
}
} else {
const uint64_t Count = BB->getExecutionCount();
Counts.push_back(std::make_pair(DstSym, Count));
Counts.emplace_back(DstSym, Count);
}
return Counts;

View File

@ -549,8 +549,8 @@ void LowerAnnotations::runOnFunctions(BinaryContext &BC) {
for (auto II = BB->begin(); II != BB->end(); ++II) {
if (BF.requiresAddressTranslation() &&
BC.MIB->hasAnnotation(*II, "Offset")) {
PreservedOffsetAnnotations.push_back(std::make_pair(
&(*II), BC.MIB->getAnnotationAs<uint32_t>(*II, "Offset")));
PreservedOffsetAnnotations.emplace_back(
&(*II), BC.MIB->getAnnotationAs<uint32_t>(*II, "Offset"));
}
BC.MIB->stripAnnotations(*II);
}
@ -823,7 +823,7 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
// the target for the unconditional branch or add a unconditional
// branch to the old target. This has to be done manually since
// fixupBranches is not called after SCTC.
NeedsUncondBranch.emplace_back(std::make_pair(PredBB, CondSucc));
NeedsUncondBranch.emplace_back(PredBB, CondSucc);
Count = PredBB->getFallthroughBranchInfo().Count;
} else {
// Change destination of the conditional branch.

View File

@ -301,9 +301,7 @@ public:
}
}
void addEdge(Chain *Other, Edge *Edge) {
Edges.push_back(std::make_pair(Other, Edge));
}
void addEdge(Chain *Other, Edge *Edge) { Edges.emplace_back(Other, Edge); }
void merge(Chain *Other, const std::vector<Block *> &MergedBlocks) {
Blocks = MergedBlocks;
@ -364,7 +362,7 @@ public:
}
void appendJump(Block *SrcBlock, Block *DstBlock, uint64_t EC) {
Jumps.push_back(std::make_pair(std::make_pair(SrcBlock, DstBlock), EC));
Jumps.emplace_back(std::make_pair(SrcBlock, DstBlock), EC);
}
void moveJumps(Edge *Other) {
@ -552,9 +550,9 @@ private:
class Block &SuccBlock = AllBlocks[SuccBB->getLayoutIndex()];
uint64_t Count = BI->Count;
SuccBlock.InWeight += Count;
SuccBlock.InJumps.push_back(std::make_pair(&Block, Count));
SuccBlock.InJumps.emplace_back(&Block, Count);
Block.OutWeight += Count;
Block.OutJumps.push_back(std::make_pair(&SuccBlock, Count));
Block.OutJumps.emplace_back(&SuccBlock, Count);
NumEdges++;
}
++BI;

View File

@ -209,7 +209,7 @@ void FrameOptimizerPass::removeUnusedStores(const FrameAnalysis &FA,
LLVM_DEBUG(dbgs() << "FIE offset = " << FIEX->StackOffset
<< " size = " << (int)FIEX->Size << "\n");
// Delete it!
ToErase.push_back(std::make_pair(&BB, &Inst));
ToErase.emplace_back(&BB, &Inst);
Prev = &Inst;
}
}

View File

@ -123,9 +123,7 @@ public:
}
}
void addEdge(Chain *Other, Edge *Edge) {
Edges.push_back(std::make_pair(Other, Edge));
}
void addEdge(Chain *Other, Edge *Edge) { Edges.emplace_back(Other, Edge); }
void merge(Chain *Other) {
Nodes.insert(Nodes.end(), Other->Nodes.begin(), Other->Nodes.end());

View File

@ -657,7 +657,7 @@ IndirectCallPromotion::findCallTargetSymbols(
assert(Target.To.Sym && "All ICP targets must be to known symbols");
assert(!Target.JTIndices.empty() && "Jump tables must have indices");
for (uint64_t Idx : Target.JTIndices) {
SymTargets.push_back(std::make_pair(Target.To.Sym, Idx));
SymTargets.emplace_back(Target.To.Sym, Idx);
++I;
}
}
@ -667,7 +667,7 @@ IndirectCallPromotion::findCallTargetSymbols(
"All ICP targets must be to known symbols");
assert(Targets[I].JTIndices.empty() &&
"Can't have jump table indices for non-jump tables");
SymTargets.push_back(std::make_pair(Targets[I].To.Sym, 0));
SymTargets.emplace_back(Targets[I].To.Sym, 0);
}
}
@ -773,7 +773,7 @@ IndirectCallPromotion::maybeGetVtableSyms(
if (Itr != MethodToVtable.end()) {
if (BinaryData *BD = BC.getBinaryDataContainingAddress(Itr->second)) {
const uint64_t Addend = Itr->second - BD->getAddress();
VtableSyms.push_back(std::make_pair(BD->getSymbol(), Addend));
VtableSyms.emplace_back(BD->getSymbol(), Addend);
continue;
}
}

View File

@ -286,7 +286,7 @@ bool Instrumentation::instrumentOneTarget(
return true;
}
// Critical edge, create BB and put counter there
SplitWorklist.emplace_back(std::make_pair(&FromBB, TargetBB));
SplitWorklist.emplace_back(&FromBB, TargetBB);
SplitInstrs.emplace_back(std::move(CounterInstrs));
return true;
}

View File

@ -572,11 +572,11 @@ bool LongJmpPass::relax(BinaryFunction &Func) {
InsertionPoint = &*std::prev(Func.end());
// Create a stub to handle a far-away target
Insertions.emplace_back(std::make_pair(
InsertionPoint,
replaceTargetWithStub(BB, Inst, DotAddress,
InsertionPoint == Frontier ? FrontierAddress
: DotAddress)));
Insertions.emplace_back(InsertionPoint,
replaceTargetWithStub(BB, Inst, DotAddress,
InsertionPoint == Frontier
? FrontierAddress
: DotAddress));
}
}

View File

@ -177,7 +177,7 @@ DataOrder ReorderData::baseOrder(BinaryContext &BC,
continue;
auto BDCI = BinaryDataCounts.find(BD);
uint64_t BDCount = BDCI == BinaryDataCounts.end() ? 0 : BDCI->second;
Order.push_back(std::make_pair(BD, BDCount));
Order.emplace_back(BD, BDCount);
}
return Order;
}

View File

@ -3887,14 +3887,14 @@ std::vector<ELFShdrTy> RewriteInstance::getOutputSections(
auto addSection = [&](const std::string &Name, const ELFShdrTy &Section) {
ELFShdrTy NewSection = Section;
NewSection.sh_name = SHStrTab.getOffset(Name);
OutputSections.emplace_back(std::make_pair(Name, std::move(NewSection)));
OutputSections.emplace_back(Name, std::move(NewSection));
};
// Copy over entries for original allocatable sections using modified name.
for (const ELFShdrTy &Section : Sections) {
// Always ignore this section.
if (Section.sh_type == ELF::SHT_NULL) {
OutputSections.emplace_back(std::make_pair("", Section));
OutputSections.emplace_back("", Section);
continue;
}

View File

@ -3369,7 +3369,7 @@ public:
};
for (unsigned int i = 0; i < Targets.size(); ++i) {
Results.push_back(std::make_pair(NextTarget, std::vector<MCInst>()));
Results.emplace_back(NextTarget, std::vector<MCInst>());
std::vector<MCInst>* NewCall = &Results.back().second;
if (MinimizeCodeSize && !LoadElim) {
@ -3495,8 +3495,8 @@ public:
Jne.addOperand(MCOperand::createImm(X86::COND_NE));
// Call specific target directly.
Results.push_back(std::make_pair(Ctx->createNamedTempSymbol(),
std::vector<MCInst>()));
Results.emplace_back(Ctx->createNamedTempSymbol(),
std::vector<MCInst>());
NewCall = &Results.back().second;
NewCall->push_back(CallInst);
MCInst &CallOrJmp = NewCall->back();
@ -3545,7 +3545,7 @@ public:
}
// Cold call block.
Results.push_back(std::make_pair(NextTarget, std::vector<MCInst>()));
Results.emplace_back(NextTarget, std::vector<MCInst>());
std::vector<MCInst> &NewCall = Results.back().second;
for (const MCInst *Inst : MethodFetchInsns) {
if (Inst != &CallInst)
@ -3558,7 +3558,7 @@ public:
jumpToMergeBlock(NewCall);
// Record merge block
Results.push_back(std::make_pair(MergeBlock, std::vector<MCInst>()));
Results.emplace_back(MergeBlock, std::vector<MCInst>());
}
return Results;
@ -3581,7 +3581,7 @@ public:
MCSymbol* NextTarget = nullptr;
for (unsigned int i = 0; i < Targets.size(); ++i) {
Results.push_back(std::make_pair(NextTarget, std::vector<MCInst>()));
Results.emplace_back(NextTarget, std::vector<MCInst>());
std::vector<MCInst>* CurBB = &Results.back().second;
// Compare current index to a specific index.
@ -3615,7 +3615,7 @@ public:
}
// Cold call block.
Results.push_back(std::make_pair(NextTarget, std::vector<MCInst>()));
Results.emplace_back(NextTarget, std::vector<MCInst>());
std::vector<MCInst> &CurBB = Results.back().second;
for (const MCInst *Inst : TargetFetchInsns) {
if (Inst != &IJmpInst)