2006-05-14 22:18:28 +00:00
|
|
|
//===- ARMRegisterInfo.cpp - ARM Register Information -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the "Instituto Nokia de Tecnologia" and
|
|
|
|
// is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the ARM implementation of the MRegisterInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineLocation.h"
|
|
|
|
#include "llvm/Type.h"
|
2006-10-31 13:03:26 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2006-10-26 13:31:26 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2006-11-27 23:37:22 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-05-14 22:18:28 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include <iostream>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2006-10-26 13:31:26 +00:00
|
|
|
// hasFP - Return true if the specified function should have a dedicated frame
|
|
|
|
// pointer register. This is true if the function has variable sized allocas or
|
|
|
|
// if frame pointer elimination is disabled.
|
|
|
|
//
|
|
|
|
static bool hasFP(const MachineFunction &MF) {
|
|
|
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
return NoFramePointerElim || MFI->hasVarSizedObjects();
|
|
|
|
}
|
|
|
|
|
2006-11-27 23:37:22 +00:00
|
|
|
ARMRegisterInfo::ARMRegisterInfo(const TargetInstrInfo &tii)
|
|
|
|
: ARMGenRegisterInfo(ARM::ADJCALLSTACKDOWN, ARM::ADJCALLSTACKUP),
|
|
|
|
TII(tii) {
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMRegisterInfo::
|
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
|
|
|
assert (RC == ARM::IntRegsRegisterClass);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::STR)).addReg(SrcReg).addFrameIndex(FI).addImm(0);
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMRegisterInfo::
|
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
|
|
|
assert (RC == ARM::IntRegsRegisterClass);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::LDR), DestReg).addFrameIndex(FI).addImm(0);
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMRegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2006-10-17 13:13:23 +00:00
|
|
|
assert(RC == ARM::IntRegsRegisterClass ||
|
|
|
|
RC == ARM::FPRegsRegisterClass ||
|
|
|
|
RC == ARM::DFPRegsRegisterClass);
|
|
|
|
|
|
|
|
if (RC == ARM::IntRegsRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::MOV), DestReg).addReg(SrcReg).addImm(0)
|
2006-10-17 13:13:23 +00:00
|
|
|
.addImm(ARMShift::LSL);
|
|
|
|
else if (RC == ARM::FPRegsRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::FCPYS), DestReg).addReg(SrcReg);
|
2006-10-17 13:13:23 +00:00
|
|
|
else
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::FCPYD), DestReg).addReg(SrcReg);
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstr *ARMRegisterInfo::foldMemoryOperand(MachineInstr* MI,
|
|
|
|
unsigned OpNum,
|
|
|
|
int FI) const {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-18 00:12:58 +00:00
|
|
|
const unsigned* ARMRegisterInfo::getCalleeSaveRegs() const {
|
2006-08-16 14:43:33 +00:00
|
|
|
static const unsigned CalleeSaveRegs[] = {
|
|
|
|
ARM::R4, ARM::R5, ARM::R6, ARM::R7,
|
|
|
|
ARM::R8, ARM::R9, ARM::R10, ARM::R11,
|
|
|
|
ARM::R14, 0
|
|
|
|
};
|
2006-05-18 00:12:58 +00:00
|
|
|
return CalleeSaveRegs;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TargetRegisterClass* const *
|
|
|
|
ARMRegisterInfo::getCalleeSaveRegClasses() const {
|
2006-08-16 14:43:33 +00:00
|
|
|
static const TargetRegisterClass * const CalleeSaveRegClasses[] = {
|
|
|
|
&ARM::IntRegsRegClass, &ARM::IntRegsRegClass, &ARM::IntRegsRegClass, &ARM::IntRegsRegClass,
|
|
|
|
&ARM::IntRegsRegClass, &ARM::IntRegsRegClass, &ARM::IntRegsRegClass, &ARM::IntRegsRegClass,
|
|
|
|
&ARM::IntRegsRegClass, 0
|
|
|
|
};
|
2006-05-18 00:12:58 +00:00
|
|
|
return CalleeSaveRegClasses;
|
|
|
|
}
|
|
|
|
|
2006-05-14 22:18:28 +00:00
|
|
|
void ARMRegisterInfo::
|
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2006-10-26 13:31:26 +00:00
|
|
|
if (hasFP(MF)) {
|
2006-10-31 13:03:26 +00:00
|
|
|
MachineInstr *Old = I;
|
|
|
|
unsigned Amount = Old->getOperand(0).getImmedValue();
|
|
|
|
if (Amount != 0) {
|
|
|
|
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
|
|
|
|
Amount = (Amount+Align-1)/Align*Align;
|
|
|
|
|
|
|
|
if (Old->getOpcode() == ARM::ADJCALLSTACKDOWN) {
|
|
|
|
// sub sp, sp, amount
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::SUB), ARM::R13).addReg(ARM::R13).addImm(Amount)
|
2006-10-31 13:03:26 +00:00
|
|
|
.addImm(0).addImm(ARMShift::LSL);
|
|
|
|
} else {
|
|
|
|
// add sp, sp, amount
|
|
|
|
assert(Old->getOpcode() == ARM::ADJCALLSTACKUP);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, TII.get(ARM::ADD), ARM::R13).addReg(ARM::R13).addImm(Amount)
|
2006-10-31 13:03:26 +00:00
|
|
|
.addImm(0).addImm(ARMShift::LSL);
|
|
|
|
}
|
|
|
|
}
|
2006-10-26 13:31:26 +00:00
|
|
|
}
|
2006-05-14 22:18:28 +00:00
|
|
|
MBB.erase(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ARMRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
|
2006-06-18 00:08:07 +00:00
|
|
|
MachineInstr &MI = *II;
|
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
|
2006-11-08 17:07:32 +00:00
|
|
|
assert (MI.getOpcode() == ARM::LDR ||
|
2006-11-09 13:58:55 +00:00
|
|
|
MI.getOpcode() == ARM::STR ||
|
|
|
|
MI.getOpcode() == ARM::ADD);
|
2006-06-18 00:08:07 +00:00
|
|
|
|
2006-11-09 13:58:55 +00:00
|
|
|
unsigned FrameIdx = 1;
|
|
|
|
unsigned OffIdx = 2;
|
2006-06-18 00:08:07 +00:00
|
|
|
|
|
|
|
int FrameIndex = MI.getOperand(FrameIdx).getFrameIndex();
|
|
|
|
|
2006-10-17 14:34:02 +00:00
|
|
|
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
|
|
|
|
MI.getOperand(OffIdx).getImmedValue();
|
2006-06-18 00:08:07 +00:00
|
|
|
|
|
|
|
unsigned StackSize = MF.getFrameInfo()->getStackSize();
|
|
|
|
|
|
|
|
Offset += StackSize;
|
|
|
|
|
2006-07-11 11:36:48 +00:00
|
|
|
assert (Offset >= 0);
|
2006-10-26 13:31:26 +00:00
|
|
|
unsigned BaseRegister = hasFP(MF) ? ARM::R11 : ARM::R13;
|
2006-07-11 11:36:48 +00:00
|
|
|
if (Offset < 4096) {
|
|
|
|
// Replace the FrameIndex with r13
|
2006-10-26 13:31:26 +00:00
|
|
|
MI.getOperand(FrameIdx).ChangeToRegister(BaseRegister, false);
|
2006-07-11 11:36:48 +00:00
|
|
|
// Replace the ldr offset with Offset
|
|
|
|
MI.getOperand(OffIdx).ChangeToImmediate(Offset);
|
|
|
|
} else {
|
|
|
|
// Insert a set of r12 with the full address
|
|
|
|
// r12 = r13 + offset
|
|
|
|
MachineBasicBlock *MBB2 = MI.getParent();
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(*MBB2, II, TII.get(ARM::ADD), ARM::R12).addReg(BaseRegister)
|
2006-10-26 13:31:26 +00:00
|
|
|
.addImm(Offset).addImm(0).addImm(ARMShift::LSL);
|
2006-07-11 11:36:48 +00:00
|
|
|
|
|
|
|
// Replace the FrameIndex with r12
|
2006-09-05 02:31:13 +00:00
|
|
|
MI.getOperand(FrameIdx).ChangeToRegister(ARM::R12, false);
|
2006-07-11 11:36:48 +00:00
|
|
|
}
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMRegisterInfo::
|
|
|
|
processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
|
|
|
|
|
|
|
|
void ARMRegisterInfo::emitPrologue(MachineFunction &MF) const {
|
2006-07-18 17:00:30 +00:00
|
|
|
MachineBasicBlock &MBB = MF.front();
|
2006-07-21 12:26:16 +00:00
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
2006-07-18 17:00:30 +00:00
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
int NumBytes = (int) MFI->getStackSize();
|
|
|
|
|
2006-10-26 13:31:26 +00:00
|
|
|
bool HasFP = hasFP(MF);
|
|
|
|
|
2006-08-08 13:02:29 +00:00
|
|
|
if (MFI->hasCalls()) {
|
|
|
|
// We reserve argument space for call sites in the function immediately on
|
|
|
|
// entry to the current function. This eliminates the need for add/sub
|
|
|
|
// brackets around call sites.
|
|
|
|
NumBytes += MFI->getMaxCallFrameSize();
|
|
|
|
}
|
|
|
|
|
2006-10-26 13:31:26 +00:00
|
|
|
if (HasFP)
|
|
|
|
// Add space for storing the FP
|
|
|
|
NumBytes += 4;
|
|
|
|
|
2006-10-06 14:29:47 +00:00
|
|
|
// Align to 8 bytes
|
|
|
|
NumBytes = ((NumBytes + 7) / 8) * 8;
|
|
|
|
|
2006-08-08 13:02:29 +00:00
|
|
|
MFI->setStackSize(NumBytes);
|
|
|
|
|
|
|
|
//sub sp, sp, #NumBytes
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(ARM::SUB), ARM::R13).addReg(ARM::R13).addImm(NumBytes)
|
2006-09-13 12:09:43 +00:00
|
|
|
.addImm(0).addImm(ARMShift::LSL);
|
2006-10-26 13:31:26 +00:00
|
|
|
|
|
|
|
if (HasFP) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(ARM::STR))
|
2006-11-08 17:07:32 +00:00
|
|
|
.addReg(ARM::R11).addReg(ARM::R13).addImm(0);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(ARM::MOV), ARM::R11).addReg(ARM::R13).addImm(0).
|
2006-10-26 13:31:26 +00:00
|
|
|
addImm(ARMShift::LSL);
|
|
|
|
}
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMRegisterInfo::emitEpilogue(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB) const {
|
2006-07-18 17:00:30 +00:00
|
|
|
MachineBasicBlock::iterator MBBI = prior(MBB.end());
|
|
|
|
assert(MBBI->getOpcode() == ARM::bx &&
|
|
|
|
"Can only insert epilog into returning blocks");
|
|
|
|
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
int NumBytes = (int) MFI->getStackSize();
|
|
|
|
|
2006-10-26 13:31:26 +00:00
|
|
|
if (hasFP(MF)) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(ARM::MOV), ARM::R13).addReg(ARM::R11).addImm(0).
|
2006-10-26 13:31:26 +00:00
|
|
|
addImm(ARMShift::LSL);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(ARM::LDR), ARM::R11).addReg(ARM::R13).addImm(0);
|
2006-10-26 13:31:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-08 13:02:29 +00:00
|
|
|
//add sp, sp, #NumBytes
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(ARM::ADD), ARM::R13).addReg(ARM::R13).addImm(NumBytes)
|
2006-09-13 12:09:43 +00:00
|
|
|
.addImm(0).addImm(ARMShift::LSL);
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMRegisterInfo::getRARegister() const {
|
|
|
|
return ARM::R14;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMRegisterInfo::getFrameRegister(MachineFunction &MF) const {
|
2006-10-26 13:31:26 +00:00
|
|
|
return hasFP(MF) ? ARM::R11 : ARM::R13;
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "ARMGenRegisterInfo.inc"
|
|
|
|
|