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