1 ; First ensure that the ThinLTO handling in llvm-link and llvm-lto handles 2 ; bitcode without function summary sections gracefully. 3 ; RUN: llvm-as %s -o %t.bc 4 ; RUN: llvm-as %p/Inputs/funcimport.ll -o %t2.bc 5 ; RUN: llvm-link %t.bc -functionindex=%t.bc -S 6 ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc 7 8 ; Do setup work for all below tests: generate bitcode and combined index 9 ; RUN: llvm-as -function-summary %s -o %t.bc 10 ; RUN: llvm-as -function-summary %p/Inputs/funcimport.ll -o %t2.bc 11 ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc 12 13 ; Ensure statics are promoted/renamed correctly from this file (all but 14 ; constant variable need promotion). 15 ; RUN: llvm-link %t.bc -functionindex=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC 16 ; EXPORTSTATIC-DAG: @staticvar.llvm.1 = hidden global 17 ; EXPORTSTATIC-DAG: @staticconstvar = internal unnamed_addr constant 18 ; EXPORTSTATIC-DAG: @P.llvm.1 = hidden global void ()* null 19 ; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.1 20 ; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.1 21 22 ; Ensure that both weak alias to an imported function and strong alias to a 23 ; non-imported function are correctly turned into declarations. 24 ; Also ensures that alias to a linkonce function is turned into a declaration 25 ; and that the associated linkonce function is not in the output, as it is 26 ; lazily linked and never referenced/materialized. 27 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB1 28 ; IMPORTGLOB1-DAG: define available_externally void @globalfunc1 29 ; IMPORTGLOB1-DAG: declare void @weakalias 30 ; IMPORTGLOB1-DAG: declare void @analias 31 ; IMPORTGLOB1-NOT: @linkoncealias 32 ; IMPORTGLOB1-NOT: @linkoncefunc 33 ; IMPORTGLOB1-NOT: declare void @globalfunc2 34 35 ; Ensure that weak alias to a non-imported function is correctly 36 ; turned into a declaration, but that strong alias to an imported function 37 ; is imported as alias. 38 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB2 39 ; IMPORTGLOB2-DAG: declare void @analias 40 ; IMPORTGLOB2-DAG: define available_externally void @globalfunc2 41 ; IMPORTGLOB2-DAG: declare void @weakalias 42 ; IMPORTGLOB2-NOT: declare void @globalfunc1 43 44 ; Ensure that strong alias imported in second pass of importing ends up 45 ; as an alias. 46 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB3 47 ; IMPORTGLOB3-DAG: declare void @analias 48 ; IMPORTGLOB3-DAG: define available_externally void @globalfunc1 49 ; IMPORTGLOB3-DAG: define available_externally void @globalfunc2 50 ; IMPORTGLOB3-DAG: declare void @weakalias 51 52 ; Ensure that strong alias imported in first pass of importing ends up 53 ; as an alias, and that seeing the alias definition during a second inlining 54 ; pass is handled correctly. 55 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc2:%t.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB4 56 ; IMPORTGLOB4-DAG: declare void @analias 57 ; IMPORTGLOB4-DAG: define available_externally void @globalfunc2 58 ; IMPORTGLOB4-DAG: define available_externally void @globalfunc1 59 ; IMPORTGLOB4-DAG: declare void @weakalias 60 61 ; An alias to an imported function is imported as alias if the function is not 62 ; available_externally. 63 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=linkoncefunc:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB5 64 ; IMPORTGLOB5-DAG: linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*) 65 ; IMPORTGLOB5-DAG: define linkonce_odr void @linkoncefunc() 66 67 ; Ensure that imported static variable and function references are correctly 68 ; promoted and renamed (including static constant variable). 69 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=referencestatics:%t.bc -S | FileCheck %s --check-prefix=IMPORTSTATIC 70 ; IMPORTSTATIC-DAG: @staticvar.llvm.1 = available_externally hidden global 71 ; IMPORTSTATIC-DAG: @staticconstvar.llvm.1 = internal unnamed_addr constant 72 ; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics 73 ; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.1 74 ; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.1 75 ; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.1 76 77 ; Ensure that imported global (external) function and variable references 78 ; are handled correctly (including referenced variable imported as 79 ; available_externally definition) 80 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=referenceglobals:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOBALS 81 ; IMPORTGLOBALS-DAG: @globalvar = available_externally global 82 ; IMPORTGLOBALS-DAG: declare void @globalfunc1() 83 ; IMPORTGLOBALS-DAG: define available_externally i32 @referenceglobals 84 85 ; Ensure that common variable correctly imported as common defition. 86 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=referencecommon:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMMON 87 ; IMPORTCOMMON-DAG: @commonvar = common global 88 ; IMPORTCOMMON-DAG: define available_externally i32 @referencecommon 89 90 ; Ensure that imported static function pointer correctly promoted and renamed. 91 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=callfuncptr:%t.bc -S | FileCheck %s --check-prefix=IMPORTFUNCPTR 92 ; IMPORTFUNCPTR-DAG: @P.llvm.1 = available_externally hidden global void ()* null 93 ; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr 94 ; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.1 95 96 ; Ensure that imported weak function reference/definition handled properly. 97 ; Imported weak_any definition should be skipped with warning, and imported 98 ; reference should turned into an external_weak declaration. 99 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=callweakfunc:%t.bc -import=weakfunc:%t.bc -S 2>&1 | FileCheck %s --check-prefix=IMPORTWEAKFUNC 100 ; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc 101 ; IMPORTWEAKFUNC-DAG: declare extern_weak void @weakfunc 102 ; IMPORTWEAKFUNC-DAG: define available_externally void @callweakfunc 103 ; IMPORTWEAKFUNC-NOT: @weakvar = extern_weak global i32, align 4 104 105 @globalvar = global i32 1, align 4 106 @staticvar = internal global i32 1, align 4 107 @staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4 108 @commonvar = common global i32 0, align 4 109 @P = internal global void ()* null, align 8 110 111 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*) 112 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*) 113 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*) 114 115 define void @globalfunc1() #0 { 116 entry: 117 ret void 118 } 119 120 define void @globalfunc2() #0 { 121 entry: 122 ret void 123 } 124 125 define linkonce_odr void @linkoncefunc() #0 { 126 entry: 127 ret void 128 } 129 130 define i32 @referencestatics(i32 %i) #0 { 131 entry: 132 %i.addr = alloca i32, align 4 133 store i32 %i, i32* %i.addr, align 4 134 %call = call i32 @staticfunc() 135 %0 = load i32, i32* @staticvar, align 4 136 %add = add nsw i32 %call, %0 137 %1 = load i32, i32* %i.addr, align 4 138 %idxprom = sext i32 %1 to i64 139 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom 140 %2 = load i32, i32* %arrayidx, align 4 141 %add1 = add nsw i32 %add, %2 142 ret i32 %add1 143 } 144 145 define i32 @referenceglobals(i32 %i) #0 { 146 entry: 147 %i.addr = alloca i32, align 4 148 store i32 %i, i32* %i.addr, align 4 149 call void @globalfunc1() 150 %0 = load i32, i32* @globalvar, align 4 151 ret i32 %0 152 } 153 154 define i32 @referencecommon(i32 %i) #0 { 155 entry: 156 %i.addr = alloca i32, align 4 157 store i32 %i, i32* %i.addr, align 4 158 %0 = load i32, i32* @commonvar, align 4 159 ret i32 %0 160 } 161 162 define void @setfuncptr() #0 { 163 entry: 164 store void ()* @staticfunc2, void ()** @P, align 8 165 ret void 166 } 167 168 define void @callfuncptr() #0 { 169 entry: 170 %0 = load void ()*, void ()** @P, align 8 171 call void %0() 172 ret void 173 } 174 175 @weakvar = weak global i32 1, align 4 176 define weak void @weakfunc() #0 { 177 entry: 178 ret void 179 } 180 181 define void @callweakfunc() #0 { 182 entry: 183 call void @weakfunc() 184 ret void 185 } 186 187 define internal i32 @staticfunc() #0 { 188 entry: 189 ret i32 1 190 } 191 192 define internal void @staticfunc2() #0 { 193 entry: 194 ret void 195 } 196