Skip to content

Commit c90b607

Browse files
committed
Insert spills before optimizations
1 parent 98c683b commit c90b607

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

mypyc/codegen/emitmodule.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ def compile_scc_to_ir(
229229
if errors.num_errors > 0:
230230
return modules
231231

232+
env_user_functions = {}
233+
for module in modules.values():
234+
for cls in module.classes:
235+
if cls.env_user_function:
236+
env_user_functions[cls.env_user_function] = cls
237+
232238
for module in modules.values():
233239
for fn in module.functions:
234240
# Insert uninit checks.
@@ -237,17 +243,16 @@ def compile_scc_to_ir(
237243
insert_exception_handling(fn)
238244
# Insert refcount handling.
239245
insert_ref_count_opcodes(fn)
246+
247+
if fn in env_user_functions:
248+
insert_spills(fn, env_user_functions[fn])
249+
240250
# Switch to lower abstraction level IR.
241251
lower_ir(fn, compiler_options)
242252
# Perform optimizations.
243253
do_copy_propagation(fn, compiler_options)
244254
do_flag_elimination(fn, compiler_options)
245-
246-
for module in modules.values():
247-
for cls in module.classes:
248-
if cls.env_user_function:
249-
insert_spills(cls.env_user_function, cls)
250-
255+
251256
return modules
252257

253258

0 commit comments

Comments
 (0)