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