aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/LocalStackSlotAllocation.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2010-08-20 20:25:31 +0000
committerJim Grosbach <grosbach@apple.com>2010-08-20 20:25:31 +0000
commit4c207c2ddb3bda2488044b7eac2a5c1051c36bd2 (patch)
tree87cfdc1138c8e8b841123e4e66ef6d1203838979 /lib/CodeGen/LocalStackSlotAllocation.cpp
parentab6bdec837ebd858b5630fe76444afd46f2591e4 (diff)
Downwards growing stack allocation order reverses relative offsets
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111673 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LocalStackSlotAllocation.cpp')
-rw-r--r--lib/CodeGen/LocalStackSlotAllocation.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/CodeGen/LocalStackSlotAllocation.cpp b/lib/CodeGen/LocalStackSlotAllocation.cpp
index f5b79059d0..7e1e287367 100644
--- a/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ b/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -174,6 +174,7 @@ static inline bool
lookupCandidateBaseReg(const SmallVector<std::pair<unsigned, int64_t>, 8> &Regs,
std::pair<unsigned, int64_t> &RegOffset,
int64_t LocalFrameOffset,
+ bool StackGrowsDown,
const MachineInstr *MI,
const TargetRegisterInfo *TRI) {
unsigned e = Regs.size();
@@ -182,6 +183,8 @@ lookupCandidateBaseReg(const SmallVector<std::pair<unsigned, int64_t>, 8> &Regs,
// 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 (StackGrowsDown)
+ Offset = -Offset;
if (TRI->isFrameOffsetLegal(MI, Offset))
return true;
}
@@ -199,6 +202,9 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
MachineFrameInfo *MFI = Fn.getFrameInfo();
const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
+ const TargetFrameInfo &TFI = *Fn.getTarget().getFrameInfo();
+ bool StackGrowsDown =
+ TFI.getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
for (MachineFunction::iterator BB = Fn.begin(),
E = Fn.end(); BB != E; ++BB) {
@@ -245,12 +251,15 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
// register.
std::pair<unsigned, int64_t> RegOffset;
if (lookupCandidateBaseReg(BaseRegisters, RegOffset,
- LocalOffsets[FrameIdx], MI, TRI)) {
+ LocalOffsets[FrameIdx],
+ StackGrowsDown, MI, TRI)) {
DEBUG(dbgs() << " Reusing base register " <<
RegOffset.first << "\n");
// We found a register to reuse.
BaseReg = RegOffset.first;
Offset = LocalOffsets[FrameIdx] - RegOffset.second;
+ if (StackGrowsDown)
+ Offset = -Offset;
} else {
// No previously defined register was in range, so create a
// new one.