[lld] d36b264 - [ELF] Optimization to LinkerScript::computeInputSections NFC

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 05:56:42 PST 2020


Author: Andrew Ng
Date: 2020-01-16T13:56:02Z
New Revision: d36b2649e5e4d90a3f439e2a16057cd75566c669

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

LOG: [ELF] Optimization to LinkerScript::computeInputSections NFC

Moved the section name check ahead of any filename matching or
exclusion. Firstly, this reduces the need to retrieve the filename and
secondly, reduces the amount of potentially expensive filename pattern
matching if such rules are present in the linker script.

The impact of this change is particularly significant when linking
objects built with -ffunction-sections and -fstack-size-section, using a
linker script that includes non-trivial filename patterns. In a number
of such cases, the link time is halved.

Differential Revision: https://reviews.llvm.org/D72775

Added: 
    

Modified: 
    lld/ELF/LinkerScript.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 57e0e1e8acbf..b0d60bc32a9f 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -426,10 +426,12 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd) {
           cast<InputSection>(sec)->getRelocatedSection())
         continue;
 
+      // Check the name early to improve performance in the common case.
+      if (!pat.sectionPat.match(sec->name))
+        continue;
+
       std::string filename = getFilename(sec->file);
-      if (!cmd->filePat.match(filename) ||
-          pat.excludedFilePat.match(filename) ||
-          !pat.sectionPat.match(sec->name))
+      if (!cmd->filePat.match(filename) || pat.excludedFilePat.match(filename))
         continue;
 
       ret.push_back(sec);


        


More information about the llvm-commits mailing list