blob: dad9b95bb9fa770238c875d3f7f41b019151167f [file] [log] [blame]
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +00001; Do setup work for all below tests: generate bitcode and combined index
2; RUN: llvm-as -function-summary %s -o %t.bc
3; RUN: llvm-as -function-summary %p/Inputs/funcimport.ll -o %t2.bc
4; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
5
6; Ensure statics are promoted/renamed correctly from this file (all but
7; constant variable need promotion).
8; RUN: llvm-link %t.bc -functionindex=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC
Teresa Johnsonba5d68d2015-11-12 19:31:46 +00009; EXPORTSTATIC-DAG: @staticvar.llvm.1 = hidden global
10; EXPORTSTATIC-DAG: @staticconstvar = internal unnamed_addr constant
11; EXPORTSTATIC-DAG: @P.llvm.1 = hidden global void ()* null
12; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.1
13; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.1
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000014
15; Ensure that both weak alias to an imported function and strong alias to a
16; non-imported function are correctly turned into declarations.
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +000017; Also ensures that alias to a linkonce function is turned into a declaration
18; and that the associated linkonce function is not in the output, as it is
19; lazily linked and never referenced/materialized.
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000020; 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 +000021; IMPORTGLOB1-DAG: define available_externally void @globalfunc1
22; IMPORTGLOB1-DAG: declare void @globalfunc2
23; IMPORTGLOB1-DAG: declare extern_weak void @weakalias
24; IMPORTGLOB1-DAG: declare void @analias
25; IMPORTGLOB1-DAG: declare void @linkoncealias
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +000026; IMPORTGLOB1-NOT: @linkoncefunc
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000027
28; Ensure that weak alias to a non-imported function is correctly
29; turned into a declaration, but that strong alias to an imported function
30; is imported as alias.
31; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB2
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000032; IMPORTGLOB2-DAG: @analias = alias void (...), bitcast (void ()* @globalfunc2
33; IMPORTGLOB2-DAG: declare void @globalfunc1
34; IMPORTGLOB2-DAG: define available_externally void @globalfunc2
35; IMPORTGLOB2-DAG: declare extern_weak void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000036
37; Ensure that strong alias imported in second pass of importing ends up
38; as an alias.
39; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB3
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000040; IMPORTGLOB3-DAG: @analias = alias void (...), bitcast (void ()* @globalfunc2
41; IMPORTGLOB3-DAG: define available_externally void @globalfunc1
42; IMPORTGLOB3-DAG: define available_externally void @globalfunc2
43; IMPORTGLOB3-DAG: declare extern_weak void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000044
45; Ensure that strong alias imported in first pass of importing ends up
46; as an alias, and that seeing the alias definition during a second inlining
47; pass is handled correctly.
48; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc2:%t.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB4
Teresa Johnsonba5d68d2015-11-12 19:31:46 +000049; IMPORTGLOB4-DAG: @analias = alias void (...), bitcast (void ()* @globalfunc2
50; IMPORTGLOB4-DAG: define available_externally void @globalfunc2
51; IMPORTGLOB4-DAG: define available_externally void @globalfunc1
52; IMPORTGLOB4-DAG: declare extern_weak void @weakalias
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000053
54; Ensure that imported static variable and function references are correctly
55; promoted and renamed (including static constant variable).
56; 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 +000057; IMPORTSTATIC-DAG: @staticvar.llvm.1 = available_externally hidden global
58; IMPORTSTATIC-DAG: @staticconstvar.llvm.1 = internal unnamed_addr constant
59; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics
60; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.1
61; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.1
62; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.1
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000063
64; Ensure that imported global (external) function and variable references
65; are handled correctly (including referenced variable imported as
66; available_externally definition)
67; 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 +000068; IMPORTGLOBALS-DAG: @globalvar = available_externally global
69; IMPORTGLOBALS-DAG: declare void @globalfunc1()
70; IMPORTGLOBALS-DAG: define available_externally i32 @referenceglobals
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000071
72; Ensure that common variable correctly imported as common defition.
73; 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 +000074; IMPORTCOMMON-DAG: @commonvar = common global
75; IMPORTCOMMON-DAG: define available_externally i32 @referencecommon
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000076
77; Ensure that imported static function pointer correctly promoted and renamed.
78; 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 +000079; IMPORTFUNCPTR-DAG: @P.llvm.1 = available_externally hidden global void ()* null
80; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr
81; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.1
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000082
83; Ensure that imported weak function reference/definition handled properly.
84; Imported weak_any definition should be skipped with warning, and imported
85; reference should turned into an external_weak declaration.
86; 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 +000087; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc
88; IMPORTWEAKFUNC-DAG: @weakvar = extern_weak global i32, align 4
89; IMPORTWEAKFUNC-DAG: declare extern_weak void @weakfunc
90; IMPORTWEAKFUNC-DAG: define available_externally void @callweakfunc
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +000091
92@globalvar = global i32 1, align 4
93@staticvar = internal global i32 1, align 4
94@staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4
95@commonvar = common global i32 0, align 4
96@P = internal global void ()* null, align 8
97
98@weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
99@analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +0000100@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000101
102define void @globalfunc1() #0 {
103entry:
104 ret void
105}
106
107define void @globalfunc2() #0 {
108entry:
109 ret void
110}
111
Teresa Johnsonf1b0a6e2015-11-04 16:01:16 +0000112define linkonce_odr void @linkoncefunc() #0 {
113entry:
114 ret void
115}
116
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000117define i32 @referencestatics(i32 %i) #0 {
118entry:
119 %i.addr = alloca i32, align 4
120 store i32 %i, i32* %i.addr, align 4
121 %call = call i32 @staticfunc()
122 %0 = load i32, i32* @staticvar, align 4
123 %add = add nsw i32 %call, %0
124 %1 = load i32, i32* %i.addr, align 4
125 %idxprom = sext i32 %1 to i64
126 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom
127 %2 = load i32, i32* %arrayidx, align 4
128 %add1 = add nsw i32 %add, %2
129 ret i32 %add1
130}
131
132define i32 @referenceglobals(i32 %i) #0 {
133entry:
134 %i.addr = alloca i32, align 4
135 store i32 %i, i32* %i.addr, align 4
136 call void @globalfunc1()
137 %0 = load i32, i32* @globalvar, align 4
138 ret i32 %0
139}
140
141define i32 @referencecommon(i32 %i) #0 {
142entry:
143 %i.addr = alloca i32, align 4
144 store i32 %i, i32* %i.addr, align 4
145 %0 = load i32, i32* @commonvar, align 4
146 ret i32 %0
147}
148
149define void @setfuncptr() #0 {
150entry:
151 store void ()* @staticfunc2, void ()** @P, align 8
152 ret void
153}
154
155define void @callfuncptr() #0 {
156entry:
157 %0 = load void ()*, void ()** @P, align 8
158 call void %0()
159 ret void
160}
161
Teresa Johnson3cd81612015-11-10 18:20:11 +0000162@weakvar = weak global i32 1, align 4
Teresa Johnsonc7ed52f2015-11-03 00:14:15 +0000163define weak void @weakfunc() #0 {
164entry:
165 ret void
166}
167
168define void @callweakfunc() #0 {
169entry:
170 call void @weakfunc()
171 ret void
172}
173
174define internal i32 @staticfunc() #0 {
175entry:
176 ret i32 1
177}
178
179define internal void @staticfunc2() #0 {
180entry:
181 ret void
182}