This is an archive of the discontinued LLVM Phabricator instance.

Add interface to order inlining
ClosedPublic

Authored by taolq on May 28 2021, 6:29 AM.

Details

Summary

This patch abstract Calls in Inliner:run to InlineOrder.
With this patch, we could customize the inlining order.

Now this patch is a minimal refactoring,
some works are still needed to be done.

Diff Detail

Event Timeline

taolq created this revision.May 28 2021, 6:29 AM
taolq requested review of this revision.May 28 2021, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2021, 6:29 AM
taolq retitled this revision from add InlineOrder to abstract Calls to Add interface to order inlining.May 28 2021, 6:35 AM
taolq edited the summary of this revision. (Show Details)
taolq added reviewers: mtrofin, kazu, teemperor.

I believe this is in the right direction.

I recommend informing the nuances of the API by trying first to replace all the uses of Calls (and the adjustment of the index iterating through Calls, line 906)

Please note the linter notes (virtual dtor, etc)

llvm/include/llvm/Analysis/InlineOrder.h
17 ↗(On Diff #348509)

Since this is an abstraction meant for the inliner, I'd just define it in Inliner.cpp (i.e. no need for a header)

kazu added a comment.May 28 2021, 10:33 AM

I also agree this is in the right direction. I've left some minor comments.

llvm/include/llvm/Analysis/InlineOrder.h
38 ↗(On Diff #348509)

I would keep this private. If you need to accommodate functions like erase, just add a method to this class.

llvm/lib/Transforms/IPO/Inliner.cpp
766

I'd remove this line.

taolq updated this revision to Diff 348694.EditedMay 30 2021, 6:34 AM

move codes from InlineOrder.h to Inliner.cpp

taolq updated this revision to Diff 348786.May 31 2021, 5:53 AM
taolq marked an inline comment as done.

change impl of DefaultInlineOrder: SmallVector -> std::deque
remove operator[] from InlineOrder
replace usage of API of DefaultInlinOrder: indexing -> front() & pop()

kazu added a comment.Jun 1 2021, 10:26 AM

Thanks for the update. I'd generalize the code around Call.erase a little bit more to accommodate other underlying data structures. See the comments below for details.

llvm/lib/Transforms/IPO/Inliner.cpp
67

Remove this if you use SmallVector. See below.

689

I would change this:

virtual void erase_if(function_ref<bool (CallBase *)> Pred) = 0;

where you would erase all elements satisfying Pred -- somewhat like erase_if in llvm/include/llvm/ADT/STLExtras.h.

I'm suggesting this because you need to heapify the contents after erasing elements if your underlying structure is a priority queue for example. std::remove_if removes items while maintaining the iteration order of surviving elements, but this property is specific to DefaultInlineOrder. Other inline orders may not be compatible with this property.

691–692

You shouldn't need these functions once you implement erase_if.

697

If we never add things to the front, I would stick to SmallVector and keep an index I to point to the first valid element just like the original code.

713

Change to erase_if accordingly.

717–718

Likewise, you shouldn't need these.

928–931

Change this to:

Calls.erase_if([&](CallBase *Call) { return Call->getCaller() == &Callee; });

This way, you shouldn't need begin or end.

taolq updated this revision to Diff 349462.EditedJun 3 2021, 12:00 AM
  • generalize Calls.erase
  • simplify API
kazu accepted this revision.Jun 3 2021, 9:33 AM

Thanks for updating the patch!

This revision is now accepted and ready to land.Jun 3 2021, 9:33 AM
This revision was automatically updated to reflect the committed changes.
taolq marked 7 inline comments as done.
dyung added a subscriber: dyung.Jun 5 2021, 10:53 PM

This change appears to be causing 6 or 7 lit tests to hang. Can you take a look and fix or revert?

https://lab.llvm.org/buildbot/#/builders/139/builds/5158 (7 tests hanging)
https://lab.llvm.org/buildbot/#/builders/43/builds/6983 (6 tests hanging)
https://lab.llvm.org/buildbot/#/builders/107/builds/8830 (6 tests hanging)
https://lab.llvm.org/buildbot/#/builders/110/builds/3878 (6 tests hanging)

taolq added a comment.Jun 5 2021, 11:04 PM

This change appears to be causing 6 or 7 lit tests to hang. Can you take a look and fix or revert?

https://lab.llvm.org/buildbot/#/builders/139/builds/5158 (7 tests hanging)
https://lab.llvm.org/buildbot/#/builders/43/builds/6983 (6 tests hanging)
https://lab.llvm.org/buildbot/#/builders/107/builds/8830 (6 tests hanging)
https://lab.llvm.org/buildbot/#/builders/110/builds/3878 (6 tests hanging)

Thanks for reminding. I will tentatively revert it soon.

taolq reopened this revision.Jun 7 2021, 2:06 AM
This revision is now accepted and ready to land.Jun 7 2021, 2:06 AM
taolq updated this revision to Diff 350202.Jun 7 2021, 2:06 AM
  • modify API & fix timeout test cases
This revision was landed with ongoing or failed builds.Jun 7 2021, 3:36 AM
This revision was automatically updated to reflect the committed changes.
taolq added a comment.Jun 7 2021, 4:50 AM

(Looks like the revert landed in 48252d7570bdf5ab77451d0f049047f1c40742dd)

Now it's fixed and landed.