@@ -244,17 +244,7 @@ const __llvm_initialized = Ref(false)
244
244
@timeit_debug to " IR post-processing" begin
245
245
entry = finish_module! (job, ir, entry)
246
246
247
- if optimize
248
- @timeit_debug to " optimization" optimize! (job, ir)
249
-
250
- # optimization may have replaced functions, so look the entry point up again
251
- entry = functions (ir)[entry_fn]
252
- end
253
-
254
- if ccall (:jl_is_debugbuild , Cint, ()) == 1
255
- @timeit_debug to " verification" verify (ir)
256
- end
257
-
247
+ # some early clean-up to reduce the amount of code to optimize
258
248
@timeit_debug to " clean-up" begin
259
249
# replace non-entry function definitions with a declaration
260
250
if only_entry
@@ -266,13 +256,13 @@ const __llvm_initialized = Ref(false)
266
256
end
267
257
end
268
258
269
- # remove everything except for the entry and any exported global variables
270
- exports = String[entry_fn]
271
- for gvar in globals (ir)
272
- push! (exports, LLVM. name (gvar))
273
- end
274
-
275
259
ModulePassManager () do pm
260
+ # mark everything internal except for the entry and exported global variables.
261
+ # this makes sure that the optimizer can, e.g., touch function signatures.
262
+ exports = String[entry_fn]
263
+ for gvar in globals (ir)
264
+ push! (exports, LLVM. name (gvar))
265
+ end
276
266
internalize! (pm, exports)
277
267
278
268
# eliminate all unused internal functions
@@ -284,8 +274,9 @@ const __llvm_initialized = Ref(false)
284
274
constant_merge! (pm)
285
275
286
276
if do_deferred_codegen
287
- # inline and optimize the call to the deferred code. in particular we want to
288
- # remove unnecessary alloca's that are created by pass-by-ref semantics.
277
+ # inline and optimize the call to e deferred code. in particular we want
278
+ # to remove unnecessary alloca's created by pass-by-ref semantics.
279
+ # TODO : is this still necesary, now that we optimize after codegen?
289
280
instruction_combining! (pm)
290
281
always_inliner! (pm)
291
282
scalar_repl_aggregates_ssa! (pm)
@@ -300,6 +291,17 @@ const __llvm_initialized = Ref(false)
300
291
run! (pm, ir)
301
292
end
302
293
end
294
+
295
+ if optimize
296
+ @timeit_debug to " optimization" optimize! (job, ir)
297
+
298
+ # optimization may have replaced functions, so look the entry point up again
299
+ entry = functions (ir)[entry_fn]
300
+ end
301
+
302
+ if ccall (:jl_is_debugbuild , Cint, ()) == 1
303
+ @timeit_debug to " verification" verify (ir)
304
+ end
303
305
end
304
306
305
307
return ir, (; entry, compiled)
0 commit comments