This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Inliner] Support recursion in Inliner
ClosedPublic

Authored by javedabsar on Jun 5 2022, 6:02 AM.

Details

Summary

This fixes Bug https://github.com/llvm/llvm-project/issues/53492
and uses InlineHistory to track recursive inlining.

Diff Detail

Event Timeline

javedabsar created this revision.Jun 5 2022, 6:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2022, 6:02 AM
javedabsar requested review of this revision.Jun 5 2022, 6:02 AM
rriddle requested changes to this revision.Jun 5 2022, 11:35 AM

Thanks for looking into this! Have you considered/looked into using the same approach as LLVM? i.e. keeping an inline history to track what's already been inlined?

This revision now requires changes to proceed.Jun 5 2022, 11:35 AM

Thanks for looking into this! Have you considered/looked into using the same approach as LLVM? i.e. keeping an inline history to track what's already been inlined?

Yes that seems a good idea. Will try to rework this using InlineHistoryIDs

javedabsar updated this revision to Diff 438436.EditedJun 20 2022, 10:31 AM

change based on review comments.
Use InlineHistory.

javedabsar edited the summary of this revision. (Show Details)Jun 21 2022, 6:39 AM

gentle reminder

River is out this week, please ping again on Monday!

River is out this week, please ping again on Monday!

Ah ok. Thanks @mehdi_amini

Thanks for updating! (Sorry, coming back from OOO)

mlir/lib/Transforms/Inliner.cpp
395–398

Please move these functions outside of the anonymous namespace.

396–400

This doesn't look scalable, given that it assumes the existence of a "callee" attribute. Can you instead use op.getCallableForCallee()? The result of that is either a SymbolRefAttr (which is easily dumpable), or a Value (which could just fallback to the _unnamed_callee_ you have here).

403–404

Can you reflow these comments? it doesn't look like it wraps at 80.

405
406
486

Can we use Optional<int> instead of int here? It would remove the magic -1 handling.

Fix based on review feedback.

javedabsar marked 6 inline comments as done.Jun 28 2022, 10:23 AM

Thanks for the review

rriddle added inline comments.Jun 28 2022, 12:29 PM
mlir/lib/Transforms/Inliner.cpp
372–373

Do we need to anchor on FlatSymbolRefAttr? We should be able to print any SymbolRefAttr, e.g. using debugString(in mlir/Support/DebugStringHelper.h).

382

Can you use MutableArrayRef here instead?

394

Unrelated?

492

Please cache the end iterator here.

540

You'll likely need a (void)hisStr after this to avoid unused variable warnings.

Also, can you extend the name of this to be more explicit on what this is doing?

mlir/test/Transforms/bugfix53492_inlining.mlir
3 ↗(On Diff #440682)

Can you rename the file (or just merge it into inlining.mlir) and the functions in this file to better represent what this is testing, as opposed to referencing the bug? The fix is for inlining recursive functions, which is descriptive enough that I don't think we need/should reference the bug here.

Fixes based on review comments.

rename test

javedabsar marked 4 inline comments as done.Jun 30 2022, 3:18 AM
javedabsar added inline comments.
mlir/lib/Transforms/Inliner.cpp
492

Actually the 'calls.size' changes in this loop. Below it calls inlineCall (in Utils/InliningUtils.cpp) which calls interface.processInlinedBlocks which then calls collectCallOps that adds new inlined calls. Since the calls is reference to inliner.calls it changes.

javedabsar retitled this revision from [mlir][Inliner] Bug-Fix #53492. Inliner goes into infinite loop to [mlir][Inliner] Support recursion in Inliner.Jun 30 2022, 3:30 AM
javedabsar marked an inline comment as done.Jun 30 2022, 7:19 AM
javedabsar added inline comments.
mlir/lib/Transforms/Inliner.cpp
492

Ignore above. I had misunderstood your comment earlier.

rriddle accepted this revision.Jun 30 2022, 10:34 AM

Thank you for tackling this! Very appreciated.

mlir/test/Transforms/inlining-recursive.mlir
4

Honestly I think we could just drop this issue reference.

8

nit: Can you indent these checks?

This revision is now accepted and ready to land.Jun 30 2022, 10:34 AM
This revision was automatically updated to reflect the committed changes.