Skip to content

Commit 0f36544

Browse files
committed
Add a MinNumRegs argument to MRI::constrainRegClass().
The function will refuse to use a register class with fewer registers than MinNumRegs. This can be used by clients to avoid accidentally increase register pressure too much. The default value of MinNumRegs=0 doesn't affect how constrainRegClass() works. llvm-svn: 140339
1 parent 16abd32 commit 0f36544

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

llvm/include/llvm/CodeGen/MachineRegisterInfo.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,15 @@ class MachineRegisterInfo {
215215
void setRegClass(unsigned Reg, const TargetRegisterClass *RC);
216216

217217
/// constrainRegClass - Constrain the register class of the specified virtual
218-
/// register to be a common subclass of RC and the current register class.
219-
/// Return the new register class, or NULL if no such class exists.
218+
/// register to be a common subclass of RC and the current register class,
219+
/// but only if the new class has at least MinNumRegs registers. Return the
220+
/// new register class, or NULL if no such class exists.
220221
/// This should only be used when the constraint is known to be trivial, like
221222
/// GR32 -> GR32_NOSP. Beware of increasing register pressure.
222223
///
223224
const TargetRegisterClass *constrainRegClass(unsigned Reg,
224-
const TargetRegisterClass *RC);
225+
const TargetRegisterClass *RC,
226+
unsigned MinNumRegs = 0);
225227

226228
/// recomputeRegClass - Try to find a legal super-class of Reg's register
227229
/// class that still satisfies the constraints from the instructions using

llvm/lib/CodeGen/MachineRegisterInfo.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ MachineRegisterInfo::setRegClass(unsigned Reg, const TargetRegisterClass *RC) {
4949

5050
const TargetRegisterClass *
5151
MachineRegisterInfo::constrainRegClass(unsigned Reg,
52-
const TargetRegisterClass *RC) {
52+
const TargetRegisterClass *RC,
53+
unsigned MinNumRegs) {
5354
const TargetRegisterClass *OldRC = getRegClass(Reg);
5455
if (OldRC == RC)
5556
return RC;
5657
const TargetRegisterClass *NewRC = getCommonSubClass(OldRC, RC);
57-
if (!NewRC)
58+
if (!NewRC || NewRC == OldRC)
59+
return NewRC;
60+
if (NewRC->getNumRegs() < MinNumRegs)
5861
return 0;
59-
if (NewRC != OldRC)
60-
setRegClass(Reg, NewRC);
62+
setRegClass(Reg, NewRC);
6163
return NewRC;
6264
}
6365

0 commit comments

Comments
 (0)