From 93ceadfb7bf9c4b07171c2dbf96ccae3c8cb59b9 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 6 Mar 2015 06:53:13 +0000 Subject: PECOFF: Optimize the writer using parallel_for. Previously applying 1 million relocations took about 2 seconds on my Xeon 2.4GHz 8 core workstation. After this patch, it takes about 300 milliseconds. As a result, time to link chrome.dll becomes 23 seconds to 21 seconds. llvm-svn: 231454 --- lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp') diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index 886e1f952e1..e501ca1019b 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -602,8 +602,9 @@ void AtomChunk::applyRelocationsARM(uint8_t *Buffer, std::vector &SectionRVA, uint64_t ImageBase) { Buffer = Buffer + _fileOffset; - for (const auto *Layout : _atomLayouts) { - const DefinedAtom *Atom = cast(Layout->_atom); + parallel_for_each(_atomLayouts.begin(), _atomLayouts.end(), + [&](const AtomLayout *layout) { + const DefinedAtom *Atom = cast(layout->_atom); for (const Reference *R : *Atom) { if (R->kindNamespace() != Reference::KindNamespace::COFF) continue; @@ -614,7 +615,7 @@ void AtomChunk::applyRelocationsARM(uint8_t *Buffer, Target->permissions() == DefinedAtom::permRWX; const auto AtomOffset = R->offsetInAtom(); - const auto FileOffset = Layout->_fileOffset; + const auto FileOffset = layout->_fileOffset; const auto TargetAddr = AtomRVA[R->target()] | (AssumeTHUMBCode ? 1 : 0); auto RelocSite16 = reinterpret_cast(Buffer + FileOffset + AtomOffset); @@ -645,7 +646,7 @@ void AtomChunk::applyRelocationsARM(uint8_t *Buffer, break; } } - } + }); } void AtomChunk::applyRelocationsX86(uint8_t *buffer, @@ -653,7 +654,8 @@ void AtomChunk::applyRelocationsX86(uint8_t *buffer, std::vector §ionRva, uint64_t imageBaseAddress) { buffer += _fileOffset; - for (const auto *layout : _atomLayouts) { + parallel_for_each(_atomLayouts.begin(), _atomLayouts.end(), + [&](const AtomLayout *layout) { const DefinedAtom *atom = cast(layout->_atom); for (const Reference *ref : *atom) { // Skip if this reference is not for COFF relocation. @@ -702,7 +704,7 @@ void AtomChunk::applyRelocationsX86(uint8_t *buffer, llvm::report_fatal_error("Unsupported relocation kind"); } } - } + }); } void AtomChunk::applyRelocationsX64(uint8_t *buffer, @@ -710,7 +712,8 @@ void AtomChunk::applyRelocationsX64(uint8_t *buffer, std::vector §ionRva, uint64_t imageBase) { buffer += _fileOffset; - for (const auto *layout : _atomLayouts) { + parallel_for_each(_atomLayouts.begin(), _atomLayouts.end(), + [&](const AtomLayout *layout) { const DefinedAtom *atom = cast(layout->_atom); for (const Reference *ref : *atom) { if (ref->kindNamespace() != Reference::KindNamespace::COFF) @@ -762,7 +765,7 @@ void AtomChunk::applyRelocationsX64(uint8_t *buffer, llvm::report_fatal_error("Unsupported relocation kind"); } } - } + }); } /// Print atom VAs. Used only for debugging. -- cgit v1.2.3