2012-02-18 12:03:15 +00:00
|
|
|
//===-- PPCRegisterInfo.cpp - PowerPC Register Information ----------------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-08-17 04:55:41 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-08-17 04:55:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-02-10 18:45:23 +00:00
|
|
|
// This file contains the PowerPC implementation of the TargetRegisterInfo
|
|
|
|
// class.
|
2004-08-17 04:55:41 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "reginfo"
|
2012-03-17 18:46:09 +00:00
|
|
|
#include "PPCRegisterInfo.h"
|
2005-10-14 23:51:18 +00:00
|
|
|
#include "PPC.h"
|
2005-10-14 23:45:43 +00:00
|
|
|
#include "PPCInstrBuilder.h"
|
2006-11-16 22:43:37 +00:00
|
|
|
#include "PPCMachineFunctionInfo.h"
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "PPCFrameLowering.h"
|
2006-07-11 00:48:23 +00:00
|
|
|
#include "PPCSubtarget.h"
|
2008-04-30 09:16:33 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2004-08-17 04:55:41 +00:00
|
|
|
#include "llvm/Constants.h"
|
2008-04-02 00:25:04 +00:00
|
|
|
#include "llvm/Function.h"
|
2004-08-17 04:55:41 +00:00
|
|
|
#include "llvm/Type.h"
|
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2007-01-26 21:22:28 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2004-08-17 04:55:41 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2008-03-03 22:19:16 +00:00
|
|
|
#include "llvm/CodeGen/RegisterScavenging.h"
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2006-04-17 21:48:13 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2004-08-17 04:55:41 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2005-11-06 09:00:38 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-02-19 21:49:54 +00:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2004-08-17 04:55:41 +00:00
|
|
|
#include <cstdlib>
|
2011-06-27 18:32:37 +00:00
|
|
|
|
|
|
|
#define GET_REGINFO_TARGET_DESC
|
2011-06-24 01:44:41 +00:00
|
|
|
#include "PPCGenRegisterInfo.inc"
|
2004-08-17 04:55:41 +00:00
|
|
|
|
2010-04-15 17:20:57 +00:00
|
|
|
namespace llvm {
|
2011-12-05 17:55:17 +00:00
|
|
|
cl::opt<bool> DisablePPC32RS("disable-ppc32-regscavenger",
|
2010-04-15 17:08:50 +00:00
|
|
|
cl::init(false),
|
2011-12-05 17:55:17 +00:00
|
|
|
cl::desc("Disable PPC32 register scavenger"),
|
2010-04-15 17:08:50 +00:00
|
|
|
cl::Hidden);
|
2011-12-05 17:55:17 +00:00
|
|
|
cl::opt<bool> DisablePPC64RS("disable-ppc64-regscavenger",
|
2010-04-15 17:08:50 +00:00
|
|
|
cl::init(false),
|
2011-12-05 17:55:17 +00:00
|
|
|
cl::desc("Disable PPC64 register scavenger"),
|
2010-04-15 17:08:50 +00:00
|
|
|
cl::Hidden);
|
2010-04-15 17:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2008-03-03 22:19:16 +00:00
|
|
|
// FIXME (64-bit): Should be inlined.
|
|
|
|
bool
|
|
|
|
PPCRegisterInfo::requiresRegisterScavenging(const MachineFunction &) const {
|
2011-12-05 17:55:17 +00:00
|
|
|
return ((!DisablePPC32RS && !Subtarget.isPPC64()) ||
|
|
|
|
(!DisablePPC64RS && Subtarget.isPPC64()));
|
2008-03-03 22:19:16 +00:00
|
|
|
}
|
|
|
|
|
2006-11-13 23:36:35 +00:00
|
|
|
PPCRegisterInfo::PPCRegisterInfo(const PPCSubtarget &ST,
|
|
|
|
const TargetInstrInfo &tii)
|
2011-07-18 20:57:22 +00:00
|
|
|
: PPCGenRegisterInfo(ST.isPPC64() ? PPC::LR8 : PPC::LR,
|
|
|
|
ST.isPPC64() ? 0 : 1,
|
|
|
|
ST.isPPC64() ? 0 : 1),
|
|
|
|
Subtarget(ST), TII(tii) {
|
2005-04-21 23:30:14 +00:00
|
|
|
ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX;
|
2004-08-17 04:55:41 +00:00
|
|
|
ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX;
|
|
|
|
ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX;
|
|
|
|
ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX;
|
|
|
|
ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX;
|
|
|
|
ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX;
|
|
|
|
ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX;
|
2005-10-18 00:28:58 +00:00
|
|
|
ImmToIdxMap[PPC::ADDI] = PPC::ADD4;
|
2007-09-07 22:01:02 +00:00
|
|
|
|
|
|
|
// 64-bit
|
|
|
|
ImmToIdxMap[PPC::LHA8] = PPC::LHAX8; ImmToIdxMap[PPC::LBZ8] = PPC::LBZX8;
|
|
|
|
ImmToIdxMap[PPC::LHZ8] = PPC::LHZX8; ImmToIdxMap[PPC::LWZ8] = PPC::LWZX8;
|
|
|
|
ImmToIdxMap[PPC::STB8] = PPC::STBX8; ImmToIdxMap[PPC::STH8] = PPC::STHX8;
|
|
|
|
ImmToIdxMap[PPC::STW8] = PPC::STWX8; ImmToIdxMap[PPC::STDU] = PPC::STDUX;
|
|
|
|
ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; ImmToIdxMap[PPC::STD_32] = PPC::STDX_32;
|
2004-08-17 04:55:41 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 21:39:35 +00:00
|
|
|
bool
|
|
|
|
PPCRegisterInfo::trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
|
|
|
return requiresRegisterScavenging(MF);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-06 17:43:24 +00:00
|
|
|
/// getPointerRegClass - Return the register class to use to hold pointers.
|
|
|
|
/// This is used for addressing modes.
|
2009-07-29 20:31:52 +00:00
|
|
|
const TargetRegisterClass *
|
2012-05-07 22:10:26 +00:00
|
|
|
PPCRegisterInfo::getPointerRegClass(const MachineFunction &MF, unsigned Kind)
|
|
|
|
const {
|
2009-02-06 17:43:24 +00:00
|
|
|
if (Subtarget.isPPC64())
|
|
|
|
return &PPC::G8RCRegClass;
|
2009-07-29 20:31:52 +00:00
|
|
|
return &PPC::GPRCRegClass;
|
2009-02-06 17:43:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 03:33:22 +00:00
|
|
|
const uint16_t*
|
Change instruction description to split OperandList into OutOperandList and
InOperandList. This gives one piece of important information: # of results
produced by an instruction.
An example of the change:
def ADD32rr : I<0x01, MRMDestReg, (ops GR32:$dst, GR32:$src1, GR32:$src2),
"add{l} {$src2, $dst|$dst, $src2}",
[(set GR32:$dst, (add GR32:$src1, GR32:$src2))]>;
=>
def ADD32rr : I<0x01, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
"add{l} {$src2, $dst|$dst, $src2}",
[(set GR32:$dst, (add GR32:$src1, GR32:$src2))]>;
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40033 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 01:14:50 +00:00
|
|
|
PPCRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
|
2012-03-06 16:41:49 +00:00
|
|
|
if (Subtarget.isDarwinABI())
|
|
|
|
return Subtarget.isPPC64() ? CSR_Darwin64_SaveList :
|
|
|
|
CSR_Darwin32_SaveList;
|
2009-08-15 11:54:46 +00:00
|
|
|
|
2012-03-06 16:41:49 +00:00
|
|
|
return Subtarget.isPPC64() ? CSR_SVR464_SaveList : CSR_SVR432_SaveList;
|
|
|
|
}
|
2009-08-15 11:54:46 +00:00
|
|
|
|
2012-03-06 16:41:49 +00:00
|
|
|
const unsigned*
|
|
|
|
PPCRegisterInfo::getCallPreservedMask(CallingConv::ID CC) const {
|
2009-07-03 06:47:08 +00:00
|
|
|
if (Subtarget.isDarwinABI())
|
2012-03-06 16:41:49 +00:00
|
|
|
return Subtarget.isPPC64() ? CSR_Darwin64_RegMask :
|
|
|
|
CSR_Darwin32_RegMask;
|
2009-08-15 11:54:46 +00:00
|
|
|
|
2012-03-06 16:41:49 +00:00
|
|
|
return Subtarget.isPPC64() ? CSR_SVR464_RegMask : CSR_SVR432_RegMask;
|
2006-05-18 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
|
|
|
|
BitVector Reserved(getNumRegs());
|
2011-01-10 12:39:04 +00:00
|
|
|
const PPCFrameLowering *PPCFI =
|
|
|
|
static_cast<const PPCFrameLowering*>(MF.getTarget().getFrameLowering());
|
2010-11-18 21:19:35 +00:00
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
Reserved.set(PPC::R0);
|
|
|
|
Reserved.set(PPC::R1);
|
|
|
|
Reserved.set(PPC::LR);
|
2008-03-03 22:19:16 +00:00
|
|
|
Reserved.set(PPC::LR8);
|
2008-10-29 18:26:45 +00:00
|
|
|
Reserved.set(PPC::RM);
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2009-07-03 06:45:56 +00:00
|
|
|
// The SVR4 ABI reserves r2 and r13
|
2009-07-03 06:47:08 +00:00
|
|
|
if (Subtarget.isSVR4ABI()) {
|
2009-07-03 06:45:56 +00:00
|
|
|
Reserved.set(PPC::R2); // System-reserved register
|
|
|
|
Reserved.set(PPC::R13); // Small Data Area pointer register
|
|
|
|
}
|
2010-02-12 22:00:40 +00:00
|
|
|
// Reserve R2 on Darwin to hack around the problem of save/restore of CR
|
|
|
|
// when the stack frame is too big to address directly; we need two regs.
|
|
|
|
// This is a hack.
|
|
|
|
if (Subtarget.isDarwinABI()) {
|
|
|
|
Reserved.set(PPC::R2);
|
|
|
|
}
|
2009-07-03 06:45:56 +00:00
|
|
|
|
2009-08-15 11:54:46 +00:00
|
|
|
// On PPC64, r13 is the thread pointer. Never allocate this register.
|
|
|
|
// Note that this is over conservative, as it also prevents allocation of R31
|
|
|
|
// when the FP is not needed.
|
2007-02-19 21:49:54 +00:00
|
|
|
if (Subtarget.isPPC64()) {
|
|
|
|
Reserved.set(PPC::R13);
|
|
|
|
Reserved.set(PPC::R31);
|
2008-03-03 22:19:16 +00:00
|
|
|
|
|
|
|
Reserved.set(PPC::X0);
|
|
|
|
Reserved.set(PPC::X1);
|
|
|
|
Reserved.set(PPC::X13);
|
|
|
|
Reserved.set(PPC::X31);
|
2009-08-15 11:54:46 +00:00
|
|
|
|
|
|
|
// The 64-bit SVR4 ABI reserves r2 for the TOC pointer.
|
|
|
|
if (Subtarget.isSVR4ABI()) {
|
|
|
|
Reserved.set(PPC::X2);
|
|
|
|
}
|
2011-12-07 06:34:02 +00:00
|
|
|
// Reserve X2 on Darwin to hack around the problem of save/restore of CR
|
2010-02-12 22:00:40 +00:00
|
|
|
// when the stack frame is too big to address directly; we need two regs.
|
|
|
|
// This is a hack.
|
|
|
|
if (Subtarget.isDarwinABI()) {
|
|
|
|
Reserved.set(PPC::X2);
|
|
|
|
}
|
2007-02-19 21:49:54 +00:00
|
|
|
}
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2010-12-18 19:53:14 +00:00
|
|
|
if (PPCFI->needsFP(MF))
|
2007-02-19 21:49:54 +00:00
|
|
|
Reserved.set(PPC::R31);
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
return Reserved;
|
|
|
|
}
|
|
|
|
|
2011-11-22 16:21:04 +00:00
|
|
|
unsigned
|
|
|
|
PPCRegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC,
|
|
|
|
MachineFunction &MF) const {
|
|
|
|
const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
|
|
|
|
const unsigned DefaultSafety = 1;
|
|
|
|
|
|
|
|
switch (RC->getID()) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case PPC::G8RCRegClassID:
|
|
|
|
case PPC::GPRCRegClassID: {
|
|
|
|
unsigned FP = TFI->hasFP(MF) ? 1 : 0;
|
|
|
|
return 32 - FP - DefaultSafety;
|
|
|
|
}
|
|
|
|
case PPC::F8RCRegClassID:
|
|
|
|
case PPC::F4RCRegClassID:
|
|
|
|
case PPC::VRRCRegClassID:
|
|
|
|
return 32 - DefaultSafety;
|
2011-12-05 17:54:17 +00:00
|
|
|
case PPC::CRRCRegClassID:
|
|
|
|
return 8 - DefaultSafety;
|
2011-11-22 16:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 13:57:17 +00:00
|
|
|
bool
|
|
|
|
PPCRegisterInfo::avoidWriteAfterWrite(const TargetRegisterClass *RC) const {
|
|
|
|
switch (RC->getID()) {
|
|
|
|
case PPC::G8RCRegClassID:
|
|
|
|
case PPC::GPRCRegClassID:
|
|
|
|
case PPC::F8RCRegClassID:
|
|
|
|
case PPC::F4RCRegClassID:
|
|
|
|
case PPC::VRRCRegClassID:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-17 04:55:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stack Frame Processing methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-10-16 05:39:50 +00:00
|
|
|
void PPCRegisterInfo::
|
2004-08-17 04:55:41 +00:00
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2011-12-02 22:16:29 +00:00
|
|
|
if (MF.getTarget().Options.GuaranteedTailCallOpt &&
|
|
|
|
I->getOpcode() == PPC::ADJCALLSTACKUP) {
|
2008-10-24 21:24:23 +00:00
|
|
|
// Add (actually subtract) back the amount the callee popped on return.
|
2008-04-30 09:16:33 +00:00
|
|
|
if (int CalleeAmt = I->getOperand(1).getImm()) {
|
|
|
|
bool is64Bit = Subtarget.isPPC64();
|
|
|
|
CalleeAmt *= -1;
|
|
|
|
unsigned StackReg = is64Bit ? PPC::X1 : PPC::R1;
|
|
|
|
unsigned TmpReg = is64Bit ? PPC::X0 : PPC::R0;
|
|
|
|
unsigned ADDIInstr = is64Bit ? PPC::ADDI8 : PPC::ADDI;
|
|
|
|
unsigned ADDInstr = is64Bit ? PPC::ADD8 : PPC::ADD4;
|
|
|
|
unsigned LISInstr = is64Bit ? PPC::LIS8 : PPC::LIS;
|
|
|
|
unsigned ORIInstr = is64Bit ? PPC::ORI8 : PPC::ORI;
|
2009-02-13 02:27:39 +00:00
|
|
|
MachineInstr *MI = I;
|
|
|
|
DebugLoc dl = MI->getDebugLoc();
|
2008-04-30 09:16:33 +00:00
|
|
|
|
2010-03-29 21:13:41 +00:00
|
|
|
if (isInt<16>(CalleeAmt)) {
|
2011-12-30 00:34:00 +00:00
|
|
|
BuildMI(MBB, I, dl, TII.get(ADDIInstr), StackReg)
|
|
|
|
.addReg(StackReg, RegState::Kill)
|
|
|
|
.addImm(CalleeAmt);
|
2008-04-30 09:16:33 +00:00
|
|
|
} else {
|
|
|
|
MachineBasicBlock::iterator MBBI = I;
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(LISInstr), TmpReg)
|
2008-04-30 09:16:33 +00:00
|
|
|
.addImm(CalleeAmt >> 16);
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(ORIInstr), TmpReg)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(TmpReg, RegState::Kill)
|
2008-04-30 09:16:33 +00:00
|
|
|
.addImm(CalleeAmt & 0xFFFF);
|
2011-12-30 00:34:00 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(ADDInstr), StackReg)
|
|
|
|
.addReg(StackReg, RegState::Kill)
|
2008-04-30 09:16:33 +00:00
|
|
|
.addReg(TmpReg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-16 22:43:37 +00:00
|
|
|
// Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
|
2004-08-17 04:55:41 +00:00
|
|
|
MBB.erase(I);
|
|
|
|
}
|
|
|
|
|
2008-03-03 22:19:16 +00:00
|
|
|
/// findScratchRegister - Find a 'free' PPC register. Try for a call-clobbered
|
|
|
|
/// register first and then a spilled callee-saved register if that fails.
|
|
|
|
static
|
|
|
|
unsigned findScratchRegister(MachineBasicBlock::iterator II, RegScavenger *RS,
|
|
|
|
const TargetRegisterClass *RC, int SPAdj) {
|
|
|
|
assert(RS && "Register scavenging must be on");
|
2009-08-18 21:14:54 +00:00
|
|
|
unsigned Reg = RS->FindUnusedReg(RC);
|
2008-03-03 22:19:16 +00:00
|
|
|
// FIXME: move ARM callee-saved reg scan to target independent code, then
|
|
|
|
// search for already spilled CS register here.
|
|
|
|
if (Reg == 0)
|
|
|
|
Reg = RS->scavengeRegister(RC, II, SPAdj);
|
|
|
|
return Reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// lowerDynamicAlloc - Generate the code for allocating an object in the
|
2006-11-16 22:43:37 +00:00
|
|
|
/// current frame. The sequence of code with be in the general form
|
|
|
|
///
|
2009-03-03 02:55:14 +00:00
|
|
|
/// addi R0, SP, \#frameSize ; get the address of the previous frame
|
2006-11-16 22:43:37 +00:00
|
|
|
/// stwxu R0, SP, Rnegsize ; add and update the SP with the negated size
|
2009-03-03 02:55:14 +00:00
|
|
|
/// addi Rnew, SP, \#maxCalFrameSize ; get the top of the allocation
|
2006-11-16 22:43:37 +00:00
|
|
|
///
|
2008-03-03 22:19:16 +00:00
|
|
|
void PPCRegisterInfo::lowerDynamicAlloc(MachineBasicBlock::iterator II,
|
|
|
|
int SPAdj, RegScavenger *RS) const {
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the instruction.
|
|
|
|
MachineInstr &MI = *II;
|
|
|
|
// Get the instruction's basic block.
|
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
// Get the basic block's function.
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
// Get the frame info.
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
// Determine whether 64-bit pointers are used.
|
|
|
|
bool LP64 = Subtarget.isPPC64();
|
2009-02-13 02:27:39 +00:00
|
|
|
DebugLoc dl = MI.getDebugLoc();
|
2006-11-16 22:43:37 +00:00
|
|
|
|
2007-01-25 22:48:25 +00:00
|
|
|
// Get the maximum call stack size.
|
2006-11-16 22:43:37 +00:00
|
|
|
unsigned maxCallFrameSize = MFI->getMaxCallFrameSize();
|
|
|
|
// Get the total frame size.
|
|
|
|
unsigned FrameSize = MFI->getStackSize();
|
|
|
|
|
|
|
|
// Get stack alignments.
|
2011-01-10 12:39:04 +00:00
|
|
|
unsigned TargetAlign = MF.getTarget().getFrameLowering()->getStackAlignment();
|
2006-11-16 22:43:37 +00:00
|
|
|
unsigned MaxAlign = MFI->getMaxAlignment();
|
2010-07-30 21:09:48 +00:00
|
|
|
if (MaxAlign > TargetAlign)
|
|
|
|
report_fatal_error("Dynamic alloca with large aligns not supported");
|
2006-11-16 22:43:37 +00:00
|
|
|
|
|
|
|
// Determine the previous frame's address. If FrameSize can't be
|
|
|
|
// represented as 16 bits or we need special alignment, then we load the
|
|
|
|
// previous frame's address from 0(SP). Why not do an addis of the hi?
|
|
|
|
// Because R0 is our only safe tmp register and addi/addis treat R0 as zero.
|
|
|
|
// Constructing the constant and adding would take 3 instructions.
|
|
|
|
// Fortunately, a frame greater than 32K is rare.
|
2008-03-03 22:19:16 +00:00
|
|
|
const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
|
|
|
|
const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
|
|
|
|
const TargetRegisterClass *RC = LP64 ? G8RC : GPRC;
|
|
|
|
|
|
|
|
// FIXME (64-bit): Use "findScratchRegister"
|
|
|
|
unsigned Reg;
|
2010-11-27 23:05:25 +00:00
|
|
|
if (requiresRegisterScavenging(MF))
|
2008-03-03 22:19:16 +00:00
|
|
|
Reg = findScratchRegister(II, RS, RC, SPAdj);
|
|
|
|
else
|
|
|
|
Reg = PPC::R0;
|
|
|
|
|
2010-03-29 21:13:41 +00:00
|
|
|
if (MaxAlign < TargetAlign && isInt<16>(FrameSize)) {
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::ADDI), Reg)
|
2006-11-16 22:43:37 +00:00
|
|
|
.addReg(PPC::R31)
|
|
|
|
.addImm(FrameSize);
|
|
|
|
} else if (LP64) {
|
2010-11-27 23:05:25 +00:00
|
|
|
if (requiresRegisterScavenging(MF)) // FIXME (64-bit): Use "true" part.
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::LD), Reg)
|
2008-03-20 01:22:40 +00:00
|
|
|
.addImm(0)
|
|
|
|
.addReg(PPC::X1);
|
2008-03-04 23:13:51 +00:00
|
|
|
else
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::LD), PPC::X0)
|
2008-03-20 01:22:40 +00:00
|
|
|
.addImm(0)
|
|
|
|
.addReg(PPC::X1);
|
2006-11-16 22:43:37 +00:00
|
|
|
} else {
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::LWZ), Reg)
|
2006-11-16 22:43:37 +00:00
|
|
|
.addImm(0)
|
|
|
|
.addReg(PPC::R1);
|
|
|
|
}
|
|
|
|
|
2008-03-03 22:19:16 +00:00
|
|
|
// Grow the stack and update the stack pointer link, then determine the
|
|
|
|
// address of new allocated space.
|
2006-11-16 22:43:37 +00:00
|
|
|
if (LP64) {
|
2010-11-27 23:05:25 +00:00
|
|
|
if (requiresRegisterScavenging(MF)) // FIXME (64-bit): Use "true" part.
|
2012-06-19 02:34:32 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::STDUX), PPC::X1)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(Reg, RegState::Kill)
|
2012-06-19 02:34:32 +00:00
|
|
|
.addReg(PPC::X1)
|
2008-03-20 01:22:40 +00:00
|
|
|
.addReg(MI.getOperand(1).getReg());
|
2008-03-04 23:13:51 +00:00
|
|
|
else
|
2012-06-19 02:34:32 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::STDUX), PPC::X1)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(PPC::X0, RegState::Kill)
|
2012-06-19 02:34:32 +00:00
|
|
|
.addReg(PPC::X1)
|
2008-03-20 01:22:40 +00:00
|
|
|
.addReg(MI.getOperand(1).getReg());
|
2008-03-03 22:19:16 +00:00
|
|
|
|
|
|
|
if (!MI.getOperand(1).isKill())
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg())
|
2008-03-20 01:22:40 +00:00
|
|
|
.addReg(PPC::X1)
|
|
|
|
.addImm(maxCallFrameSize);
|
2008-03-03 22:19:16 +00:00
|
|
|
else
|
|
|
|
// Implicitly kill the register.
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg())
|
2008-03-20 01:22:40 +00:00
|
|
|
.addReg(PPC::X1)
|
|
|
|
.addImm(maxCallFrameSize)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(MI.getOperand(1).getReg(), RegState::ImplicitKill);
|
2006-11-16 22:43:37 +00:00
|
|
|
} else {
|
2012-06-19 02:34:32 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::STWUX), PPC::R1)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(Reg, RegState::Kill)
|
2012-06-19 02:34:32 +00:00
|
|
|
.addReg(PPC::R1)
|
2006-11-16 22:43:37 +00:00
|
|
|
.addReg(MI.getOperand(1).getReg());
|
2008-03-03 22:19:16 +00:00
|
|
|
|
|
|
|
if (!MI.getOperand(1).isKill())
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg())
|
2008-03-20 01:22:40 +00:00
|
|
|
.addReg(PPC::R1)
|
|
|
|
.addImm(maxCallFrameSize);
|
2008-03-03 22:19:16 +00:00
|
|
|
else
|
|
|
|
// Implicitly kill the register.
|
2009-02-13 02:27:39 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg())
|
2008-03-20 01:22:40 +00:00
|
|
|
.addReg(PPC::R1)
|
|
|
|
.addImm(maxCallFrameSize)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(MI.getOperand(1).getReg(), RegState::ImplicitKill);
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Discard the DYNALLOC instruction.
|
|
|
|
MBB.erase(II);
|
|
|
|
}
|
|
|
|
|
2008-03-03 22:19:16 +00:00
|
|
|
/// lowerCRSpilling - Generate the code for spilling a CR register. Instead of
|
|
|
|
/// reserving a whole register (R0), we scrounge for one here. This generates
|
|
|
|
/// code like this:
|
|
|
|
///
|
|
|
|
/// mfcr rA ; Move the conditional register into GPR rA.
|
|
|
|
/// rlwinm rA, rA, SB, 0, 31 ; Shift the bits left so they are in CR0's slot.
|
|
|
|
/// stw rA, FI ; Store rA to the frame.
|
|
|
|
///
|
|
|
|
void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II,
|
|
|
|
unsigned FrameIndex, int SPAdj,
|
|
|
|
RegScavenger *RS) const {
|
|
|
|
// Get the instruction.
|
2011-12-06 20:55:36 +00:00
|
|
|
MachineInstr &MI = *II; // ; SPILL_CR <SrcReg>, <offset>
|
2008-03-03 22:19:16 +00:00
|
|
|
// Get the instruction's basic block.
|
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
2009-02-13 02:27:39 +00:00
|
|
|
DebugLoc dl = MI.getDebugLoc();
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2011-12-10 04:50:53 +00:00
|
|
|
// FIXME: Once LLVM supports creating virtual registers here, or the register
|
|
|
|
// scavenger can return multiple registers, stop using reserved registers
|
|
|
|
// here.
|
|
|
|
(void) SPAdj;
|
|
|
|
(void) RS;
|
|
|
|
|
2011-06-17 15:21:10 +00:00
|
|
|
bool LP64 = Subtarget.isPPC64();
|
2011-12-10 04:50:53 +00:00
|
|
|
unsigned Reg = Subtarget.isDarwinABI() ? (LP64 ? PPC::X2 : PPC::R2) :
|
|
|
|
(LP64 ? PPC::X0 : PPC::R0);
|
|
|
|
unsigned SrcReg = MI.getOperand(0).getReg();
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2008-03-04 23:27:33 +00:00
|
|
|
// We need to store the CR in the low 4-bits of the saved value. First, issue
|
2010-05-20 17:48:26 +00:00
|
|
|
// an MFCRpsued to save all of the CRBits and, if needed, kill the SrcReg.
|
2011-12-07 06:34:06 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFCR8pseud : PPC::MFCRpseud), Reg)
|
2010-05-20 17:48:26 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
|
2008-03-04 23:27:33 +00:00
|
|
|
|
2008-03-03 22:19:16 +00:00
|
|
|
// If the saved register wasn't CR0, shift the bits left so that they are in
|
|
|
|
// CR0's slot.
|
|
|
|
if (SrcReg != PPC::CR0)
|
|
|
|
// rlwinm rA, rA, ShiftBits, 0, 31.
|
2011-12-07 06:34:06 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(Reg, RegState::Kill)
|
2011-07-25 19:53:23 +00:00
|
|
|
.addImm(getPPCRegisterNumbering(SrcReg) * 4)
|
2008-03-03 22:19:16 +00:00
|
|
|
.addImm(0)
|
|
|
|
.addImm(31);
|
|
|
|
|
2011-06-17 15:21:10 +00:00
|
|
|
addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(Reg, getKillRegState(MI.getOperand(1).getImm())),
|
2008-03-03 22:19:16 +00:00
|
|
|
FrameIndex);
|
|
|
|
|
|
|
|
// Discard the pseudo instruction.
|
|
|
|
MBB.erase(II);
|
|
|
|
}
|
|
|
|
|
2011-12-06 20:55:36 +00:00
|
|
|
void PPCRegisterInfo::lowerCRRestore(MachineBasicBlock::iterator II,
|
|
|
|
unsigned FrameIndex, int SPAdj,
|
|
|
|
RegScavenger *RS) const {
|
|
|
|
// Get the instruction.
|
|
|
|
MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CR <offset>
|
|
|
|
// Get the instruction's basic block.
|
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
DebugLoc dl = MI.getDebugLoc();
|
|
|
|
|
2011-12-10 04:50:53 +00:00
|
|
|
// FIXME: Once LLVM supports creating virtual registers here, or the register
|
|
|
|
// scavenger can return multiple registers, stop using reserved registers
|
|
|
|
// here.
|
|
|
|
(void) SPAdj;
|
|
|
|
(void) RS;
|
|
|
|
|
|
|
|
bool LP64 = Subtarget.isPPC64();
|
|
|
|
unsigned Reg = Subtarget.isDarwinABI() ? (LP64 ? PPC::X2 : PPC::R2) :
|
|
|
|
(LP64 ? PPC::X0 : PPC::R0);
|
2011-12-06 20:55:36 +00:00
|
|
|
unsigned DestReg = MI.getOperand(0).getReg();
|
|
|
|
assert(MI.definesRegister(DestReg) &&
|
|
|
|
"RESTORE_CR does not define its destination");
|
|
|
|
|
|
|
|
addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ),
|
|
|
|
Reg), FrameIndex);
|
|
|
|
|
|
|
|
// If the reloaded register isn't CR0, shift the bits right so that they are
|
|
|
|
// in the right CR's slot.
|
|
|
|
if (DestReg != PPC::CR0) {
|
|
|
|
unsigned ShiftBits = getPPCRegisterNumbering(DestReg)*4;
|
|
|
|
// rlwinm r11, r11, 32-ShiftBits, 0, 31.
|
2012-01-16 23:22:50 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
|
2011-12-06 20:55:36 +00:00
|
|
|
.addReg(Reg).addImm(32-ShiftBits).addImm(0)
|
|
|
|
.addImm(31);
|
|
|
|
}
|
|
|
|
|
2011-12-07 06:34:06 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTCRF8 : PPC::MTCRF), DestReg)
|
2011-12-06 20:55:36 +00:00
|
|
|
.addReg(Reg);
|
|
|
|
|
|
|
|
// Discard the pseudo instruction.
|
|
|
|
MBB.erase(II);
|
|
|
|
}
|
|
|
|
|
2010-08-26 23:32:16 +00:00
|
|
|
void
|
2009-10-07 17:12:56 +00:00
|
|
|
PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
|
2010-08-26 23:32:16 +00:00
|
|
|
int SPAdj, RegScavenger *RS) const {
|
2007-05-01 09:13:03 +00:00
|
|
|
assert(SPAdj == 0 && "Unexpected");
|
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the instruction.
|
2004-08-17 04:55:41 +00:00
|
|
|
MachineInstr &MI = *II;
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the instruction's basic block.
|
2004-08-17 04:55:41 +00:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the basic block's function.
|
2004-08-17 04:55:41 +00:00
|
|
|
MachineFunction &MF = *MBB.getParent();
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the frame info.
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2011-01-10 12:39:04 +00:00
|
|
|
const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
|
2009-02-13 02:27:39 +00:00
|
|
|
DebugLoc dl = MI.getDebugLoc();
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
// Find out which operand is the frame index.
|
2007-10-16 18:00:18 +00:00
|
|
|
unsigned FIOperandNo = 0;
|
2008-10-03 15:45:36 +00:00
|
|
|
while (!MI.getOperand(FIOperandNo).isFI()) {
|
2007-10-16 18:00:18 +00:00
|
|
|
++FIOperandNo;
|
|
|
|
assert(FIOperandNo != MI.getNumOperands() &&
|
|
|
|
"Instr doesn't have FrameIndex operand!");
|
2004-08-17 04:55:41 +00:00
|
|
|
}
|
2006-11-16 22:43:37 +00:00
|
|
|
// Take into account whether it's an add or mem instruction
|
2007-10-16 18:00:18 +00:00
|
|
|
unsigned OffsetOperandNo = (FIOperandNo == 2) ? 1 : 2;
|
2010-02-09 19:54:29 +00:00
|
|
|
if (MI.isInlineAsm())
|
2007-10-16 18:00:18 +00:00
|
|
|
OffsetOperandNo = FIOperandNo-1;
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the frame index.
|
2007-12-30 23:10:15 +00:00
|
|
|
int FrameIndex = MI.getOperand(FIOperandNo).getIndex();
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
// Get the frame pointer save index. Users of this index are primarily
|
|
|
|
// DYNALLOC instructions.
|
|
|
|
PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
|
|
|
|
int FPSI = FI->getFramePointerSaveIndex();
|
|
|
|
// Get the instruction opcode.
|
|
|
|
unsigned OpC = MI.getOpcode();
|
|
|
|
|
|
|
|
// Special case for dynamic alloca.
|
|
|
|
if (FPSI && FrameIndex == FPSI &&
|
|
|
|
(OpC == PPC::DYNALLOC || OpC == PPC::DYNALLOC8)) {
|
2008-03-03 22:19:16 +00:00
|
|
|
lowerDynamicAlloc(II, SPAdj, RS);
|
2010-08-26 23:32:16 +00:00
|
|
|
return;
|
2008-03-03 22:19:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 20:55:36 +00:00
|
|
|
// Special case for pseudo-ops SPILL_CR and RESTORE_CR.
|
|
|
|
if (requiresRegisterScavenging(MF)) {
|
2008-03-04 23:13:51 +00:00
|
|
|
if (OpC == PPC::SPILL_CR) {
|
|
|
|
lowerCRSpilling(II, FrameIndex, SPAdj, RS);
|
2010-08-26 23:32:16 +00:00
|
|
|
return;
|
2011-12-06 20:55:36 +00:00
|
|
|
} else if (OpC == PPC::RESTORE_CR) {
|
|
|
|
lowerCRRestore(II, FrameIndex, SPAdj, RS);
|
|
|
|
return;
|
2008-03-04 23:13:51 +00:00
|
|
|
}
|
2011-12-06 20:55:36 +00:00
|
|
|
}
|
2004-08-17 04:55:41 +00:00
|
|
|
|
|
|
|
// Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP).
|
2011-12-07 06:34:02 +00:00
|
|
|
|
|
|
|
bool is64Bit = Subtarget.isPPC64();
|
2010-11-18 21:19:35 +00:00
|
|
|
MI.getOperand(FIOperandNo).ChangeToRegister(TFI->hasFP(MF) ?
|
2011-12-07 06:34:02 +00:00
|
|
|
(is64Bit ? PPC::X31 : PPC::R31) :
|
|
|
|
(is64Bit ? PPC::X1 : PPC::R1),
|
2007-10-16 18:00:18 +00:00
|
|
|
false);
|
2004-08-17 04:55:41 +00:00
|
|
|
|
2006-06-27 18:55:49 +00:00
|
|
|
// Figure out if the offset in the instruction is shifted right two bits. This
|
|
|
|
// is true for instructions like "STD", which the machine implicitly adds two
|
|
|
|
// low zeros to.
|
|
|
|
bool isIXAddr = false;
|
2006-11-16 22:43:37 +00:00
|
|
|
switch (OpC) {
|
2006-06-27 18:55:49 +00:00
|
|
|
case PPC::LWA:
|
|
|
|
case PPC::LD:
|
|
|
|
case PPC::STD:
|
|
|
|
case PPC::STD_32:
|
|
|
|
isIXAddr = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-17 04:55:41 +00:00
|
|
|
// Now add the frame object offset to the offset from r1.
|
2006-11-16 22:43:37 +00:00
|
|
|
int Offset = MFI->getObjectOffset(FrameIndex);
|
2006-06-27 18:55:49 +00:00
|
|
|
if (!isIXAddr)
|
2007-12-30 20:49:49 +00:00
|
|
|
Offset += MI.getOperand(OffsetOperandNo).getImm();
|
2006-06-27 18:55:49 +00:00
|
|
|
else
|
2007-12-30 20:49:49 +00:00
|
|
|
Offset += MI.getOperand(OffsetOperandNo).getImm() << 2;
|
2004-08-17 04:55:41 +00:00
|
|
|
|
|
|
|
// If we're not using a Frame Pointer that has been set to the value of the
|
|
|
|
// SP before having the stack size subtracted from it, then add the stack size
|
|
|
|
// to Offset to get the correct offset.
|
2010-04-29 19:32:19 +00:00
|
|
|
// Naked functions have stack size 0, although getStackSize may not reflect that
|
|
|
|
// because we didn't call all the pieces that compute it for naked functions.
|
|
|
|
if (!MF.getFunction()->hasFnAttr(Attribute::Naked))
|
|
|
|
Offset += MFI->getStackSize();
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2007-11-27 22:14:42 +00:00
|
|
|
// If we can, encode the offset directly into the instruction. If this is a
|
|
|
|
// normal PPC "ri" instruction, any 16-bit value can be safely encoded. If
|
|
|
|
// this is a PPC64 "ix" instruction, only a 16-bit value with the low two bits
|
|
|
|
// clear can be encoded. This is extremely uncommon, because normally you
|
|
|
|
// only "std" to a stack slot that is at least 4-byte aligned, but it can
|
|
|
|
// happen in invalid code.
|
2012-03-22 05:28:19 +00:00
|
|
|
if (OpC == PPC::DBG_VALUE || // DBG_VALUE is always Reg+Imm
|
|
|
|
(isInt<16>(Offset) && (!isIXAddr || (Offset & 3) == 0))) {
|
2007-11-27 22:14:42 +00:00
|
|
|
if (isIXAddr)
|
2007-10-16 18:00:18 +00:00
|
|
|
Offset >>= 2; // The actual encoded value has the low two bits zero.
|
|
|
|
MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset);
|
2010-08-26 23:32:16 +00:00
|
|
|
return;
|
2007-11-27 22:14:42 +00:00
|
|
|
}
|
2008-03-03 22:19:16 +00:00
|
|
|
|
|
|
|
// The offset doesn't fit into a single register, scavenge one to build the
|
|
|
|
// offset in.
|
|
|
|
|
|
|
|
unsigned SReg;
|
2011-12-07 06:34:02 +00:00
|
|
|
if (requiresRegisterScavenging(MF)) {
|
|
|
|
const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
|
|
|
|
const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
|
|
|
|
SReg = findScratchRegister(II, RS, is64Bit ? G8RC : GPRC, SPAdj);
|
|
|
|
} else
|
|
|
|
SReg = is64Bit ? PPC::X0 : PPC::R0;
|
2008-03-03 22:19:16 +00:00
|
|
|
|
|
|
|
// Insert a set of rA with the full offset value before the ld, st, or add
|
2011-12-07 06:34:02 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LIS8 : PPC::LIS), SReg)
|
2008-03-03 22:19:16 +00:00
|
|
|
.addImm(Offset >> 16);
|
2011-12-07 06:34:02 +00:00
|
|
|
BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::ORI8 : PPC::ORI), SReg)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SReg, RegState::Kill)
|
2008-03-03 22:19:16 +00:00
|
|
|
.addImm(Offset);
|
|
|
|
|
|
|
|
// Convert into indexed form of the instruction:
|
|
|
|
//
|
|
|
|
// sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0
|
|
|
|
// addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0
|
2007-11-27 22:14:42 +00:00
|
|
|
unsigned OperandBase;
|
2008-03-03 22:19:16 +00:00
|
|
|
|
2010-02-09 19:54:29 +00:00
|
|
|
if (OpC != TargetOpcode::INLINEASM) {
|
2007-11-27 22:14:42 +00:00
|
|
|
assert(ImmToIdxMap.count(OpC) &&
|
|
|
|
"No indexed form of load or store available!");
|
|
|
|
unsigned NewOpcode = ImmToIdxMap.find(OpC)->second;
|
2008-01-11 18:10:50 +00:00
|
|
|
MI.setDesc(TII.get(NewOpcode));
|
2007-11-27 22:14:42 +00:00
|
|
|
OperandBase = 1;
|
2007-10-16 18:00:18 +00:00
|
|
|
} else {
|
2007-11-27 22:14:42 +00:00
|
|
|
OperandBase = OffsetOperandNo;
|
2004-08-17 04:55:41 +00:00
|
|
|
}
|
2010-08-26 23:32:16 +00:00
|
|
|
|
2007-11-27 22:14:42 +00:00
|
|
|
unsigned StackReg = MI.getOperand(FIOperandNo).getReg();
|
|
|
|
MI.getOperand(OperandBase).ChangeToRegister(StackReg, false);
|
2011-12-30 00:34:00 +00:00
|
|
|
MI.getOperand(OperandBase + 1).ChangeToRegister(SReg, false, false, true);
|
2004-08-17 04:55:41 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 20:49:22 +00:00
|
|
|
unsigned PPCRegisterInfo::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
|
|
|
|
2006-11-11 19:05:28 +00:00
|
|
|
if (!Subtarget.isPPC64())
|
2010-11-18 21:19:35 +00:00
|
|
|
return TFI->hasFP(MF) ? PPC::R31 : PPC::R1;
|
2006-11-11 19:05:28 +00:00
|
|
|
else
|
2010-11-18 21:19:35 +00:00
|
|
|
return TFI->hasFP(MF) ? PPC::X31 : PPC::X1;
|
2006-04-07 16:34:46 +00:00
|
|
|
}
|
|
|
|
|
2007-02-21 22:54:50 +00:00
|
|
|
unsigned PPCRegisterInfo::getEHExceptionRegister() const {
|
|
|
|
return !Subtarget.isPPC64() ? PPC::R3 : PPC::X3;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PPCRegisterInfo::getEHHandlerRegister() const {
|
|
|
|
return !Subtarget.isPPC64() ? PPC::R4 : PPC::X4;
|
|
|
|
}
|