[all-commits] [llvm/llvm-project] 9fb5af: [lld][RISCV][NFC] Simplify symbol value calculatio...

Job Noorman via All-commits all-commits at lists.llvm.org
Thu May 4 00:09:20 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9fb5af59095f3f3578e11b008c98ae56c03f0102
  Author: Job Noorman <jnoorman at igalia.com>
  Date:   2023-05-04 (Thu, 04 May 2023)

  Changed paths:
    M lld/ELF/Arch/RISCV.cpp

  Log Message:
  [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

More information about the All-commits mailing list