[lld] 0cf6515 - [lld-macho][nfc] Use llvm::enumerate + destructuring in more places
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 22 07:41:39 PDT 2022
Author: Jez Ng
Date: 2022-10-22T10:41:20-04:00
New Revision: 0cf6515e27d420ab177fcd0f3afa529626a9faa8
URL: https://github.com/llvm/llvm-project/commit/0cf6515e27d420ab177fcd0f3afa529626a9faa8
DIFF: https://github.com/llvm/llvm-project/commit/0cf6515e27d420ab177fcd0f3afa529626a9faa8.diff
LOG: [lld-macho][nfc] Use llvm::enumerate + destructuring in more places
I love C++17!
chromium_framework_less_dwarf on my 16-core Mac Pro shows no stat sig change in wall time but a slight decrease in user time:
```
base diff difference (95% CI)
sys_time 1.759 ± 0.037 1.761 ± 0.033 [ -0.9% .. +1.1%]
user_time 4.920 ± 0.043 4.886 ± 0.051 [ -1.2% .. -0.2%]
wall_time 5.950 ± 0.117 5.900 ± 0.116 [ -1.8% .. +0.2%]
samples 26 37
```
Reviewed By: #lld-macho, thakis
Differential Revision: https://reviews.llvm.org/D136518
Added:
Modified:
lld/MachO/InputFiles.cpp
lld/MachO/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index e542fe24255fb..d522f1385a55f 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -1013,12 +1013,11 @@ template <class LP> void ObjFile::parseLazy() {
c->nsyms);
const char *strtab = reinterpret_cast<const char *>(buf) + c->stroff;
symbols.resize(nList.size());
- for (auto it : llvm::enumerate(nList)) {
- const NList &sym = it.value();
+ for (const auto &[i, sym] : llvm::enumerate(nList)) {
if ((sym.n_type & N_EXT) && !isUndef(sym)) {
// TODO: Bound checking
StringRef name = strtab + sym.n_strx;
- symbols[it.index()] = symtab->addLazyObject(name, *this);
+ symbols[i] = symtab->addLazyObject(name, *this);
if (!lazy)
break;
}
@@ -2204,11 +2203,9 @@ void BitcodeFile::parse() {
void BitcodeFile::parseLazy() {
symbols.resize(obj->symbols().size());
- for (auto it : llvm::enumerate(obj->symbols())) {
- const lto::InputFile::Symbol &objSym = it.value();
+ for (const auto &[i, objSym] : llvm::enumerate(obj->symbols())) {
if (!objSym.isUndefined()) {
- symbols[it.index()] =
- symtab->addLazyObject(saver().save(objSym.getName()), *this);
+ symbols[i] = symtab->addLazyObject(saver().save(objSym.getName()), *this);
if (!lazy)
break;
}
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 33988dffd2ff0..cc1b8f1d97890 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -389,11 +389,11 @@ void macho::writeChainedFixup(uint8_t *buf, const Symbol *sym, int64_t addend) {
void NonLazyPointerSectionBase::writeTo(uint8_t *buf) const {
if (config->emitChainedFixups) {
- for (size_t i = 0, n = entries.size(); i < n; ++i)
- writeChainedFixup(&buf[i * target->wordSize], entries[i], 0);
+ for (const auto &[i, entry] : llvm::enumerate(entries))
+ writeChainedFixup(&buf[i * target->wordSize], entry, 0);
} else {
- for (size_t i = 0, n = entries.size(); i < n; ++i)
- if (auto *defined = dyn_cast<Defined>(entries[i]))
+ for (const auto &[i, entry] : llvm::enumerate(entries))
+ if (auto *defined = dyn_cast<Defined>(entry))
write64le(&buf[i * target->wordSize], defined->getVA());
}
}
@@ -1623,11 +1623,11 @@ void CStringSection::addInput(CStringInputSection *isec) {
void CStringSection::writeTo(uint8_t *buf) const {
for (const CStringInputSection *isec : inputs) {
- for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) {
- if (!isec->pieces[i].live)
+ for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
+ if (!piece.live)
continue;
StringRef string = isec->getStringRef(i);
- memcpy(buf + isec->pieces[i].outSecOff, string.data(), string.size());
+ memcpy(buf + piece.outSecOff, string.data(), string.size());
}
}
}
@@ -1635,15 +1635,15 @@ void CStringSection::writeTo(uint8_t *buf) const {
void CStringSection::finalizeContents() {
uint64_t offset = 0;
for (CStringInputSection *isec : inputs) {
- for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) {
- if (!isec->pieces[i].live)
+ for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
+ if (!piece.live)
continue;
// See comment above DeduplicatedCStringSection for how alignment is
// handled.
- uint32_t pieceAlign =
- 1 << countTrailingZeros(isec->align | isec->pieces[i].inSecOff);
+ uint32_t pieceAlign = 1
+ << countTrailingZeros(isec->align | piece.inSecOff);
offset = alignTo(offset, pieceAlign);
- isec->pieces[i].outSecOff = offset;
+ piece.outSecOff = offset;
isec->isFinal = true;
StringRef string = isec->getStringRef(i);
offset += string.size() + 1; // account for null terminator
@@ -1693,8 +1693,7 @@ void CStringSection::finalizeContents() {
void DeduplicatedCStringSection::finalizeContents() {
// Find the largest alignment required for each string.
for (const CStringInputSection *isec : inputs) {
- for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) {
- const StringPiece &piece = isec->pieces[i];
+ for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
if (!piece.live)
continue;
auto s = isec->getCachedHashStringRef(i);
@@ -1710,8 +1709,8 @@ void DeduplicatedCStringSection::finalizeContents() {
// Assign an offset for each string and save it to the corresponding
// StringPieces for easy access.
for (CStringInputSection *isec : inputs) {
- for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) {
- if (!isec->pieces[i].live)
+ for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
+ if (!piece.live)
continue;
auto s = isec->getCachedHashStringRef(i);
auto it = stringOffsetMap.find(s);
@@ -1722,7 +1721,7 @@ void DeduplicatedCStringSection::finalizeContents() {
size =
offsetInfo.outSecOff + s.size() + 1; // account for null terminator
}
- isec->pieces[i].outSecOff = offsetInfo.outSecOff;
+ piece.outSecOff = offsetInfo.outSecOff;
}
isec->isFinal = true;
}
More information about the llvm-commits
mailing list