[lld] 4b2b68d - [lld] Change vector to SmallVector. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 30 18:11:25 PDT 2022
Author: Fangrui Song
Date: 2022-07-30T18:11:21-07:00
New Revision: 4b2b68d5abd8981d0a5ca47e2bbc6df3d8360fd1
URL: https://github.com/llvm/llvm-project/commit/4b2b68d5abd8981d0a5ca47e2bbc6df3d8360fd1
DIFF: https://github.com/llvm/llvm-project/commit/4b2b68d5abd8981d0a5ca47e2bbc6df3d8360fd1.diff
LOG: [lld] Change vector to SmallVector. NFC
My lld executable is 1.6KiB smaller and some functions are now more efficient.
Added:
Modified:
lld/Common/Args.cpp
lld/Common/Strings.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/MachO/Config.h
lld/include/lld/Common/Args.h
lld/include/lld/Common/Strings.h
lld/wasm/Config.h
Removed:
################################################################################
diff --git a/lld/Common/Args.cpp b/lld/Common/Args.cpp
index fe7300dd597e5..388c15b3db3ec 100644
--- a/lld/Common/Args.cpp
+++ b/lld/Common/Args.cpp
@@ -54,8 +54,9 @@ int64_t lld::args::getHex(opt::InputArgList &args, unsigned key,
return ::getInteger(args, key, Default, 16);
}
-std::vector<StringRef> lld::args::getStrings(opt::InputArgList &args, int id) {
- std::vector<StringRef> v;
+SmallVector<StringRef, 0> lld::args::getStrings(opt::InputArgList &args,
+ int id) {
+ SmallVector<StringRef, 0> v;
for (auto *arg : args.filtered(id))
v.push_back(arg->getValue());
return v;
diff --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp
index 6e5478e335ca3..31397b75b2952 100644
--- a/lld/Common/Strings.cpp
+++ b/lld/Common/Strings.cpp
@@ -46,8 +46,8 @@ bool StringMatcher::match(StringRef s) const {
}
// Converts a hex string (e.g. "deadbeef") to a vector.
-std::vector<uint8_t> lld::parseHex(StringRef s) {
- std::vector<uint8_t> hex;
+SmallVector<uint8_t, 0> lld::parseHex(StringRef s) {
+ SmallVector<uint8_t, 0> hex;
while (!s.empty()) {
StringRef b = s.substr(0, 2);
s = s.substr(2);
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 39723f0927849..c29e41d657130 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -142,16 +142,16 @@ struct Configuration {
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
std::string rpath;
- std::vector<VersionDefinition> versionDefinitions;
- std::vector<llvm::StringRef> auxiliaryList;
- std::vector<llvm::StringRef> filterList;
- std::vector<llvm::StringRef> passPlugins;
- std::vector<llvm::StringRef> searchPaths;
- std::vector<llvm::StringRef> symbolOrderingFile;
- std::vector<llvm::StringRef> thinLTOModulesToCompile;
- std::vector<llvm::StringRef> undefined;
- std::vector<SymbolVersion> dynamicList;
- std::vector<uint8_t> buildIdVector;
+ llvm::SmallVector<VersionDefinition, 0> versionDefinitions;
+ llvm::SmallVector<llvm::StringRef, 0> auxiliaryList;
+ llvm::SmallVector<llvm::StringRef, 0> filterList;
+ llvm::SmallVector<llvm::StringRef, 0> passPlugins;
+ llvm::SmallVector<llvm::StringRef, 0> searchPaths;
+ llvm::SmallVector<llvm::StringRef, 0> symbolOrderingFile;
+ llvm::SmallVector<llvm::StringRef, 0> thinLTOModulesToCompile;
+ llvm::SmallVector<llvm::StringRef, 0> undefined;
+ llvm::SmallVector<SymbolVersion, 0> dynamicList;
+ llvm::SmallVector<uint8_t, 0> buildIdVector;
llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
uint64_t>
callGraphProfile;
@@ -167,7 +167,8 @@ struct Configuration {
bool checkDynamicRelocs;
bool compressDebugSections;
bool cref;
- std::vector<std::pair<llvm::GlobPattern, uint64_t>> deadRelocInNonAlloc;
+ llvm::SmallVector<std::pair<llvm::GlobPattern, uint64_t>, 0>
+ deadRelocInNonAlloc;
bool demangle = true;
bool dependentLibraries;
bool disableVerify;
@@ -217,7 +218,7 @@ struct Configuration {
bool relrGlibc = false;
bool relrPackDynRelocs = false;
llvm::DenseSet<llvm::StringRef> saveTempsArgs;
- std::vector<std::pair<llvm::GlobPattern, uint32_t>> shuffleSections;
+ llvm::SmallVector<std::pair<llvm::GlobPattern, uint32_t>, 0> shuffleSections;
bool singleRoRx;
bool shared;
bool symbolic;
@@ -235,7 +236,7 @@ struct Configuration {
bool unique;
bool useAndroidRelrTags = false;
bool warnBackrefs;
- std::vector<llvm::GlobPattern> warnBackrefsExclude;
+ llvm::SmallVector<llvm::GlobPattern, 0> warnBackrefsExclude;
bool warnCommon;
bool warnMissingEntry;
bool warnSymbolOrdering;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 9fe4508559981..8d2a718510877 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -606,7 +606,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
}
static std::string getRpath(opt::InputArgList &args) {
- std::vector<StringRef> v = args::getStrings(args, OPT_rpath);
+ SmallVector<StringRef, 0> v = args::getStrings(args, OPT_rpath);
return llvm::join(v.begin(), v.end(), ":");
}
@@ -807,7 +807,7 @@ static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &args) {
// Parse --build-id or --build-id=<style>. We handle "tree" as a
// synonym for "sha1" because all our hash functions including
// --build-id=sha1 are actually tree hashes for performance reasons.
-static std::pair<BuildIdKind, std::vector<uint8_t>>
+static std::pair<BuildIdKind, SmallVector<uint8_t, 0>>
getBuildId(opt::InputArgList &args) {
auto *arg = args.getLastArg(OPT_build_id);
if (!arg)
@@ -982,8 +982,8 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
}
// Parse the symbol ordering file and warn for any duplicate entries.
-static std::vector<StringRef> getSymbolOrderingFile(MemoryBufferRef mb) {
- SetVector<StringRef> names;
+static SmallVector<StringRef, 0> getSymbolOrderingFile(MemoryBufferRef mb) {
+ SetVector<StringRef, SmallVector<StringRef, 0>> names;
for (StringRef s : args::getLines(mb))
if (!names.insert(s) && config->warnSymbolOrdering)
warn(mb.getBufferIdentifier() + ": duplicate ordered symbol: " + s);
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 91e7faf2e8f43..4ec5f03e8a0e9 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -13,6 +13,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/MachO.h"
@@ -169,7 +170,7 @@ struct Configuration {
std::vector<llvm::StringRef> systemLibraryRoots;
std::vector<llvm::StringRef> librarySearchPaths;
std::vector<llvm::StringRef> frameworkSearchPaths;
- std::vector<llvm::StringRef> runtimePaths;
+ llvm::SmallVector<llvm::StringRef, 0> runtimePaths;
std::vector<std::string> astPaths;
std::vector<Symbol *> explicitUndefineds;
llvm::StringSet<> explicitDynamicLookups;
diff --git a/lld/include/lld/Common/Args.h b/lld/include/lld/Common/Args.h
index 48f7b4079cd97..40c8ee4e9d0eb 100644
--- a/lld/include/lld/Common/Args.h
+++ b/lld/include/lld/Common/Args.h
@@ -30,7 +30,8 @@ int64_t getInteger(llvm::opt::InputArgList &args, unsigned key,
int64_t getHex(llvm::opt::InputArgList &args, unsigned key, int64_t Default);
-std::vector<StringRef> getStrings(llvm::opt::InputArgList &args, int id);
+llvm::SmallVector<StringRef, 0> getStrings(llvm::opt::InputArgList &args,
+ int id);
uint64_t getZOptionValue(llvm::opt::InputArgList &args, int id, StringRef key,
uint64_t Default);
diff --git a/lld/include/lld/Common/Strings.h b/lld/include/lld/Common/Strings.h
index ece801892767a..29cd83acff85f 100644
--- a/lld/include/lld/Common/Strings.h
+++ b/lld/include/lld/Common/Strings.h
@@ -11,6 +11,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/GlobPattern.h"
@@ -26,7 +27,7 @@ inline std::string demangle(llvm::StringRef symName, bool shouldDemangle) {
return std::string(symName);
}
-std::vector<uint8_t> parseHex(llvm::StringRef s);
+llvm::SmallVector<uint8_t, 0> parseHex(llvm::StringRef s);
bool isValidCIdentifier(llvm::StringRef s);
// Write the contents of the a buffer to a file
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 8eaa4acc6ab3d..2c79e4196338b 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -9,6 +9,7 @@
#ifndef LLD_WASM_CONFIG_H
#define LLD_WASM_CONFIG_H
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/Wasm.h"
@@ -72,7 +73,7 @@ struct Configuration {
llvm::StringSet<> allowUndefinedSymbols;
llvm::StringSet<> exportedSymbols;
std::vector<llvm::StringRef> requiredExports;
- std::vector<llvm::StringRef> searchPaths;
+ llvm::SmallVector<llvm::StringRef, 0> searchPaths;
llvm::CachePruningPolicy thinLTOCachePolicy;
llvm::Optional<std::vector<std::string>> features;
More information about the llvm-commits
mailing list