From dceb4576075546962ac816a05267afbc606234a6 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Wed, 11 Aug 2004 23:44:55 +0000 Subject: [PATCH] * Set the is64bit boolean flag in PowerPCRegisterInfo * Doubles are 8 bytes in 64-bit PowerPC, and use the general register class * Use double-word loads and stores for restoring from/saving to stack * Do not allocate R2 if compiling for AIX git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15670 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PPCRegisterInfo.td | 6 ++-- lib/Target/PowerPC/PowerPCRegisterInfo.cpp | 36 ++++++++++++++-------- lib/Target/PowerPC/PowerPCRegisterInfo.h | 6 ++-- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/Target/PowerPC/PPCRegisterInfo.td b/lib/Target/PowerPC/PPCRegisterInfo.td index 34ebfac6101..c103dd6f374 100644 --- a/lib/Target/PowerPC/PPCRegisterInfo.td +++ b/lib/Target/PowerPC/PPCRegisterInfo.td @@ -77,13 +77,13 @@ def TBU : SPR<5>; // then nonvolatiles in reverse order since stmw/lmw save from rN to r31 def GPRC : RegisterClass + R16, R15, R14, R13, R0, R2, R1, LR]> { let Methods = [{ iterator allocation_order_end(MachineFunction &MF) const { - return end()-3; + return end() - (AIX ? 4 : 3); } }]; } diff --git a/lib/Target/PowerPC/PowerPCRegisterInfo.cpp b/lib/Target/PowerPC/PowerPCRegisterInfo.cpp index 62f553eb048..ee2aabc3cd1 100644 --- a/lib/Target/PowerPC/PowerPCRegisterInfo.cpp +++ b/lib/Target/PowerPC/PowerPCRegisterInfo.cpp @@ -30,9 +30,14 @@ #include using namespace llvm; -PowerPCRegisterInfo::PowerPCRegisterInfo() - : PowerPCGenRegisterInfo(PPC::ADJCALLSTACKDOWN, - PPC::ADJCALLSTACKUP) {} +namespace llvm { + // Switch toggling compilation for AIX + extern cl::opt AIX; +} + +PowerPCRegisterInfo::PowerPCRegisterInfo(bool is64b) + : PowerPCGenRegisterInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP), + is64bit(is64b) {} static unsigned getIdx(const TargetRegisterClass *RC) { if (RC == PowerPC::GPRCRegisterClass) { @@ -41,12 +46,13 @@ static unsigned getIdx(const TargetRegisterClass *RC) { case 1: return 0; case 2: return 1; case 4: return 2; + case 8: return 3; } } else if (RC == PowerPC::FPRCRegisterClass) { switch (RC->getSize()) { default: assert(0 && "Invalid data size!"); - case 4: return 3; - case 8: return 4; + case 4: return 4; + case 8: return 5; } } std::cerr << "Invalid register class to getIdx()!\n"; @@ -59,7 +65,7 @@ PowerPCRegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB, unsigned SrcReg, int FrameIdx, const TargetRegisterClass *RC) const { static const unsigned Opcode[] = { - PPC::STB, PPC::STH, PPC::STW, PPC::STFS, PPC::STFD + PPC::STB, PPC::STH, PPC::STW, PPC::STD, PPC::STFS, PPC::STFD }; unsigned OC = Opcode[getIdx(RC)]; if (SrcReg == PPC::LR) { @@ -78,7 +84,7 @@ PowerPCRegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, unsigned DestReg, int FrameIdx, const TargetRegisterClass *RC) const { static const unsigned Opcode[] = { - PPC::LBZ, PPC::LHZ, PPC::LWZ, PPC::LFS, PPC::LFD + PPC::LBZ, PPC::LHZ, PPC::LWZ, PPC::LD, PPC::LFS, PPC::LFD }; unsigned OC = Opcode[getIdx(RC)]; if (DestReg == PPC::LR) { @@ -221,17 +227,19 @@ void PowerPCRegisterInfo::emitPrologue(MachineFunction &MF) const { // adjust stack pointer: r1 -= numbytes if (NumBytes <= 32768) { - MI = BuildMI(PPC::STWU, 3).addReg(PPC::R1).addSImm(-NumBytes) + unsigned StoreOpcode = is64bit ? PPC::STDU : PPC::STWU; + MI = BuildMI(StoreOpcode, 3).addReg(PPC::R1).addSImm(-NumBytes) .addReg(PPC::R1); MBB.insert(MBBI, MI); } else { int NegNumbytes = -NumBytes; + unsigned StoreOpcode = is64bit ? PPC::STDUX : PPC::STWUX; MI = BuildMI(PPC::LIS, 1, PPC::R0).addSImm(NegNumbytes >> 16); MBB.insert(MBBI, MI); MI = BuildMI(PPC::ORI, 2, PPC::R0).addReg(PPC::R0) .addImm(NegNumbytes & 0xFFFF); MBB.insert(MBBI, MI); - MI = BuildMI(PPC::STWUX, 3).addReg(PPC::R1).addReg(PPC::R1) + MI = BuildMI(StoreOpcode, 3).addReg(PPC::R1).addReg(PPC::R1) .addReg(PPC::R0); MBB.insert(MBBI, MI); } @@ -249,7 +257,8 @@ void PowerPCRegisterInfo::emitEpilogue(MachineFunction &MF, unsigned NumBytes = MFI->getStackSize(); if (NumBytes != 0) { - MI = BuildMI(PPC::LWZ, 2, PPC::R1).addSImm(0).addReg(PPC::R1); + unsigned Opcode = is64bit ? PPC::LD : PPC::LWZ; + MI = BuildMI(Opcode, 2, PPC::R1).addSImm(0).addReg(PPC::R1); MBB.insert(MBBI, MI); } } @@ -259,9 +268,10 @@ void PowerPCRegisterInfo::emitEpilogue(MachineFunction &MF, const TargetRegisterClass* PowerPCRegisterInfo::getRegClassForType(const Type* Ty) const { switch (Ty->getTypeID()) { - case Type::LongTyID: - case Type::ULongTyID: assert(0 && "Long values can't fit in registers!"); default: assert(0 && "Invalid type to getClass!"); + case Type::LongTyID: + case Type::ULongTyID: + if (!is64bit) assert(0 && "Long values can't fit in registers!"); case Type::BoolTyID: case Type::SByteTyID: case Type::UByteTyID: @@ -270,7 +280,7 @@ PowerPCRegisterInfo::getRegClassForType(const Type* Ty) const { case Type::IntTyID: case Type::UIntTyID: case Type::PointerTyID: return &GPRCInstance; - + case Type::FloatTyID: case Type::DoubleTyID: return &FPRCInstance; } diff --git a/lib/Target/PowerPC/PowerPCRegisterInfo.h b/lib/Target/PowerPC/PowerPCRegisterInfo.h index fd4b33e92ea..478693dc7c9 100644 --- a/lib/Target/PowerPC/PowerPCRegisterInfo.h +++ b/lib/Target/PowerPC/PowerPCRegisterInfo.h @@ -21,8 +21,10 @@ namespace llvm { class Type; -struct PowerPCRegisterInfo : public PowerPCGenRegisterInfo { - PowerPCRegisterInfo(); +class PowerPCRegisterInfo : public PowerPCGenRegisterInfo { + bool is64bit; +public: + PowerPCRegisterInfo(bool is64b); const TargetRegisterClass* getRegClassForType(const Type* Ty) const; /// Code Generation virtual methods...