[PATCH] D36963: Use sorting instead of a lot of stable_partitions for `ICF::segregate` function

Alex Telishev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 08:23:58 PDT 2017


alex.telishev created this revision.

As I understood, `ICF::segregate` function is trying to split `Chunks` into equivalent smaller chunks based on `equalsConstant` or `equalsVariable` . It can be done much faster using `sort` function with appropriate comparison function (current implementation is O(n^2), and `sort` is O(nlogn)). It wouldn't produce exactly the same results, but as I understand, it doesn't matter.  Right now I use `stable_sort` because I don't know if relative position should be preserved. Otherwise `sort` should be used instead.

Functions  `equalsConstant` and `equalsVariable`  were rewritten to `lessConstant` and `lessVariable` to provide strict ordering. I tried to use `std::lexicographical_compare`  in places where `std::equal`  was used but it failed because we need to know which `SectionChunk` current `coff_relocation` belongs to.  To fix it I wrote (quite ugly) `lexicographical_compare_helper` function that does the same as `lexicographical_compare` but passes additional arguments to comparison function. I guess it's better to rewrite it using something like range adapters.

In my case this patch speeds up linking from 1m40 to 1m10.


https://reviews.llvm.org/D36963

Files:
  lld/COFF/ICF.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36963.111975.patch
Type: text/x-patch
Size: 7215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170821/824f52cd/attachment.bin>


More information about the llvm-commits mailing list