SIRegisterInfo.cpp revision 263508
1249259Sdim//===-- SIRegisterInfo.cpp - SI Register Information ---------------------===// 2249259Sdim// 3249259Sdim// The LLVM Compiler Infrastructure 4249259Sdim// 5249259Sdim// This file is distributed under the University of Illinois Open Source 6249259Sdim// License. See LICENSE.TXT for details. 7249259Sdim// 8249259Sdim//===----------------------------------------------------------------------===// 9249259Sdim// 10249259Sdim/// \file 11249259Sdim/// \brief SI implementation of the TargetRegisterInfo class. 12249259Sdim// 13249259Sdim//===----------------------------------------------------------------------===// 14249259Sdim 15249259Sdim 16249259Sdim#include "SIRegisterInfo.h" 17249259Sdim#include "AMDGPUTargetMachine.h" 18263508Sdim#include "SIInstrInfo.h" 19249259Sdim 20249259Sdimusing namespace llvm; 21249259Sdim 22263508SdimSIRegisterInfo::SIRegisterInfo(AMDGPUTargetMachine &tm) 23263508Sdim: AMDGPURegisterInfo(tm), 24263508Sdim TM(tm) 25249259Sdim { } 26249259Sdim 27249259SdimBitVector SIRegisterInfo::getReservedRegs(const MachineFunction &MF) const { 28249259Sdim BitVector Reserved(getNumRegs()); 29263508Sdim Reserved.set(AMDGPU::EXEC); 30263508Sdim Reserved.set(AMDGPU::INDIRECT_BASE_ADDR); 31263508Sdim const SIInstrInfo *TII = static_cast<const SIInstrInfo*>(TM.getInstrInfo()); 32263508Sdim TII->reserveIndirectRegisters(Reserved, MF); 33249259Sdim return Reserved; 34249259Sdim} 35249259Sdim 36249259Sdimunsigned SIRegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC, 37249259Sdim MachineFunction &MF) const { 38249259Sdim return RC->getNumRegs(); 39249259Sdim} 40249259Sdim 41249259Sdimconst TargetRegisterClass * 42249259SdimSIRegisterInfo::getISARegClass(const TargetRegisterClass * rc) const { 43249259Sdim switch (rc->getID()) { 44249259Sdim case AMDGPU::GPRF32RegClassID: 45249259Sdim return &AMDGPU::VReg_32RegClass; 46249259Sdim default: return rc; 47249259Sdim } 48249259Sdim} 49249259Sdim 50249259Sdimconst TargetRegisterClass * SIRegisterInfo::getCFGStructurizerRegClass( 51249259Sdim MVT VT) const { 52249259Sdim switch(VT.SimpleTy) { 53249259Sdim default: 54249259Sdim case MVT::i32: return &AMDGPU::VReg_32RegClass; 55249259Sdim } 56249259Sdim} 57263508Sdim 58263508Sdimunsigned SIRegisterInfo::getHWRegIndex(unsigned Reg) const { 59263508Sdim return getEncodingValue(Reg); 60263508Sdim} 61263508Sdim 62263508Sdimconst TargetRegisterClass *SIRegisterInfo::getPhysRegClass(unsigned Reg) const { 63263508Sdim assert(!TargetRegisterInfo::isVirtualRegister(Reg)); 64263508Sdim 65263508Sdim const TargetRegisterClass *BaseClasses[] = { 66263508Sdim &AMDGPU::VReg_32RegClass, 67263508Sdim &AMDGPU::SReg_32RegClass, 68263508Sdim &AMDGPU::VReg_64RegClass, 69263508Sdim &AMDGPU::SReg_64RegClass, 70263508Sdim &AMDGPU::SReg_128RegClass, 71263508Sdim &AMDGPU::SReg_256RegClass 72263508Sdim }; 73263508Sdim 74263508Sdim for (unsigned i = 0, e = sizeof(BaseClasses) / 75263508Sdim sizeof(const TargetRegisterClass*); i != e; ++i) { 76263508Sdim if (BaseClasses[i]->contains(Reg)) { 77263508Sdim return BaseClasses[i]; 78263508Sdim } 79263508Sdim } 80263508Sdim return NULL; 81263508Sdim} 82263508Sdim 83263508Sdimbool SIRegisterInfo::isSGPRClass(const TargetRegisterClass *RC) const { 84263508Sdim if (!RC) { 85263508Sdim return false; 86263508Sdim } 87263508Sdim return !hasVGPRs(RC); 88263508Sdim} 89263508Sdim 90263508Sdimbool SIRegisterInfo::hasVGPRs(const TargetRegisterClass *RC) const { 91263508Sdim return getCommonSubClass(&AMDGPU::VReg_32RegClass, RC) || 92263508Sdim getCommonSubClass(&AMDGPU::VReg_64RegClass, RC) || 93263508Sdim getCommonSubClass(&AMDGPU::VReg_96RegClass, RC) || 94263508Sdim getCommonSubClass(&AMDGPU::VReg_128RegClass, RC) || 95263508Sdim getCommonSubClass(&AMDGPU::VReg_256RegClass, RC) || 96263508Sdim getCommonSubClass(&AMDGPU::VReg_512RegClass, RC); 97263508Sdim} 98263508Sdim 99263508Sdimconst TargetRegisterClass *SIRegisterInfo::getEquivalentVGPRClass( 100263508Sdim const TargetRegisterClass *SRC) const { 101263508Sdim if (hasVGPRs(SRC)) { 102263508Sdim return SRC; 103263508Sdim } else if (SRC == &AMDGPU::SCCRegRegClass) { 104263508Sdim return &AMDGPU::VCCRegRegClass; 105263508Sdim } else if (getCommonSubClass(SRC, &AMDGPU::SGPR_32RegClass)) { 106263508Sdim return &AMDGPU::VReg_32RegClass; 107263508Sdim } else if (getCommonSubClass(SRC, &AMDGPU::SGPR_64RegClass)) { 108263508Sdim return &AMDGPU::VReg_64RegClass; 109263508Sdim } else if (getCommonSubClass(SRC, &AMDGPU::SReg_128RegClass)) { 110263508Sdim return &AMDGPU::VReg_128RegClass; 111263508Sdim } else if (getCommonSubClass(SRC, &AMDGPU::SReg_256RegClass)) { 112263508Sdim return &AMDGPU::VReg_256RegClass; 113263508Sdim } else if (getCommonSubClass(SRC, &AMDGPU::SReg_512RegClass)) { 114263508Sdim return &AMDGPU::VReg_512RegClass; 115263508Sdim } 116263508Sdim return NULL; 117263508Sdim} 118263508Sdim 119263508Sdimconst TargetRegisterClass *SIRegisterInfo::getSubRegClass( 120263508Sdim const TargetRegisterClass *RC, unsigned SubIdx) const { 121263508Sdim if (SubIdx == AMDGPU::NoSubRegister) 122263508Sdim return RC; 123263508Sdim 124263508Sdim // If this register has a sub-register, we can safely assume it is a 32-bit 125263508Sdim // register, becuase all of SI's sub-registers are 32-bit. 126263508Sdim if (isSGPRClass(RC)) { 127263508Sdim return &AMDGPU::SGPR_32RegClass; 128263508Sdim } else { 129263508Sdim return &AMDGPU::VGPR_32RegClass; 130263508Sdim } 131263508Sdim} 132