[lld] 1372d53 - [ELF] Optimize two vector. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 26 23:10:53 PST 2022
Author: Fangrui Song
Date: 2022-01-26T23:10:40-08:00
New Revision: 1372d53639f7eb2273836d7e55947fe6943a5be4
URL: https://github.com/llvm/llvm-project/commit/1372d53639f7eb2273836d7e55947fe6943a5be4
DIFF: https://github.com/llvm/llvm-project/commit/1372d53639f7eb2273836d7e55947fe6943a5be4.diff
LOG: [ELF] Optimize two vector. NFC
Added:
Modified:
lld/ELF/MapFile.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index 70d0e8c65255..c7d8967358ad 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -91,9 +91,9 @@ static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
// we do that in batch using parallel-for.
static DenseMap<Symbol *, std::string>
getSymbolStrings(ArrayRef<Defined *> syms) {
- std::vector<std::string> str(syms.size());
+ auto strs = std::make_unique<std::string[]>(syms.size());
parallelForEachN(0, syms.size(), [&](size_t i) {
- raw_string_ostream os(str[i]);
+ raw_string_ostream os(strs[i]);
OutputSection *osec = syms[i]->getOutputSection();
uint64_t vma = syms[i]->getVA();
uint64_t lma = osec ? osec->getLMA() + vma - osec->getVA(0) : 0;
@@ -103,7 +103,7 @@ getSymbolStrings(ArrayRef<Defined *> syms) {
DenseMap<Symbol *, std::string> ret;
for (size_t i = 0, e = syms.size(); i < e; ++i)
- ret[syms[i]] = std::move(str[i]);
+ ret[syms[i]] = std::move(strs[i]);
return ret;
}
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 396b9c153dc2..848db1f04b42 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1750,16 +1750,15 @@ template <class ELFT> void Writer<ELFT>::optimizeBasicBlockJumps() {
if (!(osec->flags & SHF_EXECINSTR))
continue;
SmallVector<InputSection *, 0> sections = getInputSections(*osec);
- std::vector<unsigned> result(sections.size());
+ size_t numDeleted = 0;
// Delete all fall through jump instructions. Also, check if two
// consecutive jump instructions can be flipped so that a fall
// through jmp instruction can be deleted.
for (size_t i = 0, e = sections.size(); i != e; ++i) {
InputSection *next = i + 1 < sections.size() ? sections[i + 1] : nullptr;
InputSection &sec = *sections[i];
- result[i] = target->deleteFallThruJmpInsn(sec, sec.file, next) ? 1 : 0;
+ numDeleted += target->deleteFallThruJmpInsn(sec, sec.file, next);
}
- size_t numDeleted = std::count(result.begin(), result.end(), 1);
if (numDeleted > 0) {
script->assignAddresses();
LLVM_DEBUG(llvm::dbgs()
More information about the llvm-commits
mailing list