Skip to content

Commit 743d7c8

Browse files
author
Jim Grosbach
committed
Update local stack block allocation to let PEI do the allocs if no additional
base registers were required. This will allow for slightly better packing of the locals when alignment padding is necessary after callee saved registers. llvm-svn: 111508
1 parent 6bcb07a commit 743d7c8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

llvm/include/llvm/CodeGen/MachineFrameInfo.h

+16
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ class MachineFrameInfo {
216216
/// alignment of any object in it.
217217
unsigned LocalFrameMaxAlign;
218218

219+
/// Whether the local object blob needs to be allocated together. If not,
220+
/// PEI should ignore the isPreAllocated flags on the stack objects and
221+
/// just allocate them normally.
222+
bool UseLocalStackAllocationBlock;
223+
219224
public:
220225
explicit MachineFrameInfo(const TargetFrameInfo &tfi) : TFI(tfi) {
221226
StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
@@ -315,6 +320,17 @@ class MachineFrameInfo {
315320
/// object blob.
316321
unsigned getLocalFrameMaxAlign() { return LocalFrameMaxAlign; }
317322

323+
/// getUseLocalStackAllocationBlock - Get whether the local allocation blob
324+
/// should be allocated together or let PEI allocate the locals in it
325+
/// directly.
326+
bool getUseLocalStackAllocationBlock() {return UseLocalStackAllocationBlock;}
327+
328+
/// setUseLocalStackAllocationBlock - Set whether the local allocation blob
329+
/// should be allocated together or let PEI allocate the locals in it
330+
/// directly.
331+
void setUseLocalStackAllocationBlock(bool v) {
332+
UseLocalStackAllocationBlock = v;
333+
}
318334

319335
/// isObjectPreAllocated - Return true if the object was pre-allocated into
320336
/// the local block.

llvm/lib/CodeGen/LocalStackSlotAllocation.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) {
8989
// Insert virtual base registers to resolve frame index references.
9090
insertFrameReferenceRegisters(MF);
9191

92+
// Tell MFI whether any base registers were allocated. PEI will only
93+
// want to use the local block allocations from this pass if there were any.
94+
// Otherwise, PEI can do a bit better job of getting the alignment right
95+
// without a hole at the start since it knows the alignment of the stack
96+
// at the start of local allocation, and this pass doesn't.
97+
MFI->setUseLocalStackAllocationBlock(NumBaseRegisters > 0);
98+
9299
return true;
93100
}
94101

llvm/lib/CodeGen/PrologEpilogInserter.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
560560
// check for whether the frame is large enough to want to use virtual
561561
// frame index registers. Functions which don't want/need this optimization
562562
// will continue to use the existing code path.
563-
if (EnableLocalStackAlloc && MFI->getLocalFrameSize()) {
563+
if (EnableLocalStackAlloc && MFI->getUseLocalStackAllocationBlock()) {
564564
unsigned Align = MFI->getLocalFrameMaxAlign();
565565

566566
// Adjust to alignment boundary.
@@ -593,7 +593,8 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
593593

594594
// Assign large stack objects first.
595595
for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
596-
if (MFI->isObjectPreAllocated(i))
596+
if (MFI->isObjectPreAllocated(i) &&
597+
MFI->getUseLocalStackAllocationBlock())
597598
continue;
598599
if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
599600
continue;
@@ -614,7 +615,8 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
614615
// Then assign frame offsets to stack objects that are not used to spill
615616
// callee saved registers.
616617
for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
617-
if (MFI->isObjectPreAllocated(i))
618+
if (MFI->isObjectPreAllocated(i) &&
619+
MFI->getUseLocalStackAllocationBlock())
618620
continue;
619621
if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
620622
continue;

0 commit comments

Comments
 (0)