First, it fixes a crash where the eliminated function is still referenced.
This shows up if two equivalent self-recursive functions are merged and those functions are internal.
Fixes SR-4514, rdar://problem/31479425
Second, it avoids creating a not needed parameter for really equivalent self recursive functions.
Now that the FunctionComparator is a separate utility in LLVM, the SwiftMergeFunctions pass can use it instead of duplicating the code.
This is pure refactoring. NFC.
When constructing the body of the merged function, the internal function is
given internal linkage always. It is only accessible through the adjusting
thunks which retain the original DLL storage. Ensure that we reset the DLL
storage which it inherited from the first function.
This updates MergeFunctions with a custom ordering comparator for the
AtomicOrdering. This is needed after a LLVM API change which changes the
AtomicOrdering to a strongly typed enumeration.
It's like LLVM's MergeFunctions pass, except that it can also merge functions which differ by some constants.
The intention is to merge specialized functions which only differ by metadata lookups. But it can also merge other types of functions.
It gives ~7% code size reducation for the stdlib.
There are still some open TODOs, e.g. to share common code with LLVM's MergeFunctions pass (currently much code is just copied).