[PATCH] D36351: [lld][ELF] Add profile guided section layout

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 10:35:31 PST 2018


Michael Spencer <bigcheesegs at gmail.com> writes:

>> > +// Take the edge list in Config->CallGraphProfile, resolve symbol names
>> to
>> > +// Symbols, and generate a graph between InputSections with the provided
>> > +// weights.
>> > +CallGraphSort::CallGraphSort() {
>> > +  MapVector<std::pair<const InputSectionBase *, const InputSectionBase
>> *>,
>> > +            uint64_t> &Profile = Config->CallGraphProfile;
>> > +  DenseMap<const InputSectionBase *, NodeIndex> SecToNode;
>> > +  DenseMap<Edge, EdgeIndex, EdgeDenseMapInfo> EdgeMap;
>> > +
>> > +  auto GetOrCreateNode = [&](const InputSectionBase *IS) -> NodeIndex {
>> > +    auto Res = SecToNode.insert(std::make_pair(IS, Nodes.size()));
>> > +    if (Res.second)
>> > +      Nodes.emplace_back(IS);
>> > +    return Res.first->second;
>> > +  };
>> > +
>> > +  // Create the graph.
>> > +  for (const auto &C : Profile) {
>> > +    const InputSectionBase *FromSB = C.first.first;
>> > +    const InputSectionBase *ToSB = C.first.second;
>> > +    uint64_t Weight = C.second;
>> > +
>> > +    if (Weight == 0)
>> > +      continue;
>> > +
>> > +    if (FromSB->getOutputSection() != ToSB->getOutputSection())
>> > +      continue;
>>
>> We can probably filter these cases before putting them in
>> Config->CallGraphProfile.
>>
>
> That would then need to be duplicated for when the call graph comes from
> the object file.

Good point. The current location is better.

>> Please add a comment on why we should ignore and edge if the output
>> sections are different. I can see that we don't control the layout of
>> output sections, but it is not clear that one order is inherently better
>> than the other.
>>
>> Should we ignore an edge if the sections are in different ISDs?
>>
>
> Depends on if you want the linker script to always override symbol
> ordering. Given the way symbol ordering is generally generated and what
> ISDs are used for, we probably shouldn't sort between ISDs.

Note that we don't sort between ISDs anyway. The question is if an edge
from one ISD to another should be considered.

Cheers,
Rafael


More information about the llvm-commits mailing list