This is an archive of the discontinued LLVM Phabricator instance.

[lld][RISCV][NFC] Simplify symbol value calculation in relax
ClosedPublic

Authored by jobnoorman on May 3 2023, 2:57 AM.

Details

Summary

The valueDelta map was used to calculate the symbol value deltas from
the previous iteration. Since the symbol values themselves are also
updated every iteration, the following invariant holds:

sa[i].offset == sa[i].d->value + valueDelta[sa[i].d]

Note that sa[i].offset contains the original value of sa[i].d and is
never changed.

This means that the current way of updating symbol values can be
rewritten to not need the valueDelta map:

sa[i].d->value -= delta - valueDelta.find(sa[i].d)->second;
<=> (replace invariant)
sa[i].d->value -= delta - (sa[i].offset - sa[i].d->value);
<=>
sa[i].d->value = sa[i].d->value - (delta - (sa[i].offset - sa[i].d->value));
<=>
sa[i].d->value = sa[i].d->value - delta + sa[i].offset - sa[i].d->value;
<=>
sa[i].d->value = sa[i].offset - delta;

This patch implements this simplification. I believe this improves the
readability of the code as it took me quite some time to understand the
use of valueDelta. It might also have a slight performance benefit as
it removes one iteration over all relocations every relax iteration.

Diff Detail

Event Timeline

jobnoorman created this revision.May 3 2023, 2:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2023, 2:57 AM
Herald added subscribers: asb, luke, pmatos and 29 others. · View Herald Transcript
jobnoorman requested review of this revision.May 3 2023, 2:57 AM
MaskRay accepted this revision.May 3 2023, 1:26 PM
This revision is now accepted and ready to land.May 3 2023, 1:26 PM