brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.8 KiB · 3ca09c2 Raw
197 lines · plain
1; First ensure that the ThinLTO handling in llvm-link and llvm-lto handles2; bitcode without summary sections gracefully.3; RUN: opt %s -o %t.bc4; RUN: opt %p/Inputs/funcimport.ll -o %t2.bc5; RUN: llvm-link %t.bc -summary-index=%t.bc -S6; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc7 8; Do setup work for all below tests: generate bitcode and combined index9; RUN: opt -module-summary %s -o %t.bc10; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc11; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc12 13; Ensure statics are promoted/renamed correctly from this file (all but14; constant variable need promotion).15; RUN: llvm-link %t.bc -summary-index=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC16; EXPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = hidden global17; Eventually @staticconstvar can be exported as a copy and not promoted18; EXPORTSTATIC-DAG: @staticconstvar.llvm.0 = hidden unnamed_addr constant19; EXPORTSTATIC-DAG: @P.llvm.{{.*}} = hidden global ptr null20; 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 a24; non-imported function are correctly turned into declarations.25; Also ensures that alias to a linkonce function is turned into a declaration26; and that the associated linkonce function is not in the output, as it is27; 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=IMPORTGLOB129; IMPORTGLOB1-DAG: define available_externally void @globalfunc130; IMPORTGLOB1-DAG: declare void @weakalias31; IMPORTGLOB1-DAG: declare void @analias32; IMPORTGLOB1-NOT: @linkoncealias33; IMPORTGLOB1-NOT: @linkoncefunc34; IMPORTGLOB1-NOT: declare void @globalfunc235 36; Ensure that weak alias to a non-imported function is correctly37; turned into a declaration, but that strong alias to an imported function38; is imported as alias.39; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB240; IMPORTGLOB2-DAG: declare void @analias41; IMPORTGLOB2-DAG: define available_externally void @globalfunc242; IMPORTGLOB2-DAG: declare void @weakalias43; IMPORTGLOB2-NOT: declare void @globalfunc144 45; Ensure that strong alias imported in second pass of importing ends up46; 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=IMPORTGLOB348; IMPORTGLOB3-DAG: declare void @analias49; IMPORTGLOB3-DAG: define available_externally void @globalfunc150; IMPORTGLOB3-DAG: define available_externally void @globalfunc251; IMPORTGLOB3-DAG: declare void @weakalias52 53; Ensure that strong alias imported in first pass of importing ends up54; as an alias, and that seeing the alias definition during a second inlining55; 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=IMPORTGLOB457; IMPORTGLOB4-DAG: declare void @analias58; IMPORTGLOB4-DAG: define available_externally void @globalfunc259; IMPORTGLOB4-DAG: define available_externally void @globalfunc160; IMPORTGLOB4-DAG: declare void @weakalias61 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=IMPORTGLOB564; IMPORTGLOB5-NOT: @linkoncealias65; IMPORTGLOB5-DAG: define available_externally void @linkoncefunc()66 67; Ensure that imported static variable and function references are correctly68; 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=IMPORTSTATIC70; IMPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = external hidden global71; Eventually @staticconstvar can be imported as a copy72; IMPORTSTATIC-DAG: @staticconstvar.llvm.{{.*}} = external hidden unnamed_addr constant73; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics74; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.75; IMPORTSTATIC-DAG: %0 = load i32, ptr @staticvar.llvm.76; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.77 78; Ensure that imported global (external) function and variable references79; are handled correctly (including referenced variable imported as80; available_externally definition)81; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referenceglobals:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOBALS82; IMPORTGLOBALS-DAG: @globalvar = external global83; IMPORTGLOBALS-DAG: declare void @globalfunc1()84; IMPORTGLOBALS-DAG: define available_externally i32 @referenceglobals85 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=IMPORTCOMMON88; IMPORTCOMMON-DAG: @commonvar = external global89; IMPORTCOMMON-DAG: define available_externally i32 @referencecommon90 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=IMPORTFUNCPTR93; IMPORTFUNCPTR-DAG: @P.llvm.{{.*}} = external hidden global ptr94; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr95; IMPORTFUNCPTR-DAG: %0 = load ptr, ptr @P.llvm.96 97; Ensure that imported weak function reference/definition handled properly.98; Imported weak_any definition should be skipped with warning, and imported99; 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=IMPORTWEAKFUNC101; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc102; IMPORTWEAKFUNC-DAG: declare void @weakfunc103; IMPORTWEAKFUNC-DAG: define available_externally void @callweakfunc104; IMPORTWEAKFUNC-NOT: @weakvar = extern_weak global i32, align 4105 106@globalvar = global i32 1, align 4107@staticvar = internal global i32 1, align 4108@staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4109@commonvar = common global i32 0, align 4110@P = internal global ptr null, align 8111 112@weakalias = weak alias void (...), ptr @globalfunc1113@analias = alias void (...), ptr @globalfunc2114@linkoncealias = alias void (...), ptr @linkoncefunc115 116define void @globalfunc1() #0 {117entry:118  ret void119}120 121define void @globalfunc2() #0 {122entry:123  ret void124}125 126define linkonce_odr void @linkoncefunc() #0 {127entry:128  ret void129}130 131define i32 @referencestatics(i32 %i) #0 {132entry:133  %i.addr = alloca i32, align 4134  store i32 %i, ptr %i.addr, align 4135  %call = call i32 @staticfunc()136  %0 = load i32, ptr @staticvar, align 4137  %add = add nsw i32 %call, %0138  %1 = load i32, ptr %i.addr, align 4139  %idxprom = sext i32 %1 to i64140  %arrayidx = getelementptr inbounds [2 x i32], ptr @staticconstvar, i64 0, i64 %idxprom141  %2 = load i32, ptr %arrayidx, align 4142  %add1 = add nsw i32 %add, %2143  ret i32 %add1144}145 146define i32 @referenceglobals(i32 %i) #0 {147entry:148  %i.addr = alloca i32, align 4149  store i32 %i, ptr %i.addr, align 4150  call void @globalfunc1()151  %0 = load i32, ptr @globalvar, align 4152  ret i32 %0153}154 155define i32 @referencecommon(i32 %i) #0 {156entry:157  %i.addr = alloca i32, align 4158  store i32 %i, ptr %i.addr, align 4159  %0 = load i32, ptr @commonvar, align 4160  ret i32 %0161}162 163define void @setfuncptr() #0 {164entry:165  store ptr @staticfunc2, ptr @P, align 8166  ret void167}168 169define void @callfuncptr() #0 {170entry:171  %0 = load ptr, ptr @P, align 8172  call void %0()173  ret void174}175 176@weakvar = weak global i32 1, align 4177define weak void @weakfunc() #0 {178entry:179  ret void180}181 182define void @callweakfunc() #0 {183entry:184  call void @weakfunc()185  ret void186}187 188define internal i32 @staticfunc() #0 {189entry:190  ret i32 1191}192 193define internal void @staticfunc2() #0 {194entry:195  ret void196}197