[lld] r328686 - Initialize OffsetMap in a known location.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 27 20:20:18 PDT 2018
Author: rafael
Date: Tue Mar 27 20:20:18 2018
New Revision: 328686
URL: http://llvm.org/viewvc/llvm-project?rev=328686&view=rev
Log:
Initialize OffsetMap in a known location.
This is a small optimization and avoids the need to use call_once.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=328686&r1=328685&r2=328686&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Mar 27 20:20:18 2018
@@ -958,13 +958,6 @@ uint64_t MergeInputSection::getOffset(ui
if (!Live)
return 0;
- // Initialize OffsetMap lazily.
- llvm::call_once(InitOffsetMap, [&] {
- OffsetMap.reserve(Pieces.size());
- for (size_t I = 0; I < Pieces.size(); ++I)
- OffsetMap[Pieces[I].InputOff] = I;
- });
-
// Find a string starting at a given offset.
auto It = OffsetMap.find(Offset);
if (It != OffsetMap.end())
@@ -980,6 +973,12 @@ uint64_t MergeInputSection::getOffset(ui
return Piece.OutputOff + Addend;
}
+void MergeInputSection::initOffsetMap() {
+ OffsetMap.reserve(Pieces.size());
+ for (size_t I = 0; I < Pieces.size(); ++I)
+ OffsetMap[Pieces[I].InputOff] = I;
+}
+
template InputSection::InputSection(ObjFile<ELF32LE> &, const ELF32LE::Shdr &,
StringRef);
template InputSection::InputSection(ObjFile<ELF32BE> &, const ELF32BE::Shdr &,
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=328686&r1=328685&r2=328686&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Mar 27 20:20:18 2018
@@ -18,8 +18,6 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Object/ELF.h"
-#include "llvm/Support/Threading.h"
-#include <mutex>
namespace lld {
namespace elf {
@@ -256,13 +254,13 @@ public:
}
SyntheticSection *getParent() const;
+ void initOffsetMap();
private:
void splitStrings(ArrayRef<uint8_t> A, size_t Size);
void splitNonStrings(ArrayRef<uint8_t> A, size_t Size);
- mutable llvm::DenseMap<uint32_t, uint32_t> OffsetMap;
- mutable llvm::once_flag InitOffsetMap;
+ llvm::DenseMap<uint32_t, uint32_t> OffsetMap;
llvm::DenseSet<uint32_t> LiveOffsets;
};
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=328686&r1=328685&r2=328686&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Mar 27 20:20:18 2018
@@ -2573,8 +2573,11 @@ void elf::mergeSections() {
}
(*I)->addSection(MS);
}
- for (auto *MS : MergeSections)
+ for (auto *MS : MergeSections) {
MS->finalizeContents();
+ parallelForEach(MS->Sections,
+ [](MergeInputSection *Sec) { Sec->initOffsetMap(); });
+ }
std::vector<InputSectionBase *> &V = InputSections;
V.erase(std::remove(V.begin(), V.end(), nullptr), V.end());
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=328686&r1=328685&r2=328686&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Tue Mar 27 20:20:18 2018
@@ -684,13 +684,12 @@ public:
class MergeSyntheticSection : public SyntheticSection {
public:
void addSection(MergeInputSection *MS);
+ std::vector<MergeInputSection *> Sections;
protected:
MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
uint32_t Alignment)
: SyntheticSection(Flags, Type, Alignment, Name) {}
-
- std::vector<MergeInputSection *> Sections;
};
class MergeTailSection final : public MergeSyntheticSection {
More information about the llvm-commits
mailing list