This is an archive of the discontinued LLVM Phabricator instance.

[ARM][MachineOutliner] Add calls default handling.
ClosedPublic

Authored by yroux on Sep 4 2020, 4:56 AM.

Details

Summary

Handles calls inside outlined regions, by saving and restoring the link register.

Diff Detail

Event Timeline

yroux created this revision.Sep 4 2020, 4:56 AM
yroux requested review of this revision.Sep 4 2020, 4:56 AM
samparker added inline comments.Sep 8 2020, 12:52 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5846

I've forgotten what FrameDefault represents, but is this right considering that NumBytesToCreateFrame is also initialised to this?

yroux added inline comments.Sep 8 2020, 6:35 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5846

Ah right, the logic here is that NumBytesToCreateFrame is initialised to the costs in byte of adding a "bx lr" to the outlined code (2 or 4 bytes if we are in T2 or ARM) then if we are in a taillcall or thunk case it is set to 0 since the nothing is added to the code, and here we check if there is a call in the outlined chunk, which means that we need to insert a save and restore of the link register, thus we need to increase NumBytesToCreateFrame by the cost of a CallDefault and not FrameDefault, and it is the same in the test below. I'll update the patch.

yroux added inline comments.Sep 8 2020, 6:41 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5846

well, since CallDefault cost contains the cost of the branch it will not be accurate, I'll add a proper cost for save/restore lr

yroux updated this revision to Diff 290939.Sep 10 2020, 4:38 AM
samparker added inline comments.Sep 14 2020, 4:08 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5694

So this is the cost of the store and load, but don't we also need to consider the frame setup too?

yroux added inline comments.Sep 14 2020, 4:15 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5694

The variable NumBytesToCreateFrame is initialized to the default cost of the frame setup and then incremented by the cost of the load/store if needed

samparker added inline comments.Sep 14 2020, 4:39 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5694

So I'm sorry if I'm just being a bit blind (and/or horribly confused!) But I see:

unsigned NumBytesToCreateFrame = Costs.FrameDefault;
NumBytesToCreateFrame += Costs.SaveRestoreLROnStack;

Does this really translate the the cost of inserting:

  • a call to the outlined function.
  • a sub to adjust the stack pointer in the outlined function.
  • the stack store of LR.
  • the bx lr from the outlined function.
  • the stack restore of LR.

Am I missing some logic that calls SetCandidateCallInfo?

yroux added inline comments.Sep 14 2020, 5:09 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5694

Ok, let's look at the Default case for ARM mode:

  • The cost of the call to the outlined function is handled by the setCallInfo method of a candidate, in which Cost.CallDefault is passed.
  • Then for the frame:
    • I used a STR_PRE_IMM which decrement SP and store LR in 4 bytes
    • then LR and stack are restored LDR_POST_IMM which is alsor 4 bytes (so the cost of save and restore is 8)
    • and we have the BX LR, is cost is handled by FrameDefault (4 bytes)
samparker added inline comments.Sep 14 2020, 5:18 AM
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
5694

Ah, indexed load/store! Sorry for missing that in the tests, thanks for clearing that up.

samparker accepted this revision.Sep 14 2020, 6:49 AM

Thanks, LGTM

This revision is now accepted and ready to land.Sep 14 2020, 6:49 AM
This revision was landed with ongoing or failed builds.Sep 16 2020, 1:00 AM
This revision was automatically updated to reflect the committed changes.