[ThinLTO] Enable importing of aliases as copy of aliasee

Summary:
This implements a missing feature to allow importing of aliases, which
was previously disabled because alias cannot be available_externally.
We instead import an alias as a copy of its aliasee.

Some additional work was required in the IndexBitcodeWriter for the
distributed build case, to ensure that the aliasee has a value id
in the distributed index file (i.e. even when it is not being
imported directly).

This is a performance win in codes that have many aliases, e.g. C++
applications that have many constructor and destructor aliases.

Reviewers: pcc

Subscribers: mehdi_amini, inglorion, eraman, llvm-commits

Differential Revision: https://reviews.llvm.org/D40747

llvm-svn: 320895
diff --git a/llvm/test/ThinLTO/X86/distributed_indexes.ll b/llvm/test/ThinLTO/X86/distributed_indexes.ll
index b81c94c..d7e68ed 100644
--- a/llvm/test/ThinLTO/X86/distributed_indexes.ll
+++ b/llvm/test/ThinLTO/X86/distributed_indexes.ll
@@ -7,16 +7,22 @@
 
 ; The backend index for this module contains summaries from itself and
 ; Inputs/distributed_indexes.ll, as it imports from the latter.
+; We should import @g and alias @analias. While we don't import the aliasee
+; directly (and therefore don't have a third COMBINED record from module
+; id 1), we will have a VALUE_GUID for it (hence the 4 VALUE_GUID entries).
 ; BACKEND1: <MODULE_STRTAB_BLOCK
 ; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}distributed_indexes.ll.tmp{{.*}}.bc'
 ; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}distributed_indexes.ll.tmp{{.*}}.bc'
 ; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
 ; BACKEND1-NEXT: <GLOBALVAL_SUMMARY_BLOCK
 ; BACKEND1-NEXT: <VERSION
-; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
-; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
-; BACKEND1-NEXT: <COMBINED
-; BACKEND1-NEXT: <COMBINED
+; BACKEND1-DAG: <VALUE_GUID op0=2 op1=-5751648690987223394
+; BACKEND1-DAG: <VALUE_GUID op0=4 op1=-5300342847281564238
+; BACKEND1-DAG: <VALUE_GUID op0=1 op1=-3706093650706652785
+; BACKEND1-DAG: <VALUE_GUID op0=3 op1=-1039159065113703048
+; BACKEND1-DAG: <COMBINED {{.*}} op1=0
+; BACKEND1-DAG: <COMBINED {{.*}} op1=1
+; BACKEND1-DAG: <COMBINED_ALIAS {{.*}} op1=1
 ; BACKEND1-NEXT: </GLOBALVAL_SUMMARY_BLOCK
 
 ; The backend index for Input/distributed_indexes.ll contains summaries from
@@ -26,14 +32,20 @@
 ; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
 ; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
 ; BACKEND2-NEXT: <VERSION
-; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
+; BACKEND2-DAG: <VALUE_GUID op0=1 op1=-5751648690987223394/>
+; BACKEND2-DAG: <VALUE_GUID op0=4 op1=-5300342847281564238/>
+; BACKEND2-DAG: <VALUE_GUID op0=3 op1=-1039159065113703048/>
 ; BACKEND2-NEXT: <COMBINED
+; BACKEND2-NEXT: <COMBINED
+; BACKEND2-NEXT: <COMBINED_ALIAS
 ; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
 
 declare void @g(...)
+declare void @analias(...)
 
 define void @f() {
 entry:
   call void (...) @g()
+  call void (...) @analias()
   ret void
 }