summaryrefslogtreecommitdiff
path: root/lld/include
diff options
context:
space:
mode:
authorAndrew Ng <andrew.ng@sony.com>2020-09-09 10:48:21 +0100
committerAndrew Ng <andrew.ng@sony.com>2020-09-16 10:26:11 +0100
commit77152a6b7ac07ce65568d7c69305653e7cad4bb0 (patch)
treeb57020a65ff49b5b92f9c365855db8507330493b /lld/include
parent6040e2a6d97d9f9445715dfc468c3112f40e2588 (diff)
downloadllvm-77152a6b7ac07ce65568d7c69305653e7cad4bb0.tar.gz
[LLD][ELF] Optimize linker script filename glob pattern matching NFC
Optimize the filename glob pattern matching in LinkerScript::computeInputSections() and LinkerScript::shouldKeep(). Add InputFile::getNameForScript() which gets and if required caches the Inputfile's name used for linker script matching. This avoids the overhead of name creation that was in getFilename() in LinkerScript.cpp. Add InputSectionDescription::matchesFile() and SectionPattern::excludesFile() which perform the glob pattern matching for an InputFile and make use of a cache of the previous result. As both computeInputSections() and shouldKeep() process sections in order and the sections of the same InputFile are contiguous, these single entry caches can significantly speed up performance for more complex glob patterns. These changes have been seen to reduce link time with --gc-sections by up to ~40% with linker scripts that contain KEEP filename glob patterns such as "*crtbegin*.o". Differential Revision: https://reviews.llvm.org/D87469
Diffstat (limited to 'lld/include')
-rw-r--r--lld/include/lld/Common/Strings.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/lld/include/lld/Common/Strings.h b/lld/include/lld/Common/Strings.h
index 3940d2443cd4..38d93e01c0b9 100644
--- a/lld/include/lld/Common/Strings.h
+++ b/lld/include/lld/Common/Strings.h
@@ -39,6 +39,11 @@ public:
// Match s against this pattern, exactly if ExactMatch is true.
bool match(llvm::StringRef s) const;
+ // Returns true for pattern "*" which will match all inputs.
+ bool isTrivialMatchAll() const {
+ return !ExactMatch && GlobPatternMatcher.isTrivialMatchAll();
+ }
+
private:
// Whether to do an exact match irregardless of the presence of wildcard
// character.
@@ -69,7 +74,7 @@ public:
// Add a new pattern to the existing ones to match against.
void addPattern(SingleStringMatcher Matcher) { patterns.push_back(Matcher); }
- bool empty() { return patterns.empty(); }
+ bool empty() const { return patterns.empty(); }
// Match s against the patterns.
bool match(llvm::StringRef s) const;