blob: 53dbc6d849aaa6f7c3911d79f3ad0895ae906e03 [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 Johnsonba5d68d2015-11-12 19:31:46 +000017; EXPORTSTATIC-DAG: @staticconstvar = internal unnamed_addr constant
Mehdi Aminiae280e52016-04-11 23:26:46 +000018; EXPORTSTATIC-DAG: @P.llvm.{{.*}} = hidden global void ()* null
19; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.
20; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.
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 Johnson26ab5772016-03-15 00:04:37 +000027; 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 +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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000038; 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 +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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000046; 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 +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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000055; 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 +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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000063; 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 +000064; 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).
Teresa Johnson26ab5772016-03-15 00:04:37 +000069; 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 +000070; IMPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = external hidden global
71; IMPORTSTATIC-DAG: @staticconstvar.llvm.{{.*}} = internal unnamed_addr constant
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000072; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics
Mehdi Aminiae280e52016-04-11 23:26:46 +000073; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.
74; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.
75; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.
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)
Teresa Johnson26ab5772016-03-15 00:04:37 +000080; 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 +000081; IMPORTGLOBALS-DAG: @globalvar = external global
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000082; 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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000086; 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 +000087; IMPORTCOMMON-DAG: @commonvar = external global
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000088; 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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000091; 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 +000092; IMPORTFUNCPTR-DAG: @P.llvm.{{.*}} = external hidden global void ()*
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000093; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr
Mehdi Aminiae280e52016-04-11 23:26:46 +000094; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.
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.
Teresa Johnson26ab5772016-03-15 00:04:37 +000099; 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 +0000100; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc
Mehdi Aminibb3a1d92016-04-20 04:18:11 +0000101; IMPORTWEAKFUNC-DAG: declare void @weakfunc
Teresa Johnsonba5d68d2015-11-12 19:31:46 +0000102; 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}