[RDA] Avoid full reprocessing of blocks in loops (NFCI)
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 4 Apr 2020 22:22:54 +0000 (00:22 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 7 Apr 2020 15:55:37 +0000 (17:55 +0200)
commit259649a51982d0ea6fdbaa62a87e802c9a8a86d2
treeb0461aef3e877f042568ee6edf176f5828e54be3
parent76e987b37220128929519c28bef5c566841d9aed
[RDA] Avoid full reprocessing of blocks in loops (NFCI)

RDA sometimes needs to visit blocks twice, to take into account
reaching defs coming in along loop back edges. Currently it handles
repeated visitation the same way as usual, which means that it will
scan through all instructions and their reg unit defs again. Not
only is this very inefficient, it also means that all reaching defs
in loops are going to be inserted twice.

We can do much better than this. The only thing we need to handle
is a new reaching def from a predecessor, which either needs to be
prepended to the reaching definitions (if there was no reaching def
from a predecessor), or needs to replace an existing predecessor
reaching def, if it is more recent. Since D77508 we only store the
most recent predecessor reaching def, so that's the only one that
may need updating.

This also has the nice side-effect that reaching definitions are
now automatically sorted and unique, so drop the llvm::sort() call
in favor of an assertion.

Differential Revision: https://reviews.llvm.org/D77511
llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
llvm/lib/CodeGen/ReachingDefAnalysis.cpp