Rafael EspĂndola
2006-Oct-06 13:08 UTC
[LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
In ARM the stack should be 8 bytes aligned during function calls. A function that has at least one function call then has a stack size of 8 bytes. PEI::calculateFrameObjectOffsets corretly computes this correctly. The problem is that the alignment is computed before adding space for the call frame size. This is done in emitProlog. Currently the ARM backend has a bug in that it doesn't align the new stack. Fixing this bug is simple, but it introduces an inefficiency due to aligning twice. For example, consider f: ------------------------------------------------- void g(int a, int b, int c, int d, int e); void f(void) { g(1,2,3,4,5); } -------------------------------------------------- It needs only 8 bytes for the stack (4 bytes for SP and 4 for "e"). But PEI::calculateFrameObjectOffsets will align to 8 and, after adding the call frame, the stack will be aligned to 16. I see two options: 1) make PEI::calculateFrameObjectOffsets consider the call frame before aligning 2) don't align at all in PEI::calculateFrameObjectOffsets. Best Regards, Rafael
Chris Lattner
2006-Oct-06 21:41 UTC
[LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
On Fri, 6 Oct 2006, [UTF-8] Rafael Esp?ndola wrote:> In ARM the stack should be 8 bytes aligned during function calls. A > function that has at least one function call then has a stack size of > 8 bytes. PEI::calculateFrameObjectOffsets corretly computes this > correctly. > > The problem is that the alignment is computed before adding space for > the call frame size. This is done in emitProlog. Currently the ARM > backend has a bug in that it doesn't align the new stack.This sounds like the ADJCALLSTACK DOWN/UP 'instructions' around the call aren't set right, or you have declared a SP offset. It doesn't look like the ARM backend does this, so this is probably the problem. If the PEI stuff knows the right offsets, it should do the alignment for you. -Chris -- http://nondot.org/sabre/ http://llvm.org/
Rafael EspĂndola
2006-Oct-07 12:26 UTC
[LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
> This sounds like the ADJCALLSTACK DOWN/UP 'instructions' around the call > aren't set right, or you have declared a SP offset. It doesn't look like > the ARM backend does this, so this is probably the problem.The ARM backend currently doesn't use a frame pointer. It uses the same technique of the PPC backend to avoid add/subs around calls. In the PPC backend we have: ---------------------------------------------------------------------- if (MFI->hasCalls()) { NumBytes += MFI->getMaxCallFrameSize(); } if ((NumBytes == 0) || (NumBytes <= 224 && !HasFP && !MFI->hasCalls() && MaxAlign <= TargetAlign)) { MFI->setStackSize(0); return; } unsigned Align = std::max(TargetAlign, MaxAlign); unsigned GPRSize = 4; unsigned Size = HasFP ? GPRSize + GPRSize : GPRSize; NumBytes = (NumBytes+Size+Align-1)/Align*Align; ----------------------------------------------------------------------------------- Numbytes was correctly aligned before adding getMaxCallFrameSize, but it must be aligned again afterwards.> If the PEI stuff knows the right offsets, it should do the alignment for > you.It does. The problem is that, when a second alignment must be made, some stack may be wasted.> -ChrisThanks, Rafael
Apparently Analagous Threads
- [LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
- [LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
- [LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
- [LLVMdev] should PEI::calculateFrameObjectOffsets align the stack?
- asan for allocas on powerpc64