[lld] 10316a6 - [ELF] Change InputSectionDescription members from vector to SmallVector

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 26 13:07:00 PST 2021


Author: Fangrui Song
Date: 2021-12-26T13:06:54-08:00
New Revision: 10316a6f94d47e859a8c2e5b42905f40b9c5c44e

URL: https://github.com/llvm/llvm-project/commit/10316a6f94d47e859a8c2e5b42905f40b9c5c44e
DIFF: https://github.com/llvm/llvm-project/commit/10316a6f94d47e859a8c2e5b42905f40b9c5c44e.diff

LOG: [ELF] Change InputSectionDescription members from vector to SmallVector

This decreases sizeof(lld::elf::InputSectionDescription) from 264 to 232.

Added: 
    

Modified: 
    lld/ELF/AArch64ErrataFix.cpp
    lld/ELF/ARMErrataFix.cpp
    lld/ELF/LinkerScript.cpp
    lld/ELF/LinkerScript.h
    lld/ELF/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp
index 50d4c237778b..a1e276ea9c77 100644
--- a/lld/ELF/AArch64ErrataFix.cpp
+++ b/lld/ELF/AArch64ErrataFix.cpp
@@ -512,7 +512,7 @@ void AArch64Err843419Patcher::insertPatches(
   // determine the insertion point. This is ok as we only merge into an
   // InputSectionDescription once per pass, and at the end of the pass
   // assignAddresses() will recalculate all the outSecOff values.
-  std::vector<InputSection *> tmp;
+  SmallVector<InputSection *, 0> tmp;
   tmp.reserve(isd.sections.size() + patches.size());
   auto mergeCmp = [](const InputSection *a, const InputSection *b) {
     if (a->outSecOff != b->outSecOff)

diff  --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp
index 5ad55f1326b3..cfaa3109afe8 100644
--- a/lld/ELF/ARMErrataFix.cpp
+++ b/lld/ELF/ARMErrataFix.cpp
@@ -395,7 +395,7 @@ void ARMErr657417Patcher::insertPatches(
   // determine the insertion point. This is ok as we only merge into an
   // InputSectionDescription once per pass, and at the end of the pass
   // assignAddresses() will recalculate all the outSecOff values.
-  std::vector<InputSection *> tmp;
+  SmallVector<InputSection *, 0> tmp;
   tmp.reserve(isd.sections.size() + patches.size());
   auto mergeCmp = [](const InputSection *a, const InputSection *b) {
     if (a->outSecOff != b->outSecOff)

diff  --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e8f2ce4fdf1f..9a95256a15af 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -270,8 +270,8 @@ using SymbolAssignmentMap =
 
 // Collect section/value pairs of linker-script-defined symbols. This is used to
 // check whether symbol values converge.
-static SymbolAssignmentMap getSymbolAssignmentValues(
-    const std::vector<SectionCommand *> &sectionCommands) {
+static SymbolAssignmentMap
+getSymbolAssignmentValues(ArrayRef<SectionCommand *> sectionCommands) {
   SymbolAssignmentMap ret;
   for (SectionCommand *cmd : sectionCommands) {
     if (auto *assign = dyn_cast<SymbolAssignment>(cmd)) {
@@ -486,10 +486,10 @@ static void sortInputSections(MutableArrayRef<InputSectionBase *> vec,
 }
 
 // Compute and remember which sections the InputSectionDescription matches.
-std::vector<InputSectionBase *>
+SmallVector<InputSectionBase *, 0>
 LinkerScript::computeInputSections(const InputSectionDescription *cmd,
                                    ArrayRef<InputSectionBase *> sections) {
-  std::vector<InputSectionBase *> ret;
+  SmallVector<InputSectionBase *, 0> ret;
   std::vector<size_t> indexes;
   DenseSet<size_t> seen;
   auto sortByPositionThenCommandLine = [&](size_t begin, size_t end) {
@@ -585,18 +585,15 @@ void LinkerScript::discardSynthetic(OutputSection &outCmd) {
     std::vector<InputSectionBase *> secs(part.armExidx->exidxSections.begin(),
                                          part.armExidx->exidxSections.end());
     for (SectionCommand *cmd : outCmd.commands)
-      if (auto *isd = dyn_cast<InputSectionDescription>(cmd)) {
-        std::vector<InputSectionBase *> matches =
-            computeInputSections(isd, secs);
-        for (InputSectionBase *s : matches)
+      if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
+        for (InputSectionBase *s : computeInputSections(isd, secs))
           discard(*s);
-      }
   }
 }
 
-std::vector<InputSectionBase *>
+SmallVector<InputSectionBase *, 0>
 LinkerScript::createInputSectionList(OutputSection &outCmd) {
-  std::vector<InputSectionBase *> ret;
+  SmallVector<InputSectionBase *, 0> ret;
 
   for (SectionCommand *cmd : outCmd.commands) {
     if (auto *isd = dyn_cast<InputSectionDescription>(cmd)) {
@@ -612,7 +609,7 @@ LinkerScript::createInputSectionList(OutputSection &outCmd) {
 // Create output sections described by SECTIONS commands.
 void LinkerScript::processSectionCommands() {
   auto process = [this](OutputSection *osec) {
-    std::vector<InputSectionBase *> v = createInputSectionList(*osec);
+    SmallVector<InputSectionBase *, 0> v = createInputSectionList(*osec);
 
     // The output section name `/DISCARD/' is special.
     // Any input section assigned to it is discarded.

diff  --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index f385c8320978..9fafdb64bfaf 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -203,20 +203,20 @@ class InputSectionDescription : public SectionCommand {
 
   // Input sections that matches at least one of SectionPatterns
   // will be associated with this InputSectionDescription.
-  std::vector<SectionPattern> sectionPatterns;
+  SmallVector<SectionPattern, 0> sectionPatterns;
 
   // Includes InputSections and MergeInputSections. Used temporarily during
   // assignment of input sections to output sections.
-  std::vector<InputSectionBase *> sectionBases;
+  SmallVector<InputSectionBase *, 0> sectionBases;
 
   // Used after the finalizeInputSections() pass. MergeInputSections have been
   // merged into MergeSyntheticSections.
-  std::vector<InputSection *> sections;
+  SmallVector<InputSection *, 0> sections;
 
   // Temporary record of synthetic ThunkSection instances and the pass that
   // they were created in. This is used to insert newly created ThunkSections
   // into Sections at the end of a createThunks() pass.
-  std::vector<std::pair<ThunkSection *, uint32_t>> thunkSections;
+  SmallVector<std::pair<ThunkSection *, uint32_t>, 0> thunkSections;
 
   // SectionPatterns can be filtered with the INPUT_SECTION_FLAGS command.
   uint64_t withFlags;
@@ -279,11 +279,11 @@ class LinkerScript final {
   void expandOutputSection(uint64_t size);
   void expandMemoryRegions(uint64_t size);
 
-  std::vector<InputSectionBase *>
+  SmallVector<InputSectionBase *, 0>
   computeInputSections(const InputSectionDescription *,
                        ArrayRef<InputSectionBase *>);
 
-  std::vector<InputSectionBase *> createInputSectionList(OutputSection &cmd);
+  SmallVector<InputSectionBase *, 0> createInputSectionList(OutputSection &cmd);
 
   void discardSynthetic(OutputSection &);
 
@@ -347,23 +347,23 @@ class LinkerScript final {
 
   // List of section patterns specified with KEEP commands. They will
   // be kept even if they are unused and --gc-sections is specified.
-  std::vector<InputSectionDescription *> keptSections;
+  SmallVector<InputSectionDescription *, 0> keptSections;
 
   // A map from memory region name to a memory region descriptor.
   llvm::MapVector<llvm::StringRef, MemoryRegion *> memoryRegions;
 
   // A list of symbols referenced by the script.
-  std::vector<llvm::StringRef> referencedSymbols;
+  SmallVector<llvm::StringRef, 0> referencedSymbols;
 
   // Used to implement INSERT [AFTER|BEFORE]. Contains output sections that need
   // to be reordered.
-  std::vector<InsertCommand> insertCommands;
+  SmallVector<InsertCommand, 0> insertCommands;
 
   // OutputSections specified by OVERWRITE_SECTIONS.
-  std::vector<OutputSection *> overwriteSections;
+  SmallVector<OutputSection *, 0> overwriteSections;
 
   // Sections that will be warned/errored by --orphan-handling.
-  std::vector<const InputSectionBase *> orphanSections;
+  SmallVector<const InputSectionBase *, 0> orphanSections;
 };
 
 extern std::unique_ptr<LinkerScript> script;

diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 5841c509aa67..33227bd2447b 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1816,7 +1816,7 @@ void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> outputSections) {
                           });
 
         // Merge sorted vectors of Thunks and InputSections by outSecOff
-        std::vector<InputSection *> tmp;
+        SmallVector<InputSection *, 0> tmp;
         tmp.reserve(isd->sections.size() + newThunks.size());
 
         std::merge(isd->sections.begin(), isd->sections.end(),


        


More information about the llvm-commits mailing list