<div dir="ltr">Great improvement!</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 10, 2017 at 12:13 PM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Wed May 10 14:13:38 2017<br>
New Revision: 302708<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=302708&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=302708&view=rev</a><br>
Log:<br>
Use a DenseMap in LinkerScript::getCmd.<br>
<br>
This improves many-sections.s with a linker script from 22s to 0.9s.<br>
<br>
Modified:<br>
lld/trunk/ELF/LinkerScript.cpp<br>
lld/trunk/ELF/LinkerScript.h<br>
lld/trunk/test/ELF/many-<wbr>sections.s<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=302708&r1=302707&r2=302708&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.cpp?rev=302708&<wbr>r1=302707&r2=302708&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Wed May 10 14:13:38 2017<br>
@@ -415,6 +415,7 @@ void LinkerScript::processCommands(<wbr>Outpu<br>
if (OutputSection *Sec = Cmd->Sec) {<br>
assert(Sec->SectionIndex == INT_MAX);<br>
Sec->SectionIndex = I;<br>
+ SecToCommand[Sec] = Cmd;<br>
}<br>
}<br>
}<br>
@@ -444,6 +445,7 @@ void LinkerScript::<wbr>fabricateDefaultComma<br>
<br>
auto *OSCmd = make<OutputSectionCommand>(<wbr>Sec->Name);<br>
OSCmd->Sec = Sec;<br>
+ SecToCommand[Sec] = OSCmd;<br>
<br>
// Prefer user supplied address over additional alignment constraint<br>
auto I = Config->SectionStartMap.find(<wbr>Sec->Name);<br>
@@ -488,6 +490,7 @@ void LinkerScript::<wbr>addOrphanSections(Out<br>
auto *Cmd = cast<OutputSectionCommand>(*I)<wbr>;<br>
Factory.addInputSec(S, Name, Cmd->Sec);<br>
if (OutputSection *Sec = Cmd->Sec) {<br>
+ SecToCommand[Sec] = Cmd;<br>
unsigned Index = std::distance(Opt.Commands.<wbr>begin(), I);<br>
assert(Sec->SectionIndex == INT_MAX || Sec->SectionIndex == Index);<br>
Sec->SectionIndex = Index;<br>
@@ -703,6 +706,7 @@ void LinkerScript::<wbr>adjustSectionsBeforeS<br>
OutSec->SectionIndex = I;<br>
OutputSections->push_back(<wbr>OutSec);<br>
Cmd->Sec = OutSec;<br>
+ SecToCommand[OutSec] = Cmd;<br>
}<br>
}<br>
<br>
@@ -833,6 +837,7 @@ void LinkerScript::<wbr>placeOrphanSections()<br>
++CmdIndex;<br>
<br>
Cmd->Sec = Sec;<br>
+ SecToCommand[Sec] = Cmd;<br>
auto *ISD = make<InputSectionDescription>(<wbr>"");<br>
for (InputSection *IS : Sec->Sections)<br>
ISD->Sections.push_back(IS);<br>
@@ -1025,12 +1030,11 @@ bool LinkerScript::<wbr>ignoreInterpSection()<br>
return true;<br>
}<br>
<br>
-OutputSectionCommand *LinkerScript::getCmd(<wbr>OutputSection *Sec) {<br>
- for (BaseCommand *Base : Opt.Commands)<br>
- if (auto *Cmd = dyn_cast<OutputSectionCommand><wbr>(Base))<br>
- if (Cmd->Sec == Sec)<br>
- return Cmd;<br>
- return nullptr;<br>
+OutputSectionCommand *LinkerScript::getCmd(<wbr>OutputSection *Sec) const {<br>
+ auto I = SecToCommand.find(Sec);<br>
+ if (I == SecToCommand.end())<br>
+ return nullptr;<br>
+ return I->second;<br>
}<br>
<br>
Optional<uint32_t> LinkerScript::getFiller(<wbr>OutputSection *Sec) {<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=302708&r1=302707&r2=302708&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.h?rev=302708&r1=<wbr>302707&r2=302708&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.h (original)<br>
+++ lld/trunk/ELF/LinkerScript.h Wed May 10 14:13:38 2017<br>
@@ -212,7 +212,8 @@ struct ScriptConfiguration {<br>
};<br>
<br>
class LinkerScript final {<br>
- OutputSectionCommand *getCmd(OutputSection *Sec);<br>
+ llvm::DenseMap<OutputSection *, OutputSectionCommand *> SecToCommand;<br>
+ OutputSectionCommand *getCmd(OutputSection *Sec) const;<br>
void assignSymbol(SymbolAssignment *Cmd, bool InSec);<br>
void setDot(Expr E, const Twine &Loc, bool InSec);<br>
<br>
<br>
Modified: lld/trunk/test/ELF/many-<wbr>sections.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/many-sections.s?rev=302708&r1=302707&r2=302708&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/ELF/<wbr>many-sections.s?rev=302708&r1=<wbr>302707&r2=302708&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/many-<wbr>sections.s (original)<br>
+++ lld/trunk/test/ELF/many-<wbr>sections.s Wed May 10 14:13:38 2017<br>
@@ -14,6 +14,11 @@<br>
// RUN: ld.lld %t -o %t2<br>
// RUN: llvm-readobj -t %t2 | FileCheck --check-prefix=LINKED %s<br>
<br>
+// Test also with a linker script.<br>
+// RUN: echo "SECTIONS { . = SIZEOF_HEADERS; .text : { *(.text) } }" > %t.script<br>
+// RUN: ld.lld -T %t.script %t -o %t2<br>
+// RUN: llvm-readobj -t %t2 | FileCheck --check-prefix=LINKED %s<br>
+<br>
// Test that _start is in the correct section.<br>
// LINKED: Name: _start<br>
// LINKED-NEXT: Value: 0x0<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>