Skip to content

Commit

Permalink
AMDGPU: Cache information about register pressure sets
Browse files Browse the repository at this point in the history
We can statically decide whether or not a register pressure set is for
SGPRs or VGPRs, so we don't need to re-compute this information in
SIRegisterInfo::getRegPressureSetLimit().

Differential Revision: http://reviews.llvm.org/D14805

llvm-svn: 264126
  • Loading branch information
tstellarAMD committed Mar 23, 2016
1 parent 3eaf5dc commit 52ecd2d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
57 changes: 33 additions & 24 deletions llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
Expand Up @@ -23,7 +23,28 @@

using namespace llvm;

SIRegisterInfo::SIRegisterInfo() : AMDGPURegisterInfo() {
static bool hasPressureSet(const int *PSets, unsigned PSetID) {
for (unsigned i = 0; PSets[i] != -1; ++i) {
if (PSets[i] == (int)PSetID)
return true;
}
return false;
}

void SIRegisterInfo::classifyPressureSet(unsigned PSetID, unsigned Reg,
BitVector &PressureSets) const {
for (MCRegUnitIterator U(Reg, this); U.isValid(); ++U) {
const int *PSets = getRegUnitPressureSets(*U);
if (hasPressureSet(PSets, PSetID)) {
PressureSets.set(PSetID);
break;
}
}
}

SIRegisterInfo::SIRegisterInfo() : AMDGPURegisterInfo(),
SGPRPressureSets(getNumRegPressureSets()),
VGPRPressureSets(getNumRegPressureSets()) {
unsigned NumRegPressureSets = getNumRegPressureSets();

SGPR32SetID = NumRegPressureSets;
Expand All @@ -33,6 +54,9 @@ SIRegisterInfo::SIRegisterInfo() : AMDGPURegisterInfo() {
SGPR32SetID = i;
else if (strncmp("VGPR_32", getRegPressureSetName(i), 7) == 0)
VGPR32SetID = i;

classifyPressureSet(i, AMDGPU::SGPR0, SGPRPressureSets);
classifyPressureSet(i, AMDGPU::VGPR0, VGPRPressureSets);
}
assert(SGPR32SetID < NumRegPressureSets &&
VGPR32SetID < NumRegPressureSets);
Expand Down Expand Up @@ -151,31 +175,16 @@ unsigned SIRegisterInfo::getRegPressureSetLimit(const MachineFunction &MF,

unsigned VSLimit = SGPRLimit + VGPRLimit;

for (regclass_iterator I = regclass_begin(), E = regclass_end();
I != E; ++I) {
const TargetRegisterClass *RC = *I;
if (SGPRPressureSets.test(Idx) && VGPRPressureSets.test(Idx)) {
// FIXME: This is a hack. We should never be considering the pressure of
// these since no virtual register should ever have this class.
return VSLimit;
}

unsigned NumSubRegs = std::max((int)RC->getSize() / 4, 1);
unsigned Limit;
if (SGPRPressureSets.test(Idx))
return SGPRLimit;

if (isPseudoRegClass(RC)) {
// FIXME: This is a hack. We should never be considering the pressure of
// these since no virtual register should ever have this class.
Limit = VSLimit;
} else if (isSGPRClass(RC)) {
Limit = SGPRLimit / NumSubRegs;
} else {
Limit = VGPRLimit / NumSubRegs;
}

const int *Sets = getRegClassPressureSets(RC);
assert(Sets);
for (unsigned i = 0; Sets[i] != -1; ++i) {
if (Sets[i] == (int)Idx)
return Limit;
}
}
return 256;
return VGPRLimit;
}

bool SIRegisterInfo::requiresRegisterScavenging(const MachineFunction &Fn) const {
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/AMDGPU/SIRegisterInfo.h
Expand Up @@ -27,8 +27,12 @@ struct SIRegisterInfo final : public AMDGPURegisterInfo {
private:
unsigned SGPR32SetID;
unsigned VGPR32SetID;
BitVector SGPRPressureSets;
BitVector VGPRPressureSets;

void reserveRegisterTuples(BitVector &, unsigned Reg) const;
void classifyPressureSet(unsigned PSetID, unsigned Reg,
BitVector &PressureSets) const;

public:
SIRegisterInfo();
Expand Down

0 comments on commit 52ecd2d

Please sign in to comment.