34
34
; RUN: -r=main.bc,main,px \
35
35
; RUN: -r=main.bc,small_func, \
36
36
; RUN: -r=main.bc,large_func, \
37
+ ; RUN: -r=main.bc,read_write_global_vars, \
38
+ ; RUN: -r=main.bc,external_func, \
37
39
; RUN: -r=lib.bc,callee,pl \
38
40
; RUN: -r=lib.bc,large_indirect_callee,px \
39
41
; RUN: -r=lib.bc,large_indirect_bar,px \
40
42
; RUN: -r=lib.bc,small_func,px \
41
43
; RUN: -r=lib.bc,large_func,px \
44
+ ; RUN: -r=lib.bc,read_write_global_vars,px \
42
45
; RUN: -r=lib.bc,large_indirect_callee_alias,px \
43
46
; RUN: -r=lib.bc,large_indirect_bar_alias,px \
44
47
; RUN: -r=lib.bc,calleeAddrs,px -r=lib.bc,calleeAddrs2,px -o summary main.bc lib.bc 2>&1 | FileCheck %s --check-prefix=DUMP
71
74
; MAIN-DIS: [[LARGEINDIRECT:\^[0-9]+]] = gv: (guid: 14343440786664691134, summaries: (function: (module: [[LIBMOD]], flags: ({{.*}} importType: declaration), insts: 8, {{.*}})))
72
75
; MAIN-DIS: gv: (guid: 16730173943625350469, summaries: (alias: (module: [[LIBMOD]], flags: ({{.*}} importType: declaration), aliasee: [[LARGEINDIRECT]])))
73
76
77
+ ; RUN: opt -passes=function-import -import-all-index -summary-file=main.bc.thinlto.bc main.bc -o main-after-import.bc
78
+ ; RUN: llvm-dis -o - main-after-import.bc | FileCheck %s --check-prefix=MAIN-IMPORT
79
+
80
+ ; Tests that dso_local attribute is applied on a global var from its summary.
81
+ MAIN-IMPORT: @read_write_global_vars = external dso_local global [1 x ptr ]
82
+
74
83
; Run in-process ThinLTO and tests that
75
84
; 1. `callee` remains internalized even if the symbols of its callers
76
85
; (large_func, large_indirect_callee, large_indirect_bar) are exported as
77
86
; declarations and visible to main module.
78
87
; 2. the debugging logs from `function-import` pass are expected.
88
+ ; Set relocation model to static so the dso_local attribute from a summary is
89
+ ; applied on the global variable declaration.
79
90
80
91
; RUN: llvm-lto2 run \
92
+ ; RUN: -relocation-model=static \
81
93
; RUN: -debug-only=function-import \
82
94
; RUN: -save-temps \
83
95
; RUN: -thinlto-threads=1 \
87
99
; RUN: -r=main.bc,main,px \
88
100
; RUN: -r=main.bc,small_func, \
89
101
; RUN: -r=main.bc,large_func, \
102
+ ; RUN: -r=main.bc,read_write_global_vars, \
103
+ ; RUN: -r=main.bc,external_func, \
90
104
; RUN: -r=lib.bc,callee,pl \
91
105
; RUN: -r=lib.bc,large_indirect_callee,px \
92
106
; RUN: -r=lib.bc,large_indirect_bar,px \
93
107
; RUN: -r=lib.bc,small_func,px \
94
108
; RUN: -r=lib.bc,large_func,px \
109
+ ; RUN: -r=lib.bc,read_write_global_vars,px \
95
110
; RUN: -r=lib.bc,large_indirect_callee_alias,px \
96
111
; RUN: -r=lib.bc,large_indirect_bar_alias,px \
97
112
; RUN: -r=lib.bc,calleeAddrs,px -r=lib.bc,calleeAddrs2,px -o in-process main.bc lib.bc 2>&1 | FileCheck %s --check-prefix=IMPORTDUMP
103
118
; IMPORTDUMP-DAG: Is importing function definition 13568239288960714650 small_indirect_callee from lib.cc
104
119
; IMPORTDUMP-DAG: Is importing function definition 6976996067367342685 small_func from lib.cc
105
120
; IMPORTDUMP-DAG: Is importing function declaration 2418497564662708935 large_func from lib.cc
106
- ; IMPORTDUMP-DAG: Not importing global 7680325410415171624 calleeAddrs from lib.cc
121
+ ; IMPORTDUMP-DAG: Is importing global declaration 7680325410415171624 calleeAddrs from lib.cc
107
122
; IMPORTDUMP-DAG: Is importing alias declaration 16730173943625350469 large_indirect_callee_alias from lib.cc
108
123
; IMPORTDUMP-DAG: Is importing alias declaration 13590951773474913315 large_indirect_bar_alias from lib.cc
109
124
; IMPORTDUMP-DAG: Not importing function 13770917885399536773 large_indirect_bar
115
130
; IMPORT-DAG: define available_externally void @small_func
116
131
; IMPORT-DAG: define available_externally hidden void @small_indirect_callee
117
132
; IMPORT-DAG: declare void @large_func
133
+ ; Tests that dso_local attribute is applied on a global var from its summary.
134
+ ; IMPORT-DAG: @read_write_global_vars = external dso_local global [1 x ptr]
118
135
; IMPORT-NOT: large_indirect_callee
119
136
; IMPORT-NOT: large_indirect_callee_alias
120
137
; IMPORT-NOT: large_indirect_bar
126
143
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
127
144
target triple = "x86_64-unknown-linux-gnu"
128
145
146
+ @read_write_global_vars = external global [1 x ptr ]
147
+
129
148
define i32 @main () {
130
149
call void @small_func ()
131
150
call void @large_func ()
151
+ %num = call ptr @external_func (ptr @read_write_global_vars )
152
+ store ptr %num , ptr getelementptr inbounds ([1 x ptr ], ptr @read_write_global_vars , i64 0 , i64 0 )
153
+ %res1 = call i32 @external_func (ptr @read_write_global_vars )
132
154
ret i32 0
133
155
}
134
156
@@ -137,6 +159,8 @@ declare void @small_func()
137
159
; large_func without attributes
138
160
declare void @large_func ()
139
161
162
+ declare ptr @external_func (ptr )
163
+
140
164
;--- lib.ll
141
165
source_filename = "lib.cc"
142
166
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
@@ -149,6 +173,10 @@ target triple = "x86_64-unknown-linux-gnu"
149
173
; large_indirect_bar_alias is visible to main.ll but its aliasee isn't.
150
174
@calleeAddrs2 = global [1 x ptr ] [ptr @large_indirect_bar_alias ]
151
175
176
+ ; @read_write_global_vars is not read-only nor write-only (in main.ll). It's not
177
+ ; a constant global var and has references, so it's not importable as a definition.
178
+ @read_write_global_vars = dso_local global [1 x ptr ] [ptr @large_indirect_callee ]
179
+
152
180
define void @callee () #1 {
153
181
ret void
154
182
}
0 commit comments