MachineRegisterInfo: Introduce isPhysRegUsed()

This method checks whether a physical regiser or any of its aliases are
used in the function.

Using this function in SIRegisterInfo::findUnusedReg() should also fix
this reported failure:

http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/292143.html
http://reviews.llvm.org/rL242173#inline-533

The report doesn't come with a testcase and I don't know enough about
AMDGPU to create one myself.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245329 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matthias Braun 2015-08-18 18:54:27 +00:00
parent ebb4ccb3a8
commit 28fbb4be5d
4 changed files with 29 additions and 14 deletions

View File

@ -644,9 +644,16 @@ public:
/// Return true if the specified register is modified in this function. /// Return true if the specified register is modified in this function.
/// This checks that no defining machine operands exist for the register or /// This checks that no defining machine operands exist for the register or
/// any of its aliases. Definitions found on functions marked noreturn are /// any of its aliases. Definitions found on functions marked noreturn are
/// ignored. /// ignored. The register is also considered modified when it is set in the
/// UsedPhysRegMask.
bool isPhysRegModified(unsigned PhysReg) const; bool isPhysRegModified(unsigned PhysReg) const;
/// Return true if the specified register is modified or read in this
/// function. This checks that no machine operands exist for the register or
/// any of its aliases. The register is also considered used when it is set
/// in the UsedPhysRegMask.
bool isPhysRegUsed(unsigned PhysReg) const;
/// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used. /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
/// This corresponds to the bit mask attached to register mask operands. /// This corresponds to the bit mask attached to register mask operands.
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask) { void addPhysRegsUsedFromRegMask(const uint32_t *RegMask) {

View File

@ -733,13 +733,12 @@ bool ExeDepsFix::runOnMachineFunction(MachineFunction &mf) {
// completely. // completely.
bool anyregs = false; bool anyregs = false;
const MachineRegisterInfo &MRI = mf.getRegInfo(); const MachineRegisterInfo &MRI = mf.getRegInfo();
for (TargetRegisterClass::const_iterator I = RC->begin(), E = RC->end(); for (unsigned Reg : *RC) {
I != E && !anyregs; ++I) if (MRI.isPhysRegUsed(Reg)) {
for (MCRegAliasIterator AI(*I, TRI, true); AI.isValid(); ++AI)
if (!MRI.reg_nodbg_empty(*AI)) {
anyregs = true; anyregs = true;
break; break;
} }
}
if (!anyregs) return false; if (!anyregs) return false;
// Initialize the AliasMap on the first use. // Initialize the AliasMap on the first use.

View File

@ -489,3 +489,15 @@ bool MachineRegisterInfo::isPhysRegModified(unsigned PhysReg) const {
} }
return false; return false;
} }
bool MachineRegisterInfo::isPhysRegUsed(unsigned PhysReg) const {
if (UsedPhysRegMask.test(PhysReg))
return true;
const TargetRegisterInfo *TRI = getTargetRegisterInfo();
for (MCRegAliasIterator AliasReg(PhysReg, TRI, true); AliasReg.isValid();
++AliasReg) {
if (!reg_nodbg_empty(*AliasReg))
return true;
}
return false;
}

View File

@ -495,12 +495,9 @@ unsigned SIRegisterInfo::getPreloadedValue(const MachineFunction &MF,
// AMDGPU::NoRegister. // AMDGPU::NoRegister.
unsigned SIRegisterInfo::findUnusedRegister(const MachineRegisterInfo &MRI, unsigned SIRegisterInfo::findUnusedRegister(const MachineRegisterInfo &MRI,
const TargetRegisterClass *RC) const { const TargetRegisterClass *RC) const {
for (unsigned Reg : *RC)
for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end(); if (!MRI.isPhysRegUsed(Reg))
I != E; ++I) { return Reg;
if (MRI.reg_nodbg_empty(*I))
return *I;
}
return AMDGPU::NoRegister; return AMDGPU::NoRegister;
} }