[AsmWriter] Properly handle uselistorder for global symbols
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 26 Jun 2021 13:42:49 +0000 (15:42 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 28 Jun 2021 21:15:32 +0000 (23:15 +0200)
commitaad87328fabff9382bac0b452c83934515e6d0c8
tree881e9ec14de297f9d22422a1523f3abdb9d6692f
parent2190c48fdece1712735c507e3f343ae5b872189e
[AsmWriter] Properly handle uselistorder for global symbols

Currently, AsmWriter will stick uselistorder directives for global
values inside individual functions. This doesn't make a lot of sense,
and interacts badly with D104950, as use list order adjustments will
be performed while still working on a forward reference.

This patch instead always prints uselistorder directives for globals
at the module level. This isn't really compatible with the previously
used implementation approach. Rather than walking through all values
again, use the OrderMap (after stabilizing its order) to go through
all values and compute the use list shuffles for them. Classify them
per-function, or nullptr for globals.

Even independently of D104950, this seems to fix a few
verify-uselistorder failures. Conveniently, there is even a
pre-existing failing test that this fixes.

Differential Revision: https://reviews.llvm.org/D104976
llvm/lib/IR/AsmWriter.cpp
llvm/test/Assembler/uselistorder_global.ll [new file with mode: 0644]
llvm/test/Bitcode/use-list-order2.ll