[ELF] Optimization to LinkerScript::computeInputSections NFC
authorAndrew Ng <andrew.ng@sony.com>
Wed, 15 Jan 2020 11:48:37 +0000 (11:48 +0000)
committerAndrew Ng <andrew.ng@sony.com>
Thu, 16 Jan 2020 13:56:02 +0000 (13:56 +0000)
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

lld/ELF/LinkerScript.cpp

index 57e0e1e8acbf36be6dcf1a03a1aaf830eaf46342..b0d60bc32a9faf2a98131f45ccb9ae6b464d3f19 100644 (file)
@@ -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);