forked from OSchip/llvm-project
PPC: Use HWEncoding and TRI->getEncodingValue
As pointed out by Jakob, we don't need to maintain a separate register-numbering table. Instead we should let TableGen generate the table for us from the information (already present) in PPCRegisterInfo.td. TRI->getEncodingValue is now used to access register-encoding values. No functionality change intended. llvm-svn: 178067
This commit is contained in:
parent
3234178bf9
commit
feea653974
|
@ -13,7 +13,7 @@
|
|||
|
||||
#define DEBUG_TYPE "asm-printer"
|
||||
#include "PPCInstPrinter.h"
|
||||
#include "MCTargetDesc/PPCBaseInfo.h"
|
||||
#include "MCTargetDesc/PPCMCTargetDesc.h"
|
||||
#include "MCTargetDesc/PPCPredicates.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
//===-- PPCBaseInfo.h - Top level definitions for PPC -----------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains small standalone helper functions and enum definitions for
|
||||
// the PPC target useful for the compiler back-end and the MC libraries.
|
||||
// As such, it deliberately does not include references to LLVM core
|
||||
// code gen types, passes, etc..
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef PPCBASEINFO_H
|
||||
#define PPCBASEINFO_H
|
||||
|
||||
#include "PPCMCTargetDesc.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// getPPCRegisterNumbering - Given the enum value for some register, e.g.
|
||||
/// PPC::F14, return the number that it corresponds to (e.g. 14).
|
||||
inline static unsigned getPPCRegisterNumbering(unsigned RegEnum) {
|
||||
using namespace PPC;
|
||||
switch (RegEnum) {
|
||||
case 0: return 0;
|
||||
case ZERO : case ZERO8 :
|
||||
case R0 : case X0 : case F0 : case V0 : case CR0: case CR0LT: return 0;
|
||||
case R1 : case X1 : case F1 : case V1 : case CR1: case CR0GT: return 1;
|
||||
case R2 : case X2 : case F2 : case V2 : case CR2: case CR0EQ: return 2;
|
||||
case R3 : case X3 : case F3 : case V3 : case CR3: case CR0UN: return 3;
|
||||
case R4 : case X4 : case F4 : case V4 : case CR4: case CR1LT: return 4;
|
||||
case R5 : case X5 : case F5 : case V5 : case CR5: case CR1GT: return 5;
|
||||
case R6 : case X6 : case F6 : case V6 : case CR6: case CR1EQ: return 6;
|
||||
case R7 : case X7 : case F7 : case V7 : case CR7: case CR1UN: return 7;
|
||||
case R8 : case X8 : case F8 : case V8 : case CR2LT: return 8;
|
||||
case R9 : case X9 : case F9 : case V9 : case CR2GT: return 9;
|
||||
case R10: case X10: case F10: case V10: case CR2EQ: return 10;
|
||||
case R11: case X11: case F11: case V11: case CR2UN: return 11;
|
||||
case R12: case X12: case F12: case V12: case CR3LT: return 12;
|
||||
case R13: case X13: case F13: case V13: case CR3GT: return 13;
|
||||
case R14: case X14: case F14: case V14: case CR3EQ: return 14;
|
||||
case R15: case X15: case F15: case V15: case CR3UN: return 15;
|
||||
case R16: case X16: case F16: case V16: case CR4LT: return 16;
|
||||
case R17: case X17: case F17: case V17: case CR4GT: return 17;
|
||||
case R18: case X18: case F18: case V18: case CR4EQ: return 18;
|
||||
case R19: case X19: case F19: case V19: case CR4UN: return 19;
|
||||
case R20: case X20: case F20: case V20: case CR5LT: return 20;
|
||||
case R21: case X21: case F21: case V21: case CR5GT: return 21;
|
||||
case R22: case X22: case F22: case V22: case CR5EQ: return 22;
|
||||
case R23: case X23: case F23: case V23: case CR5UN: return 23;
|
||||
case R24: case X24: case F24: case V24: case CR6LT: return 24;
|
||||
case R25: case X25: case F25: case V25: case CR6GT: return 25;
|
||||
case R26: case X26: case F26: case V26: case CR6EQ: return 26;
|
||||
case R27: case X27: case F27: case V27: case CR6UN: return 27;
|
||||
case R28: case X28: case F28: case V28: case CR7LT: return 28;
|
||||
case R29: case X29: case F29: case V29: case CR7GT: return 29;
|
||||
case R30: case X30: case F30: case V30: case CR7EQ: return 30;
|
||||
case R31: case X31: case F31: case V31: case CR7UN: return 31;
|
||||
default:
|
||||
llvm_unreachable("Unhandled reg in PPCRegisterInfo::getRegisterNumbering!");
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace llvm;
|
||||
|
||||
#endif
|
|
@ -13,10 +13,10 @@
|
|||
|
||||
#define DEBUG_TYPE "mccodeemitter"
|
||||
#include "MCTargetDesc/PPCMCTargetDesc.h"
|
||||
#include "MCTargetDesc/PPCBaseInfo.h"
|
||||
#include "MCTargetDesc/PPCFixupKinds.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/MC/MCCodeEmitter.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCInstrInfo.h"
|
||||
|
@ -33,12 +33,13 @@ class PPCMCCodeEmitter : public MCCodeEmitter {
|
|||
void operator=(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION;
|
||||
|
||||
const MCSubtargetInfo &STI;
|
||||
const MCContext &CTX;
|
||||
Triple TT;
|
||||
|
||||
public:
|
||||
PPCMCCodeEmitter(const MCInstrInfo &mcii, const MCSubtargetInfo &sti,
|
||||
MCContext &ctx)
|
||||
: STI(sti), TT(STI.getTargetTriple()) {
|
||||
: STI(sti), CTX(ctx), TT(STI.getTargetTriple()) {
|
||||
}
|
||||
|
||||
~PPCMCCodeEmitter() {}
|
||||
|
@ -203,7 +204,7 @@ unsigned PPCMCCodeEmitter::getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
|
|||
// Return the thread-pointer register's encoding.
|
||||
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
||||
(MCFixupKind)PPC::fixup_ppc_tlsreg));
|
||||
return getPPCRegisterNumbering(PPC::X13);
|
||||
return CTX.getRegisterInfo().getEncodingValue(PPC::X13);
|
||||
}
|
||||
|
||||
unsigned PPCMCCodeEmitter::
|
||||
|
@ -214,7 +215,7 @@ get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
|
|||
MI.getOpcode() == PPC::MFOCRF ||
|
||||
MI.getOpcode() == PPC::MTCRF8) &&
|
||||
(MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7));
|
||||
return 0x80 >> getPPCRegisterNumbering(MO.getReg());
|
||||
return 0x80 >> CTX.getRegisterInfo().getEncodingValue(MO.getReg());
|
||||
}
|
||||
|
||||
|
||||
|
@ -226,7 +227,7 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO,
|
|||
// The GPR operand should come through here though.
|
||||
assert((MI.getOpcode() != PPC::MTCRF && MI.getOpcode() != PPC::MFOCRF) ||
|
||||
MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7);
|
||||
return getPPCRegisterNumbering(MO.getReg());
|
||||
return CTX.getRegisterInfo().getEncodingValue(MO.getReg());
|
||||
}
|
||||
|
||||
assert(MO.isImm() &&
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#ifndef LLVM_TARGET_POWERPC_H
|
||||
#define LLVM_TARGET_POWERPC_H
|
||||
|
||||
#include "MCTargetDesc/PPCBaseInfo.h"
|
||||
#include "MCTargetDesc/PPCMCTargetDesc.h"
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ unsigned PPCCodeEmitter::get_crbitm_encoding(const MachineInstr &MI,
|
|||
assert((MI.getOpcode() == PPC::MTCRF || MI.getOpcode() == PPC::MTCRF8 ||
|
||||
MI.getOpcode() == PPC::MFOCRF) &&
|
||||
(MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7));
|
||||
return 0x80 >> getPPCRegisterNumbering(MO.getReg());
|
||||
return 0x80 >> TM.getRegisterInfo()->getEncodingValue(MO.getReg());
|
||||
}
|
||||
|
||||
MachineRelocation PPCCodeEmitter::GetRelocation(const MachineOperand &MO,
|
||||
|
@ -260,7 +260,7 @@ unsigned PPCCodeEmitter::getMachineOpValue(const MachineInstr &MI,
|
|||
assert((MI.getOpcode() != PPC::MTCRF && MI.getOpcode() != PPC::MTCRF8 &&
|
||||
MI.getOpcode() != PPC::MFOCRF) ||
|
||||
MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7);
|
||||
return getPPCRegisterNumbering(MO.getReg());
|
||||
return TM.getRegisterInfo()->getEncodingValue(MO.getReg());
|
||||
}
|
||||
|
||||
assert(MO.isImm() &&
|
||||
|
|
|
@ -103,6 +103,7 @@ static void RemoveVRSaveCode(MachineInstr *MI) {
|
|||
// transform this into the appropriate ORI instruction.
|
||||
static void HandleVRSaveUpdate(MachineInstr *MI, const TargetInstrInfo &TII) {
|
||||
MachineFunction *MF = MI->getParent()->getParent();
|
||||
const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();
|
||||
DebugLoc dl = MI->getDebugLoc();
|
||||
|
||||
unsigned UsedRegMask = 0;
|
||||
|
@ -115,7 +116,7 @@ static void HandleVRSaveUpdate(MachineInstr *MI, const TargetInstrInfo &TII) {
|
|||
for (MachineRegisterInfo::livein_iterator
|
||||
I = MF->getRegInfo().livein_begin(),
|
||||
E = MF->getRegInfo().livein_end(); I != E; ++I) {
|
||||
unsigned RegNo = getPPCRegisterNumbering(I->first);
|
||||
unsigned RegNo = TRI->getEncodingValue(I->first);
|
||||
if (VRRegNo[RegNo] == I->first) // If this really is a vector reg.
|
||||
UsedRegMask &= ~(1 << (31-RegNo)); // Doesn't need to be marked.
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ static void HandleVRSaveUpdate(MachineInstr *MI, const TargetInstrInfo &TII) {
|
|||
const MachineOperand &MO = Ret.getOperand(I);
|
||||
if (!MO.isReg() || !PPC::VRRCRegClass.contains(MO.getReg()))
|
||||
continue;
|
||||
unsigned RegNo = getPPCRegisterNumbering(MO.getReg());
|
||||
unsigned RegNo = TRI->getEncodingValue(MO.getReg());
|
||||
UsedRegMask &= ~(1 << (31-RegNo));
|
||||
}
|
||||
}
|
||||
|
@ -950,6 +951,7 @@ void PPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
|||
}
|
||||
|
||||
PPCFunctionInfo *PFI = MF.getInfo<PPCFunctionInfo>();
|
||||
const TargetRegisterInfo *TRI = MF.getTarget().getRegisterInfo();
|
||||
|
||||
int64_t LowerBound = 0;
|
||||
|
||||
|
@ -969,7 +971,7 @@ void PPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
|||
FFI->setObjectOffset(FI, LowerBound + FFI->getObjectOffset(FI));
|
||||
}
|
||||
|
||||
LowerBound -= (31 - getPPCRegisterNumbering(MinFPR) + 1) * 8;
|
||||
LowerBound -= (31 - TRI->getEncodingValue(MinFPR) + 1) * 8;
|
||||
}
|
||||
|
||||
// Check whether the frame pointer register is allocated. If so, make sure it
|
||||
|
@ -1003,8 +1005,8 @@ void PPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
|||
}
|
||||
|
||||
unsigned MinReg =
|
||||
std::min<unsigned>(getPPCRegisterNumbering(MinGPR),
|
||||
getPPCRegisterNumbering(MinG8R));
|
||||
std::min<unsigned>(TRI->getEncodingValue(MinGPR),
|
||||
TRI->getEncodingValue(MinG8R));
|
||||
|
||||
if (Subtarget.isPPC64()) {
|
||||
LowerBound -= (31 - MinReg + 1) * 8;
|
||||
|
|
|
@ -328,7 +328,7 @@ void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II,
|
|||
// rlwinm rA, rA, ShiftBits, 0, 31.
|
||||
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
|
||||
.addReg(Reg1, RegState::Kill)
|
||||
.addImm(getPPCRegisterNumbering(SrcReg) * 4)
|
||||
.addImm(getEncodingValue(SrcReg) * 4)
|
||||
.addImm(0)
|
||||
.addImm(31);
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ void PPCRegisterInfo::lowerCRRestore(MachineBasicBlock::iterator II,
|
|||
unsigned Reg1 = Reg;
|
||||
Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
|
||||
|
||||
unsigned ShiftBits = getPPCRegisterNumbering(DestReg)*4;
|
||||
unsigned ShiftBits = getEncodingValue(DestReg)*4;
|
||||
// rlwinm r11, r11, 32-ShiftBits, 0, 31.
|
||||
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
|
||||
.addReg(Reg1, RegState::Kill).addImm(32-ShiftBits).addImm(0)
|
||||
|
|
|
@ -26,41 +26,41 @@ class PPCReg<string n> : Register<n> {
|
|||
// We identify all our registers with a 5-bit ID, for consistency's sake.
|
||||
|
||||
// GPR - One of the 32 32-bit general-purpose registers
|
||||
class GPR<bits<5> num, string n> : PPCReg<n> {
|
||||
field bits<5> Num = num;
|
||||
class GPR<bits<16> num, string n> : PPCReg<n> {
|
||||
let HWEncoding = num;
|
||||
}
|
||||
|
||||
// GP8 - One of the 32 64-bit general-purpose registers
|
||||
class GP8<GPR SubReg, string n> : PPCReg<n> {
|
||||
field bits<5> Num = SubReg.Num;
|
||||
let HWEncoding = SubReg.HWEncoding;
|
||||
let SubRegs = [SubReg];
|
||||
let SubRegIndices = [sub_32];
|
||||
}
|
||||
|
||||
// SPR - One of the 32-bit special-purpose registers
|
||||
class SPR<bits<10> num, string n> : PPCReg<n> {
|
||||
field bits<10> Num = num;
|
||||
class SPR<bits<16> num, string n> : PPCReg<n> {
|
||||
let HWEncoding = num;
|
||||
}
|
||||
|
||||
// FPR - One of the 32 64-bit floating-point registers
|
||||
class FPR<bits<5> num, string n> : PPCReg<n> {
|
||||
field bits<5> Num = num;
|
||||
class FPR<bits<16> num, string n> : PPCReg<n> {
|
||||
let HWEncoding = num;
|
||||
}
|
||||
|
||||
// VR - One of the 32 128-bit vector registers
|
||||
class VR<bits<5> num, string n> : PPCReg<n> {
|
||||
field bits<5> Num = num;
|
||||
class VR<bits<16> num, string n> : PPCReg<n> {
|
||||
let HWEncoding = num;
|
||||
}
|
||||
|
||||
// CR - One of the 8 4-bit condition registers
|
||||
class CR<bits<3> num, string n, list<Register> subregs> : PPCReg<n> {
|
||||
field bits<3> Num = num;
|
||||
class CR<bits<16> num, string n, list<Register> subregs> : PPCReg<n> {
|
||||
let HWEncoding = num;
|
||||
let SubRegs = subregs;
|
||||
}
|
||||
|
||||
// CRBIT - One of the 32 1-bit condition register fields
|
||||
class CRBIT<bits<5> num, string n> : PPCReg<n> {
|
||||
field bits<5> Num = num;
|
||||
class CRBIT<bits<16> num, string n> : PPCReg<n> {
|
||||
let HWEncoding = num;
|
||||
}
|
||||
|
||||
// General-purpose registers
|
||||
|
|
Loading…
Reference in New Issue