blob: 6d9395faed344e3227d495154b59c77f855bf30e [file] [log] [blame]
Teresa Johnson6290dbc2015-11-21 21:55:48 +00001; First ensure that the ThinLTO handling in llvm-link and llvm-lto handles
Teresa Johnson26ab5772016-03-15 00:04:37 +00002; bitcode without summary sections gracefully.
Mehdi Amini68da4262016-04-12 21:35:18 +00003; RUN: opt %s -o %t.bc
4; RUN: opt %p/Inputs/funcimport.ll -o %t2.bc
Teresa Johnson26ab5772016-03-15 00:04:37 +00005; RUN: llvm-link %t.bc -summary-index=%t.bc -S
Teresa Johnson6290dbc2015-11-21 21:55:48 +00006; 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
Mehdi Amini68da4262016-04-12 21:35:18 +00009; RUN: opt -module-summary %s -o %t.bc
10; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000011; 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).
Teresa Johnson26ab5772016-03-15 00:04:37 +000015; RUN: llvm-link %t.bc -summary-index=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC
Mehdi Aminiae280e52016-04-11 23:26:46 +000016; EXPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = hidden global
Teresa Johnson185b4ab2016-12-02 01:02:30 +000017; Eventually @staticconstvar can be exported as a copy and not promoted
18; EXPORTSTATIC-DAG: @staticconstvar.llvm.0 = hidden unnamed_addr constant
Mehdi Aminiae280e52016-04-11 23:26:46 +000019; EXPORTSTATIC-DAG: @P.llvm.{{.*}} = hidden global void ()* null
20; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.
21; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000022
23; Ensure that both weak alias to an imported function and strong alias to a
24; non-imported function are correctly turned into declarations.
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +000025; 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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000028; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB1
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000029; IMPORTGLOB1-DAG: define available_externally void @globalfunc1
Rafael Espindola8c044722015-12-02 22:22:24 +000030; IMPORTGLOB1-DAG: declare void @weakalias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000031; IMPORTGLOB1-DAG: declare void @analias
Rafael Espindola4b5ec262015-12-02 22:59:04 +000032; IMPORTGLOB1-NOT: @linkoncealias
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +000033; IMPORTGLOB1-NOT: @linkoncefunc
Rafael Espindola4b5ec262015-12-02 22:59:04 +000034; IMPORTGLOB1-NOT: declare void @globalfunc2
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000035
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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000039; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB2
Rafael Espindola8c044722015-12-02 22:22:24 +000040; IMPORTGLOB2-DAG: declare void @analias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000041; IMPORTGLOB2-DAG: define available_externally void @globalfunc2
Rafael Espindola8c044722015-12-02 22:22:24 +000042; IMPORTGLOB2-DAG: declare void @weakalias
Rafael Espindola4b5ec262015-12-02 22:59:04 +000043; IMPORTGLOB2-NOT: declare void @globalfunc1
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000044
45; Ensure that strong alias imported in second pass of importing ends up
46; as an alias.
Teresa Johnson26ab5772016-03-15 00:04:37 +000047; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc1:%t.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB3
Rafael Espindola8c044722015-12-02 22:22:24 +000048; IMPORTGLOB3-DAG: declare void @analias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000049; IMPORTGLOB3-DAG: define available_externally void @globalfunc1
50; IMPORTGLOB3-DAG: define available_externally void @globalfunc2
Rafael Espindola8c044722015-12-02 22:22:24 +000051; IMPORTGLOB3-DAG: declare void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000052
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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000056; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc2:%t.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB4
Rafael Espindola8c044722015-12-02 22:22:24 +000057; IMPORTGLOB4-DAG: declare void @analias
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000058; IMPORTGLOB4-DAG: define available_externally void @globalfunc2
59; IMPORTGLOB4-DAG: define available_externally void @globalfunc1
Rafael Espindola8c044722015-12-02 22:22:24 +000060; IMPORTGLOB4-DAG: declare void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000061
Rafael Espindola89345772015-11-26 19:22:59 +000062; An alias to an imported function is imported as alias if the function is not
63; available_externally.
Teresa Johnson26ab5772016-03-15 00:04:37 +000064; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=linkoncefunc:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB5
Rafael Espindola89345772015-11-26 19:22:59 +000065; IMPORTGLOB5-DAG: linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
66; IMPORTGLOB5-DAG: define linkonce_odr void @linkoncefunc()
67
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000068; Ensure that imported static variable and function references are correctly
69; promoted and renamed (including static constant variable).
Teresa Johnson26ab5772016-03-15 00:04:37 +000070; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referencestatics:%t.bc -S | FileCheck %s --check-prefix=IMPORTSTATIC
Mehdi Aminiae280e52016-04-11 23:26:46 +000071; IMPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = external hidden global
Teresa Johnson185b4ab2016-12-02 01:02:30 +000072; Eventually @staticconstvar can be imported as a copy
73; IMPORTSTATIC-DAG: @staticconstvar.llvm.{{.*}} = external hidden unnamed_addr constant
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000074; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics
Mehdi Aminiae280e52016-04-11 23:26:46 +000075; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.
76; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.
77; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000078
79; Ensure that imported global (external) function and variable references
80; are handled correctly (including referenced variable imported as
81; available_externally definition)
Teresa Johnson26ab5772016-03-15 00:04:37 +000082; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referenceglobals:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOBALS
Mehdi Amini8d051852016-03-19 00:40:31 +000083; IMPORTGLOBALS-DAG: @globalvar = external global
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000084; IMPORTGLOBALS-DAG: declare void @globalfunc1()
85; IMPORTGLOBALS-DAG: define available_externally i32 @referenceglobals
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000086
87; Ensure that common variable correctly imported as common defition.
Teresa Johnson26ab5772016-03-15 00:04:37 +000088; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referencecommon:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMMON
Mehdi Amini8d051852016-03-19 00:40:31 +000089; IMPORTCOMMON-DAG: @commonvar = external global
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000090; IMPORTCOMMON-DAG: define available_externally i32 @referencecommon
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000091
92; Ensure that imported static function pointer correctly promoted and renamed.
Teresa Johnson26ab5772016-03-15 00:04:37 +000093; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=callfuncptr:%t.bc -S | FileCheck %s --check-prefix=IMPORTFUNCPTR
Mehdi Aminiae280e52016-04-11 23:26:46 +000094; IMPORTFUNCPTR-DAG: @P.llvm.{{.*}} = external hidden global void ()*
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000095; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr
Mehdi Aminiae280e52016-04-11 23:26:46 +000096; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000097
98; Ensure that imported weak function reference/definition handled properly.
99; Imported weak_any definition should be skipped with warning, and imported
100; reference should turned into an external_weak declaration.
Teresa Johnson26ab5772016-03-15 00:04:37 +0000101; 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
Teresa Johnsonba5d68d2015-11-12 19:31:46 +0000102; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc
Mehdi Aminibb3a1d92016-04-20 04:18:11 +0000103; IMPORTWEAKFUNC-DAG: declare void @weakfunc
Teresa Johnsonba5d68d2015-11-12 19:31:46 +0000104; IMPORTWEAKFUNC-DAG: define available_externally void @callweakfunc
Rafael Espindola4b5ec262015-12-02 22:59:04 +0000105; IMPORTWEAKFUNC-NOT: @weakvar = extern_weak global i32, align 4
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000106
107@globalvar = global i32 1, align 4
108@staticvar = internal global i32 1, align 4
109@staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4
110@commonvar = common global i32 0, align 4
111@P = internal global void ()* null, align 8
112
113@weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
114@analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +0000115@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000116
117define void @globalfunc1() #0 {
118entry:
119 ret void
120}
121
122define void @globalfunc2() #0 {
123entry:
124 ret void
125}
126
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +0000127define linkonce_odr void @linkoncefunc() #0 {
128entry:
129 ret void
130}
131
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000132define i32 @referencestatics(i32 %i) #0 {
133entry:
134 %i.addr = alloca i32, align 4
135 store i32 %i, i32* %i.addr, align 4
136 %call = call i32 @staticfunc()
137 %0 = load i32, i32* @staticvar, align 4
138 %add = add nsw i32 %call, %0
139 %1 = load i32, i32* %i.addr, align 4
140 %idxprom = sext i32 %1 to i64
141 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom
142 %2 = load i32, i32* %arrayidx, align 4
143 %add1 = add nsw i32 %add, %2
144 ret i32 %add1
145}
146
147define i32 @referenceglobals(i32 %i) #0 {
148entry:
149 %i.addr = alloca i32, align 4
150 store i32 %i, i32* %i.addr, align 4
151 call void @globalfunc1()
152 %0 = load i32, i32* @globalvar, align 4
153 ret i32 %0
154}
155
156define i32 @referencecommon(i32 %i) #0 {
157entry:
158 %i.addr = alloca i32, align 4
159 store i32 %i, i32* %i.addr, align 4
160 %0 = load i32, i32* @commonvar, align 4
161 ret i32 %0
162}
163
164define void @setfuncptr() #0 {
165entry:
166 store void ()* @staticfunc2, void ()** @P, align 8
167 ret void
168}
169
170define void @callfuncptr() #0 {
171entry:
172 %0 = load void ()*, void ()** @P, align 8
173 call void %0()
174 ret void
175}
176
Teresa Johnson3cd81612015-11-10 18:20:11 +0000177@weakvar = weak global i32 1, align 4
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000178define weak void @weakfunc() #0 {
179entry:
180 ret void
181}
182
183define void @callweakfunc() #0 {
184entry:
185 call void @weakfunc()
186 ret void
187}
188
189define internal i32 @staticfunc() #0 {
190entry:
191 ret i32 1
192}
193
194define internal void @staticfunc2() #0 {
195entry:
196 ret void
197}