[PATCH] D36109: [CodeGen] Provide an advanced shrink-wrapping interface

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 11:22:05 PDT 2017


thegameg added a comment.

In https://reviews.llvm.org/D36109#856854, @lei wrote:

> Can you provide documentation on the various functions?  I was trying to extend this for PPC and I had a hard time trying to figure out what I needed to do enable to get this working.


Great! I tried to explain most of the bits here: https://lists.llvm.org/pipermail/llvm-dev/2017-August/116131.html. As I pointed out at the end of the email, you could take a look at:

- PEI: Use the ShrinkWrapper interface for placing callee-saved registers <https://github.com/thegameg/llvm/commit/57111b77a9536cad4a4b07ece2d29c784f5deeac>
- ShrinkWrapper: Add AArch64 support <https://github.com/thegameg/llvm/commit/c74e92390126c1fc40e4bf0d4cdd53ab1b420f0a>

Basically, what you're interested in is the `ShrinkWrapInfo` class. You will need to subclass that to adapt it to PPC's needs. This is similar to `TargetFrameLowering::determineCalleeSaves`, but you will need to map the CSR uses to a specific basic block of the function. For a generic behaviour just call `determineCSRUses()`, which tracks CSR uses using register units.

> I was able to see it did something for loops

Right, the loop-specific behaviour here is only to avoid placing any save / restores inside a loop, if there are any uses. You shouldn't need to worry about it if you are only looking to implement this for PPC.

> but it wasn't able to identify any shrink wrap opportunities for this simple tc:
> 
>   int doSomething(int a, int b);
>   
>   int test (int a, int b) {
>     int c=a;
>     if (a < b) {
>       c = doSomething(0, a);
>     }
>     return c;
>   }

I'm not sure I can tell what's going on without knowing what flags you used, what's the MIR code that shrink-wrapping takes as an input, and what `ShrinkWrapInfo` marks as *used*. I would be more than happy to try it out!

Also, if you have any suggestions and remarks about the algorithm or the interface it provides to work with the target, don't hesitate!


https://reviews.llvm.org/D36109





More information about the llvm-commits mailing list