blob: 38deafd3e3f16b69adf197e7a9362bf7c2beb7a1 [file] [log] [blame]
Teresa Johnson6290dbc2015-11-21 21:55:48 +00001; 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
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +00008; 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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000016; 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
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000021
22; Ensure that both weak alias to an imported function and strong alias to a
23; non-imported function are correctly turned into declarations.
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +000024; 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.
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000027; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB1
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000028; IMPORTGLOB1-DAG: define available_externally void @globalfunc1
Rafael Espindola8c044722015-12-02 22:22:24 +000029; IMPORTGLOB1-DAG: declare void @weakalias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000030; IMPORTGLOB1-DAG: declare void @analias
Rafael Espindola4b5ec262015-12-02 22:59:04 +000031; IMPORTGLOB1-NOT: @linkoncealias
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +000032; IMPORTGLOB1-NOT: @linkoncefunc
Rafael Espindola4b5ec262015-12-02 22:59:04 +000033; IMPORTGLOB1-NOT: declare void @globalfunc2
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000034
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
Rafael Espindola8c044722015-12-02 22:22:24 +000039; IMPORTGLOB2-DAG: declare void @analias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000040; IMPORTGLOB2-DAG: define available_externally void @globalfunc2
Rafael Espindola8c044722015-12-02 22:22:24 +000041; IMPORTGLOB2-DAG: declare void @weakalias
Rafael Espindola4b5ec262015-12-02 22:59:04 +000042; IMPORTGLOB2-NOT: declare void @globalfunc1
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000043
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
Rafael Espindola8c044722015-12-02 22:22:24 +000047; IMPORTGLOB3-DAG: declare void @analias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000048; IMPORTGLOB3-DAG: define available_externally void @globalfunc1
49; IMPORTGLOB3-DAG: define available_externally void @globalfunc2
Rafael Espindola8c044722015-12-02 22:22:24 +000050; IMPORTGLOB3-DAG: declare void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000051
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
Rafael Espindola8c044722015-12-02 22:22:24 +000056; IMPORTGLOB4-DAG: declare void @analias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000057; IMPORTGLOB4-DAG: define available_externally void @globalfunc2
58; IMPORTGLOB4-DAG: define available_externally void @globalfunc1
Rafael Espindola8c044722015-12-02 22:22:24 +000059; IMPORTGLOB4-DAG: declare void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000060
Rafael Espindola89345772015-11-26 19:22:59 +000061; 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
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000067; 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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000070; 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
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000076
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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000081; IMPORTGLOBALS-DAG: @globalvar = available_externally global
82; IMPORTGLOBALS-DAG: declare void @globalfunc1()
83; IMPORTGLOBALS-DAG: define available_externally i32 @referenceglobals
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000084
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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000087; IMPORTCOMMON-DAG: @commonvar = common global
88; IMPORTCOMMON-DAG: define available_externally i32 @referencecommon
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000089
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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000092; 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
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000095
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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +0000100; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc
Teresa Johnsonba5d68d2015-11-12 19:31:46 +0000101; IMPORTWEAKFUNC-DAG: declare extern_weak void @weakfunc
102; IMPORTWEAKFUNC-DAG: define available_externally void @callweakfunc
Rafael Espindola4b5ec262015-12-02 22:59:04 +0000103; IMPORTWEAKFUNC-NOT: @weakvar = extern_weak global i32, align 4
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000104
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 (...)*)
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +0000113@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000114
115define void @globalfunc1() #0 {
116entry:
117 ret void
118}
119
120define void @globalfunc2() #0 {
121entry:
122 ret void
123}
124
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +0000125define linkonce_odr void @linkoncefunc() #0 {
126entry:
127 ret void
128}
129
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000130define i32 @referencestatics(i32 %i) #0 {
131entry:
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
145define i32 @referenceglobals(i32 %i) #0 {
146entry:
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
154define i32 @referencecommon(i32 %i) #0 {
155entry:
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
162define void @setfuncptr() #0 {
163entry:
164 store void ()* @staticfunc2, void ()** @P, align 8
165 ret void
166}
167
168define void @callfuncptr() #0 {
169entry:
170 %0 = load void ()*, void ()** @P, align 8
171 call void %0()
172 ret void
173}
174
Teresa Johnson3cd81612015-11-10 18:20:11 +0000175@weakvar = weak global i32 1, align 4
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000176define weak void @weakfunc() #0 {
177entry:
178 ret void
179}
180
181define void @callweakfunc() #0 {
182entry:
183 call void @weakfunc()
184 ret void
185}
186
187define internal i32 @staticfunc() #0 {
188entry:
189 ret i32 1
190}
191
192define internal void @staticfunc2() #0 {
193entry:
194 ret void
195}