[PATCH] D44967: Initialize OffsetMap in a known location
Rafael Avila de Espindola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 27 18:44:09 PDT 2018
espindola created this revision.
espindola added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
This is a small optimization: 3% in clang, probably noise everywhere else.
It is also a bit simpler IMHO.
https://reviews.llvm.org/D44967
Files:
ELF/InputSection.cpp
ELF/InputSection.h
ELF/SyntheticSections.cpp
ELF/SyntheticSections.h
Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ ELF/SyntheticSections.h
@@ -684,13 +684,12 @@
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 {
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2573,8 +2573,11 @@
}
(*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());
Index: ELF/InputSection.h
===================================================================
--- ELF/InputSection.h
+++ ELF/InputSection.h
@@ -254,13 +254,13 @@
const SectionPiece *getSectionPiece(uint64_t Offset) const;
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<uint64_t> LiveOffsets;
};
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -963,13 +963,6 @@
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())
@@ -985,6 +978,12 @@
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 &,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44967.140031.patch
Type: text/x-patch
Size: 2781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180328/a7e1cc4f/attachment.bin>
More information about the llvm-commits
mailing list