Import the similar functions into the module with another function matching the hash.
Depends on: https://reviews.llvm.org/D53253
This is a good suggestion. Also, some high level comments describing what this code is doing/how it works would be helpful.
Seems like this should be an actual assert. Actually, there is such an assert below, why the early return - leftover from debugging?
You should fix this, and it should be straightforward. See where we check the return value of the ImportList insertion for importing above (variable PreviouslyImported).
This could be avoided (and save an expensive hash lookup), if the SimFunctions saved the VIs to start with (although I haven't yet looked through your other patches to see how this is being populated).
Why this constraint? Note that any global variables being referenced by an imported function will automatically have their declarations imported too.
Note though that in its place you need to ensure that the function is eligible to import (notEligibleToImport() on the function summary), and you should also skip anything that was found to be globally unreachable (isGlobalValueLive() on the index). Not sure about checking whether it has interposable linkage. See some of the checks being done in selectCallee() in this file. Some of those are profitability (related to whether we can inline the imported function), but others are correctness checks. I.e. if it is notEligibleToImport then it might be referencing functions/variables that cannot be promoted to global scope for some reason.