Daniil Troshkov
2014-Jul-17 13:15 UTC
[LLVMdev] [llvm]/lib/CodeGen/PrologEpilogInserter.cpp RestoreCSRegs before epilogue, why?
Hello all!
Does anybody know why "lib/CodeGen/PrologEpilogInserter.cpp" has code:
---------------------------
// Add the code to save and restore the callee saved registers
if (!F->hasFnAttribute(Attribute::Naked))
insertCSRSpillsAndRestores(Fn);
.....
if (!F->hasFnAttribute(Attribute::Naked))
insertPrologEpilogCode(Fn);
-----------------------------
and than we use 'hacks' like this(example for MSP430(emitEpilogue,
MSP430FrameLowering.cpp) but other archs has the same code):
----------------------------
// Skip the callee-saved pop instructions.
while (MBBI != MBB.begin()) {
MachineBasicBlock::iterator PI = prior(MBBI);
unsigned Opc = PI->getOpcode();
if (Opc != MSP430::POP16r && !PI->isTerminator())
break;
--MBBI;
}
-----------------------------
Why we don't use directly:
insertCSRSpiil
insertProlog
insertEpilog
InsertCSRRestore
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20140717/d0e2b1a2/attachment.html>
Anton Korobeynikov
2014-Jul-18 11:56 UTC
[LLVMdev] [llvm]/lib/CodeGen/PrologEpilogInserter.cpp RestoreCSRegs before epilogue, why?
> Why we don't use directly: > insertCSRSpiil > insertProlog > insertEpilog > InsertCSRRestoreBecause the world is not that simple. In particular, if you will real MSP430FrameLowering::emitEpilogue function, you will see that it needs to insert stuff both *before* and *after* the callee-saved spill / restore code. In particular, we need to start to set up frame just at the start of the function, then integrate the callee-saved spill code as a normal frame setup and continue afterwards. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University