This is an archive of the discontinued LLVM Phabricator instance.

New interface to enable shrink wrapping
ClosedPublic

Authored by kbarton on Jul 22 2015, 11:04 AM.

Details

Summary

This patch changes the interface to enable the shrink wrapping optimization.
It adds a new constructor, which takes a std::function predicate function that is run at the beginning of shrink wrapping to determine whether the optimization should run on the given machine function. The std::function can be overridden by each target, allowing target-specific decisions to be made on each machine function.

This is necessary for PowerPC, as the decision to run shrink wrapping is partially based on the ABI. Futhermore, this operates nicely with the GCC iFunc capability, which allows option overrides on a per-function basis.

Diff Detail

Event Timeline

kbarton updated this revision to Diff 30368.Jul 22 2015, 11:04 AM
kbarton retitled this revision from to New interface to enable shrink wrapping.
kbarton updated this object.
kbarton added a subscriber: llvm-commits.
nemanjai added inline comments.Jul 24 2015, 7:57 AM
lib/CodeGen/ShrinkWrap.cpp
323

Does this mean that shrink wrapping will run on a passed function if the PredicateFtor is not callable? Although as currently set-up, this cannot happen.

kbarton added inline comments.Jul 24 2015, 9:02 AM
lib/CodeGen/ShrinkWrap.cpp
323

Yes, that is true.
I could not remove the default constructor, as it is needed somewhere else.
I could change this logic to disable Shrink Wrapping if PredicateFtor has not been set if there is a concern about this.

kbarton added inline comments.Jul 24 2015, 11:25 AM
lib/CodeGen/Passes.cpp
539–540

This will add shrink wrapping all the time. I think it makes more sense to guard this by (getOptLevel() != CodeGenOpt::None), as is done below for addMachineLateOptimization().
I will make this change in the next revision.

wschmidt added inline comments.Jul 24 2015, 1:08 PM
lib/CodeGen/Passes.cpp
539–540

Depending on the computational complexity of shrink wrapping, you may want to enable this at -O2 and up rather than -O1. I haven't looked at the code, but I assume Quentin can advise.

hfinkel edited edge metadata.Jul 25 2015, 12:49 PM

This is necessary for PowerPC, as the decision to run shrink wrapping is partially based on the ABI.

How do you imagine this working such that we can still turn off shrink wrapping on PowerPC using the command-line option?

lib/CodeGen/Passes.cpp
539–540

Two comments here:

The pass should always be added, but it should contain a check for:

if (skipOptnoneFunction(*MF.getFunction()))

and, if it does not, we should fix that.

Second, regarding complexity, it does not seem as though it should be significantly more expensive than MachineLICM, etc. that are used at -O1, so I think that leaving it always enabled if (getOptLevel() != CodeGenOpt::None) should be fine.

lib/CodeGen/ShrinkWrap.cpp
323

This seems reasonable. If you somehow were able to invoke the pass manually from the command line using the default constructor, you'd expect it to run.

kbarton updated this revision to Diff 30712.Jul 27 2015, 11:35 AM
kbarton edited edge metadata.

Two changes since last revision:

  1. Do not add shrink wrap pass for noopt
  2. Check the skipOptnoneFunction method at beginning of shrink wrapping

This is necessary for PowerPC, as the decision to run shrink wrapping is partially based on the ABI.

How do you imagine this working such that we can still turn off shrink wrapping on PowerPC using the command-line option?

I ended up adding a new command line option to disable it for PPC, but it should be doable with the existing option of -enable-shrink-wrap=false if we don't want to add a new option. I think you can build this check into the checks for the ABI on a per-function bases and achieve the desired behaviour.
Or, I misunderstand the question.

qcolombet edited edge metadata.Jul 27 2015, 2:14 PM

Hi Kit,

LGTM with Hal’s comments addressed.

Thanks,
Q.

lib/CodeGen/Passes.cpp
539–540

Like Hal said, having it running at O1 should be fine.

lib/CodeGen/ShrinkWrap.cpp
191

Period at end of comments.

kbarton accepted this revision.Aug 6 2015, 11:03 AM
kbarton added a reviewer: kbarton.
This revision is now accepted and ready to land.Aug 6 2015, 11:03 AM
kbarton closed this revision.Aug 6 2015, 11:04 AM

Committed revision 244235.