-
Notifications
You must be signed in to change notification settings - Fork 15.8k
[lld][COFF] Use .contains rather than .count for set membership. NFC
#177067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Also converted a couple of `std::std` to `llvm::SmallSet`. This matches the usage in the other linker backends. See llvm#176610
|
@llvm/pr-subscribers-lld @llvm/pr-subscribers-platform-windows Author: Sam Clegg (sbc100) ChangesAlso converted a couple of See #176610 Full diff: https://github.com/llvm/llvm-project/pull/177067.diff 5 Files Affected:
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 2ee60aca116d6..1c0f874ddfd79 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -15,12 +15,12 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <cstdint>
#include <map>
-#include <set>
#include <string>
namespace lld::coff {
@@ -155,14 +155,14 @@ struct Configuration {
// Symbols in this set are considered as live by the garbage collector.
std::vector<Symbol *> gcroot;
- std::set<std::string> noDefaultLibs;
+ llvm::StringSet<> noDefaultLibs;
bool noDefaultLibAll = false;
// True if we are creating a DLL.
bool dll = false;
StringRef implib;
bool noimplib = false;
- std::set<std::string> delayLoads;
+ llvm::StringSet<> delayLoads;
std::map<std::string, int> dllOrder;
Symbol *arm64ECIcallHelper = nullptr;
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index b1337ea8157ab..3bc9c98bcdbc3 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -23,6 +23,7 @@
#include "lld/Common/Timer.h"
#include "lld/Common/Version.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Config/llvm-config.h"
@@ -715,7 +716,7 @@ std::optional<StringRef> LinkerDriver::findLibIfNew(StringRef filename) {
return std::nullopt;
StringRef path = findLib(filename);
- if (ctx.config.noDefaultLibs.count(path.lower()))
+ if (ctx.config.noDefaultLibs.contains(path.lower()))
return std::nullopt;
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
@@ -864,9 +865,9 @@ void LinkerDriver::addWinSysRootLibSearchPaths() {
// Libraries specified by `/nodefaultlib:` may not be found in incomplete
// search paths before lld infers a machine type from input files.
- std::set<std::string> noDefaultLibs;
- for (const std::string &path : ctx.config.noDefaultLibs)
- noDefaultLibs.insert(findLib(path).lower());
+ llvm::StringSet<> noDefaultLibs;
+ for (auto &iter : ctx.config.noDefaultLibs)
+ noDefaultLibs.insert(findLib(iter.first()).lower());
ctx.config.noDefaultLibs = noDefaultLibs;
}
@@ -1153,7 +1154,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
if (ctx.config.machine == I386 && !isDecorated(s))
s = "_" + s;
- if (set.count(s) == 0) {
+ if (!set.contains(s)) {
if (ctx.config.warnMissingOrderSymbol)
Warn(ctx) << "/order:" << arg << ": missing symbol: " << s
<< " [LNK4037]";
@@ -2284,7 +2285,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (errCount(ctx))
return;
- std::set<sys::fs::UniqueID> wholeArchives;
+ SmallSet<sys::fs::UniqueID, 0> wholeArchives;
for (auto *arg : args.filtered(OPT_wholearchive_file))
if (std::optional<StringRef> path = findFile(arg->getValue()))
if (std::optional<sys::fs::UniqueID> id = getUniqueID(*path))
@@ -2298,7 +2299,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (args.hasArg(OPT_wholearchive_flag))
return true;
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
- return wholeArchives.count(*id);
+ return wholeArchives.contains(*id);
return false;
};
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 597c508115a34..17760eae4eff8 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -150,7 +150,8 @@ bool AutoExporter::shouldExport(Defined *sym) const {
// disallow import symbols.
if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym))
return false;
- if (excludeSymbols.count(sym->getName()) || manualExcludeSymbols.count(sym->getName()))
+ if (excludeSymbols.contains(sym->getName()) ||
+ manualExcludeSymbols.contains(sym->getName()))
return false;
for (StringRef prefix : excludeSymbolPrefixes.keys())
@@ -174,10 +175,10 @@ bool AutoExporter::shouldExport(Defined *sym) const {
// Drop the file extension.
libName = libName.substr(0, libName.rfind('.'));
if (!libName.empty())
- return !excludeLibs.count(libName);
+ return !excludeLibs.contains(libName);
StringRef fileName = sys::path::filename(sym->getFile()->getName());
- return !excludeObjects.count(fileName);
+ return !excludeObjects.contains(fileName);
}
void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name,
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 26a2b4944dc6c..38a43390c15ab 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -381,7 +381,7 @@ void SymbolTable::reportProblemSymbols(
return;
for (Symbol *b : ctx.config.gcroot) {
- if (undefs.count(b))
+ if (undefs.contains(b))
errorOrWarn(ctx) << "<root>: undefined symbol: " << printSymbol(b);
if (localImports)
if (Symbol *imp = localImports->lookup(b))
@@ -399,7 +399,7 @@ void SymbolTable::reportProblemSymbols(
++symIndex;
if (!sym)
continue;
- if (undefs.count(sym)) {
+ if (undefs.contains(sym)) {
auto [it, inserted] = firstDiag.try_emplace(sym, undefDiags.size());
if (inserted)
undefDiags.push_back({sym, {{file, symIndex}}});
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 37c12a2b9fd8a..559bd387fa9cb 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1330,7 +1330,7 @@ void Writer::createImportTables() {
if (file->impSym && !isa<DefinedImportData>(file->impSym))
Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
- if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
+ if (ctx.config.delayLoads.contains(StringRef(file->dllName).lower())) {
if (!file->thunkSym)
Fatal(ctx) << "cannot delay-load " << toString(file)
<< " due to import of data: "
|
|
@llvm/pr-subscribers-lld-coff Author: Sam Clegg (sbc100) ChangesAlso converted a couple of See #176610 Full diff: https://github.com/llvm/llvm-project/pull/177067.diff 5 Files Affected:
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 2ee60aca116d6..1c0f874ddfd79 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -15,12 +15,12 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <cstdint>
#include <map>
-#include <set>
#include <string>
namespace lld::coff {
@@ -155,14 +155,14 @@ struct Configuration {
// Symbols in this set are considered as live by the garbage collector.
std::vector<Symbol *> gcroot;
- std::set<std::string> noDefaultLibs;
+ llvm::StringSet<> noDefaultLibs;
bool noDefaultLibAll = false;
// True if we are creating a DLL.
bool dll = false;
StringRef implib;
bool noimplib = false;
- std::set<std::string> delayLoads;
+ llvm::StringSet<> delayLoads;
std::map<std::string, int> dllOrder;
Symbol *arm64ECIcallHelper = nullptr;
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index b1337ea8157ab..3bc9c98bcdbc3 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -23,6 +23,7 @@
#include "lld/Common/Timer.h"
#include "lld/Common/Version.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Config/llvm-config.h"
@@ -715,7 +716,7 @@ std::optional<StringRef> LinkerDriver::findLibIfNew(StringRef filename) {
return std::nullopt;
StringRef path = findLib(filename);
- if (ctx.config.noDefaultLibs.count(path.lower()))
+ if (ctx.config.noDefaultLibs.contains(path.lower()))
return std::nullopt;
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
@@ -864,9 +865,9 @@ void LinkerDriver::addWinSysRootLibSearchPaths() {
// Libraries specified by `/nodefaultlib:` may not be found in incomplete
// search paths before lld infers a machine type from input files.
- std::set<std::string> noDefaultLibs;
- for (const std::string &path : ctx.config.noDefaultLibs)
- noDefaultLibs.insert(findLib(path).lower());
+ llvm::StringSet<> noDefaultLibs;
+ for (auto &iter : ctx.config.noDefaultLibs)
+ noDefaultLibs.insert(findLib(iter.first()).lower());
ctx.config.noDefaultLibs = noDefaultLibs;
}
@@ -1153,7 +1154,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
if (ctx.config.machine == I386 && !isDecorated(s))
s = "_" + s;
- if (set.count(s) == 0) {
+ if (!set.contains(s)) {
if (ctx.config.warnMissingOrderSymbol)
Warn(ctx) << "/order:" << arg << ": missing symbol: " << s
<< " [LNK4037]";
@@ -2284,7 +2285,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (errCount(ctx))
return;
- std::set<sys::fs::UniqueID> wholeArchives;
+ SmallSet<sys::fs::UniqueID, 0> wholeArchives;
for (auto *arg : args.filtered(OPT_wholearchive_file))
if (std::optional<StringRef> path = findFile(arg->getValue()))
if (std::optional<sys::fs::UniqueID> id = getUniqueID(*path))
@@ -2298,7 +2299,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (args.hasArg(OPT_wholearchive_flag))
return true;
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
- return wholeArchives.count(*id);
+ return wholeArchives.contains(*id);
return false;
};
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 597c508115a34..17760eae4eff8 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -150,7 +150,8 @@ bool AutoExporter::shouldExport(Defined *sym) const {
// disallow import symbols.
if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym))
return false;
- if (excludeSymbols.count(sym->getName()) || manualExcludeSymbols.count(sym->getName()))
+ if (excludeSymbols.contains(sym->getName()) ||
+ manualExcludeSymbols.contains(sym->getName()))
return false;
for (StringRef prefix : excludeSymbolPrefixes.keys())
@@ -174,10 +175,10 @@ bool AutoExporter::shouldExport(Defined *sym) const {
// Drop the file extension.
libName = libName.substr(0, libName.rfind('.'));
if (!libName.empty())
- return !excludeLibs.count(libName);
+ return !excludeLibs.contains(libName);
StringRef fileName = sys::path::filename(sym->getFile()->getName());
- return !excludeObjects.count(fileName);
+ return !excludeObjects.contains(fileName);
}
void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name,
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 26a2b4944dc6c..38a43390c15ab 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -381,7 +381,7 @@ void SymbolTable::reportProblemSymbols(
return;
for (Symbol *b : ctx.config.gcroot) {
- if (undefs.count(b))
+ if (undefs.contains(b))
errorOrWarn(ctx) << "<root>: undefined symbol: " << printSymbol(b);
if (localImports)
if (Symbol *imp = localImports->lookup(b))
@@ -399,7 +399,7 @@ void SymbolTable::reportProblemSymbols(
++symIndex;
if (!sym)
continue;
- if (undefs.count(sym)) {
+ if (undefs.contains(sym)) {
auto [it, inserted] = firstDiag.try_emplace(sym, undefDiags.size());
if (inserted)
undefDiags.push_back({sym, {{file, symIndex}}});
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 37c12a2b9fd8a..559bd387fa9cb 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1330,7 +1330,7 @@ void Writer::createImportTables() {
if (file->impSym && !isa<DefinedImportData>(file->impSym))
Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
- if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
+ if (ctx.config.delayLoads.contains(StringRef(file->dllName).lower())) {
if (!file->thunkSym)
Fatal(ctx) << "cannot delay-load " << toString(file)
<< " due to import of data: "
|
Also converted a couple of
std::settollvm::StringSet. This matches the usage in the other linker backends.See #176610