Skip to content
Commit 9fb5af59 authored by Job Noorman's avatar Job Noorman
Browse files

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

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.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D149735
parent 338c2489
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment