[PATCH] D46228: [ELF] Use union-find set in Call-Chain Clustering (C³) heuristic to improve worst-case time complexity.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 12 15:24:40 PDT 2018


MaskRay added a comment.

In https://reviews.llvm.org/D46228#1264054, @ruiu wrote:

> Honestly I do not understand the code. What is this code doing? Can you explain it for me?


Sure. A cluster is a list of sections (`C.Sections`). This loop iterates over sections by descending density and tries grouping sections together (grouped sections are linearly ordered for locality).

The loop body needs a way to find the cluster a section belongs. What it used to do is the lookup table `SecToCluster` which is maintained after each merge operation. The merge operation is slow (thus the old comment "NOTE: Consider using a disjoint-set to track section -> cluster mapping"). Since a section can only belong to a cluster and clusters are disjoined, union-find algorithm naturally fits here.

I use the path-halving technique (one-liner `Leaders[V] = Leaders[Leaders[V]];`) to decrease complexity and it is extremely simple to implement. Other techniques can achieve the same goal but they would have more code (https://www.cs.princeton.edu/courses/archive/spring13/cos423/lectures/UnionFind.pdf).


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D46228





More information about the llvm-commits mailing list