This is pure refactoring. NFC.
Motivation: in the swift compiler we have a pass, called SwiftMergeFunctions, which is a modified version of llvm's MergeFunctions:
The purpose of SwiftMergeFunctions is to merge _similar_ functions which only differ by some constants. It's used to merge specialized generic functions.
Some background info: it's important that SwiftMergeFunctions runs _after_ llvm's MergeFunctions, because we want to merge similar functions only after all equivalent functions are already merged.
SwiftMergeFunctions shares most of the FunctionComparator code with the llvm pass. Currently this code is just copied.
This change moves the FunctionComparator (together with the GlobalNumberState utility) in to a separate file so that it can be used by both passes. The SwiftMergeFunctions pass derives its own comparator from FunctionComparator. This is how it looks like: https://github.com/eeckstein/swift/blob/merge-func-refactor/lib/LLVMPasses/LLVMMergeFunctions.cpp
Details of the change:
*) The big part is just moving code out of MergeFunctions.cpp into FunctionComparator.h/cpp
*) Make FunctionComparator member functions protected (instead of private) so that the derived comparator in SwiftMergeFunctions can use them.
Following refactoring helps to share code between the base FunctionComparator class and the derived class:
*) Add a beginCompare() function
*) Move some basic function property comparisons into a separate function compareSignature()
*) Do the GEP comparison inside cmpOperations() which now has a new needToCmpOperands reference parameter