New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inliners to run all passes on IR and clean up correctly. #5673
Conversation
As title. Fixes numba#4691 Fixes numba#4693 Fixes numba#5476
iinfo = _inline_info(ir, typemap, calltypes, sig) | ||
self._inline_overloads[sig.args] = {'folded_args': folded_args, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this overrides the behaviour here https://github.com/numba/numba/pull/5673/files#diff-aee5ebdb5580a36762cba728715f96d1R536-R537 and needs looking at
# Disable SSA transformation, the call site won't be in SSA form and | ||
# self.inline_ir depends on this being the case. | ||
state.flags.enable_ssa = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true for overload inlines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without it, this:
======================================================================
ERROR: test_inlining_optional_constant (numba.tests.test_ir_inlining.TestGeneralInlining)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<path>numba/tests/test_ir_inlining.py", line 1043, in test_inlining_optional_constant
self.check(impl, block_count='SKIP', inline_expect={'bar': True})
File "<path>numba/tests/test_ir_inlining.py", line 103, in check
self.assertEqual(test_impl(*args), j_func(*args))
File "<path>numba/core/dispatcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "<path>numba/core/dispatcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "<path>numba/core/utils.py", line 79, in reraise
raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in inliner_custom_pipe mode pipeline (step: nopython frontend)
Type of variable 'b.1.382' cannot be determined, operation: unknown operation, location: unknown location (0:0)
File "unknown location", line 0:
<source missing, REPL/exec in use?>
# Updating these causes problems?! | ||
#fcomp.targetdescr.options.parse_as_flags(flags, | ||
# fcomp.targetoptions) | ||
#flags = fcomp._customize_flags(flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a problem? Do flags influence IR gen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only in cfuncs
it seems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave it for now?
But less involved.
stuartarchibald@94f6bb2 achieves the same/similar, but as a strategy pushes inlining as high up the compilation chain as possible, and then just lets other passes run as usual. The inlined IR is not subjected to the full compilation pipelines, only closure inlining and generic rewrites. |
Note: failing at numba/numba/tests/test_mixed_tuple_unroller.py Lines 1586 to 1599 in ff24fb1
literal_unroll(x) where x = [10, y]
|
NOTE: prefer this PR over stuartarchibald@94f6bb2 |
elect to skip for now, needs updates elsewhere |
is this ready for review? |
Let's say yes to get it moving, but also note there's a couple of thing we may need to look at already mentioned in the above. |
numba/core/inline_closurecall.py
Outdated
return self.inline_ir(caller_ir, block, i, callee_ir, freevars, | ||
arg_typs=arg_typs) | ||
|
||
def inline_closure(self, caller_ir, block, i, closure_obj, glbls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this function is dead
numba/core/inline_closurecall.py
Outdated
self.typemap.update(f_typemap) | ||
self.calltypes.update(f_calltypes) | ||
|
||
def convert_code_object_to_function(self, obj, glbls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this too
I added some tests for the dead functions to the tip of this branch: https://github.com/stuartarchibald/numba/commits/fix/5476_5_cont My conclusion from adding them is that the interface still isn't quite right and that it'd make sense to also add to the class something that actually does the inlining work (stitches the blocks together etc), as well as computing the changes required. I'm going to remove those dead methods from the class as a result and open a ticket about future things to be done. |
Work ticket: #5775 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix here. The inliner passes are complicated and there may need further work to clean it up, but this patch already provides important fixes and we know some downstream projects will need.
As title.
Fixes #4691
Fixes #4693
Fixes #5476