Karel Gardas
2011-Oct-14 14:55 UTC
[LLVMdev] Request for merge: GHC/ARM calling convention.
Hi Duncan, On 10/14/11 03:56 PM, Duncan Sands wrote:> Hi Karel, > >> > const unsigned* >> > ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) >> const { >> > + bool ghcCall = false; >> > + >> > + if (MF) { >> > + const Function *F = MF->getFunction(); >> > + ghcCall = (F ? F->getCallingConv() == CallingConv::GHC : false); >> > + } >> >> > This bit looks dubious. Why do you need to do it? >> >> What exactly? We need to test if this is GHC calling convention or not >> and if >> its, then return different set of callee saved regs. What exactly >> don't you like >> on this piece? > > I don't see anyone else rummaging around inside the original function > for the > calling convention, so why do you need to?Based on knowledge of calling convention we return different set of callee saved registers. For example on ARM and when GHC CC is used, we return empty set.> If this information is useful to > have, why isn't it in the machine function?Honestly speaking, I don't know. The code in question is not written by me, but IMHO the motivation was just to get job done and allow later someone with better knowledge of LLVM internals to do required refactoring -- if you are pointing on the fact why we have not refactored calling convention call from Function to MachineFuction yet. Thanks, Karel
Duncan Sands
2011-Oct-14 15:22 UTC
[LLVMdev] Request for merge: GHC/ARM calling convention.
Hi Karel,>>> > const unsigned* >>> > ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) >>> const { >>> > + bool ghcCall = false; >>> > + >>> > + if (MF) { >>> > + const Function *F = MF->getFunction(); >>> > + ghcCall = (F ? F->getCallingConv() == CallingConv::GHC : false); >>> > + } >>> >>> > This bit looks dubious. Why do you need to do it? >>> >>> What exactly? We need to test if this is GHC calling convention or not >>> and if >>> its, then return different set of callee saved regs. What exactly >>> don't you like >>> on this piece? >> >> I don't see anyone else rummaging around inside the original function >> for the >> calling convention, so why do you need to? > > Based on knowledge of calling convention we return different set of callee saved > registers. For example on ARM and when GHC CC is used, we return empty set.yeah, but here MF is (presumably) the callee. The callee shouldn't be relevant to how arguments are marshalled at the call-site. Especially as there might not even be a callee function (case of an indirect call). Since calls themselves are annotated with the calling convention to use, I guess the calling convention should be grabbed from the call instruction itself somehow.> >> If this information is useful to >> have, why isn't it in the machine function? > > Honestly speaking, I don't know. The code in question is not written by me, but > IMHO the motivation was just to get job done and allow later someone with better > knowledge of LLVM internals to do required refactoring -- if you are pointing on > the fact why we have not refactored calling convention call from Function to > MachineFuction yet.If it's because MF is represents the callee then it hasn't been done because using it would almost certainly be wrong I guess :( Ciao, Duncan.
David Terei
2011-Oct-14 20:27 UTC
[LLVMdev] Request for merge: GHC/ARM calling convention.
Hi Duncan, Karel, On 14 October 2011 08:22, Duncan Sands <baldrick at free.fr> wrote:> Hi Karel, > >>>> > const unsigned* >>>> > ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) >>>> const { >>>> > + bool ghcCall = false; >>>> > + >>>> > + if (MF) { >>>> > + const Function *F = MF->getFunction(); >>>> > + ghcCall = (F ? F->getCallingConv() == CallingConv::GHC : false); >>>> > + } >>>> >>>> > This bit looks dubious. Why do you need to do it? >>>> >>>> What exactly? We need to test if this is GHC calling convention or not >>>> and if >>>> its, then return different set of callee saved regs. What exactly >>>> don't you like >>>> on this piece? >>> >>> I don't see anyone else rummaging around inside the original function >>> for the >>> calling convention, so why do you need to?So I wrote the first version of the GHC calling convention for X86, and also basically the code in question above as its copied from the X86 implementation. I had a look over the code and will try to explain what I believe is going on but I may be mistaken as this is code I haven't looked at for over a year. The code above is needed as the GHC calling convention redefines what registers are considered callee save. No one else rummages in to the original function as all the other calling conventions use the same set of callee and caller save registers, so GHC is the only one that needs to differentiate.>> Based on knowledge of calling convention we return different set of callee saved >> registers. For example on ARM and when GHC CC is used, we return empty set. > > yeah, but here MF is (presumably) the callee. The callee shouldn't be relevant > to how arguments are marshalled at the call-site. Especially as there might not > even be a callee function (case of an indirect call). Since calls themselves > are annotated with the calling convention to use, I guess the calling convention > should be grabbed from the call instruction itself somehow.This isn't about the call-site. My understanding is that when the prologue / epilogue code for a function (MF) is being generated this 'getCalleeSavedRegs' function is consulted to determine what to push and pop. So yes MF is callee but I don't think this function is affecting the call site marshaling. One thing to note is that the GHC calling convention is intended to be used as in a tail call optimization fashion (the code GHC generates with LLVM never returns, its CPS code) so maybe this is complicating matters a little. We don't really have 'call sites' using the GHC call convention since they're all tail calls that are jumps and will never return. Cheers, David
Jakob Stoklund Olesen
2011-Oct-14 21:08 UTC
[LLVMdev] Request for merge: GHC/ARM calling convention.
On Oct 14, 2011, at 8:22 AM, Duncan Sands wrote:> Hi Karel, > >>>>> const unsigned* >>>>> ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) >>>> const { >>>>> + bool ghcCall = false; >>>>> + >>>>> + if (MF) { >>>>> + const Function *F = MF->getFunction(); >>>>> + ghcCall = (F ? F->getCallingConv() == CallingConv::GHC : false); >>>>> + }> yeah, but here MF is (presumably) the callee. The callee shouldn't be relevant > to how arguments are marshalled at the call-site. Especially as there might not > even be a callee function (case of an indirect call). Since calls themselves > are annotated with the calling convention to use, I guess the calling convention > should be grabbed from the call instruction itself somehow.TargetRegisterInfo::getCalleeSavedRegs() is called with a pointer to the machine function currently being compiled. It is used by PEI to determine the registers to spill in the prolog, and it is used by RegisterClassInfo to rearrange allocation orders so the register allocator will use volatile registers before callee-saved registers. Its behavior depends on the calling convention of the function being compiled. It is not related to call instructions in the function. /jakob
Apparently Analagous Threads
- [LLVMdev] Request for merge: GHC/ARM calling convention.
- [LLVMdev] Request for merge: GHC/ARM calling convention.
- [LLVMdev] Request for merge: GHC/ARM calling convention.
- [LLVMdev] Request for merge: GHC/ARM calling convention.
- [LLVMdev] Request for merge: GHC/ARM calling convention.