diff options
| author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-08-10 18:37:40 +0000 |
|---|---|---|
| committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-08-10 18:37:40 +0000 |
| commit | 53c502204046ac583f447903272a2aa1288e5b8e (patch) | |
| tree | 2c99e237d9ccdf390e56e5a1d68838844c87687a /llvm/lib/CodeGen | |
| parent | d52543ee22bcdd5d5db962ee03b744264d3ec0de (diff) | |
| download | bcm5719-llvm-53c502204046ac583f447903272a2aa1288e5b8e.tar.gz bcm5719-llvm-53c502204046ac583f447903272a2aa1288e5b8e.zip | |
Implement register class inflation.
When splitting a live range, the new registers have fewer uses and the
permissible register class may be less constrained. Recompute the register class
constraint from the uses of new registers created for a split. This may let them
be allocated from a larger set, possibly avoiding a spill.
llvm-svn: 110703
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/CalcSpillWeights.cpp | 41 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SplitKit.cpp | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp index 02adae0eddf..a39503ba2ee 100644 --- a/llvm/lib/CodeGen/CalcSpillWeights.cpp +++ b/llvm/lib/CodeGen/CalcSpillWeights.cpp @@ -174,3 +174,44 @@ void VirtRegAuxInfo::CalculateWeightAndHint(LiveInterval &li) { lis_.normalizeSpillWeight(li); } +void VirtRegAuxInfo::CalculateRegClass(unsigned reg) { + MachineRegisterInfo &mri = mf_.getRegInfo(); + const TargetRegisterInfo *tri = mf_.getTarget().getRegisterInfo(); + const TargetRegisterClass *orc = mri.getRegClass(reg); + SmallPtrSet<const TargetRegisterClass*,8> rcs; + + for (MachineRegisterInfo::reg_nodbg_iterator I = mri.reg_nodbg_begin(reg), + E = mri.reg_nodbg_end(); I != E; ++I) + if (const TargetRegisterClass *rc = + I->getDesc().getRegClass(I.getOperandNo(), tri)) + rcs.insert(rc); + + // If we found no regclass constraints, just leave reg as is. + // In theory, we could inflate to the largest superclass of reg's existing + // class, but that might not be legal for the current cpu setting. + // This could happen if reg is only used by COPY instructions, so we may need + // to improve on this. + if (rcs.empty()) { + DEBUG(dbgs() << "Not inflating unconstrained" << orc->getName() << ":%reg" + << reg << ".\n"); + return; + } + + // Compute the intersection of all classes in rcs. + // This ought to be independent of iteration order, but if the target register + // classes don't form a proper algebra, it is possible to get different + // results. The solution is to make sure the intersection of any two register + // classes is also a register class or the null set. + const TargetRegisterClass *rc = 0; + for (SmallPtrSet<const TargetRegisterClass*,8>::iterator I = rcs.begin(), + E = rcs.end(); I != E; ++I) { + rc = rc ? getCommonSubClass(rc, *I) : *I; + assert(rc && "Incompatible regclass constraints found"); + } + + if (rc == orc) + return; + DEBUG(dbgs() << "Inflating " << orc->getName() << ":%reg" << reg << " to " + << rc->getName() <<".\n"); + mri.setRegClass(reg, rc); +} diff --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp index b7af73f627a..ddd95e6adc1 100644 --- a/llvm/lib/CodeGen/SplitKit.cpp +++ b/llvm/lib/CodeGen/SplitKit.cpp @@ -571,6 +571,7 @@ void SplitEditor::rewrite() { VirtRegAuxInfo vrai(vrm_.getMachineFunction(), lis_, sa_.loops_); for (unsigned i = firstInterval, e = intervals_.size(); i != e; ++i) { LiveInterval &li = *intervals_[i]; + vrai.CalculateRegClass(li.reg); vrai.CalculateWeightAndHint(li); } } |

