@@ -179,6 +179,21 @@ const __llvm_initialized = Ref(false)
179
179
end
180
180
end
181
181
182
+ # mark everything internal except for the entry and any exported global variables.
183
+ # this makes sure that the optimizer can, e.g., touch function signatures.
184
+ ModulePassManager () do pm
185
+ # NOTE: this needs to happen after linking libraries to remove unused functions,
186
+ # but before deferred codegen so that all kernels remain available.
187
+ exports = String[entry_fn]
188
+ for gvar in globals (ir)
189
+ if linkage (gvar) == LLVM. API. LLVMExternalLinkage
190
+ push! (exports, LLVM. name (gvar))
191
+ end
192
+ end
193
+ internalize! (pm, exports)
194
+ run! (pm, ir)
195
+ end
196
+
182
197
# deferred code generation
183
198
do_deferred_codegen = ! only_entry && deferred_codegen &&
184
199
haskey (functions (ir), " deferred_codegen" )
@@ -247,14 +262,6 @@ const __llvm_initialized = Ref(false)
247
262
# some early clean-up to reduce the amount of code to optimize
248
263
@timeit_debug to " clean-up" begin
249
264
ModulePassManager () do pm
250
- # mark everything internal except for the entry and exported global variables.
251
- # this makes sure that the optimizer can, e.g., touch function signatures.
252
- exports = String[entry_fn]
253
- for gvar in globals (ir)
254
- push! (exports, LLVM. name (gvar))
255
- end
256
- internalize! (pm, exports)
257
-
258
265
# eliminate all unused internal functions
259
266
global_optimizer! (pm)
260
267
global_dce! (pm)
0 commit comments