diff options
author | Jim Grosbach <grosbach@apple.com> | 2010-08-18 22:44:49 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2010-08-18 22:44:49 +0000 |
commit | dbfc2ce95df950ac9a3cacfd6c74642716af59c3 (patch) | |
tree | a7d55a7d4d5dd5cbf6fae51975995a184f06095e /llvm/lib/CodeGen/LocalStackSlotAllocation.cpp | |
parent | 492c2ea31ee1da26199a67d14eb2abe3a524e366 (diff) | |
download | llvm-dbfc2ce95df950ac9a3cacfd6c74642716af59c3.zip llvm-dbfc2ce95df950ac9a3cacfd6c74642716af59c3.tar.gz llvm-dbfc2ce95df950ac9a3cacfd6c74642716af59c3.tar.bz2 |
Enable ARM base register reuse to local stack slot allocation. Whenever a new
frame index reference to an object in the local block is seen, check if
it's near enough to any previously allocaated base register to re-use.
rdar://8277890
llvm-svn: 111443
Diffstat (limited to 'llvm/lib/CodeGen/LocalStackSlotAllocation.cpp')
-rw-r--r-- | llvm/lib/CodeGen/LocalStackSlotAllocation.cpp | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp index 219b845..61d6b10 100644 --- a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp +++ b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp @@ -43,8 +43,11 @@ STATISTIC(NumReplacements, "Number of frame indices references replaced"); namespace { class LocalStackSlotPass: public MachineFunctionPass { - void calculateFrameObjectOffsets(MachineFunction &Fn); + SmallVector<int64_t,16> LocalOffsets; + void AdjustStackOffset(MachineFrameInfo *MFI, int FrameIdx, int64_t &Offset, + unsigned &MaxAlign); + void calculateFrameObjectOffsets(MachineFunction &Fn); void insertFrameReferenceRegisters(MachineFunction &Fn); public: static char ID; // Pass identification, replacement for typeid @@ -70,18 +73,29 @@ FunctionPass *llvm::createLocalStackSlotAllocationPass() { } bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) { + MachineFrameInfo *MFI = MF.getFrameInfo(); + unsigned LocalObjectCount = MFI->getObjectIndexEnd(); + + // Early exit if there are no locals to consider + if (!LocalObjectCount) + return true; + + // Make sure we have enough space to store the local offsets. + LocalOffsets.resize(MFI->getObjectIndexEnd()); + // Lay out the local blob. calculateFrameObjectOffsets(MF); // Insert virtual base registers to resolve frame index references. insertFrameReferenceRegisters(MF); + return true; } /// AdjustStackOffset - Helper function used to adjust the stack frame offset. -static inline void -AdjustStackOffset(MachineFrameInfo *MFI, int FrameIdx, int64_t &Offset, - unsigned &MaxAlign) { +void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo *MFI, + int FrameIdx, int64_t &Offset, + unsigned &MaxAlign) { unsigned Align = MFI->getObjectAlignment(FrameIdx); // If the alignment of this object is greater than that of the stack, then @@ -93,6 +107,9 @@ AdjustStackOffset(MachineFrameInfo *MFI, int FrameIdx, int64_t &Offset, DEBUG(dbgs() << "Allocate FI(" << FrameIdx << ") to local offset " << Offset << "\n"); + // Keep the offset available for base register allocation + LocalOffsets[FrameIdx] = Offset; + // And tell MFI about it for PEI to use later MFI->mapLocalFrameObject(FrameIdx, Offset); Offset += MFI->getObjectSize(FrameIdx); @@ -149,12 +166,16 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) { static inline bool lookupCandidateBaseReg(const SmallVector<std::pair<unsigned, int64_t>, 8> &Regs, std::pair<unsigned, int64_t> &RegOffset, + int64_t LocalFrameOffset, const MachineInstr *MI, const TargetRegisterInfo *TRI) { unsigned e = Regs.size(); for (unsigned i = 0; i < e; ++i) { RegOffset = Regs[i]; - if (TRI->isBaseRegInRange(MI, RegOffset.first, RegOffset.second)) + // Check if the relative offset from the where the base register references + // to the target address is in range for the instruction. + int64_t Offset = LocalFrameOffset - RegOffset.second; + if (TRI->isBaseRegInRange(MI, RegOffset.first, Offset)) return true; } return false; @@ -173,6 +194,9 @@ void LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) { for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) { + // A base register definition is a register+offset pair. + SmallVector<std::pair<unsigned, int64_t>, 8> BaseRegisters; + for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { MachineInstr *MI = I; // Debug value instructions can't be out of range, so they don't need @@ -183,9 +207,6 @@ void LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) { if (MI->isDebugValue()) continue; - // A base register definition is a register+offset pair. - SmallVector<std::pair<unsigned, int64_t>, 8> BaseRegisters; - // For now, allocate the base register(s) within the basic block // where they're used, and don't try to keep them around outside // of that. It may be beneficial to try sharing them more broadly @@ -212,10 +233,12 @@ void LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) { // create a new one. std::pair<unsigned, int64_t> RegOffset; - if (lookupCandidateBaseReg(BaseRegisters, RegOffset, MI, TRI)) { + if (lookupCandidateBaseReg(BaseRegisters, RegOffset, + LocalOffsets[FrameIdx], MI, TRI)) { + DEBUG(dbgs() << " Reusing base register " << RegOffset.first); // We found a register to reuse. BaseReg = RegOffset.first; - Offset = RegOffset.second; + Offset = LocalOffsets[FrameIdx] - RegOffset.second; } else { // No previously defined register was in range, so create a // new one. |