This is an archive of the discontinued LLVM Phabricator instance.

[llvm][MachineOutliner] Add support for repeating machine outliner N times.
AbandonedPublic

Authored by plotfi on Oct 25 2019, 12:57 PM.

Details

Summary

This has been discussed for a while now, that rerunning the outliner can have some size wins.
So I am posting this change for review to address this.

Special Thanks to Kyungwoo Lee for experimenting on this.

Diff Detail

Event Timeline

plotfi created this revision.Oct 25 2019, 12:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2019, 12:57 PM

This is pretty cool, thanks for working on this.

This needs a couple tests. A few things I can think of:

  1. Show that the outliner will stop when there are no changes, even if you haven't run the specified number of rounds
  2. Show that adding extra iterations actually produces more outlining
  3. Show what happens when you outline from an outlined function

I think that the easiest way to test (1) is to add some debug output which we can test. E.g. "did not outline on iteration <iteration> out of <number of iterations>"

Also, do you think you could test the code size + compile time impact of this patch on CTMark at -Oz for AArch64? I think that two or three data points would be sufficient. Say, 1 round versus 2 rounds versus 5 rounds versus 10 rounds.

(If it turns out that compile time is an issue, I suspect we might be able to save *some* time by keeping track of which functions and basic blocks can never be outlined from, for example.)

It would also be nice to know how many rounds on average this provides benefit for. I think 1 iteration is the correct default; this is more for my own curiosity.

llvm/lib/CodeGen/MachineOutliner.cpp
100

Maybe "outlining-iterations" to imply that it's something plural?

100

What should happen if this is set to 0? Is there a way to specify a minimum value here?

903

We can probably just remove the entire comment from runOnModule now, since it would all be folded into the comment on doOutline

907

\p M

1438

I don't think this if is necessary. Since Iterations is 1 by default, the loop should only run once when Iterations is not specified.

1441–1445

I think this can be simplified:

for(...)
  if (!doOutline(M))
    return false;
return true;
plotfi updated this revision to Diff 226741.Oct 28 2019, 1:27 PM
plotfi marked 8 inline comments as done.Oct 28 2019, 1:31 PM
plotfi added inline comments.
llvm/lib/CodeGen/MachineOutliner.cpp
100

I changed it to "outliner-reruns", so 0 just means don't do any reruns. This way it has to run the outliner at least once.

1438

I've decided for now that it would be good to keep the reruning aspect of this patch separate from the existing behavior. I'm still looking to add some good tests here, stay tuned.

plotfi updated this revision to Diff 226756.Oct 28 2019, 3:11 PM
plotfi marked 2 inline comments as done.
tellenbach added a comment.EditedNov 1 2019, 3:56 AM

I'd actually prefer an option outliner-runs that is defaulted to 1 rather than a rerun option. From a user perspective I'd be unclear what outliner-reruns=0 exactly means? Does that mean one run or zero?

As @paquette already said this definitely needs tests for all supported targets. I just want to mention that an outlined function doesn't run through the ordinary lowering passes so some information might be missing that the outliner relies on.

A first example that comes to my mind: My patch https://reviews.llvm.org/D69097 introduces return address signing for outlined functions on AArch64 targets. However, these functions currently get signed based on the signing behaviour of candidates rather than their own signing-related function attributes. The outlined functions actually do not even have these attributes. That means a rerun of the outliner would not catch up that the outlined function has been signed and that a new outlined function could also need signing.

tellenbach added inline comments.Nov 1 2019, 5:05 AM
llvm/lib/CodeGen/MachineOutliner.cpp
100

Could this be renamed to something like machine-outliner-[re]runs? I find an option outliner... to be somewhat ambiguous (there is e.g. outlining during HotColdSpilling) and the prefix machine would be more consistent here.

plotfi marked an inline comment as done.Nov 17 2019, 11:05 PM
plotfi added inline comments.
llvm/lib/CodeGen/MachineOutliner.cpp
100

Sounds good to me. Although, this is explicitly reruns. When it is set to 0, there should be only one run. I don't think it makes sense to enable the pass and have a flag where it does not run.

Reverse ping: Is this revision still active?

D71027 introduces similar functionality so a short clarification on the status of D69446 would be appreciated.

Thanks!

plotfi abandoned this revision.Apr 29 2020, 12:21 AM