aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2010-07-08 00:38:54 +0000
committerJim Grosbach <grosbach@apple.com>2010-07-08 00:38:54 +0000
commit7a5dff91a3068ae6e2898db5814d6494fd1b13a8 (patch)
tree046f3eaf0f3e02ebbc6ad7d174cce551c72b4817 /lib/CodeGen
parent9471a9d22389eedcd7f52f73c9e6605204fc2517 (diff)
downloadexternal_llvm-7a5dff91a3068ae6e2898db5814d6494fd1b13a8.zip
external_llvm-7a5dff91a3068ae6e2898db5814d6494fd1b13a8.tar.gz
external_llvm-7a5dff91a3068ae6e2898db5814d6494fd1b13a8.tar.bz2
When processing frame index virtual registers, consider all available registers
(if there are any) and use the one which remains available for the longest rather than just using the first one. This should help enable better re-use of the loaded frame index values. rdar://7318760 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107847 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/PrologEpilogInserter.cpp14
-rw-r--r--lib/CodeGen/RegisterScavenging.cpp12
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp
index d6ee034..d1112d3 100644
--- a/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/lib/CodeGen/PrologEpilogInserter.cpp
@@ -885,10 +885,20 @@ void PEI::scavengeFrameVirtualRegs(MachineFunction &Fn) {
// Scavenge a new scratch register
CurrentVirtReg = Reg;
const TargetRegisterClass *RC = Fn.getRegInfo().getRegClass(Reg);
- CurrentScratchReg = RS->FindUnusedReg(RC);
- if (CurrentScratchReg == 0)
+ const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
+ BitVector Candidates(TRI->getNumRegs());
+ RS->getRegsAvailable(RC, Candidates);
+
+ // If there are any registers available, use the one that's
+ // unused for the longest after this instruction. That increases
+ // the ability to reuse the value.
+ if (Candidates.any()) {
+ MachineBasicBlock::iterator UMI;
+ CurrentScratchReg = RS->findSurvivorReg(I, Candidates, 25, UMI);
+ } else {
// No register is "free". Scavenge a register.
CurrentScratchReg = RS->scavengeRegister(RC, I, SPAdj);
+ }
PrevValue = Value;
}
diff --git a/lib/CodeGen/RegisterScavenging.cpp b/lib/CodeGen/RegisterScavenging.cpp
index 3eefeda..8a1ef5a 100644
--- a/lib/CodeGen/RegisterScavenging.cpp
+++ b/lib/CodeGen/RegisterScavenging.cpp
@@ -242,8 +242,18 @@ unsigned RegScavenger::FindUnusedReg(const TargetRegisterClass *RC) const {
return 0;
}
+/// getRegsAvailable - Return all available registers in the register class
+/// in Mask.
+void RegScavenger::getRegsAvailable(const TargetRegisterClass *RC,
+ BitVector &Mask) {
+ for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();
+ I != E; ++I)
+ if (!isAliasUsed(*I))
+ Mask.set(*I);
+}
+
/// findSurvivorReg - Return the candidate register that is unused for the
-/// longest after MBBI. UseMI is set to the instruction where the search
+/// longest after StargMII. UseMI is set to the instruction where the search
/// stopped.
///
/// No more than InstrLimit instructions are inspected.