diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-04-06 21:05:39 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-04-06 21:05:39 +0000 |
commit | 9b9800951da1c342223bd174dc1fcd441b6061b7 (patch) | |
tree | 8533368b2b3d0d99b141eb1d59fd12b5fdaa1ea7 | |
parent | 5cf4271883e18e729ddc7cac74aaa4cc59406dff (diff) | |
download | bcm5719-llvm-9b9800951da1c342223bd174dc1fcd441b6061b7.tar.gz bcm5719-llvm-9b9800951da1c342223bd174dc1fcd441b6061b7.zip |
Cache the result of findSection.
This avoids calling it multiple times. In particular, we don't have to
call in in assignAddresses any more.
llvm-svn: 299709
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 10 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.h | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9e39a5de32e..c7a8a056a84 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -567,7 +567,7 @@ MemoryRegion *LinkerScript::findMemoryRegion(OutputSectionCommand *Cmd, // This function assigns offsets to input sections and an output section // for a single sections command (e.g. ".text { *(.text); }"). void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) { - OutputSection *Sec = findSection(Cmd->Name, *OutputSections); + OutputSection *Sec = Cmd->Sec; if (!Sec) return; @@ -614,7 +614,7 @@ void LinkerScript::removeEmptyCommands() { auto Pos = std::remove_if( Opt.Commands.begin(), Opt.Commands.end(), [&](BaseCommand *Base) { if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base)) - return !findSection(Cmd->Name, *OutputSections); + return !Cmd->Sec; return false; }); Opt.Commands.erase(Pos, Opt.Commands.end()); @@ -639,6 +639,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { if (!Cmd) continue; if (OutputSection *Sec = findSection(Cmd->Name, *OutputSections)) { + Cmd->Sec = Sec; Flags = Sec->Flags; Type = Sec->Type; continue; @@ -649,6 +650,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { auto *OutSec = make<OutputSection>(Cmd->Name, Type, Flags); OutputSections->push_back(OutSec); + Cmd->Sec = OutSec; } } @@ -764,7 +766,9 @@ void LinkerScript::placeOrphanSections() { return Cmd && Cmd->Name == Name; }); if (Pos == E) { - Opt.Commands.insert(CmdIter, make<OutputSectionCommand>(Name)); + auto *Cmd = make<OutputSectionCommand>(Name); + Cmd->Sec = Sec; + Opt.Commands.insert(CmdIter, Cmd); ++CmdIndex; continue; } diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index e1962c04d92..e1fc3c43aee 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -105,6 +105,7 @@ struct OutputSectionCommand : BaseCommand { static bool classof(const BaseCommand *C); + OutputSection *Sec = nullptr; StringRef Name; Expr AddrExpr; Expr AlignExpr; |