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

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 14:22:06 PST 2018


Michael Spencer via Phabricator <reviews at reviews.llvm.org> writes:

> @@ -1050,6 +1051,15 @@
>  // If no layout was provided by linker script, we want to apply default
>  // sorting for special input sections. This also handles --symbol-ordering-file.
>  template <class ELFT> void Writer<ELFT>::sortInputSections() {
> +  // Use the rarely used option -call-graph-ordering-file to sort sections.
> +  if (!Config->CallGraphProfile.empty()) {
> +    DenseMap<const InputSectionBase *, int> OrderMap =
> +        computeCallGraphProfileOrder();
> +
> +    if (OutputSection *Sec = findSection(".text"))
> +      Sec->sort([&](InputSectionBase *S) { return OrderMap.lookup(S); });
> +  }
> +

Don't do this just for text. We should sort all live sections, like we
do for --symbol-ordering-file.

Add a test showing that we sort sections with other names too.


> +  std::vector<StringRef> Lines = args::getLines(MB);
> +  for (StringRef L : Lines) {
> +    SmallVector<StringRef, 3> Fields;
> +    L.split(Fields, ' ');
> +    if (Fields.size() != 3)
> +      fatal("parse error");
> +    uint64_t Count;
> +    if (!to_integer(Fields[2], Count))
> +      fatal("parse error");
> +    StringRef From = Fields[0];
> +    InputSectionBase *FromSec = SymbolSection.lookup(From);
> +    StringRef To = Fields[1];
> +    InputSectionBase *ToSec = SymbolSection.lookup(To);

Simplify to

  InputSectionBase *FromSec = SymbolSection.lookup(Fields[0]);
  InputSectionBase *ToSec = SymbolSection.lookup(Fields[1]);

> Index: ELF/Config.h
> ===================================================================
> --- ELF/Config.h
> +++ ELF/Config.h
> @@ -11,6 +11,7 @@
>  #define LLD_ELF_CONFIG_H
>  
>  #include "lld/Common/ErrorHandler.h"
> +#include "llvm/ADT/DenseMap.h"

This include is not used anymore.

Cheers,
Rafael


More information about the llvm-commits mailing list