2010-02-23 19:15:24 +00:00
|
|
|
//===- MBlazeRegisterInfo.cpp - MBlaze Register Information -== -*- C++ -*-===//
|
2011-01-10 12:39:04 +00:00
|
|
|
//
|
2010-02-23 19:15:24 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the MBlaze implementation of the TargetRegisterInfo
|
|
|
|
// class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-12-29 19:46:28 +00:00
|
|
|
#define DEBUG_TYPE "mblaze-frame-info"
|
2010-02-23 19:15:24 +00:00
|
|
|
|
|
|
|
#include "MBlaze.h"
|
|
|
|
#include "MBlazeSubtarget.h"
|
|
|
|
#include "MBlazeRegisterInfo.h"
|
|
|
|
#include "MBlazeMachineFunction.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/Type.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2010-02-23 19:15:24 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/ADT/BitVector.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2011-06-27 18:32:37 +00:00
|
|
|
|
|
|
|
#define GET_REGINFO_TARGET_DESC
|
2011-06-24 01:44:41 +00:00
|
|
|
#include "MBlazeGenRegisterInfo.inc"
|
2011-06-27 18:32:37 +00:00
|
|
|
|
2010-02-23 19:15:24 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
MBlazeRegisterInfo::
|
|
|
|
MBlazeRegisterInfo(const MBlazeSubtarget &ST, const TargetInstrInfo &tii)
|
2011-07-18 20:57:22 +00:00
|
|
|
: MBlazeGenRegisterInfo(MBlaze::R15), Subtarget(ST), TII(tii) {}
|
2010-02-23 19:15:24 +00:00
|
|
|
|
|
|
|
unsigned MBlazeRegisterInfo::getPICCallReg() {
|
|
|
|
return MBlaze::R20;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Callee Saved Registers methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// MBlaze Callee Saved Registers
|
|
|
|
const unsigned* MBlazeRegisterInfo::
|
|
|
|
getCalleeSavedRegs(const MachineFunction *MF) const {
|
2010-02-24 20:16:27 +00:00
|
|
|
// MBlaze callee-save register range is R20 - R31
|
2010-02-23 19:15:24 +00:00
|
|
|
static const unsigned CalleeSavedRegs[] = {
|
|
|
|
MBlaze::R20, MBlaze::R21, MBlaze::R22, MBlaze::R23,
|
|
|
|
MBlaze::R24, MBlaze::R25, MBlaze::R26, MBlaze::R27,
|
|
|
|
MBlaze::R28, MBlaze::R29, MBlaze::R30, MBlaze::R31,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
return CalleeSavedRegs;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitVector MBlazeRegisterInfo::
|
|
|
|
getReservedRegs(const MachineFunction &MF) const {
|
|
|
|
BitVector Reserved(getNumRegs());
|
|
|
|
Reserved.set(MBlaze::R0);
|
|
|
|
Reserved.set(MBlaze::R1);
|
|
|
|
Reserved.set(MBlaze::R2);
|
|
|
|
Reserved.set(MBlaze::R13);
|
|
|
|
Reserved.set(MBlaze::R14);
|
|
|
|
Reserved.set(MBlaze::R15);
|
|
|
|
Reserved.set(MBlaze::R16);
|
|
|
|
Reserved.set(MBlaze::R17);
|
|
|
|
Reserved.set(MBlaze::R18);
|
|
|
|
Reserved.set(MBlaze::R19);
|
|
|
|
return Reserved;
|
|
|
|
}
|
|
|
|
|
2010-12-09 03:42:04 +00:00
|
|
|
// This function eliminate ADJCALLSTACKDOWN/ADJCALLSTACKUP pseudo instructions
|
2010-02-23 19:15:24 +00:00
|
|
|
void MBlazeRegisterInfo::
|
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2011-01-10 12:39:04 +00:00
|
|
|
const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
|
2010-12-09 03:42:04 +00:00
|
|
|
|
|
|
|
if (!TFI->hasReservedCallFrame(MF)) {
|
|
|
|
// If we have a frame pointer, turn the adjcallstackup instruction into a
|
|
|
|
// 'addi r1, r1, -<amt>' and the adjcallstackdown instruction into
|
|
|
|
// 'addi r1, r1, <amt>'
|
|
|
|
MachineInstr *Old = I;
|
|
|
|
int Amount = Old->getOperand(0).getImm() + 4;
|
|
|
|
if (Amount != 0) {
|
|
|
|
// We need to keep the stack aligned properly. To do this, we round the
|
|
|
|
// amount of space needed for the outgoing arguments up to the next
|
|
|
|
// alignment boundary.
|
2011-01-10 12:39:04 +00:00
|
|
|
unsigned Align = TFI->getStackAlignment();
|
2010-12-09 03:42:04 +00:00
|
|
|
Amount = (Amount+Align-1)/Align*Align;
|
|
|
|
|
|
|
|
MachineInstr *New;
|
|
|
|
if (Old->getOpcode() == MBlaze::ADJCALLSTACKDOWN) {
|
2010-12-12 22:02:31 +00:00
|
|
|
New = BuildMI(MF,Old->getDebugLoc(),TII.get(MBlaze::ADDIK),MBlaze::R1)
|
2010-12-09 03:42:04 +00:00
|
|
|
.addReg(MBlaze::R1).addImm(-Amount);
|
|
|
|
} else {
|
|
|
|
assert(Old->getOpcode() == MBlaze::ADJCALLSTACKUP);
|
2010-12-12 22:02:31 +00:00
|
|
|
New = BuildMI(MF,Old->getDebugLoc(),TII.get(MBlaze::ADDIK),MBlaze::R1)
|
2010-12-09 03:42:04 +00:00
|
|
|
.addReg(MBlaze::R1).addImm(Amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace the pseudo instruction with a new instruction...
|
|
|
|
MBB.insert(I, New);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-23 19:15:24 +00:00
|
|
|
// Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
|
|
|
|
MBB.erase(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FrameIndex represent objects inside a abstract stack.
|
|
|
|
// We must replace FrameIndex with an stack/frame pointer
|
|
|
|
// direct reference.
|
2010-08-26 23:32:16 +00:00
|
|
|
void MBlazeRegisterInfo::
|
2010-02-23 19:15:24 +00:00
|
|
|
eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
|
2010-08-26 23:32:16 +00:00
|
|
|
RegScavenger *RS) const {
|
2010-02-23 19:15:24 +00:00
|
|
|
MachineInstr &MI = *II;
|
|
|
|
MachineFunction &MF = *MI.getParent()->getParent();
|
2010-12-12 20:52:31 +00:00
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2010-02-23 19:15:24 +00:00
|
|
|
|
|
|
|
unsigned i = 0;
|
|
|
|
while (!MI.getOperand(i).isFI()) {
|
|
|
|
++i;
|
|
|
|
assert(i < MI.getNumOperands() &&
|
|
|
|
"Instr doesn't have FrameIndex operand!");
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned oi = i == 2 ? 1 : 2;
|
|
|
|
|
2010-12-29 19:46:28 +00:00
|
|
|
DEBUG(dbgs() << "\nFunction : " << MF.getFunction()->getName() << "\n";
|
|
|
|
dbgs() << "<--------->\n" << MI);
|
2010-02-23 19:15:24 +00:00
|
|
|
|
|
|
|
int FrameIndex = MI.getOperand(i).getIndex();
|
2011-01-06 13:01:02 +00:00
|
|
|
int stackSize = MFI->getStackSize();
|
|
|
|
int spOffset = MFI->getObjectOffset(FrameIndex);
|
2010-02-23 19:15:24 +00:00
|
|
|
|
2011-01-06 13:01:02 +00:00
|
|
|
DEBUG(MBlazeFunctionInfo *MBlazeFI = MF.getInfo<MBlazeFunctionInfo>();
|
|
|
|
dbgs() << "FrameIndex : " << FrameIndex << "\n"
|
2010-02-23 19:15:24 +00:00
|
|
|
<< "spOffset : " << spOffset << "\n"
|
2010-12-29 19:46:28 +00:00
|
|
|
<< "stackSize : " << stackSize << "\n"
|
|
|
|
<< "isFixed : " << MFI->isFixedObjectIndex(FrameIndex) << "\n"
|
|
|
|
<< "isLiveIn : " << MBlazeFI->isLiveIn(FrameIndex) << "\n"
|
|
|
|
<< "isSpill : " << MFI->isSpillSlotObjectIndex(FrameIndex)
|
|
|
|
<< "\n" );
|
2010-02-23 19:15:24 +00:00
|
|
|
|
|
|
|
// as explained on LowerFormalArguments, detect negative offsets
|
|
|
|
// and adjust SPOffsets considering the final stack size.
|
2010-12-12 20:52:31 +00:00
|
|
|
int Offset = (spOffset < 0) ? (stackSize - spOffset) : spOffset;
|
|
|
|
Offset += MI.getOperand(oi).getImm();
|
2010-02-23 19:15:24 +00:00
|
|
|
|
2010-12-29 19:46:28 +00:00
|
|
|
DEBUG(dbgs() << "Offset : " << Offset << "\n" << "<--------->\n");
|
2010-12-12 20:52:31 +00:00
|
|
|
|
|
|
|
MI.getOperand(oi).ChangeToImmediate(Offset);
|
2010-02-23 19:15:24 +00:00
|
|
|
MI.getOperand(i).ChangeToRegister(getFrameRegister(MF), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MBlazeRegisterInfo::
|
|
|
|
processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
|
|
|
|
// Set the stack offset where GP must be saved/loaded from.
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
MBlazeFunctionInfo *MBlazeFI = MF.getInfo<MBlazeFunctionInfo>();
|
|
|
|
if (MBlazeFI->needGPSaveRestore())
|
|
|
|
MFI->setObjectOffset(MBlazeFI->getGPFI(), MBlazeFI->getGPStackOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MBlazeRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
|
2011-01-10 12:39:04 +00:00
|
|
|
const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
|
2010-11-18 21:19:35 +00:00
|
|
|
|
|
|
|
return TFI->hasFP(MF) ? MBlaze::R19 : MBlaze::R1;
|
2010-02-23 19:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MBlazeRegisterInfo::getEHExceptionRegister() const {
|
|
|
|
llvm_unreachable("What is the exception register");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MBlazeRegisterInfo::getEHHandlerRegister() const {
|
|
|
|
llvm_unreachable("What is the exception handler register");
|
|
|
|
return 0;
|
|
|
|
}
|