This is an archive of the discontinued LLVM Phabricator instance.

[MachineOutliner] Add support for saving LR to a callee-saved register
ClosedPublic

Authored by paquette on Jul 26 2018, 3:52 PM.

Details

Summary

When the prospective caller of an outlined function saves registers, we can save LR to one of those registers instead of the stack. This teaches the outliner to do that when possible.

This allows us to avoid bumping the stack in outlined functions in some cases. By doing this, in a later patch, we can teach the outliner to do something like this:

f1:
  ...
  bl OUTLINED_FUNCTION
  ...

f2:
  ...
  save LR
  bl OUTLINED_FUNCTION
  restore LR
  ...

instead of falling back to saving LR in both cases.

Diff Detail

Event Timeline

paquette created this revision.Jul 26 2018, 3:52 PM
efriedma added inline comments.
lib/Target/AArch64/AArch64InstrInfo.cpp
4929

An alternative sequence would be "ADR scratch, .+8; B OUTLINED_FUNCTION", and then in the outlined function "I1; I2; I3; BR scratch". Disadvantage is that every caller has to use the same register, and I guess you can't skip the save/restore in some callers like you're planning.

4952

Why not a caller-save register?

paquette marked an inline comment as done.Jul 27 2018, 5:11 PM
paquette added inline comments.
lib/Target/AArch64/AArch64InstrInfo.cpp
4929

Yeah, the goal here is to set it up so that we can use the NoLRSave case whenever possible. However, it could still be worth it to use a sequence like this if it turns out that there are too few NoLRSave candidates for it to be worth it to keep them around.

4952

I talked with Matthias about this, and apparently LiveRegUnits actually handles basically everything weird that could happen here, so it's not even really an issue...

MatzeB added inline comments.Jul 27 2018, 5:13 PM
lib/Target/AArch64/AArch64InstrInfo.cpp
4952

Meaning we can change this to just go over the whole GPR register class instead of the CSR list :)

paquette updated this revision to Diff 157814.Jul 27 2018, 5:19 PM
paquette marked an inline comment as done.

Updated the diff. We now just look over the GPR64 register class instead of callee-saves.

This revision is now accepted and ready to land.Jul 27 2018, 5:37 PM
paquette closed this revision.Jul 30 2018, 10:46 AM

Thanks!

Committed in r338278. (https://reviews.llvm.org/rL338278)