diff options
author | Andrew Lenharth <andrewl@lenharth.org> | 2005-03-04 21:40:02 +0000 |
---|---|---|
committer | Andrew Lenharth <andrewl@lenharth.org> | 2005-03-04 21:40:02 +0000 |
commit | f3cd1477c389a08d84e43a3b7011f05ec4b5c7e7 (patch) | |
tree | 3484d27f85a625e9ae139450f943b384259309f9 /llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp | |
parent | c01e2f76c3ee56ed244a86da29494bc2cfd96106 (diff) | |
download | bcm5719-llvm-f3cd1477c389a08d84e43a3b7011f05ec4b5c7e7.tar.gz bcm5719-llvm-f3cd1477c389a08d84e43a3b7011f05ec4b5c7e7.zip |
fix up stack pointer adjustments
llvm-svn: 20442
Diffstat (limited to 'llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp')
-rw-r--r-- | llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp b/llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp index 74281512791..2513e7aa218 100644 --- a/llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp +++ b/llvm/lib/Target/Alpha/AlphaRegisterInfo.cpp @@ -30,22 +30,25 @@ #include <iostream> using namespace llvm; -static long getLower16(long l) -{ - long y = l / 65536; - if (l % 65536 > 32767) - ++y; - return l - y * 65536; -} +//These describe LDAx +static const long IMM_LOW = 0xffffffffffff8000; +static const long IMM_HIGH = 0x0000000000007fff; +static const long IMM_MULT = 65536; static long getUpper16(long l) { - long y = l / 65536; - if (l % 65536 > 32767) + long y = l / IMM_MULT; + if (l % IMM_MULT > IMM_HIGH) ++y; return y; } +static long getLower16(long l) +{ + long h = getUpper16(l); + return l - h * IMM_MULT; +} + AlphaRegisterInfo::AlphaRegisterInfo() : AlphaGenRegisterInfo(Alpha::ADJUSTSTACKDOWN, Alpha::ADJUSTSTACKUP) { @@ -183,7 +186,7 @@ AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const { DEBUG(std::cerr << "Corrected Offset " << Offset << " for stack size: " << MF.getFrameInfo()->getStackSize() << "\n"); - if (Offset > 32767 || Offset < -32768) { + if (Offset > IMM_HIGH || Offset < IMM_LOW) { //so in this case, we need to use a temporary register, and move the original //inst off the SP/FP //fix up the old: @@ -212,7 +215,7 @@ void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const { MBB.insert(MBBI, MI); // Get the number of bytes to allocate from the FrameInfo - unsigned NumBytes = MFI->getStackSize(); + long NumBytes = MFI->getStackSize(); if (MFI->hasCalls() && !FP) { // We reserve argument space for call sites in the function immediately on @@ -234,13 +237,14 @@ void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const { MFI->setStackSize(NumBytes); // adjust stack pointer: r30 -= numbytes - if (NumBytes <= 32767) { - MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(-NumBytes).addReg(Alpha::R30); + NumBytes = -NumBytes; + if (NumBytes >= IMM_LOW) { + MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(NumBytes).addReg(Alpha::R30); MBB.insert(MBBI, MI); - } else if ((unsigned long)NumBytes <= (unsigned long)32767 * (unsigned long)65536) { - MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(getUpper16(-NumBytes)).addReg(Alpha::R30); + } else if (getUpper16(NumBytes) >= IMM_LOW) { + MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(getUpper16(NumBytes)).addReg(Alpha::R30); MBB.insert(MBBI, MI); - MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(getLower16(-NumBytes)).addReg(Alpha::R30); + MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(getLower16(NumBytes)).addReg(Alpha::R30); MBB.insert(MBBI, MI); } else { std::cerr << "Too big a stack frame at " << NumBytes << "\n"; @@ -285,10 +289,10 @@ void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF, if (NumBytes != 0) { - if (NumBytes <= 32767) { + if (NumBytes <= IMM_HIGH) { MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(NumBytes).addReg(Alpha::R30); MBB.insert(MBBI, MI); - } else if ((unsigned long)NumBytes <= (unsigned long)32767 * (unsigned long)65536) { + } else if (getUpper16(NumBytes) <= IMM_HIGH) { MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(getUpper16(NumBytes)).addReg(Alpha::R30); MBB.insert(MBBI, MI); MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(getLower16(NumBytes)).addReg(Alpha::R30); |