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
This commit is contained in:
Rafael Espindola 2017-04-06 21:05:39 +00:00
parent 5cf4271883
commit 9b9800951d
2 changed files with 8 additions and 3 deletions

View File

@ -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;
}

View File

@ -105,6 +105,7 @@ struct OutputSectionCommand : BaseCommand {
static bool classof(const BaseCommand *C);
OutputSection *Sec = nullptr;
StringRef Name;
Expr AddrExpr;
Expr AlignExpr;