forked from OSchip/llvm-project
[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:
parent
94653797f3
commit
9a884543f1
|
@ -1326,15 +1326,14 @@ void BinaryContext::fixBinaryDataHoles() {
|
||||||
while (Itr != End) {
|
while (Itr != End) {
|
||||||
if (Itr->second->getAddress() > EndAddress) {
|
if (Itr->second->getAddress() > EndAddress) {
|
||||||
uint64_t Gap = 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();
|
EndAddress = Itr->second->getEndAddress();
|
||||||
++Itr;
|
++Itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EndAddress < Section.getEndAddress()) {
|
if (EndAddress < Section.getEndAddress()) {
|
||||||
Holes.push_back(std::make_pair(EndAddress,
|
Holes.emplace_back(EndAddress, Section.getEndAddress() - EndAddress);
|
||||||
Section.getEndAddress() - EndAddress));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is already a symbol at the start of the hole, grow that symbol
|
// If there is already a symbol at the start of the hole, grow that symbol
|
||||||
|
|
|
@ -461,7 +461,7 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, bool EmitColdPart,
|
||||||
const auto Offset = BC.MIB->getAnnotationAs<uint32_t>(Instr, "Offset");
|
const auto Offset = BC.MIB->getAnnotationAs<uint32_t>(Instr, "Offset");
|
||||||
MCSymbol *LocSym = BC.Ctx->createTempSymbol();
|
MCSymbol *LocSym = BC.Ctx->createTempSymbol();
|
||||||
Streamer.emitLabel(LocSym);
|
Streamer.emitLabel(LocSym);
|
||||||
BB->getLocSyms().emplace_back(std::make_pair(Offset, LocSym));
|
BB->getLocSyms().emplace_back(Offset, LocSym);
|
||||||
}
|
}
|
||||||
|
|
||||||
Streamer.emitInstruction(Instr, *BC.STI);
|
Streamer.emitInstruction(Instr, *BC.STI);
|
||||||
|
|
|
@ -1610,7 +1610,7 @@ public:
|
||||||
BB->setIndex(BasicBlocks.size() - 1);
|
BB->setIndex(BasicBlocks.size() - 1);
|
||||||
|
|
||||||
if (CurrentState == State::Disassembled) {
|
if (CurrentState == State::Disassembled) {
|
||||||
BasicBlockOffsets.emplace_back(std::make_pair(Offset, BB));
|
BasicBlockOffsets.emplace_back(Offset, BB);
|
||||||
} else if (CurrentState == State::CFG) {
|
} else if (CurrentState == State::CFG) {
|
||||||
BB->setLayoutIndex(layout_size());
|
BB->setLayoutIndex(layout_size());
|
||||||
BasicBlocksLayout.emplace_back(BB);
|
BasicBlocksLayout.emplace_back(BB);
|
||||||
|
|
|
@ -266,7 +266,7 @@ BoltAddressTranslation::getFallthroughsInTrace(
|
||||||
}
|
}
|
||||||
if (Iter->second & BRANCHENTRY)
|
if (Iter->second & BRANCHENTRY)
|
||||||
break;
|
break;
|
||||||
Res.emplace_back(std::make_pair(Src, Iter->first));
|
Res.emplace_back(Src, Iter->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Res;
|
return Res;
|
||||||
|
|
|
@ -138,7 +138,7 @@ extractFunctionCalls(const std::vector<BinaryFunction *> &BinaryFunctions) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Record the call
|
// Record the call
|
||||||
Calls[DstFunction].push_back(std::make_pair(SrcFunction, Count));
|
Calls[DstFunction].emplace_back(SrcFunction, Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -969,7 +969,7 @@ bool DataAggregator::recordTrace(
|
||||||
} else {
|
} else {
|
||||||
Offset = BB->getOffset();
|
Offset = BB->getOffset();
|
||||||
}
|
}
|
||||||
Branches->emplace_back(std::make_pair(Offset, NextBB->getOffset()));
|
Branches->emplace_back(Offset, NextBB->getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
BB = NextBB;
|
BB = NextBB;
|
||||||
|
|
|
@ -175,11 +175,11 @@ DebugLocWriter::addList(const DebugLocationsVector &LocList) {
|
||||||
|
|
||||||
void SimpleBinaryPatcher::addBinaryPatch(uint32_t Offset,
|
void SimpleBinaryPatcher::addBinaryPatch(uint32_t Offset,
|
||||||
const std::string &NewValue) {
|
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) {
|
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,
|
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;
|
LE64[I] = NewValue & 0xff;
|
||||||
NewValue >>= 8;
|
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) {
|
void SimpleBinaryPatcher::addUDataPatch(uint32_t Offset, uint64_t Value, uint64_t Size) {
|
||||||
|
|
|
@ -184,11 +184,11 @@ BinaryFunctionCallGraph buildCallGraph(BinaryContext &BC,
|
||||||
BC.MIB->getAnnotationAs<IndirectCallSiteProfile>(Inst, "CallProfile");
|
BC.MIB->getAnnotationAs<IndirectCallSiteProfile>(Inst, "CallProfile");
|
||||||
for (const IndirectCallProfile &CSI : ICSP) {
|
for (const IndirectCallProfile &CSI : ICSP) {
|
||||||
if (CSI.Symbol)
|
if (CSI.Symbol)
|
||||||
Counts.push_back(std::make_pair(CSI.Symbol, CSI.Count));
|
Counts.emplace_back(CSI.Symbol, CSI.Count);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const uint64_t Count = BB->getExecutionCount();
|
const uint64_t Count = BB->getExecutionCount();
|
||||||
Counts.push_back(std::make_pair(DstSym, Count));
|
Counts.emplace_back(DstSym, Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Counts;
|
return Counts;
|
||||||
|
|
|
@ -549,8 +549,8 @@ void LowerAnnotations::runOnFunctions(BinaryContext &BC) {
|
||||||
for (auto II = BB->begin(); II != BB->end(); ++II) {
|
for (auto II = BB->begin(); II != BB->end(); ++II) {
|
||||||
if (BF.requiresAddressTranslation() &&
|
if (BF.requiresAddressTranslation() &&
|
||||||
BC.MIB->hasAnnotation(*II, "Offset")) {
|
BC.MIB->hasAnnotation(*II, "Offset")) {
|
||||||
PreservedOffsetAnnotations.push_back(std::make_pair(
|
PreservedOffsetAnnotations.emplace_back(
|
||||||
&(*II), BC.MIB->getAnnotationAs<uint32_t>(*II, "Offset")));
|
&(*II), BC.MIB->getAnnotationAs<uint32_t>(*II, "Offset"));
|
||||||
}
|
}
|
||||||
BC.MIB->stripAnnotations(*II);
|
BC.MIB->stripAnnotations(*II);
|
||||||
}
|
}
|
||||||
|
@ -823,7 +823,7 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
|
||||||
// the target for the unconditional branch or add a unconditional
|
// the target for the unconditional branch or add a unconditional
|
||||||
// branch to the old target. This has to be done manually since
|
// branch to the old target. This has to be done manually since
|
||||||
// fixupBranches is not called after SCTC.
|
// fixupBranches is not called after SCTC.
|
||||||
NeedsUncondBranch.emplace_back(std::make_pair(PredBB, CondSucc));
|
NeedsUncondBranch.emplace_back(PredBB, CondSucc);
|
||||||
Count = PredBB->getFallthroughBranchInfo().Count;
|
Count = PredBB->getFallthroughBranchInfo().Count;
|
||||||
} else {
|
} else {
|
||||||
// Change destination of the conditional branch.
|
// Change destination of the conditional branch.
|
||||||
|
|
|
@ -301,9 +301,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEdge(Chain *Other, Edge *Edge) {
|
void addEdge(Chain *Other, Edge *Edge) { Edges.emplace_back(Other, Edge); }
|
||||||
Edges.push_back(std::make_pair(Other, Edge));
|
|
||||||
}
|
|
||||||
|
|
||||||
void merge(Chain *Other, const std::vector<Block *> &MergedBlocks) {
|
void merge(Chain *Other, const std::vector<Block *> &MergedBlocks) {
|
||||||
Blocks = MergedBlocks;
|
Blocks = MergedBlocks;
|
||||||
|
@ -364,7 +362,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendJump(Block *SrcBlock, Block *DstBlock, uint64_t EC) {
|
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) {
|
void moveJumps(Edge *Other) {
|
||||||
|
@ -552,9 +550,9 @@ private:
|
||||||
class Block &SuccBlock = AllBlocks[SuccBB->getLayoutIndex()];
|
class Block &SuccBlock = AllBlocks[SuccBB->getLayoutIndex()];
|
||||||
uint64_t Count = BI->Count;
|
uint64_t Count = BI->Count;
|
||||||
SuccBlock.InWeight += Count;
|
SuccBlock.InWeight += Count;
|
||||||
SuccBlock.InJumps.push_back(std::make_pair(&Block, Count));
|
SuccBlock.InJumps.emplace_back(&Block, Count);
|
||||||
Block.OutWeight += Count;
|
Block.OutWeight += Count;
|
||||||
Block.OutJumps.push_back(std::make_pair(&SuccBlock, Count));
|
Block.OutJumps.emplace_back(&SuccBlock, Count);
|
||||||
NumEdges++;
|
NumEdges++;
|
||||||
}
|
}
|
||||||
++BI;
|
++BI;
|
||||||
|
|
|
@ -209,7 +209,7 @@ void FrameOptimizerPass::removeUnusedStores(const FrameAnalysis &FA,
|
||||||
LLVM_DEBUG(dbgs() << "FIE offset = " << FIEX->StackOffset
|
LLVM_DEBUG(dbgs() << "FIE offset = " << FIEX->StackOffset
|
||||||
<< " size = " << (int)FIEX->Size << "\n");
|
<< " size = " << (int)FIEX->Size << "\n");
|
||||||
// Delete it!
|
// Delete it!
|
||||||
ToErase.push_back(std::make_pair(&BB, &Inst));
|
ToErase.emplace_back(&BB, &Inst);
|
||||||
Prev = &Inst;
|
Prev = &Inst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,9 +123,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEdge(Chain *Other, Edge *Edge) {
|
void addEdge(Chain *Other, Edge *Edge) { Edges.emplace_back(Other, Edge); }
|
||||||
Edges.push_back(std::make_pair(Other, Edge));
|
|
||||||
}
|
|
||||||
|
|
||||||
void merge(Chain *Other) {
|
void merge(Chain *Other) {
|
||||||
Nodes.insert(Nodes.end(), Other->Nodes.begin(), Other->Nodes.end());
|
Nodes.insert(Nodes.end(), Other->Nodes.begin(), Other->Nodes.end());
|
||||||
|
|
|
@ -657,7 +657,7 @@ IndirectCallPromotion::findCallTargetSymbols(
|
||||||
assert(Target.To.Sym && "All ICP targets must be to known symbols");
|
assert(Target.To.Sym && "All ICP targets must be to known symbols");
|
||||||
assert(!Target.JTIndices.empty() && "Jump tables must have indices");
|
assert(!Target.JTIndices.empty() && "Jump tables must have indices");
|
||||||
for (uint64_t Idx : Target.JTIndices) {
|
for (uint64_t Idx : Target.JTIndices) {
|
||||||
SymTargets.push_back(std::make_pair(Target.To.Sym, Idx));
|
SymTargets.emplace_back(Target.To.Sym, Idx);
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -667,7 +667,7 @@ IndirectCallPromotion::findCallTargetSymbols(
|
||||||
"All ICP targets must be to known symbols");
|
"All ICP targets must be to known symbols");
|
||||||
assert(Targets[I].JTIndices.empty() &&
|
assert(Targets[I].JTIndices.empty() &&
|
||||||
"Can't have jump table indices for non-jump tables");
|
"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 (Itr != MethodToVtable.end()) {
|
||||||
if (BinaryData *BD = BC.getBinaryDataContainingAddress(Itr->second)) {
|
if (BinaryData *BD = BC.getBinaryDataContainingAddress(Itr->second)) {
|
||||||
const uint64_t Addend = Itr->second - BD->getAddress();
|
const uint64_t Addend = Itr->second - BD->getAddress();
|
||||||
VtableSyms.push_back(std::make_pair(BD->getSymbol(), Addend));
|
VtableSyms.emplace_back(BD->getSymbol(), Addend);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ bool Instrumentation::instrumentOneTarget(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Critical edge, create BB and put counter there
|
// 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));
|
SplitInstrs.emplace_back(std::move(CounterInstrs));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,11 +572,11 @@ bool LongJmpPass::relax(BinaryFunction &Func) {
|
||||||
InsertionPoint = &*std::prev(Func.end());
|
InsertionPoint = &*std::prev(Func.end());
|
||||||
|
|
||||||
// Create a stub to handle a far-away target
|
// Create a stub to handle a far-away target
|
||||||
Insertions.emplace_back(std::make_pair(
|
Insertions.emplace_back(InsertionPoint,
|
||||||
InsertionPoint,
|
replaceTargetWithStub(BB, Inst, DotAddress,
|
||||||
replaceTargetWithStub(BB, Inst, DotAddress,
|
InsertionPoint == Frontier
|
||||||
InsertionPoint == Frontier ? FrontierAddress
|
? FrontierAddress
|
||||||
: DotAddress)));
|
: DotAddress));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ DataOrder ReorderData::baseOrder(BinaryContext &BC,
|
||||||
continue;
|
continue;
|
||||||
auto BDCI = BinaryDataCounts.find(BD);
|
auto BDCI = BinaryDataCounts.find(BD);
|
||||||
uint64_t BDCount = BDCI == BinaryDataCounts.end() ? 0 : BDCI->second;
|
uint64_t BDCount = BDCI == BinaryDataCounts.end() ? 0 : BDCI->second;
|
||||||
Order.push_back(std::make_pair(BD, BDCount));
|
Order.emplace_back(BD, BDCount);
|
||||||
}
|
}
|
||||||
return Order;
|
return Order;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3887,14 +3887,14 @@ std::vector<ELFShdrTy> RewriteInstance::getOutputSections(
|
||||||
auto addSection = [&](const std::string &Name, const ELFShdrTy &Section) {
|
auto addSection = [&](const std::string &Name, const ELFShdrTy &Section) {
|
||||||
ELFShdrTy NewSection = Section;
|
ELFShdrTy NewSection = Section;
|
||||||
NewSection.sh_name = SHStrTab.getOffset(Name);
|
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.
|
// Copy over entries for original allocatable sections using modified name.
|
||||||
for (const ELFShdrTy &Section : Sections) {
|
for (const ELFShdrTy &Section : Sections) {
|
||||||
// Always ignore this section.
|
// Always ignore this section.
|
||||||
if (Section.sh_type == ELF::SHT_NULL) {
|
if (Section.sh_type == ELF::SHT_NULL) {
|
||||||
OutputSections.emplace_back(std::make_pair("", Section));
|
OutputSections.emplace_back("", Section);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3369,7 +3369,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < Targets.size(); ++i) {
|
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;
|
std::vector<MCInst>* NewCall = &Results.back().second;
|
||||||
|
|
||||||
if (MinimizeCodeSize && !LoadElim) {
|
if (MinimizeCodeSize && !LoadElim) {
|
||||||
|
@ -3495,8 +3495,8 @@ public:
|
||||||
Jne.addOperand(MCOperand::createImm(X86::COND_NE));
|
Jne.addOperand(MCOperand::createImm(X86::COND_NE));
|
||||||
|
|
||||||
// Call specific target directly.
|
// Call specific target directly.
|
||||||
Results.push_back(std::make_pair(Ctx->createNamedTempSymbol(),
|
Results.emplace_back(Ctx->createNamedTempSymbol(),
|
||||||
std::vector<MCInst>()));
|
std::vector<MCInst>());
|
||||||
NewCall = &Results.back().second;
|
NewCall = &Results.back().second;
|
||||||
NewCall->push_back(CallInst);
|
NewCall->push_back(CallInst);
|
||||||
MCInst &CallOrJmp = NewCall->back();
|
MCInst &CallOrJmp = NewCall->back();
|
||||||
|
@ -3545,7 +3545,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cold call block.
|
// 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;
|
std::vector<MCInst> &NewCall = Results.back().second;
|
||||||
for (const MCInst *Inst : MethodFetchInsns) {
|
for (const MCInst *Inst : MethodFetchInsns) {
|
||||||
if (Inst != &CallInst)
|
if (Inst != &CallInst)
|
||||||
|
@ -3558,7 +3558,7 @@ public:
|
||||||
jumpToMergeBlock(NewCall);
|
jumpToMergeBlock(NewCall);
|
||||||
|
|
||||||
// Record merge block
|
// Record merge block
|
||||||
Results.push_back(std::make_pair(MergeBlock, std::vector<MCInst>()));
|
Results.emplace_back(MergeBlock, std::vector<MCInst>());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Results;
|
return Results;
|
||||||
|
@ -3581,7 +3581,7 @@ public:
|
||||||
MCSymbol* NextTarget = nullptr;
|
MCSymbol* NextTarget = nullptr;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < Targets.size(); ++i) {
|
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;
|
std::vector<MCInst>* CurBB = &Results.back().second;
|
||||||
|
|
||||||
// Compare current index to a specific index.
|
// Compare current index to a specific index.
|
||||||
|
@ -3615,7 +3615,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cold call block.
|
// 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;
|
std::vector<MCInst> &CurBB = Results.back().second;
|
||||||
for (const MCInst *Inst : TargetFetchInsns) {
|
for (const MCInst *Inst : TargetFetchInsns) {
|
||||||
if (Inst != &IJmpInst)
|
if (Inst != &IJmpInst)
|
||||||
|
|
Loading…
Reference in New Issue