#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 int IMM_LOW = -32768;
+static const int IMM_HIGH = 32767;
+static const int 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)
{
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:
//insert the new
MachineInstr* nMI=BuildMI(Alpha::LDAH, 2, Alpha::R28)
.addImm(getUpper16(Offset)).addReg(FP ? Alpha::R15 : Alpha::R30);
- MBB.insert(--II, nMI);
+ MBB.insert(II, nMI);
} else {
MI.SetMachineOperandConst(i, MachineOperand::MO_SignExtendedImmed, Offset);
}
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
// brackets around call sites.
//If there is a frame pointer, then we don't do this
NumBytes += MFI->getMaxCallFrameSize();
- std::cerr << "Added " << MFI->getMaxCallFrameSize() << " to the stack due to calls\n";
+ DEBUG(std::cerr << "Added " << MFI->getMaxCallFrameSize()
+ << " to the stack due to calls\n");
}
if (FP)
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";
bool FP = hasFP(MF);
// Get the number of bytes allocated from the FrameInfo...
- unsigned NumBytes = MFI->getStackSize();
+ long NumBytes = MFI->getStackSize();
//now if we need to, restore the old FP
if (FP)
{
+ //copy the FP into the SP (discards allocas)
+ MI=BuildMI(Alpha::BIS, 2, Alpha::R30).addReg(Alpha::R15).addReg(Alpha::R15);
+ MBB.insert(MBBI, MI);
+ //restore the FP
MI=BuildMI(Alpha::LDQ, 2, Alpha::R15).addImm(0).addReg(Alpha::R15);
MBB.insert(MBBI, MI);
}
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);